blob: a4e9c6808899a46ec61fdfa3e570936f6f3f5b09 [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
Jeff Brown37df39a92015-02-25 15:42:31 -08002 * Copyright (C) 2006 The Android Open Source Project
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jorim Jaggib10e33f2015-02-04 21:57:40 +010017package com.android.server.policy;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080018
Dianne Hackborna4972e92012-03-14 10:38:05 -070019import android.app.ActivityManager;
Jeff Brown061ea992015-04-17 19:55:47 -070020import android.app.ActivityManagerInternal;
21import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080022import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080023import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040024import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070025import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070026import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040027import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080028import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070029import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080030import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040031import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080032import android.content.ContentResolver;
33import android.content.Context;
34import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070035import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070036import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080037import android.content.pm.ActivityInfo;
38import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040039import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070040import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.content.res.Configuration;
42import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070043import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080044import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080045import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080046import android.graphics.Rect;
John Spurlock7b414672014-07-18 13:02:39 -040047import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080048import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050049import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080050import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070051import android.media.Ringtone;
52import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070053import android.media.session.MediaSessionLegacyHelper;
Mark Renoufc1256912015-03-11 14:38:23 -040054import android.os.Build;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070055import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080056import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070057import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080058import android.os.Handler;
59import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080060import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070061import android.os.Message;
62import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080063import android.os.PowerManager;
64import android.os.RemoteException;
65import android.os.ServiceManager;
66import android.os.SystemClock;
67import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080068import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070069import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080070import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070071import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080072import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070073import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040074import android.service.dreams.DreamService;
75import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070076import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070077import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070078import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080079import android.util.EventLog;
80import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070081import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080082import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070083import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080084import android.view.Gravity;
85import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080086import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080087import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070088import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070089import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080090import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080091import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080092import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080093import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080094import android.view.KeyEvent;
95import android.view.MotionEvent;
Adam Powell6711f3b2015-05-06 15:57:09 -070096import com.android.internal.policy.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080097import android.view.Surface;
98import android.view.View;
99import android.view.ViewConfiguration;
Mark Renoufc1256912015-03-11 14:38:23 -0400100import android.view.ViewRootImpl;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800101import android.view.Window;
102import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800103import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700104import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800105import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800106import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800107import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800108import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200109import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800110import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800111import com.android.internal.R;
Craig Mautnerae446592012-12-06 19:05:05 -0800112import com.android.internal.statusbar.IStatusBarService;
Craig Mautnerae446592012-12-06 19:05:05 -0800113import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700114import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100115import com.android.server.policy.keyguard.KeyguardServiceDelegate;
116import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800117
118import java.io.File;
119import java.io.FileReader;
120import java.io.IOException;
121import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700122import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800123import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800124
Dianne Hackbornc652de82013-02-15 16:32:56 -0800125import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700126import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
127import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
128import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700129import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
130import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
131import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800132
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800133/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700134 * WindowManagerPolicy implementation for the Android phone UI. This
135 * introduces a new method suffix, Lp, for an internal lock of the
136 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400137 * can be acquired with either the Lw and Li lock held, so has the restrictions
The Android Open Source Project0727d222009-03-11 12:11:58 -0700138 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800139 */
140public class PhoneWindowManager implements WindowManagerPolicy {
141 static final String TAG = "WindowManager";
142 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700143 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700144 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700145 static final boolean DEBUG_KEYGUARD = false;
146 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700147 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700148 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800149 static final boolean SHOW_STARTING_ANIMATIONS = true;
150 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400151
Daniel Sandler6396c722013-04-16 20:19:09 -0400152 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
153 // No longer recommended for desk docks; still useful in car docks.
154 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
155 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
156
Jeff Brown6d8fd272014-05-20 21:24:38 -0700157 static final int SHORT_PRESS_POWER_NOTHING = 0;
158 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
159 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
160 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800161 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700162
Joe Onoratod208e702010-10-08 16:22:43 -0400163 static final int LONG_PRESS_POWER_NOTHING = 0;
164 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
165 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700166 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700167
Jeff Brown13f00f02014-10-31 14:45:50 -0700168 static final int MULTI_PRESS_POWER_NOTHING = 0;
169 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
170 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
171
Michael Jurka3b1fc472011-06-13 10:54:40 -0700172 // These need to match the documentation/constant in
173 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800174 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800175 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700176 static final int LONG_PRESS_HOME_ASSIST = 2;
177
178 static final int DOUBLE_TAP_HOME_NOTHING = 0;
179 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800180
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000181 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
182 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
183
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700184 static final int APPLICATION_MEDIA_SUBLAYER = -2;
185 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800186 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800187 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700188 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700189
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800190 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
191 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
192 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500193 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700194 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800195
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700196 /**
197 * These are the system UI flags that, when changing, can cause the layout
198 * of the screen to change.
199 */
200 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400201 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400202 | View.SYSTEM_UI_FLAG_FULLSCREEN
203 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200204 | View.NAVIGATION_BAR_TRANSLUCENT
205 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700206
John Spurlock7b414672014-07-18 13:02:39 -0400207 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
208 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
209 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
210 .build();
211
Jim Miller5ecd8112013-01-09 18:50:26 -0800212 /**
213 * Keyguard stuff
214 */
215 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100216 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700217 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800218
Jeff Brown6651a632011-11-28 12:59:11 -0800219 /* Table of Application Launch keys. Maps from key codes to intent categories.
220 *
221 * These are special keys that are used to launch particular kinds of applications,
222 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
223 * usage page. We don't support quite that many yet...
224 */
225 static SparseArray<String> sApplicationLaunchKeyCategories;
226 static {
227 sApplicationLaunchKeyCategories = new SparseArray<String>();
228 sApplicationLaunchKeyCategories.append(
229 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
230 sApplicationLaunchKeyCategories.append(
231 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
232 sApplicationLaunchKeyCategories.append(
233 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
234 sApplicationLaunchKeyCategories.append(
235 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
236 sApplicationLaunchKeyCategories.append(
237 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
238 sApplicationLaunchKeyCategories.append(
239 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
240 }
241
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700242 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
243 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
244
Dianne Hackborndf89e652011-10-06 22:35:11 -0700245 /**
246 * Lock protecting internal state. Must not call out into window
247 * manager with lock held. (This lock will be acquired in places
248 * where the window manager is calling in with its own lock held.)
249 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800250 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700251
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800252 Context mContext;
253 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700254 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700255 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700256 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700257 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700258 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400259 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700260 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700261 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800262 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700263 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800264 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000265 BurnInProtectionHelper mBurnInProtectionHelper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800266
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700267 // Vibrator pattern for haptic feedback of a long press.
268 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700269
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700270 // Vibrator pattern for haptic feedback of virtual key press.
271 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700272
Amith Yamasanic33cb712010-02-10 15:21:49 -0800273 // Vibrator pattern for a short vibration.
274 long[] mKeyboardTapVibePattern;
275
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700276 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
277 long[] mClockTickVibePattern;
278
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700279 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
280 long[] mCalendarDateVibePattern;
281
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700282 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
283 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700284
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700285 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
286 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700287
Mady Mellore82067b2015-04-30 09:58:35 -0700288 // Vibrator pattern for haptic feedback of a stylus button press.
289 long[] mStylusButtonPressVibePattern;
290
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800291 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
292 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400293
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800294 boolean mSafeMode;
295 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700296 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400297 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400298 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700299 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400300 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
301 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
302 int[] mNavigationBarHeightForRotation = new int[4];
303 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400304
Craig Mautnera631d492014-08-05 15:16:01 -0700305 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800306 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700307 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700308 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700309 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700310 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
311 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
312 }
313 };
314 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
315 @Override
316 public void onShown(IBinder windowToken) {
317 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
318 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
319 }
320 };
321
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800322 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800323 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900324 WindowState mLastInputMethodWindow = null;
325 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800326
Jeff Brown13f00f02014-10-31 14:45:50 -0700327 // FIXME This state is shared between the input reader and handler thread.
328 // Technically it's broken and buggy but it has been like this for many years
329 // and we have not yet seen any problems. Someday we'll rewrite this logic
330 // so that only one thread is involved in handling input policy. Unfortunately
331 // it's on a critical path for power management so we can't just post the work to the
332 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
333 // to hold wakelocks during dispatch and eliminating the critical path.
334 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800335 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700336 volatile int mPowerKeyPressCounter;
337 volatile boolean mEndCallKeyHandled;
338
Winson Chungd42a6cf2014-06-03 16:24:04 -0700339 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700340 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700341 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800342
Jeff Brown2e7760e2012-04-11 15:14:55 -0700343 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700344 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700345 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800346
Dianne Hackbornc777e072010-02-12 13:07:59 -0800347 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700348 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800349 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700350 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400351 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700352 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700353 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400354 int mCarDockRotation;
355 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700356 int mUndockedHdmiRotation;
357 int mDemoHdmiRotation;
358 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800359 int mDemoRotation;
360 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400361
Jeff Browna20dda42014-05-27 20:57:24 -0700362 boolean mWakeGestureEnabledSetting;
363 MyWakeGestureListener mWakeGestureListener;
364
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700365 // Default display does not rotate, apps that require non-default orientation will have to
366 // have the orientation emulated.
367 private boolean mForceDefaultOrientation = false;
368
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400369 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
370 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700371 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400372
Jeff Brownbcdfc622014-03-06 19:13:04 -0800373 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700374 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400375 boolean mCarDockEnablesAccelerometer;
376 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700377 int mLidKeyboardAccessibility;
378 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700379 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700380 int mShortPressOnPowerBehavior;
381 int mLongPressOnPowerBehavior;
382 int mDoublePressOnPowerBehavior;
383 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000384 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700385 boolean mAwake;
386 boolean mScreenOnEarly;
387 boolean mScreenOnFully;
388 ScreenOnListener mScreenOnListener;
389 boolean mKeyguardDrawComplete;
390 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800391 boolean mOrientationSensorEnabled = false;
392 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800393 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400394 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800395 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700396
Jeff Brown70825162012-03-28 17:27:48 -0700397 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800398
399 // The last window we were told about in focusChanged.
400 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800401 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800402
Jeff Brown70825162012-03-28 17:27:48 -0700403 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800404
Dianne Hackbornc652de82013-02-15 16:32:56 -0800405 // The current size of the screen; really; extends into the overscan area of
406 // the screen and doesn't account for any system elements like the status bar.
407 int mOverscanScreenLeft, mOverscanScreenTop;
408 int mOverscanScreenWidth, mOverscanScreenHeight;
409 // The current visible size of the screen; really; (ir)regardless of whether the status
410 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800411 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
412 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800413 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
414 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
415 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700416 // The current size of the screen; these may be different than (0,0)-(dw,dh)
417 // if the status bar can't be hidden; in that case it effectively carves out
418 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800419 int mRestrictedScreenLeft, mRestrictedScreenTop;
420 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700421 // During layout, the current screen borders accounting for any currently
422 // visible system UI elements.
423 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700424 // For applications requesting stable content insets, these are them.
425 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700426 // For applications requesting stable content insets but have also set the
427 // fullscreen window flag, these are the stable dimensions without the status bar.
428 int mStableFullscreenLeft, mStableFullscreenTop;
429 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800430 // During layout, the current screen borders with all outer decoration
431 // (status bar, input method dock) accounted for.
432 int mCurLeft, mCurTop, mCurRight, mCurBottom;
433 // During layout, the frame in which content should be displayed
434 // to the user, accounting for all screen decoration except for any
435 // space they deem as available for other content. This is usually
436 // the same as mCur*, but may be larger if the screen decor has supplied
437 // content insets.
438 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700439 // During layout, the frame in which voice content should be displayed
440 // to the user, accounting for all screen decoration except for any
441 // space they deem as available for other content.
442 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800443 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800444 // windows are placed.
445 int mDockLeft, mDockTop, mDockRight, mDockBottom;
446 // During layout, the layer at which the doc window is placed.
447 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700448 // During layout, this is the layer of the status bar.
449 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700450 int mLastSystemUiFlags;
451 // Bits that we are in the process of clearing, so we want to prevent
452 // them from being set by applications until everything has been updated
453 // to have them clear.
454 int mResettingSystemUiFlags = 0;
455 // Bits that we are currently always keeping cleared.
456 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800457 // What we last reported to system UI about whether the compatibility
458 // menu needs to be displayed.
459 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700460
461 FakeWindow mHideNavFakeWindow = null;
462
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800463 static final Rect mTmpParentFrame = new Rect();
464 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800465 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800466 static final Rect mTmpContentFrame = new Rect();
467 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400468 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700469 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700470 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700471
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800472 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100473 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700474 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200475 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400476 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800477 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700478 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700479 private boolean mForceStatusBarTransparent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700480 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800481 boolean mForcingShowNavBar;
482 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700483
484 // States of keyguard dismiss.
485 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
486 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
487 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
488 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
489
490 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
491 * be done once per window. */
492 private WindowState mWinDismissingKeyguard;
493
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700494 /** The window that is currently showing "over" the keyguard. If there is an app window
495 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
496 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
497 * the wallpaper. */
498 private WindowState mWinShowWhenLocked;
499
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700500 boolean mShowingLockscreen;
501 boolean mShowingDream;
502 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700503 boolean mDreamingSleepTokenNeeded;
504 SleepToken mDreamingSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700505 boolean mKeyguardSecure;
506 boolean mKeyguardSecureIncludingHidden;
507 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800508 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700509 boolean mHomeConsumed;
510 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800511 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700512 Intent mCarDockIntent;
513 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700514 boolean mSearchKeyShortcutPending;
515 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700516 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700517 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800518
Mike Lockwood28569302010-01-28 11:54:40 -0500519 // support for activating the lock screen while the screen is on
520 boolean mAllowLockscreenWhenOn;
521 int mLockScreenTimeout;
522 boolean mLockScreenTimerActive;
523
David Brownbaf8d092010-03-08 21:52:59 -0800524 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800525 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800526
527 // Behavior of POWER button while in-call and screen on.
528 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
529 int mIncallPowerBehavior;
530
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700531 Display mDisplay;
532
Dianne Hackborn9d132642011-04-21 17:26:39 -0700533 int mLandscapeRotation = 0; // default landscape rotation
534 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
535 int mPortraitRotation = 0; // default portrait rotation
536 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700537
Dianne Hackbornc652de82013-02-15 16:32:56 -0800538 int mOverscanLeft = 0;
539 int mOverscanTop = 0;
540 int mOverscanRight = 0;
541 int mOverscanBottom = 0;
542
Joe Onorato46b0d682010-11-22 17:37:27 -0800543 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700544 private int mLongPressOnHomeBehavior;
545
546 // What we do when the user double-taps on home
547 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800548
Bryce Lee584a4452014-10-21 15:55:55 -0700549 // Allowed theater mode wake actions
550 private boolean mAllowTheaterModeWakeFromKey;
551 private boolean mAllowTheaterModeWakeFromPowerKey;
552 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800553 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700554 private boolean mAllowTheaterModeWakeFromCameraLens;
555 private boolean mAllowTheaterModeWakeFromLidSwitch;
556 private boolean mAllowTheaterModeWakeFromWakeGesture;
557
Bryce Leed3b28402015-03-09 15:49:13 +0000558 // Whether to support long press from power button in non-interactive mode
559 private boolean mSupportLongPressPowerWhenNonInteractive;
560
Bryce Lee55e846d2014-11-04 12:43:44 -0800561 // Whether to go to sleep entering theater mode from power button
562 private boolean mGoToSleepOnButtonPressTheaterMode;
563
Winson Chung9112ec32011-06-27 13:15:32 -0700564 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700565 // Time to volume and power must be pressed within this interval of each other.
566 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700567 // Increase the chord delay when taking a screenshot from the keyguard
568 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800569 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700570 private boolean mScreenshotChordVolumeDownKeyTriggered;
571 private long mScreenshotChordVolumeDownKeyTime;
572 private boolean mScreenshotChordVolumeDownKeyConsumed;
573 private boolean mScreenshotChordVolumeUpKeyTriggered;
574 private boolean mScreenshotChordPowerKeyTriggered;
575 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700576
Michael Wrightb854e242013-02-05 17:54:02 -0800577 /* The number of steps between min and max brightness */
578 private static final int BRIGHTNESS_STEPS = 10;
579
Christopher Tate5e08af02012-09-21 17:17:22 -0700580 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800581 ShortcutManager mShortcutManager;
582 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700583 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700584 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800585
Craig Mautnerd625ab22013-09-06 13:40:31 -0700586 private int mCurrentUserId;
587
Justin Kohd378ad72013-04-01 12:18:26 -0700588 // Maps global key codes to the components that will handle them.
589 private GlobalKeyManager mGlobalKeyManager;
590
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700591 // Fallback actions by key code.
592 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
593 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800594
Jorim Jaggi76a16232014-08-08 17:00:47 +0200595 private final LogDecelerateInterpolator mLogDecelerateInterpolator
596 = new LogDecelerateInterpolator(100, 0);
597
Jeff Brown70825162012-03-28 17:27:48 -0700598 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
599 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700600 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
601 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700602 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
603 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
604 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700605 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700606 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700607 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700608 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700609 private static final int MSG_POWER_DELAYED_PRESS = 13;
610 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700611 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jeff Brown70825162012-03-28 17:27:48 -0700612
613 private class PolicyHandler extends Handler {
614 @Override
615 public void handleMessage(Message msg) {
616 switch (msg.what) {
617 case MSG_ENABLE_POINTER_LOCATION:
618 enablePointerLocation();
619 break;
620 case MSG_DISABLE_POINTER_LOCATION:
621 disablePointerLocation();
622 break;
Jeff Brown40013652012-05-16 21:22:36 -0700623 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
624 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
625 break;
626 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
627 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
628 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700629 case MSG_DISPATCH_SHOW_RECENTS:
630 showRecentApps(false);
631 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700632 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
633 showGlobalActionsInternal();
634 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700635 case MSG_KEYGUARD_DRAWN_COMPLETE:
636 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700637 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700638 break;
639 case MSG_KEYGUARD_DRAWN_TIMEOUT:
640 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700641 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700642 break;
643 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
644 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700645 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700646 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700647 case MSG_HIDE_BOOT_MESSAGE:
648 handleHideBootMessage();
649 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700650 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
651 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
652 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700653 case MSG_POWER_DELAYED_PRESS:
654 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
655 finishPowerKeyPress();
656 break;
657 case MSG_POWER_LONG_PRESS:
658 powerLongPress();
659 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700660 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
661 updateDreamingSleepToken(msg.arg1 != 0);
662 break;
Jeff Brown70825162012-03-28 17:27:48 -0700663 }
664 }
665 }
666
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800667 private UEventObserver mHDMIObserver = new UEventObserver() {
668 @Override
669 public void onUEvent(UEventObserver.UEvent event) {
670 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
671 }
672 };
673
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800674 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800675 SettingsObserver(Handler handler) {
676 super(handler);
677 }
David Brownbaf8d092010-03-08 21:52:59 -0800678
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800679 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700680 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800681 ContentResolver resolver = mContext.getContentResolver();
682 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700683 Settings.System.END_BUTTON_BEHAVIOR), false, this,
684 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800685 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700686 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
687 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700688 resolver.registerContentObserver(Settings.Secure.getUriFor(
689 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
690 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800691 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700692 Settings.System.ACCELEROMETER_ROTATION), false, this,
693 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500694 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700695 Settings.System.USER_ROTATION), false, this,
696 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400697 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700698 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
699 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800700 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700701 Settings.System.POINTER_LOCATION), false, this,
702 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800703 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700704 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
705 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500706 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400707 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700708 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500709 resolver.registerContentObserver(Settings.Global.getUriFor(
710 Settings.Global.POLICY_CONTROL), false, this,
711 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800712 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800713 }
714
715 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800716 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700717 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800718 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800719 }
Craig Mautner967212c2013-04-13 21:10:58 -0700720
Jeff Browna20dda42014-05-27 20:57:24 -0700721 class MyWakeGestureListener extends WakeGestureListener {
722 MyWakeGestureListener(Context context, Handler handler) {
723 super(context, handler);
724 }
725
726 @Override
727 public void onWakeUp() {
728 synchronized (mLock) {
729 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700730 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700731 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700732 }
733 }
734 }
735 }
736
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800737 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800738 MyOrientationListener(Context context, Handler handler) {
739 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800740 }
Craig Mautner967212c2013-04-13 21:10:58 -0700741
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800742 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700743 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700744 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700745 updateRotation(false);
746 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800747 }
748 MyOrientationListener mOrientationListener;
749
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100750 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400751
John Spurlock27735a42013-08-14 17:57:38 -0400752 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400753 View.NAVIGATION_BAR_TRANSIENT,
754 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400755 View.NAVIGATION_BAR_TRANSLUCENT,
756 StatusBarManager.WINDOW_NAVIGATION_BAR,
757 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400758
John Spurlockf1a36642013-10-12 17:50:42 -0400759 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400760
Craig Mautner037aa8d2013-06-07 10:35:44 -0700761 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400762
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700763 IStatusBarService getStatusBarService() {
764 synchronized (mServiceAquireLock) {
765 if (mStatusBarService == null) {
766 mStatusBarService = IStatusBarService.Stub.asInterface(
767 ServiceManager.getService("statusbar"));
768 }
769 return mStatusBarService;
770 }
771 }
772
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700773 /*
774 * We always let the sensor be switched on by default except when
775 * the user has explicitly disabled sensor based rotation or when the
776 * screen is switched off.
777 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700778 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800779 if (mSupportAutoRotation) {
780 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
781 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
782 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
783 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
784 // If the application has explicitly requested to follow the
785 // orientation, then we need to turn the sensor on.
786 return true;
787 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800788 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700789 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800790 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
791 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
792 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400793 // enable accelerometer if we are docked in a dock that enables accelerometer
794 // orientation management,
795 return true;
796 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700797 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800798 // If the setting for using the sensor by default is enabled, then
799 // we will always leave it on. Note that the user could go to
800 // a window that forces an orientation that does not use the
801 // sensor and in theory we could turn it off... however, when next
802 // turning it on we won't have a good value for the current
803 // orientation for a little bit, which can cause orientation
804 // changes to lag, so we'd like to keep it always on. (It will
805 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700806 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800807 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800808 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800809 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700810
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800811 /*
812 * Various use cases for invoking this function
813 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700814 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800815 * if not already enabled
816 * screen turned on and current app does not have sensor orientation, disable listeners if
817 * already enabled
818 * screen turning on and current app has sensor based orientation, enable listeners if needed
819 * screen turning on and current app has nosensor based orientation, do nothing
820 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700821 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800822 if (!mOrientationListener.canDetectOrientation()) {
823 // If sensor is turned off or nonexistent for some reason
824 return;
825 }
826 //Could have been invoked due to screen turning on or off or
827 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700828 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
829 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
830 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800831 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700832 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700833 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800834 disable = false;
835 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700836 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800837 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700838 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800839 mOrientationSensorEnabled = true;
840 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700841 }
842 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800843 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700844 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800845 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700846 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800847 mOrientationSensorEnabled = false;
848 }
849 }
850
Jeff Brown13f00f02014-10-31 14:45:50 -0700851 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
852 // Hold a wake lock until the power key is released.
853 if (!mPowerKeyWakeLock.isHeld()) {
854 mPowerKeyWakeLock.acquire();
855 }
856
857 // Cancel multi-press detection timeout.
858 if (mPowerKeyPressCounter != 0) {
859 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
860 }
861
862 // Detect user pressing the power button in panic when an application has
863 // taken over the whole screen.
864 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800865 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700866 if (panic) {
867 mHandler.post(mRequestTransientNav);
868 }
869
870 // Latch power key state to detect screenshot chord.
871 if (interactive && !mScreenshotChordPowerKeyTriggered
872 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
873 mScreenshotChordPowerKeyTriggered = true;
874 mScreenshotChordPowerKeyTime = event.getDownTime();
875 interceptScreenshotChord();
876 }
877
878 // Stop ringing or end call if configured to do so when power is pressed.
879 TelecomManager telecomManager = getTelecommService();
880 boolean hungUp = false;
881 if (telecomManager != null) {
882 if (telecomManager.isRinging()) {
883 // Pressing Power while there's a ringing incoming
884 // call should silence the ringer.
885 telecomManager.silenceRinger();
886 } else if ((mIncallPowerBehavior
887 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
888 && telecomManager.isInCall() && interactive) {
889 // Otherwise, if "Power button ends call" is enabled,
890 // the Power button will hang up any current active call.
891 hungUp = telecomManager.endCall();
892 }
893 }
894
895 // If the power key has still not yet been handled, then detect short
896 // press, long press, or multi press and decide what to do.
897 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
898 || mScreenshotChordVolumeUpKeyTriggered;
899 if (!mPowerKeyHandled) {
900 if (interactive) {
901 // When interactive, we're already awake.
902 // Wait for a long press or for the button to be released to decide what to do.
903 if (hasLongPressOnPowerBehavior()) {
904 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
905 msg.setAsynchronous(true);
906 mHandler.sendMessageDelayed(msg,
907 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
908 }
909 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800910 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800911
Bryce Leed3b28402015-03-09 15:49:13 +0000912 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
913 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
914 msg.setAsynchronous(true);
915 mHandler.sendMessageDelayed(msg,
916 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800917 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000918 } else {
919 final int maxCount = getMaxMultiPressPowerCount();
920
921 if (maxCount <= 1) {
922 mPowerKeyHandled = true;
923 } else {
924 mBeganFromNonInteractive = true;
925 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700926 }
927 }
Jeff Brown4d396052010-10-29 21:50:21 -0700928 }
929 }
930
Jeff Brown13f00f02014-10-31 14:45:50 -0700931 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
932 final boolean handled = canceled || mPowerKeyHandled;
933 mScreenshotChordPowerKeyTriggered = false;
934 cancelPendingScreenshotChordAction();
935 cancelPendingPowerKeyAction();
936
937 if (!handled) {
938 // Figure out how to handle the key now that it has been released.
939 mPowerKeyPressCounter += 1;
940
941 final int maxCount = getMaxMultiPressPowerCount();
942 final long eventTime = event.getDownTime();
943 if (mPowerKeyPressCounter < maxCount) {
944 // This could be a multi-press. Wait a little bit longer to confirm.
945 // Continue holding the wake lock.
946 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
947 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
948 msg.setAsynchronous(true);
949 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
950 return;
951 }
952
953 // No other actions. Handle it immediately.
954 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700955 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700956
957 // Done. Reset our state.
958 finishPowerKeyPress();
959 }
960
961 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800962 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700963 mPowerKeyPressCounter = 0;
964 if (mPowerKeyWakeLock.isHeld()) {
965 mPowerKeyWakeLock.release();
966 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700967 }
968
969 private void cancelPendingPowerKeyAction() {
970 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700971 mPowerKeyHandled = true;
972 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700973 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700974 }
975
976 private void powerPress(long eventTime, boolean interactive, int count) {
977 if (mScreenOnEarly && !mScreenOnFully) {
978 Slog.i(TAG, "Suppressed redundant power key press while "
979 + "already in the process of turning the screen on.");
980 return;
Jeff Brownff204712011-10-25 21:27:54 -0700981 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700982
983 if (count == 2) {
984 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
985 } else if (count == 3) {
986 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -0800987 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700988 switch (mShortPressOnPowerBehavior) {
989 case SHORT_PRESS_POWER_NOTHING:
990 break;
991 case SHORT_PRESS_POWER_GO_TO_SLEEP:
992 mPowerManager.goToSleep(eventTime,
993 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
994 break;
995 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
996 mPowerManager.goToSleep(eventTime,
997 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
998 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
999 break;
1000 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1001 mPowerManager.goToSleep(eventTime,
1002 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1003 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1004 launchHomeFromHotKey();
1005 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001006 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001007 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001008 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001009 }
1010 }
1011 }
1012
1013 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1014 switch (behavior) {
1015 case MULTI_PRESS_POWER_NOTHING:
1016 break;
1017 case MULTI_PRESS_POWER_THEATER_MODE:
1018 if (isTheaterModeEnabled()) {
1019 Slog.i(TAG, "Toggling theater mode off.");
1020 Settings.Global.putInt(mContext.getContentResolver(),
1021 Settings.Global.THEATER_MODE_ON, 0);
1022 if (!interactive) {
1023 wakeUpFromPowerKey(eventTime);
1024 }
1025 } else {
1026 Slog.i(TAG, "Toggling theater mode on.");
1027 Settings.Global.putInt(mContext.getContentResolver(),
1028 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001029
1030 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001031 mPowerManager.goToSleep(eventTime,
1032 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1033 }
1034 }
1035 break;
1036 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001037 Slog.i(TAG, "Starting brightness boost.");
1038 if (!interactive) {
1039 wakeUpFromPowerKey(eventTime);
1040 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001041 mPowerManager.boostScreenBrightness(eventTime);
1042 break;
1043 }
1044 }
1045
1046 private int getMaxMultiPressPowerCount() {
1047 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1048 return 3;
1049 }
1050 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1051 return 2;
1052 }
1053 return 1;
1054 }
1055
1056 private void powerLongPress() {
1057 final int behavior = getResolvedLongPressOnPowerBehavior();
1058 switch (behavior) {
1059 case LONG_PRESS_POWER_NOTHING:
1060 break;
1061 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1062 mPowerKeyHandled = true;
1063 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1064 performAuditoryFeedbackForAccessibilityIfNeed();
1065 }
1066 showGlobalActionsInternal();
1067 break;
1068 case LONG_PRESS_POWER_SHUT_OFF:
1069 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1070 mPowerKeyHandled = true;
1071 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1072 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1073 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1074 break;
1075 }
1076 }
1077
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001078 private void sleepPress(KeyEvent event) {
1079 switch (mShortPressOnSleepBehavior) {
1080 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
1081 mPowerManager.goToSleep(event.getEventTime(),
1082 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1083 break;
1084 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001085 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001086 mPowerManager.goToSleep(event.getEventTime(),
1087 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1088 break;
1089 }
1090 }
1091
Jeff Brown13f00f02014-10-31 14:45:50 -07001092 private int getResolvedLongPressOnPowerBehavior() {
1093 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1094 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1095 }
1096 return mLongPressOnPowerBehavior;
1097 }
1098
1099 private boolean hasLongPressOnPowerBehavior() {
1100 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001101 }
1102
1103 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001104 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001105 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1106 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001107 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001108 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1109 && now <= mScreenshotChordPowerKeyTime
1110 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1111 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001112 cancelPendingPowerKeyAction();
1113
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001114 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001115 }
1116 }
1117 }
1118
Winson Chung1cea2f32012-10-08 20:42:01 -07001119 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001120 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001121 // Double the time it takes to take a screenshot from the keyguard
1122 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001123 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001124 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001125 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001126 }
1127
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001128 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001129 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001130 }
1131
Jeff Brown13f00f02014-10-31 14:45:50 -07001132 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001133 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001134 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001135 mEndCallKeyHandled = true;
1136 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1137 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001138 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001139 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001140 }
1141 };
1142
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001143 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001144 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001145 public void run() {
1146 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001147 }
1148 };
1149
Alan Viverettee34560b22014-07-10 14:50:06 -07001150 @Override
1151 public void showGlobalActions() {
1152 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1153 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1154 }
1155
1156 void showGlobalActionsInternal() {
1157 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001158 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001159 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001160 }
Jim Millerab954542014-10-10 18:21:49 -07001161 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001162 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1163 if (keyguardShowing) {
1164 // since it took two seconds of long press to bring this up,
1165 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001166 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001167 }
1168 }
1169
1170 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001171 return Settings.Global.getInt(
1172 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001173 }
1174
Maurice Lam99c6e072014-04-28 18:24:28 -07001175 boolean isUserSetupComplete() {
1176 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1177 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1178 }
1179
Jeff Brown13f00f02014-10-31 14:45:50 -07001180 private void handleShortPressOnHome() {
1181 // If there's a dream running then use home to escape the dream
1182 // but don't actually go home.
1183 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1184 mDreamManagerInternal.stopDream(false /*immediate*/);
1185 return;
1186 }
1187
1188 // Go home!
1189 launchHomeFromHotKey();
1190 }
1191
Patrick Dubroyece94522011-02-23 18:35:01 -08001192 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -08001193 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001194 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001195 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001196
Jeff Browncaca8812013-05-09 13:34:33 -07001197 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1198 toggleRecentApps();
1199 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1200 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -07001201 }
1202 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001203 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001204
Jeff Browncaca8812013-05-09 13:34:33 -07001205 private void handleDoubleTapOnHome() {
1206 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1207 mHomeConsumed = true;
1208 toggleRecentApps();
1209 }
1210 }
1211
1212 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1213 @Override
1214 public void run() {
1215 if (mHomeDoubleTapPending) {
1216 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001217 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001218 }
1219 }
1220 };
1221
Mark Renoufc1256912015-03-11 14:38:23 -04001222 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001223 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001224 }
1225
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001226 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001227 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001228 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001229 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001230 mContext = context;
1231 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001232 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001233 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001234 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001235 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Mark Renoufc1256912015-03-11 14:38:23 -04001236
1237 // Init display burn-in protection
1238 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1239 com.android.internal.R.bool.config_enableBurnInProtection);
1240 // Allow a system property to override this. Used by developer settings.
1241 boolean burnInProtectionDevMode =
1242 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1243 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1244 final int minHorizontal;
1245 final int maxHorizontal;
1246 final int minVertical;
1247 final int maxVertical;
1248 final int maxRadius;
1249 if (burnInProtectionDevMode) {
1250 minHorizontal = -8;
1251 maxHorizontal = 8;
1252 minVertical = -8;
1253 maxVertical = -4;
1254 maxRadius = (isRoundWindow()) ? 6 : -1;
1255 } else {
1256 Resources resources = context.getResources();
1257 minHorizontal = resources.getInteger(
1258 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1259 maxHorizontal = resources.getInteger(
1260 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1261 minVertical = resources.getInteger(
1262 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1263 maxVertical = resources.getInteger(
1264 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1265 maxRadius = resources.getInteger(
1266 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1267 }
1268 mBurnInProtectionHelper = new BurnInProtectionHelper(
1269 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001270 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001271
Jeff Brown70825162012-03-28 17:27:48 -07001272 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001273 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001274 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001275 try {
1276 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1277 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001278 mSettingsObserver = new SettingsObserver(mHandler);
1279 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001280 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001281 mUiMode = context.getResources().getInteger(
1282 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001283 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1284 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1285 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1286 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001287 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1288 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1289 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1290 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1291 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1292 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1293 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1294 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001295
Jeff Brown96307042012-07-27 15:51:34 -07001296 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1297 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001298 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001299 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1300 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001301 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001302 mSupportAutoRotation = mContext.getResources().getBoolean(
1303 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001304 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001305 com.android.internal.R.integer.config_lidOpenRotation);
1306 mCarDockRotation = readRotation(
1307 com.android.internal.R.integer.config_carDockRotation);
1308 mDeskDockRotation = readRotation(
1309 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001310 mUndockedHdmiRotation = readRotation(
1311 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001312 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1313 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1314 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1315 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001316 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1317 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1318 mLidNavigationAccessibility = mContext.getResources().getInteger(
1319 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001320 mLidControlsSleep = mContext.getResources().getBoolean(
1321 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001322 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1323 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001324
1325 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1326 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1327 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1328 || mContext.getResources().getBoolean(
1329 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1330 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1331 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001332 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1333 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001334 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1335 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1336 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1337 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1338 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1339 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1340
Bryce Lee55e846d2014-11-04 12:43:44 -08001341 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1342 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1343
Bryce Leed3b28402015-03-09 15:49:13 +00001344 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1345 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1346
Jeff Brown13f00f02014-10-31 14:45:50 -07001347 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1348 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1349 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1350 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1351 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1352 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1353 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1354 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001355 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1356 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001357
John Spurlock61560172015-02-06 19:46:04 -05001358 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001359
Jeff Brownf71343d2013-05-31 17:59:11 -07001360 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001361
Svetoslav8e3feb12014-02-24 13:46:47 -08001362 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1363 Context.ACCESSIBILITY_SERVICE);
1364
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001365 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001366 IntentFilter filter = new IntentFilter();
1367 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1368 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1369 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1370 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001371 filter.addAction(Intent.ACTION_DOCK_EVENT);
1372 Intent intent = context.registerReceiver(mDockReceiver, filter);
1373 if (intent != null) {
1374 // Retrieve current sticky dock event broadcast.
1375 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1376 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1377 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001378
Jeff Brown6aaf2952012-10-05 16:01:08 -07001379 // register for dream-related broadcasts
1380 filter = new IntentFilter();
1381 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1382 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1383 context.registerReceiver(mDreamReceiver, filter);
1384
Christopher Tate5e08af02012-09-21 17:17:22 -07001385 // register for multiuser-relevant broadcasts
1386 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1387 context.registerReceiver(mMultiuserReceiver, filter);
1388
John Spurlock57306e62013-04-22 09:48:49 -04001389 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001390 mSystemGestures = new SystemGesturesPointerEventListener(context,
1391 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001392 @Override
1393 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001394 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001395 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001396 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001397 }
1398 @Override
1399 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001400 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001401 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001402 }
1403 }
1404 @Override
1405 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001406 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001407 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001408 }
1409 }
1410 @Override
1411 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001412 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001413 }
Adrian Roos3595be42015-03-05 16:31:15 +01001414 @Override
1415 public void onDown() {
1416 mOrientationListener.onTouchStart();
1417 }
1418 @Override
1419 public void onUpOrCancel() {
1420 mOrientationListener.onTouchEnd();
1421 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001422 });
John Spurlockf1a36642013-10-12 17:50:42 -04001423 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001424 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001425
Jeff Brownc2346132012-04-13 01:55:38 -07001426 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001427 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1428 com.android.internal.R.array.config_longPressVibePattern);
1429 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1430 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001431 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1432 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001433 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1434 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001435 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1436 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001437 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1438 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1439 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1440 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore82067b2015-04-30 09:58:35 -07001441 mStylusButtonPressVibePattern = getLongIntArray(mContext.getResources(),
1442 com.android.internal.R.array.config_stylusButtonPressVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001443
Christopher Tatee90585f2012-03-05 18:56:25 -08001444 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1445 com.android.internal.R.bool.config_enableScreenshotChord);
1446
Justin Kohd378ad72013-04-01 12:18:26 -07001447 mGlobalKeyManager = new GlobalKeyManager(mContext);
1448
Joe Onoratoea495d42011-04-06 11:41:11 -07001449 // Controls rotation and the like.
1450 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001451
1452 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001453 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001454 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001455 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001456
1457 mWindowManagerInternal.registerAppTransitionListener(
1458 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001459 }
1460
Jeff Brownf71343d2013-05-31 17:59:11 -07001461 /**
1462 * Read values from config.xml that may be overridden depending on
1463 * the configuration of the device.
1464 * eg. Disable long press on home goes to recents on sw600dp.
1465 */
1466 private void readConfigurationDependentBehaviors() {
1467 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1468 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1469 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1470 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1471 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1472 }
1473
1474 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1475 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1476 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1477 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1478 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1479 }
1480 }
1481
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001482 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001483 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001484 // This method might be called before the policy has been fully initialized
1485 // or for other displays we don't care about.
1486 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1487 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001488 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001489 mDisplay = display;
1490
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001491 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001492 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001493 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001494 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001495 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001496 mLandscapeRotation = Surface.ROTATION_0;
1497 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001498 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001499 mPortraitRotation = Surface.ROTATION_90;
1500 mUpsideDownRotation = Surface.ROTATION_270;
1501 } else {
1502 mPortraitRotation = Surface.ROTATION_270;
1503 mUpsideDownRotation = Surface.ROTATION_90;
1504 }
1505 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001506 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001507 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001508 mPortraitRotation = Surface.ROTATION_0;
1509 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001510 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001511 mLandscapeRotation = Surface.ROTATION_270;
1512 mSeascapeRotation = Surface.ROTATION_90;
1513 } else {
1514 mLandscapeRotation = Surface.ROTATION_90;
1515 mSeascapeRotation = Surface.ROTATION_270;
1516 }
1517 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001518
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001519 mStatusBarHeight =
1520 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001521
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001522 // Height of the navigation bar when presented horizontally at bottom
1523 mNavigationBarHeightForRotation[mPortraitRotation] =
1524 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001525 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001526 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001527 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1528 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001529
1530 // Width of the navigation bar when presented vertically along one side
1531 mNavigationBarWidthForRotation[mPortraitRotation] =
1532 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1533 mNavigationBarWidthForRotation[mLandscapeRotation] =
1534 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001535 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001536
1537 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001538 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001539 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001540
Devin Kimd7b12b42014-05-05 14:34:58 -07001541 // Allow the navigation bar to move on non-square small devices (phones).
1542 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001543
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001544 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001545 // Allow a system property to override this. Used by the emulator.
1546 // See also hasNavigationBar().
1547 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1548 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001549 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001550 } else if ("0".equals(navBarOverride)) {
1551 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001552 }
1553
Jeff Brown27f1d672012-10-17 18:32:34 -07001554 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1555 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001556 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001557 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001558 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001559 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001560 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001561 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001562
Chong Zhangae6119ff2014-11-11 18:54:39 -08001563 // For demo purposes, allow the rotation of the remote display to be controlled.
1564 // By default, remote display locks rotation to landscape.
1565 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1566 mDemoRotation = mPortraitRotation;
1567 } else {
1568 mDemoRotation = mLandscapeRotation;
1569 }
1570 mDemoRotationLock = SystemProperties.getBoolean(
1571 "persist.demo.rotationlock", false);
1572
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001573 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1574 // http://developer.android.com/guide/practices/screens_support.html#range
1575 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1576 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1577 // For debug purposes the next line turns this feature off with:
1578 // $ adb shell setprop config.override_forced_orient true
1579 // $ adb shell wm size reset
1580 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1581 }
1582
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001583 /**
1584 * @return whether the navigation bar can be hidden, e.g. the device has a
1585 * navigation bar and touch exploration is not enabled
1586 */
1587 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001588 return mHasNavigationBar
1589 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001590 }
1591
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001592 @Override
1593 public boolean isDefaultOrientationForced() {
1594 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001595 }
1596
Dianne Hackbornc652de82013-02-15 16:32:56 -08001597 @Override
1598 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1599 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1600 mOverscanLeft = left;
1601 mOverscanTop = top;
1602 mOverscanRight = right;
1603 mOverscanBottom = bottom;
1604 }
1605 }
1606
Dianne Hackbornc777e072010-02-12 13:07:59 -08001607 public void updateSettings() {
1608 ContentResolver resolver = mContext.getContentResolver();
1609 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001610 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001611 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001612 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001613 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1614 UserHandle.USER_CURRENT);
1615 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001616 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001617 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1618 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001619
Jeff Browna20dda42014-05-27 20:57:24 -07001620 // Configure wake gesture.
1621 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1622 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1623 UserHandle.USER_CURRENT) != 0;
1624 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1625 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1626 updateWakeGestureListenerLp();
1627 }
1628
Jeff Brown207673cd2012-06-05 17:47:11 -07001629 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001630 int userRotation = Settings.System.getIntForUser(resolver,
1631 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1632 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001633 if (mUserRotation != userRotation) {
1634 mUserRotation = userRotation;
1635 updateRotation = true;
1636 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001637 int userRotationMode = Settings.System.getIntForUser(resolver,
1638 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001639 WindowManagerPolicy.USER_ROTATION_FREE :
1640 WindowManagerPolicy.USER_ROTATION_LOCKED;
1641 if (mUserRotationMode != userRotationMode) {
1642 mUserRotationMode = userRotationMode;
1643 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001644 updateOrientationListenerLp();
1645 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001646
Dianne Hackbornc777e072010-02-12 13:07:59 -08001647 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001648 int pointerLocation = Settings.System.getIntForUser(resolver,
1649 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001650 if (mPointerLocationMode != pointerLocation) {
1651 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001652 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1653 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001654 }
1655 }
1656 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001657 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1658 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1659 String imId = Settings.Secure.getStringForUser(resolver,
1660 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001661 boolean hasSoftInput = imId != null && imId.length() > 0;
1662 if (mHasSoftInput != hasSoftInput) {
1663 mHasSoftInput = hasSoftInput;
1664 updateRotation = true;
1665 }
John Spurlockf1a36642013-10-12 17:50:42 -04001666 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001667 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001668 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001669 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001670 }
1671 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001672 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001673 }
Jeff Brown70825162012-03-28 17:27:48 -07001674 }
1675
Jeff Browna20dda42014-05-27 20:57:24 -07001676 private void updateWakeGestureListenerLp() {
1677 if (shouldEnableWakeGestureLp()) {
1678 mWakeGestureListener.requestWakeUpTrigger();
1679 } else {
1680 mWakeGestureListener.cancelWakeUpTrigger();
1681 }
1682 }
1683
1684 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001685 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001686 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1687 && mWakeGestureListener.isSupported();
1688 }
1689
Jeff Brown70825162012-03-28 17:27:48 -07001690 private void enablePointerLocation() {
1691 if (mPointerLocationView == null) {
1692 mPointerLocationView = new PointerLocationView(mContext);
1693 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001694 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1695 WindowManager.LayoutParams.MATCH_PARENT,
1696 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001697 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001698 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1699 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1700 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1701 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001702 if (ActivityManager.isHighEndGfx()) {
1703 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1704 lp.privateFlags |=
1705 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1706 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001707 lp.format = PixelFormat.TRANSLUCENT;
1708 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001709 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001710 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001711 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001712 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001713 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001714 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001715 }
Jeff Brown70825162012-03-28 17:27:48 -07001716
1717 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001718 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001719 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1720 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001721 wm.removeView(mPointerLocationView);
1722 mPointerLocationView = null;
1723 }
1724 }
1725
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001726 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001727 try {
1728 int rotation = mContext.getResources().getInteger(resID);
1729 switch (rotation) {
1730 case 0:
1731 return Surface.ROTATION_0;
1732 case 90:
1733 return Surface.ROTATION_90;
1734 case 180:
1735 return Surface.ROTATION_180;
1736 case 270:
1737 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001738 }
1739 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001740 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001741 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001742 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001743 }
1744
1745 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001746 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001747 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001748 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001749
1750 outAppOp[0] = AppOpsManager.OP_NONE;
1751
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001752 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1753 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1754 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1755 return WindowManagerGlobal.ADD_INVALID_TYPE;
1756 }
1757
1758 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1759 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001760 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001761 }
1762 String permission = null;
1763 switch (type) {
1764 case TYPE_TOAST:
1765 // XXX right now the app process has complete control over
1766 // this... should introduce a token to let the system
1767 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001768 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001769 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001770 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001771 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001772 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001773 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001774 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001775 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001776 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001777 break;
1778 case TYPE_PHONE:
1779 case TYPE_PRIORITY_PHONE:
1780 case TYPE_SYSTEM_ALERT:
1781 case TYPE_SYSTEM_ERROR:
1782 case TYPE_SYSTEM_OVERLAY:
1783 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001784 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001785 break;
1786 default:
1787 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1788 }
1789 if (permission != null) {
1790 if (mContext.checkCallingOrSelfPermission(permission)
1791 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001792 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001793 }
1794 }
Jeff Brown98365d72012-08-19 20:30:52 -07001795 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001796 }
Craig Mautner88400d32012-09-30 12:35:45 -07001797
1798 @Override
1799 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1800
1801 // If this switch statement is modified, modify the comment in the declarations of
1802 // the type in {@link WindowManager.LayoutParams} as well.
1803 switch (attrs.type) {
1804 default:
1805 // These are the windows that by default are shown only to the user that created
1806 // them. If this needs to be overridden, set
1807 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1808 // {@link WindowManager.LayoutParams}. Note that permission
1809 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1810 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1811 return true;
1812 }
1813 break;
1814
1815 // These are the windows that by default are shown to all users. However, to
1816 // protect against spoofing, check permissions below.
1817 case TYPE_APPLICATION_STARTING:
1818 case TYPE_BOOT_PROGRESS:
1819 case TYPE_DISPLAY_OVERLAY:
1820 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001821 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001822 case TYPE_KEYGUARD_DIALOG:
1823 case TYPE_MAGNIFICATION_OVERLAY:
1824 case TYPE_NAVIGATION_BAR:
1825 case TYPE_NAVIGATION_BAR_PANEL:
1826 case TYPE_PHONE:
1827 case TYPE_POINTER:
1828 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001829 case TYPE_SEARCH_BAR:
1830 case TYPE_STATUS_BAR:
1831 case TYPE_STATUS_BAR_PANEL:
1832 case TYPE_STATUS_BAR_SUB_PANEL:
1833 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001834 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001835 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001836 break;
1837 }
1838
1839 // Check if third party app has set window to system window type.
1840 return mContext.checkCallingOrSelfPermission(
1841 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1842 != PackageManager.PERMISSION_GRANTED;
1843 }
1844
Craig Mautner967212c2013-04-13 21:10:58 -07001845 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001846 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1847 switch (attrs.type) {
1848 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001849 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001850 // These types of windows can't receive input events.
1851 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1852 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001853 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001854 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001855 case TYPE_STATUS_BAR:
1856
1857 // If the Keyguard is in a hidden state (occluded by another window), we force to
1858 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1859 // the keyguard as occluded wouldn't set these flags again.
1860 // See {@link #processKeyguardSetHiddenResultLw}.
1861 if (mKeyguardHidden) {
1862 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1863 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1864 }
1865 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001866 }
Adrian Roos38502112014-04-09 21:04:11 +02001867
1868 if (attrs.type != TYPE_STATUS_BAR) {
1869 // The status bar is the only window allowed to exhibit keyguard behavior.
1870 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1871 }
Adrian Roosea562512014-05-05 13:33:03 +02001872
1873 if (ActivityManager.isHighEndGfx()
1874 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001875 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001876 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1877 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001878 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001879
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001880 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001881 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001882 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001883
Michael Wright3818c922014-09-02 13:59:07 -07001884 private void readCameraLensCoverState() {
1885 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1886 }
1887
Jeff Browndaa37532012-05-01 15:54:03 -07001888 private boolean isHidden(int accessibilityMode) {
1889 switch (accessibilityMode) {
1890 case 1:
1891 return mLidState == LID_CLOSED;
1892 case 2:
1893 return mLidState == LID_OPEN;
1894 default:
1895 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001896 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001897 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001898
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001899 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001900 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001901 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1902 int navigationPresence) {
1903 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1904
Jeff Brownf71343d2013-05-31 17:59:11 -07001905 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001906 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001907 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001908
Jeff Browndaa37532012-05-01 15:54:03 -07001909 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1910 || (keyboardPresence == PRESENCE_INTERNAL
1911 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001912 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001913 if (!mHasSoftInput) {
1914 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1915 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001916 }
1917
Jeff Browndaa37532012-05-01 15:54:03 -07001918 if (config.navigation == Configuration.NAVIGATION_NONAV
1919 || (navigationPresence == PRESENCE_INTERNAL
1920 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001921 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001922 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001923 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001924
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001925 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001926 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001927 public int windowTypeToLayerLw(int type) {
1928 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001929 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001930 }
1931 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001932 case TYPE_PRIVATE_PRESENTATION:
1933 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001934 case TYPE_WALLPAPER:
1935 // wallpaper is at the bottom, though the window manager may move it.
1936 return 2;
1937 case TYPE_PHONE:
1938 return 3;
1939 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07001940 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001941 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001942 case TYPE_VOICE_INTERACTION:
1943 // voice interaction layer is almost immediately above apps.
1944 return 5;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001945 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001946 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001947 case TYPE_TOAST:
1948 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001949 return 7;
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.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001952 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001953 case TYPE_DREAM:
1954 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001955 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001956 case TYPE_SYSTEM_ALERT:
1957 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001958 return 10;
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.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001961 return 11;
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.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001964 return 12;
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 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001968 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001969 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001970 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001971 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001972 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001973 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001974 case TYPE_KEYGUARD_DIALOG:
1975 return 17;
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
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001979 return 18;
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
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001983 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001984 case TYPE_NAVIGATION_BAR:
1985 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001986 return 20;
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
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001989 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001990 case TYPE_SYSTEM_ERROR:
1991 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001992 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001993 case TYPE_MAGNIFICATION_OVERLAY:
1994 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001995 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001996 case TYPE_DISPLAY_OVERLAY:
1997 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001998 return 24;
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
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002002 return 25;
Svetoslav3a5c7212014-10-14 09:54:26 -07002003 case TYPE_ACCESSIBILITY_OVERLAY:
2004 // overlay put by accessibility services to intercept user interaction
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002005 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002006 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002007 return 27;
Svetoslav3a5c7212014-10-14 09:54:26 -07002008 case TYPE_BOOT_PROGRESS:
2009 return 28;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002010 case TYPE_POINTER:
2011 // the (mouse) pointer layer
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002012 return 29;
Svetoslav3a5c7212014-10-14 09:54:26 -07002013 case TYPE_HIDDEN_NAV_CONSUMER:
2014 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002015 }
2016 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002017 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002018 }
2019
2020 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002021 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002022 public int subWindowTypeToLayerLw(int type) {
2023 switch (type) {
2024 case TYPE_APPLICATION_PANEL:
2025 case TYPE_APPLICATION_ATTACHED_DIALOG:
2026 return APPLICATION_PANEL_SUBLAYER;
2027 case TYPE_APPLICATION_MEDIA:
2028 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002029 case TYPE_APPLICATION_MEDIA_OVERLAY:
2030 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002031 case TYPE_APPLICATION_SUB_PANEL:
2032 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002033 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2034 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002035 }
2036 Log.e(TAG, "Unknown sub-window type: " + type);
2037 return 0;
2038 }
2039
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002040 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002041 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002042 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002043 }
2044
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002045 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002046 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002047 if (mHasNavigationBar) {
2048 // For a basic navigation bar, when we are in landscape mode we place
2049 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002050 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2051 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002052 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002053 }
2054 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002055 }
2056
Jose Lima9546b202014-07-02 17:21:51 -07002057 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002058 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002059 if (mHasNavigationBar) {
2060 // For a basic navigation bar, when we are in portrait mode we place
2061 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002062 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2063 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002064 }
2065 }
2066 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002067 }
2068
Jose Lima9546b202014-07-02 17:21:51 -07002069 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002070 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2071 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002072 }
2073
Jose Lima9546b202014-07-02 17:21:51 -07002074 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002075 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002076 // There is a separate status bar at the top of the display. We don't count that as part
2077 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002078 // we do want to exclude it since applications can't generally use that part
2079 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002080 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002081 }
2082
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002083 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002084 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2085 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002086 (isKeyguardHostWindow(attrs) &&
2087 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002088 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002089 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002090
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002091 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002092 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2093 return attrs.type == TYPE_STATUS_BAR;
2094 }
2095
2096 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002097 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002098 switch (attrs.type) {
2099 case TYPE_STATUS_BAR:
2100 case TYPE_NAVIGATION_BAR:
2101 case TYPE_WALLPAPER:
2102 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002103 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002104 return false;
2105 default:
2106 return true;
2107 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002108 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002109
Craig Mautner7d7808f2014-09-11 18:02:38 -07002110 @Override
2111 public WindowState getWinShowWhenLockedLw() {
2112 return mWinShowWhenLocked;
2113 }
2114
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002115 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002116 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002117 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2118 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002119 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002120 if (!SHOW_STARTING_ANIMATIONS) {
2121 return null;
2122 }
2123 if (packageName == null) {
2124 return null;
2125 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002126
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002127 WindowManager wm = null;
2128 View view = null;
2129
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002130 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002131 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002132 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2133 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2134 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002135 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002136 try {
2137 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002138 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002139 } catch (PackageManager.NameNotFoundException e) {
2140 // Ignore
2141 }
2142 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002143
Jorim Jaggib10e33f2015-02-04 21:57:40 +01002144 Window win = new PhoneWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002145 final TypedArray ta = win.getWindowStyle();
2146 if (ta.getBoolean(
2147 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2148 || ta.getBoolean(
2149 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002150 return null;
2151 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002152
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002153 Resources r = context.getResources();
2154 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002155
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002156 win.setType(
2157 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002158
2159 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2160 // Assumes it's safe to show starting windows of launched apps while
2161 // the keyguard is being hidden. This is okay because starting windows never show
2162 // secret information.
2163 if (mKeyguardHidden) {
2164 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2165 }
2166 }
2167
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002168 // Force the window flags: this is a fake window, so it is not really
2169 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2170 // flag because we do know that the next window will take input
2171 // focus, so we want to get the IME window up on top of us right away.
2172 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002173 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002174 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2175 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2176 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002177 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002178 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2179 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2180 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002181
Adam Powell04fe6eb2013-05-31 14:39:48 -07002182 win.setDefaultIcon(icon);
2183 win.setDefaultLogo(logo);
2184
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002185 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002186 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002187
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002188 final WindowManager.LayoutParams params = win.getAttributes();
2189 params.token = appToken;
2190 params.packageName = packageName;
2191 params.windowAnimations = win.getWindowStyle().getResourceId(
2192 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002193 params.privateFlags |=
2194 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002195 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002196
2197 if (!compatInfo.supportsScreen()) {
2198 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2199 }
2200
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002201 params.setTitle("Starting " + packageName);
2202
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002203 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2204 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002205
2206 if (win.isFloating()) {
2207 // Whoops, there is no way to display an animation/preview
2208 // of such a thing! After all that work... let's skip it.
2209 // (Note that we must do this here because it is in
2210 // getDecorView() where the theme is evaluated... maybe
2211 // we should peek the floating attribute from the theme
2212 // earlier.)
2213 return null;
2214 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002215
Craig Mautner6fbda632012-07-03 09:26:39 -07002216 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002217 TAG, "Adding starting window for " + packageName
2218 + " / " + appToken + ": "
2219 + (view.getParent() != null ? view : null));
2220
2221 wm.addView(view, params);
2222
2223 // Only return the view if it was successfully added to the
2224 // window manager... which we can tell by it having a parent.
2225 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002226 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002227 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002228 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2229 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002230 } catch (RuntimeException e) {
2231 // don't crash if something else bad happens, for example a
2232 // failure loading resources because we are loading from an app
2233 // on external storage that has been unmounted.
2234 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002235 } finally {
2236 if (view != null && view.getParent() == null) {
2237 Log.w(TAG, "view not successfully added to wm, removing view");
2238 wm.removeViewImmediate(view);
2239 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002240 }
2241
2242 return null;
2243 }
2244
2245 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002246 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002247 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002248 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2249 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002250
2251 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002252 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002253 wm.removeView(window);
2254 }
2255 }
2256
2257 /**
2258 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002259 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002260 * Currently enforces that three window types are singletons:
2261 * <ul>
2262 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002263 * <li>KEYGUARD_TYPE</li>
2264 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002265 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002266 * @param win The window to be added
2267 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002268 *
Jeff Brown98365d72012-08-19 20:30:52 -07002269 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2270 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002271 */
Jose Lima9546b202014-07-02 17:21:51 -07002272 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002273 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2274 switch (attrs.type) {
2275 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002276 mContext.enforceCallingOrSelfPermission(
2277 android.Manifest.permission.STATUS_BAR_SERVICE,
2278 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002279 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002280 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002281 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002282 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002283 }
2284 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002285 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002286 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002287 case TYPE_NAVIGATION_BAR:
2288 mContext.enforceCallingOrSelfPermission(
2289 android.Manifest.permission.STATUS_BAR_SERVICE,
2290 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002291 if (mNavigationBar != null) {
2292 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002293 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002294 }
2295 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002296 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002297 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002298 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002299 break;
Jim Millere898ac52012-04-06 17:10:57 -07002300 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002301 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002302 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002303 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002304 mContext.enforceCallingOrSelfPermission(
2305 android.Manifest.permission.STATUS_BAR_SERVICE,
2306 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002307 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002308 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002309 if (mKeyguardScrim != null) {
2310 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2311 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002312 mKeyguardScrim = win;
2313 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002314 }
Jeff Brown98365d72012-08-19 20:30:52 -07002315 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002316 }
2317
2318 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002319 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002320 public void removeWindowLw(WindowState win) {
2321 if (mStatusBar == win) {
2322 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002323 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002324 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002325 } else if (mKeyguardScrim == win) {
2326 Log.v(TAG, "Removing keyguard scrim");
2327 mKeyguardScrim = null;
2328 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002329 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002330 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002331 }
2332 }
2333
2334 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002335
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002336 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002337 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002338 public int selectAnimationLw(WindowState win, int transit) {
2339 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2340 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002341 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002342 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002343 if (transit == TRANSIT_EXIT
2344 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002345 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002346 } else if (transit == TRANSIT_ENTER
2347 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002348 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002349 }
2350 } else if (win == mNavigationBar) {
2351 // This can be on either the bottom or the right.
2352 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002353 if (transit == TRANSIT_EXIT
2354 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002355 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002356 } else if (transit == TRANSIT_ENTER
2357 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002358 return R.anim.dock_bottom_enter;
2359 }
2360 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002361 if (transit == TRANSIT_EXIT
2362 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002363 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002364 } else if (transit == TRANSIT_ENTER
2365 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002366 return R.anim.dock_right_enter;
2367 }
2368 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002369 }
2370
2371 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002372 if (win.hasAppShownWindows()) {
2373 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2374 return com.android.internal.R.anim.app_starting_exit;
2375 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002376 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002377 && transit == TRANSIT_ENTER) {
2378 // Special case: we are animating in a dream, while the keyguard
2379 // is shown. We don't want an animation on the dream, because
2380 // we need it shown immediately with the keyguard animating away
2381 // to reveal it.
2382 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002383 }
2384
2385 return 0;
2386 }
2387
Craig Mautner3c174372013-02-21 17:54:37 -08002388 @Override
2389 public void selectRotationAnimationLw(int anim[]) {
2390 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2391 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2392 + (mTopFullscreenOpaqueWindowState == null ?
2393 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2394 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2395 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2396 case ROTATION_ANIMATION_CROSSFADE:
2397 anim[0] = R.anim.rotation_animation_xfade_exit;
2398 anim[1] = R.anim.rotation_animation_enter;
2399 break;
2400 case ROTATION_ANIMATION_JUMPCUT:
2401 anim[0] = R.anim.rotation_animation_jump_exit;
2402 anim[1] = R.anim.rotation_animation_enter;
2403 break;
2404 case ROTATION_ANIMATION_ROTATE:
2405 default:
2406 anim[0] = anim[1] = 0;
2407 break;
2408 }
2409 } else {
2410 anim[0] = anim[1] = 0;
2411 }
2412 }
2413
2414 @Override
2415 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2416 boolean forceDefault) {
2417 switch (exitAnimId) {
2418 case R.anim.rotation_animation_xfade_exit:
2419 case R.anim.rotation_animation_jump_exit:
2420 // These are the only cases that matter.
2421 if (forceDefault) {
2422 return false;
2423 }
2424 int anim[] = new int[2];
2425 selectRotationAnimationLw(anim);
2426 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2427 default:
2428 return true;
2429 }
2430 }
2431
2432 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002433 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2434 boolean goingToNotificationShade) {
2435 if (goingToNotificationShade) {
2436 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002437 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002438
2439 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2440 R.anim.lock_screen_behind_enter_wallpaper :
2441 R.anim.lock_screen_behind_enter);
2442
2443 // TODO: Use XML interpolators when we have log interpolators available in XML.
2444 final List<Animation> animations = set.getAnimations();
2445 for (int i = animations.size() - 1; i >= 0; --i) {
2446 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2447 }
2448
2449 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002450 }
2451
2452
2453 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002454 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2455 if (goingToNotificationShade) {
2456 return null;
2457 } else {
2458 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2459 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002460 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002461
2462 private static void awakenDreams() {
2463 IDreamManager dreamManager = getDreamManager();
2464 if (dreamManager != null) {
2465 try {
2466 dreamManager.awaken();
2467 } catch (RemoteException e) {
2468 // fine, stay asleep then
2469 }
2470 }
2471 }
2472
2473 static IDreamManager getDreamManager() {
2474 return IDreamManager.Stub.asInterface(
2475 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2476 }
2477
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002478 TelecomManager getTelecommService() {
2479 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002480 }
2481
Jeff Brown4d396052010-10-29 21:50:21 -07002482 static IAudioService getAudioService() {
2483 IAudioService audioService = IAudioService.Stub.asInterface(
2484 ServiceManager.checkService(Context.AUDIO_SERVICE));
2485 if (audioService == null) {
2486 Log.w(TAG, "Unable to find IAudioService interface.");
2487 }
2488 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002489 }
2490
2491 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002492 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002493 }
2494
2495 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2496 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2497 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2498 };
2499
2500 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002501 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002502 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002503 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002504 final int keyCode = event.getKeyCode();
2505 final int repeatCount = event.getRepeatCount();
2506 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002507 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002508 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2509 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002510
Jeff Brown40013652012-05-16 21:22:36 -07002511 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002512 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002513 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2514 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002515 }
2516
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002517 // If we think we might have a volume down & power key chord on the way
2518 // but we're not sure, then tell the dispatcher to wait a little while and
2519 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002520 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002521 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002522 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002523 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2524 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002525 if (now < timeoutTime) {
2526 return timeoutTime - now;
2527 }
2528 }
2529 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002530 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002531 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002532 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002533 }
2534 return -1;
2535 }
2536 }
2537
Michael Wright6a62e552014-06-03 19:19:48 -07002538 // Cancel any pending meta actions if we see any other keys being pressed between the down
2539 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002540 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002541 mPendingMetaAction = false;
2542 }
2543
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002544 // First we always handle the home key here, so applications
2545 // can never break it, although if keyguard is on, we do let
2546 // it handle it, because that gives us the correct 5 second
2547 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002548 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002549
Jeff Brown49ed71d2010-12-06 17:13:33 -08002550 // If we have released the home key, and didn't do anything else
2551 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002552 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002553 cancelPreloadRecentApps();
2554
Jeff Brown49ed71d2010-12-06 17:13:33 -08002555 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002556 if (mHomeConsumed) {
2557 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002558 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002559 }
Jeff Browncaca8812013-05-09 13:34:33 -07002560
2561 if (canceled) {
2562 Log.i(TAG, "Ignoring HOME; event canceled.");
2563 return -1;
2564 }
2565
Yorke Lee4f803242014-12-15 23:22:06 +00002566 // If an incoming call is ringing, HOME is totally disabled.
2567 // (The user is already on the InCallUI at this point,
2568 // and his ONLY options are to answer or reject the call.)
2569 TelecomManager telecomManager = getTelecommService();
2570 if (telecomManager != null && telecomManager.isRinging()) {
2571 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2572 return -1;
2573 }
2574
Jeff Browncaca8812013-05-09 13:34:33 -07002575 // Delay handling home if a double-tap is possible.
2576 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2577 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2578 mHomeDoubleTapPending = true;
2579 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2580 ViewConfiguration.getDoubleTapTimeout());
2581 return -1;
2582 }
2583
Jeff Brown13f00f02014-10-31 14:45:50 -07002584 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002585 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002586 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002587
2588 // If a system window has focus, then it doesn't make sense
2589 // right now to interact with applications.
2590 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2591 if (attrs != null) {
2592 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002593 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2594 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2595 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002596 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002597 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002598 }
2599 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2600 for (int i=0; i<typeCount; i++) {
2601 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2602 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002603 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002604 }
2605 }
2606 }
Jeff Browncaca8812013-05-09 13:34:33 -07002607
2608 // Remember that home is pressed and handle special actions.
2609 if (repeatCount == 0) {
2610 mHomePressed = true;
2611 if (mHomeDoubleTapPending) {
2612 mHomeDoubleTapPending = false;
2613 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2614 handleDoubleTapOnHome();
2615 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2616 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2617 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002618 }
Jeff Browncaca8812013-05-09 13:34:33 -07002619 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2620 if (!keyguardOn) {
2621 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002622 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002623 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002624 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002625 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002626 // Hijack modified menu keys for debugging features
2627 final int chordBug = KeyEvent.META_SHIFT_ON;
2628
2629 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002630 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002631 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002632 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2633 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002634 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002635 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002636 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002637 Intent service = new Intent();
2638 service.setClassName(mContext, "com.android.server.LoadAverageService");
2639 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002640 boolean shown = Settings.Global.getInt(
2641 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002642 if (!shown) {
2643 mContext.startService(service);
2644 } else {
2645 mContext.stopService(service);
2646 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002647 Settings.Global.putInt(
2648 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002649 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002650 }
2651 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002652 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002653 if (down) {
2654 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002655 mSearchKeyShortcutPending = true;
2656 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002657 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002658 } else {
2659 mSearchKeyShortcutPending = false;
2660 if (mConsumeSearchKeyUp) {
2661 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002662 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002663 }
2664 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002665 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002666 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002667 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002668 if (down && repeatCount == 0) {
2669 preloadRecentApps();
2670 } else if (!down) {
2671 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002672 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002673 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002674 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002675 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2676 if (down) {
2677 IStatusBarService service = getStatusBarService();
2678 if (service != null) {
2679 try {
2680 service.expandNotificationsPanel();
2681 } catch (RemoteException e) {
2682 // do nothing.
2683 }
2684 }
2685 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002686 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2687 if (down) {
2688 if (repeatCount == 0) {
2689 mAssistKeyLongPressed = false;
2690 } else if (repeatCount == 1) {
2691 mAssistKeyLongPressed = true;
2692 if (!keyguardOn) {
2693 launchAssistLongPressAction();
2694 }
2695 }
2696 } else {
2697 if (mAssistKeyLongPressed) {
2698 mAssistKeyLongPressed = false;
2699 } else {
2700 if (!keyguardOn) {
2701 launchAssistAction();
2702 }
2703 }
2704 }
2705 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002706 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2707 if (!down) {
2708 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002709 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002710 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2711 } else {
2712 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002713 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002714 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002715 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002716 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002717 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2718 if (down && repeatCount == 0) {
2719 mHandler.post(mScreenshotRunnable);
2720 }
2721 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002722 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2723 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2724 if (down) {
2725 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2726
2727 // Disable autobrightness if it's on
2728 int auto = Settings.System.getIntForUser(
2729 mContext.getContentResolver(),
2730 Settings.System.SCREEN_BRIGHTNESS_MODE,
2731 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2732 UserHandle.USER_CURRENT_OR_SELF);
2733 if (auto != 0) {
2734 Settings.System.putIntForUser(mContext.getContentResolver(),
2735 Settings.System.SCREEN_BRIGHTNESS_MODE,
2736 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2737 UserHandle.USER_CURRENT_OR_SELF);
2738 }
2739
2740 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2741 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2742 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2743 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2744 Settings.System.SCREEN_BRIGHTNESS,
2745 mPowerManager.getDefaultScreenBrightnessSetting(),
2746 UserHandle.USER_CURRENT_OR_SELF);
2747 brightness += step;
2748 // Make sure we don't go beyond the limits.
2749 brightness = Math.min(max, brightness);
2750 brightness = Math.max(min, brightness);
2751
2752 Settings.System.putIntForUser(mContext.getContentResolver(),
2753 Settings.System.SCREEN_BRIGHTNESS, brightness,
2754 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002755 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002756 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002757 }
2758 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002759 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002760 if (down) {
2761 mPendingMetaAction = true;
2762 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002763 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002764 }
2765 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002766 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002767
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002768 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002769 // Any printing key that is chorded with Search should be consumed
2770 // even if no shortcut was invoked. This prevents text from being
2771 // inadvertently inserted when using a keyboard that has built-in macro
2772 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002773 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002774 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2775 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002776 mConsumeSearchKeyUp = true;
2777 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002778 if (down && repeatCount == 0 && !keyguardOn) {
2779 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2780 if (shortcutIntent != null) {
2781 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002782 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002783 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002784 } catch (ActivityNotFoundException ex) {
2785 Slog.w(TAG, "Dropping shortcut key combination because "
2786 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002787 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002788 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002789 } else {
2790 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002791 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002792 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002793 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002794 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002795 }
2796 }
2797
Jeff Brown68b909d2011-12-07 16:36:01 -08002798 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002799 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002800 && (metaState & KeyEvent.META_META_ON) != 0) {
2801 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002802 if (kcm.isPrintingKey(keyCode)) {
2803 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2804 metaState & ~(KeyEvent.META_META_ON
2805 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2806 if (shortcutIntent != null) {
2807 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2808 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002809 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002810 } catch (ActivityNotFoundException ex) {
2811 Slog.w(TAG, "Dropping shortcut key combination because "
2812 + "the activity to which it is registered was not found: "
2813 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2814 }
2815 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002816 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002817 }
2818 }
2819
Jeff Brown6651a632011-11-28 12:59:11 -08002820 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002821 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002822 String category = sApplicationLaunchKeyCategories.get(keyCode);
2823 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002824 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002825 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2826 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002827 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002828 } catch (ActivityNotFoundException ex) {
2829 Slog.w(TAG, "Dropping application launch key because "
2830 + "the activity to which it is registered was not found: "
2831 + "keyCode=" + keyCode + ", category=" + category, ex);
2832 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002833 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002834 }
2835 }
2836
Michael Wright61c46752014-08-21 16:57:33 -07002837 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002838 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002839 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002840 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002841 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002842 mRecentAppsHeldModifiers = shiftlessModifiers;
2843 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002844 return -1;
2845 }
2846 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002847 } else if (!down && mRecentAppsHeldModifiers != 0
2848 && (metaState & mRecentAppsHeldModifiers) == 0) {
2849 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002850 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002851 }
2852
Jeff Browncf39bdf2012-05-18 14:41:19 -07002853 // Handle keyboard language switching.
2854 if (down && repeatCount == 0
2855 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2856 || (keyCode == KeyEvent.KEYCODE_SPACE
2857 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2858 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2859 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2860 return -1;
2861 }
2862 if (mLanguageSwitchKeyPressed && !down
2863 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2864 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2865 mLanguageSwitchKeyPressed = false;
2866 return -1;
2867 }
2868
Jeff Brown13f00f02014-10-31 14:45:50 -07002869 if (isValidGlobalKey(keyCode)
2870 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002871 return -1;
2872 }
2873
Michael Wright6a62e552014-06-03 19:19:48 -07002874 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002875 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002876 return -1;
2877 }
2878
Jeff Brown68b909d2011-12-07 16:36:01 -08002879 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002880 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002881 }
2882
Jeff Brown3915bb82010-11-05 15:02:16 -07002883 /** {@inheritDoc} */
2884 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002885 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002886 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002887 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002888 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2889 + ", flags=" + event.getFlags()
2890 + ", keyCode=" + event.getKeyCode()
2891 + ", scanCode=" + event.getScanCode()
2892 + ", metaState=" + event.getMetaState()
2893 + ", repeatCount=" + event.getRepeatCount()
2894 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002895 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002896
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002897 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002898 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2899 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002900 final int keyCode = event.getKeyCode();
2901 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002902 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2903 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002904
Jeff Brown54875002011-04-06 15:33:01 -07002905 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002906 final FallbackAction fallbackAction;
2907 if (initialDown) {
2908 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2909 } else {
2910 fallbackAction = mFallbackActions.get(keyCode);
2911 }
2912
2913 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002914 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002915 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2916 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002917 }
2918
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002919 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2920 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002921 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002922 event.getAction(), fallbackAction.keyCode,
2923 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002924 event.getDeviceId(), event.getScanCode(),
2925 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002926
2927 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2928 fallbackEvent.recycle();
2929 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002930 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002931
2932 if (initialDown) {
2933 mFallbackActions.put(keyCode, fallbackAction);
2934 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2935 mFallbackActions.remove(keyCode);
2936 fallbackAction.recycle();
2937 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002938 }
2939 }
2940
Jeff Brown40013652012-05-16 21:22:36 -07002941 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002942 if (fallbackEvent == null) {
2943 Slog.d(TAG, "No fallback.");
2944 } else {
2945 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2946 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002947 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002948 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002949 }
2950
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002951 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002952 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002953 if ((actions & ACTION_PASS_TO_USER) != 0) {
2954 long delayMillis = interceptKeyBeforeDispatching(
2955 win, fallbackEvent, policyFlags);
2956 if (delayMillis == 0) {
2957 return true;
2958 }
2959 }
2960 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002961 }
2962
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002963 private void launchAssistLongPressAction() {
2964 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2965 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2966
2967 // launch the search activity
2968 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2969 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2970 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002971 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002972 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002973 SearchManager searchManager = getSearchManager();
2974 if (searchManager != null) {
2975 searchManager.stopSearch();
2976 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002977 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002978 } catch (ActivityNotFoundException e) {
2979 Slog.w(TAG, "No activity to handle assist long press action.", e);
2980 }
2981 }
2982
2983 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002984 launchAssistAction(null);
2985 }
2986
2987 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002988 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002989 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002990 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002991 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002992 if (hint != null) {
2993 intent.putExtra(hint, true);
2994 }
Jim Miller45308b12012-06-18 19:23:39 -07002995 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2996 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2997 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2998 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002999 startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07003000 } catch (ActivityNotFoundException e) {
3001 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003002 }
3003 }
3004 }
3005
Bart Sears8b1c27c2015-03-18 23:51:02 +00003006 private void startActivityAsUser(Intent intent, UserHandle handle) {
3007 if (isUserSetupComplete()) {
3008 mContext.startActivityAsUser(intent, handle);
3009 } else {
3010 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3011 }
3012 }
3013
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003014 private SearchManager getSearchManager() {
3015 if (mSearchManager == null) {
3016 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3017 }
3018 return mSearchManager;
3019 }
3020
Jeff Browncaca8812013-05-09 13:34:33 -07003021 private void preloadRecentApps() {
3022 mPreloadedRecentApps = true;
3023 try {
3024 IStatusBarService statusbar = getStatusBarService();
3025 if (statusbar != null) {
3026 statusbar.preloadRecentApps();
3027 }
3028 } catch (RemoteException e) {
3029 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3030 // re-acquire status bar service next time it is needed.
3031 mStatusBarService = null;
3032 }
3033 }
3034
3035 private void cancelPreloadRecentApps() {
3036 if (mPreloadedRecentApps) {
3037 mPreloadedRecentApps = false;
3038 try {
3039 IStatusBarService statusbar = getStatusBarService();
3040 if (statusbar != null) {
3041 statusbar.cancelPreloadRecentApps();
3042 }
3043 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003044 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003045 // re-acquire status bar service next time it is needed.
3046 mStatusBarService = null;
3047 }
3048 }
3049 }
3050
3051 private void toggleRecentApps() {
3052 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003053 try {
3054 IStatusBarService statusbar = getStatusBarService();
3055 if (statusbar != null) {
3056 statusbar.toggleRecentApps();
3057 }
3058 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003059 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3060 // re-acquire status bar service next time it is needed.
3061 mStatusBarService = null;
3062 }
3063 }
3064
Craig Mautner84984fa2014-06-19 11:19:20 -07003065 @Override
3066 public void showRecentApps() {
3067 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3068 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3069 }
3070
Winson Chung1e8d71b2014-05-16 17:05:22 -07003071 private void showRecentApps(boolean triggeredFromAltTab) {
3072 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3073 try {
3074 IStatusBarService statusbar = getStatusBarService();
3075 if (statusbar != null) {
3076 statusbar.showRecentApps(triggeredFromAltTab);
3077 }
3078 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003079 Slog.e(TAG, "RemoteException when showing recent apps", e);
3080 // re-acquire status bar service next time it is needed.
3081 mStatusBarService = null;
3082 }
3083 }
3084
Winson Chungcdcd4872014-08-05 18:00:13 -07003085 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003086 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3087 try {
3088 IStatusBarService statusbar = getStatusBarService();
3089 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003090 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003091 }
3092 } catch (RemoteException e) {
3093 Slog.e(TAG, "RemoteException when closing recent apps", e);
3094 // re-acquire status bar service next time it is needed.
3095 mStatusBarService = null;
3096 }
3097 }
3098
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003099 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003100 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003101 }
3102
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003103 /**
3104 * A home key -> launch home action was detected. Take the appropriate action
3105 * given the situation with the keyguard.
3106 */
Bryce Lee662ed802015-04-10 20:11:39 +00003107 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3108 if (respectKeyguard) {
3109 if (isKeyguardShowingAndNotOccluded()) {
3110 // don't launch home if keyguard showing
3111 return;
3112 }
3113
3114 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3115 // when in keyguard restricted mode, must first verify unlock
3116 // before launching home
3117 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3118 @Override
3119 public void onKeyguardExitResult(boolean success) {
3120 if (success) {
3121 try {
3122 ActivityManagerNative.getDefault().stopAppSwitches();
3123 } catch (RemoteException e) {
3124 }
3125 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3126 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003127 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003128 }
Bryce Lee662ed802015-04-10 20:11:39 +00003129 });
3130 return;
3131 }
3132 }
3133
3134 // no keyguard stuff to worry about, just launch home!
3135 try {
3136 ActivityManagerNative.getDefault().stopAppSwitches();
3137 } catch (RemoteException e) {
3138 }
3139 if (mRecentsVisible) {
3140 // Hide Recents and notify it to launch Home
3141 if (awakenFromDreams) {
3142 awakenDreams();
3143 }
3144 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3145 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003146 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003147 // Otherwise, just launch Home
3148 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3149 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003150 }
3151 }
3152
John Spurlock04db1762013-05-13 12:46:41 -04003153 private final Runnable mClearHideNavigationFlag = new Runnable() {
3154 @Override
3155 public void run() {
3156 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3157 // Clear flags.
3158 mForceClearedSystemUiFlags &=
3159 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3160 }
3161 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003162 }
3163 };
3164
3165 /**
3166 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3167 * to determine when the nav bar should be shown and prevent applications from
3168 * receiving those touches.
3169 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003170 final class HideNavInputEventReceiver extends InputEventReceiver {
3171 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3172 super(inputChannel, looper);
3173 }
3174
Dianne Hackborndf89e652011-10-06 22:35:11 -07003175 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003176 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003177 boolean handled = false;
3178 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003179 if (event instanceof MotionEvent
3180 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3181 final MotionEvent motionEvent = (MotionEvent)event;
3182 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003183 // When the user taps down, we re-show the nav bar.
3184 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003185 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003186 // Any user activity always causes us to show the
3187 // navigation controls, if they had been hidden.
3188 // We also clear the low profile and only content
3189 // flags so that tapping on the screen will atomically
3190 // restore all currently hidden screen decorations.
3191 int newVal = mResettingSystemUiFlags |
3192 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3193 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3194 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003195 if (mResettingSystemUiFlags != newVal) {
3196 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003197 changed = true;
3198 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003199 // We don't allow the system's nav bar to be hidden
3200 // again for 1 second, to prevent applications from
3201 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003202 newVal = mForceClearedSystemUiFlags |
3203 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003204 if (mForceClearedSystemUiFlags != newVal) {
3205 mForceClearedSystemUiFlags = newVal;
3206 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003207 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003208 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003209 }
3210 if (changed) {
3211 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3212 }
3213 }
3214 }
3215 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003216 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003217 }
3218 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003219 }
3220 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3221 new InputEventReceiver.Factory() {
3222 @Override
3223 public InputEventReceiver createInputEventReceiver(
3224 InputChannel inputChannel, Looper looper) {
3225 return new HideNavInputEventReceiver(inputChannel, looper);
3226 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003227 };
3228
3229 @Override
3230 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003231 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3232 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003233 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003234
Dianne Hackborndf89e652011-10-06 22:35:11 -07003235 // Reset any bits in mForceClearingStatusBarVisibility that
3236 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003237 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003238 // Clear any bits in the new visibility that are currently being
3239 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003240 return visibility & ~mResettingSystemUiFlags
3241 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003242 }
3243
Craig Mautner69b08182012-09-05 13:07:13 -07003244 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003245 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3246 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003247 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003248 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3249 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003250
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003251 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003252 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003253 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003254 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003255 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003256 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3257 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3258 } else {
3259 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3260 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3261 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003262 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3263 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003264 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003265 availRight - mStableFullscreenRight,
3266 availBottom - mStableFullscreenBottom);
3267 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003268 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003269 availRight - mStableRight, availBottom - mStableBottom);
3270 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003271 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003272 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003273 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003274 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003275 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003276 availRight - mCurRight, availBottom - mCurBottom);
3277 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003278 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003279 availRight - mCurRight, availBottom - mCurBottom);
3280 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003281
3282 outStableInsets.set(mStableLeft, mStableTop,
3283 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003284 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003285 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003286 outContentInsets.setEmpty();
3287 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003288 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003289
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003290 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003291 @Override
3292 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3293 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003294 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3295 if (isDefaultDisplay) {
3296 switch (displayRotation) {
3297 case Surface.ROTATION_90:
3298 overscanLeft = mOverscanTop;
3299 overscanTop = mOverscanRight;
3300 overscanRight = mOverscanBottom;
3301 overscanBottom = mOverscanLeft;
3302 break;
3303 case Surface.ROTATION_180:
3304 overscanLeft = mOverscanRight;
3305 overscanTop = mOverscanBottom;
3306 overscanRight = mOverscanLeft;
3307 overscanBottom = mOverscanTop;
3308 break;
3309 case Surface.ROTATION_270:
3310 overscanLeft = mOverscanBottom;
3311 overscanTop = mOverscanLeft;
3312 overscanRight = mOverscanTop;
3313 overscanBottom = mOverscanRight;
3314 break;
3315 default:
3316 overscanLeft = mOverscanLeft;
3317 overscanTop = mOverscanTop;
3318 overscanRight = mOverscanRight;
3319 overscanBottom = mOverscanBottom;
3320 break;
3321 }
3322 } else {
3323 overscanLeft = 0;
3324 overscanTop = 0;
3325 overscanRight = 0;
3326 overscanBottom = 0;
3327 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003328 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3329 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3330 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3331 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003332 mSystemLeft = 0;
3333 mSystemTop = 0;
3334 mSystemRight = displayWidth;
3335 mSystemBottom = displayHeight;
3336 mUnrestrictedScreenLeft = overscanLeft;
3337 mUnrestrictedScreenTop = overscanTop;
3338 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3339 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3340 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3341 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003342 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3343 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003344 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003345 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003346 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003347 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003348 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003349 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003350 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003351 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003352 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003353 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003354
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003355 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3356 final Rect pf = mTmpParentFrame;
3357 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003358 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003359 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003360 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003361 pf.left = df.left = of.left = vf.left = mDockLeft;
3362 pf.top = df.top = of.top = vf.top = mDockTop;
3363 pf.right = df.right = of.right = vf.right = mDockRight;
3364 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003365 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003366
Craig Mautner69b08182012-09-05 13:07:13 -07003367 if (isDefaultDisplay) {
3368 // For purposes of putting out fake window up to steal focus, we will
3369 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003370 final int sysui = mLastSystemUiFlags;
3371 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003372 boolean navTranslucent = (sysui
3373 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003374 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3375 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3376 boolean navAllowedHidden = immersive || immersiveSticky;
3377 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003378 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3379 if (!isKeyguardShowing) {
3380 navTranslucent &= areTranslucentBarsAllowed();
3381 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003382
Craig Mautner69b08182012-09-05 13:07:13 -07003383 // When the navigation bar isn't visible, we put up a fake
3384 // input window to catch all touch events. This way we can
3385 // detect when the user presses anywhere to bring back the nav
3386 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003387 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07003388 if (mHideNavFakeWindow != null) {
3389 mHideNavFakeWindow.dismiss();
3390 mHideNavFakeWindow = null;
3391 }
3392 } else if (mHideNavFakeWindow == null) {
3393 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
3394 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07003395 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07003396 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003397 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003398
Craig Mautner69b08182012-09-05 13:07:13 -07003399 // For purposes of positioning and showing the nav bar, if we have
3400 // decided that it can't be hidden (because of the screen aspect ratio),
3401 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003402 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003403
John Spurlockad3e6cb2013-04-30 08:47:43 -04003404 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003405 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003406 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003407 // Force the navigation bar to its appropriate place and
3408 // size. We need to do this directly, instead of relying on
3409 // it to bubble up from the nav bar, because this needs to
3410 // change atomically with screen rotations.
3411 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3412 if (mNavigationBarOnBottom) {
3413 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003414 int top = displayHeight - overscanBottom
3415 - mNavigationBarHeightForRotation[displayRotation];
3416 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003417 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003418 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003419 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003420 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003421 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003422 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003423 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3424 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003425 } else {
3426 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003427 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003428 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003429 if (navVisible && !navTranslucent && !navAllowedHidden
3430 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003431 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003432 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003433 // and not in the process of animating on or off, then
3434 // we can tell the app that it is covered by it.
3435 mSystemBottom = mTmpNavigationFrame.top;
3436 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003437 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003438 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003439 int left = displayWidth - overscanRight
3440 - mNavigationBarWidthForRotation[displayRotation];
3441 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003442 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003443 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003444 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003445 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003446 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003447 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003448 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3449 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003450 } else {
3451 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003452 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003453 }
John Spurlockbd957402013-10-03 11:38:39 -04003454 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3455 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003456 // If the nav bar is currently requested to be visible,
3457 // and not in the process of animating on or off, then
3458 // we can tell the app that it is covered by it.
3459 mSystemRight = mTmpNavigationFrame.left;
3460 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003461 }
Craig Mautner69b08182012-09-05 13:07:13 -07003462 // Make sure the content and current rectangles are updated to
3463 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003464 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3465 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3466 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3467 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003468 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3469 // And compute the final frame.
3470 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003471 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3472 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003473 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003474 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003475 updateSysUiVisibility = true;
3476 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003477 }
Craig Mautnereda67292013-04-28 13:50:14 -07003478 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003479 mDockLeft, mDockTop, mDockRight, mDockBottom));
3480
3481 // decide where the status bar goes ahead of time
3482 if (mStatusBar != null) {
3483 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003484 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3485 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3486 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3487 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3488 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003489 vf.left = mStableLeft;
3490 vf.top = mStableTop;
3491 vf.right = mStableRight;
3492 vf.bottom = mStableBottom;
3493
3494 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3495
3496 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003497 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003498
3499 // For layout, the status bar is always at the top with our fixed height.
3500 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3501
John Spurlocke1f366f2013-08-05 12:22:40 -04003502 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003503 boolean statusBarTranslucent = (sysui
3504 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003505 if (!isKeyguardShowing) {
3506 statusBarTranslucent &= areTranslucentBarsAllowed();
3507 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003508
Craig Mautner69b08182012-09-05 13:07:13 -07003509 // If the status bar is hidden, we don't want to cause
3510 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003511 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003512 // Status bar may go away, so the screen area it occupies
3513 // is available to apps but just covering them when the
3514 // status bar is visible.
3515 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3516
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003517 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3518 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3519 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3520 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003521
Craig Mautnereda67292013-04-28 13:50:14 -07003522 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003523 String.format(
3524 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3525 mDockLeft, mDockTop, mDockRight, mDockBottom,
3526 mContentLeft, mContentTop, mContentRight, mContentBottom,
3527 mCurLeft, mCurTop, mCurRight, mCurBottom));
3528 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003529 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003530 && !statusBarTransient && !statusBarTranslucent
3531 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003532 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003533 // and not in the process of animating on or off, then
3534 // we can tell the app that it is covered by it.
3535 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3536 }
John Spurlock27735a42013-08-14 17:57:38 -04003537 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003538 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003539 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003540 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003541 if (updateSysUiVisibility) {
3542 updateSystemUiVisibilityLw();
3543 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003544 }
3545 }
3546
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003547 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003548 @Override
John Spurlock46646232013-09-30 22:32:42 -04003549 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003550 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3551 return mStatusBar.getSurfaceLayer();
3552 }
3553
3554 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3555 return mNavigationBar.getSurfaceLayer();
3556 }
3557
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003558 return 0;
3559 }
3560
Craig Mautner967212c2013-04-13 21:10:58 -07003561 @Override
3562 public void getContentRectLw(Rect r) {
3563 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3564 }
3565
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003566 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3567 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003568 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3569 // Here's a special case: if this attached window is a panel that is
3570 // above the dock window, and the window it is attached to is below
3571 // the dock window, then the frames we computed for the window it is
3572 // attached to can not be used because the dock is effectively part
3573 // of the underlying window and the attached window is floating on top
3574 // of the whole thing. So, we ignore the attached window and explicitly
3575 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003576 df.left = of.left = cf.left = vf.left = mDockLeft;
3577 df.top = of.top = cf.top = vf.top = mDockTop;
3578 df.right = of.right = cf.right = vf.right = mDockRight;
3579 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003580 } else {
3581 // The effective display frame of the attached window depends on
3582 // whether it is taking care of insetting its content. If not,
3583 // we need to use the parent's content frame so that the entire
3584 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003585 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003586 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003587 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003588 // Set the content frame of the attached window to the parent's decor frame
3589 // (same as content frame when IME isn't present) if specifically requested by
3590 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3591 // Otherwise, use the overscan frame.
3592 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3593 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003594 } else {
3595 // If the window is resizing, then we want to base the content
3596 // frame on our attached content frame to resize... however,
3597 // things can be tricky if the attached window is NOT in resize
3598 // mode, in which case its content frame will be larger.
3599 // Ungh. So to deal with that, make sure the content frame
3600 // we end up using is not covering the IM dock.
3601 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003602 if (attached.isVoiceInteraction()) {
3603 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3604 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3605 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3606 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3607 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003608 if (cf.left < mContentLeft) cf.left = mContentLeft;
3609 if (cf.top < mContentTop) cf.top = mContentTop;
3610 if (cf.right > mContentRight) cf.right = mContentRight;
3611 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3612 }
3613 }
3614 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003615 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003616 vf.set(attached.getVisibleFrameLw());
3617 }
3618 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3619 // window should be positioned relative to its parent or the entire
3620 // screen.
3621 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3622 ? attached.getFrameLw() : df);
3623 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003624
3625 private void applyStableConstraints(int sysui, int fl, Rect r) {
3626 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3627 // If app is requesting a stable layout, don't let the
3628 // content insets go below the stable values.
3629 if ((fl & FLAG_FULLSCREEN) != 0) {
3630 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3631 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3632 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3633 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3634 } else {
3635 if (r.left < mStableLeft) r.left = mStableLeft;
3636 if (r.top < mStableTop) r.top = mStableTop;
3637 if (r.right > mStableRight) r.right = mStableRight;
3638 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3639 }
3640 }
3641 }
3642
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003643 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003644 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003645 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003646 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003647 final WindowManager.LayoutParams attrs = win.getAttrs();
3648 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3649 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003650 return;
3651 }
Craig Mautner69b08182012-09-05 13:07:13 -07003652 final boolean isDefaultDisplay = win.isDefaultDisplay();
3653 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003654 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3655 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003656 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003657 offsetInputMethodWindowLw(mLastInputMethodWindow);
3658 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003659
John Spurlockc6d1c602014-01-17 15:22:06 -05003660 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003661 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003662 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003663
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003664 final Rect pf = mTmpParentFrame;
3665 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003666 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003667 final Rect cf = mTmpContentFrame;
3668 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003669 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003670 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003671 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003672
3673 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003674 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003675
Craig Mautnerf683b562012-10-02 11:10:57 -07003676 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3677
Adrian Roosfa104232014-06-20 16:10:14 -07003678 if (isDefaultDisplay) {
3679 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3680 } else {
3681 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3682 }
3683
Craig Mautner69b08182012-09-05 13:07:13 -07003684 if (!isDefaultDisplay) {
3685 if (attached != null) {
3686 // If this window is attached to another, our display
3687 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003688 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003689 } else {
3690 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003691 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3692 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3693 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003694 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003695 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003696 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003697 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003698 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003699 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3700 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3701 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003702 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003703 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003704 // ...with content insets above the nav bar
3705 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003706 // IM dock windows always go to the bottom of the screen.
3707 attrs.gravity = Gravity.BOTTOM;
3708 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003709 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
3710 pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft;
3711 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3712 pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft
3713 + mUnrestrictedScreenWidth;
3714 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3715 + mUnrestrictedScreenHeight;
3716 cf.bottom = vf.bottom = mStableBottom;
3717 cf.top = vf.top = mStableTop;
Jorim Jaggie0700182014-08-21 01:12:37 +02003718 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3719 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3720 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3721 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3722 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3723 cf.left = vf.left = mStableLeft;
3724 cf.top = vf.top = mStableTop;
3725 cf.right = vf.right = mStableRight;
3726 vf.bottom = mStableBottom;
3727 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003728 } else {
John Spurlock46646232013-09-30 22:32:42 -04003729
3730 // Default policy decor for the default display
3731 dcf.left = mSystemLeft;
3732 dcf.top = mSystemTop;
3733 dcf.right = mSystemRight;
3734 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003735 final boolean inheritTranslucentDecor = (attrs.privateFlags
3736 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003737 final boolean isAppWindow =
3738 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3739 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3740 final boolean topAtRest =
3741 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3742 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003743 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3744 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003745 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3746 && (fl & WindowManager.LayoutParams.
3747 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003748 // Ensure policy decor includes status bar
3749 dcf.top = mStableTop;
3750 }
John Spurlockbd957402013-10-03 11:38:39 -04003751 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003752 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3753 && (fl & WindowManager.LayoutParams.
3754 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003755 // Ensure policy decor includes navigation bar
3756 dcf.bottom = mStableBottom;
3757 dcf.right = mStableRight;
3758 }
3759 }
3760
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003761 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3762 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003763 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003764 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003765 // This is the case for a normal activity window: we want it
3766 // to cover all of the screen space, and it can take care of
3767 // moving its contents to account for screen decorations that
3768 // intrude into that space.
3769 if (attached != null) {
3770 // If this window is attached to another, our display
3771 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003772 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003773 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003774 if (attrs.type == TYPE_STATUS_BAR_PANEL
3775 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003776 // Status bar panels are the only windows who can go on top of
3777 // the status bar. They are protected by the STATUS_BAR_SERVICE
3778 // permission, so they have the same privileges as the status
3779 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003780 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003781 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003782
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003783 pf.left = df.left = of.left = hasNavBar
3784 ? mDockLeft : mUnrestrictedScreenLeft;
3785 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3786 pf.right = df.right = of.right = hasNavBar
3787 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3788 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3789 pf.bottom = df.bottom = of.bottom = hasNavBar
3790 ? mRestrictedScreenTop+mRestrictedScreenHeight
3791 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003792
Craig Mautnereda67292013-04-28 13:50:14 -07003793 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003794 "Laying out status bar window: (%d,%d - %d,%d)",
3795 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003796 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003797 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3798 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3799 // Asking to layout into the overscan region, so give it that pure
3800 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003801 pf.left = df.left = of.left = mOverscanScreenLeft;
3802 pf.top = df.top = of.top = mOverscanScreenTop;
3803 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3804 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3805 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003806 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003807 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003808 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3809 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003810 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003811 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003812 // only do this for application windows to ensure no window that
3813 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003814 pf.left = df.left = mOverscanScreenLeft;
3815 pf.top = df.top = mOverscanScreenTop;
3816 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3817 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003818 // We need to tell the app about where the frame inside the overscan
3819 // is, so it can inset its content by that amount -- it didn't ask
3820 // to actually extend itself into the overscan region.
3821 of.left = mUnrestrictedScreenLeft;
3822 of.top = mUnrestrictedScreenTop;
3823 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3824 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003825 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003826 pf.left = df.left = mRestrictedOverscanScreenLeft;
3827 pf.top = df.top = mRestrictedOverscanScreenTop;
3828 pf.right = df.right = mRestrictedOverscanScreenLeft
3829 + mRestrictedOverscanScreenWidth;
3830 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3831 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003832 // We need to tell the app about where the frame inside the overscan
3833 // is, so it can inset its content by that amount -- it didn't ask
3834 // to actually extend itself into the overscan region.
3835 of.left = mUnrestrictedScreenLeft;
3836 of.top = mUnrestrictedScreenTop;
3837 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3838 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003839 }
Craig Mautner69b08182012-09-05 13:07:13 -07003840
John Spurlock46646232013-09-30 22:32:42 -04003841 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003842 if (win.isVoiceInteraction()) {
3843 cf.left = mVoiceContentLeft;
3844 cf.top = mVoiceContentTop;
3845 cf.right = mVoiceContentRight;
3846 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003847 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003848 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3849 cf.left = mDockLeft;
3850 cf.top = mDockTop;
3851 cf.right = mDockRight;
3852 cf.bottom = mDockBottom;
3853 } else {
3854 cf.left = mContentLeft;
3855 cf.top = mContentTop;
3856 cf.right = mContentRight;
3857 cf.bottom = mContentBottom;
3858 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003859 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003860 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003861 // Full screen windows are always given a layout that is as if the
3862 // status bar and other transient decors are gone. This is to avoid
3863 // bad states when moving from a window that is not hding the
3864 // status bar to one that is.
3865 cf.left = mRestrictedScreenLeft;
3866 cf.top = mRestrictedScreenTop;
3867 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3868 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003869 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003870 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003871 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3872 vf.left = mCurLeft;
3873 vf.top = mCurTop;
3874 vf.right = mCurRight;
3875 vf.bottom = mCurBottom;
3876 } else {
3877 vf.set(cf);
3878 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003879 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003880 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3881 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3882 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003883 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3884 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003885 // A window that has requested to fill the entire screen just
3886 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003887 if (attrs.type == TYPE_STATUS_BAR_PANEL
3888 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003889 pf.left = df.left = of.left = cf.left = hasNavBar
3890 ? mDockLeft : mUnrestrictedScreenLeft;
3891 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3892 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003893 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003894 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003895 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003896 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003897 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003898 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003899 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3900 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003901 } else if (attrs.type == TYPE_NAVIGATION_BAR
3902 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003903 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003904 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3905 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3906 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3907 + mUnrestrictedScreenWidth;
3908 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3909 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003910 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003911 "Laying out navigation bar window: (%d,%d - %d,%d)",
3912 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003913 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3914 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003915 && ((fl & FLAG_FULLSCREEN) != 0)) {
3916 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003917 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3918 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3919 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3920 + mOverscanScreenWidth;
3921 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3922 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003923 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003924 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003925 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3926 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3927 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3928 + mOverscanScreenWidth;
3929 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3930 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003931 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003932 // The wallpaper also has Real Ultimate Power, but we want to tell
3933 // it about the overscan area.
3934 pf.left = df.left = mOverscanScreenLeft;
3935 pf.top = df.top = mOverscanScreenTop;
3936 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3937 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3938 of.left = cf.left = mUnrestrictedScreenLeft;
3939 of.top = cf.top = mUnrestrictedScreenTop;
3940 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3941 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003942 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003943 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3944 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3945 // Asking to layout into the overscan region, so give it that pure
3946 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003947 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3948 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3949 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003950 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003951 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003952 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003953 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003954 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003955 && (attrs.type == TYPE_STATUS_BAR
3956 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07003957 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04003958 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3959 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003960 // Asking for layout as if the nav bar is hidden, lets the
3961 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003962 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003963 // can be above the nav bar can do this.
3964 // XXX This assumes that an app asking for this will also
3965 // ask for layout in only content. We can't currently figure out
3966 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003967 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3968 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3969 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3970 + mUnrestrictedScreenWidth;
3971 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3972 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003973 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003974 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3975 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3976 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3977 + mRestrictedScreenWidth;
3978 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3979 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003980 }
Craig Mautner69b08182012-09-05 13:07:13 -07003981
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003982 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003983
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003984 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3985 vf.left = mCurLeft;
3986 vf.top = mCurTop;
3987 vf.right = mCurRight;
3988 vf.bottom = mCurBottom;
3989 } else {
3990 vf.set(cf);
3991 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003992 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003993 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3994 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003995 // A child window should be placed inside of the same visible
3996 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003997 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003998 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003999 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4000 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004001 // Otherwise, a normal window must be placed inside the content
4002 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07004003 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
4004 // Status bar panels are the only windows who can go on top of
4005 // the status bar. They are protected by the STATUS_BAR_SERVICE
4006 // permission, so they have the same privileges as the status
4007 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004008 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4009 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4010 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4011 + mRestrictedScreenWidth;
4012 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4013 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05004014 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
4015 || attrs.type == TYPE_VOLUME_OVERLAY) {
4016 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004017 pf.left = df.left = of.left = cf.left = mStableLeft;
4018 pf.top = df.top = of.top = cf.top = mStableTop;
4019 pf.right = df.right = of.right = cf.right = mStableRight;
4020 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004021 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004022 pf.left = mContentLeft;
4023 pf.top = mContentTop;
4024 pf.right = mContentRight;
4025 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004026 if (win.isVoiceInteraction()) {
4027 df.left = of.left = cf.left = mVoiceContentLeft;
4028 df.top = of.top = cf.top = mVoiceContentTop;
4029 df.right = of.right = cf.right = mVoiceContentRight;
4030 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4031 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004032 df.left = of.left = cf.left = mDockLeft;
4033 df.top = of.top = cf.top = mDockTop;
4034 df.right = of.right = cf.right = mDockRight;
4035 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004036 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004037 df.left = of.left = cf.left = mContentLeft;
4038 df.top = of.top = cf.top = mContentTop;
4039 df.right = of.right = cf.right = mContentRight;
4040 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004041 }
4042 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4043 vf.left = mCurLeft;
4044 vf.top = mCurTop;
4045 vf.right = mCurRight;
4046 vf.bottom = mCurBottom;
4047 } else {
4048 vf.set(cf);
4049 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004050 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004051 }
4052 }
Craig Mautner69b08182012-09-05 13:07:13 -07004053
Craig Mautnerb816bed2013-07-23 10:26:17 -07004054 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4055 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004056 df.left = df.top = -10000;
4057 df.right = df.bottom = 10000;
4058 if (attrs.type != TYPE_WALLPAPER) {
4059 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4060 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4061 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004062 }
4063
Craig Mautnereda67292013-04-28 13:50:14 -07004064 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004065 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004066 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004067 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004068 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004069 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004070 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004071 + " dcf=" + dcf.toShortString()
4072 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07004073
Adrian Roosfa104232014-06-20 16:10:14 -07004074 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07004075
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004076 // Dock windows carve out the bottom of the screen, so normal windows
4077 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004078 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4079 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004080 setLastInputMethodWindowLw(null, null);
4081 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004082 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004083 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4084 && !win.getGivenInsetsPendingLw()) {
4085 offsetVoiceInputWindowLw(win);
4086 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004087 }
4088
satok1bc0a492012-04-25 22:47:12 +09004089 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004090 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004091 top += win.getGivenContentInsetsLw().top;
4092 if (mContentBottom > top) {
4093 mContentBottom = top;
4094 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004095 if (mVoiceContentBottom > top) {
4096 mVoiceContentBottom = top;
4097 }
satok1bc0a492012-04-25 22:47:12 +09004098 top = win.getVisibleFrameLw().top;
4099 top += win.getGivenVisibleInsetsLw().top;
4100 if (mCurBottom > top) {
4101 mCurBottom = top;
4102 }
Craig Mautnereda67292013-04-28 13:50:14 -07004103 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004104 + mDockBottom + " mContentBottom="
4105 + mContentBottom + " mCurBottom=" + mCurBottom);
4106 }
4107
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004108 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004109 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004110 top += win.getGivenContentInsetsLw().top;
4111 if (mVoiceContentBottom > top) {
4112 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004113 }
4114 }
4115
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004116 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004117 @Override
4118 public void finishLayoutLw() {
4119 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004120 }
4121
4122 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004123 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004124 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004125 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004126 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004127 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004128 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004129 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004130 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004131 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004132 mForcingShowNavBar = false;
4133 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004134
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004135 mHideLockScreen = false;
4136 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004137 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004138 mShowingLockscreen = false;
4139 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004140 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004141 mKeyguardSecure = isKeyguardSecure();
4142 mKeyguardSecureIncludingHidden = mKeyguardSecure
4143 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004144 }
4145
4146 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004147 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004148 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004149 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4150 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004151 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004152 if (mTopFullscreenOpaqueWindowState == null
4153 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4154 mForcingShowNavBar = true;
4155 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004156 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004157 if (attrs.type == TYPE_STATUS_BAR) {
4158 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4159 mForceStatusBarFromKeyguard = true;
4160 }
4161 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4162 mForceStatusBarTransparent = true;
4163 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004164 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004165
4166 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4167 && attrs.type < FIRST_SYSTEM_WINDOW;
4168 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4169 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4170
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004171 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004172 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004173 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004174 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004175 mForceStatusBarFromKeyguard = true;
4176 } else {
4177 mForceStatusBar = true;
4178 }
4179 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004180 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004181 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004182 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004183 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004184 // If the lockscreen was showing when the dream started then wait
4185 // for the dream to draw before hiding the lockscreen.
4186 if (!mDreamingLockscreen
4187 || (win.isVisibleLw() && win.hasDrawnLw())) {
4188 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004189 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004190 }
4191 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004192
Craig Mautnerab55e522014-03-03 13:26:03 -08004193 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004194 final IApplicationToken appToken = win.getAppToken();
4195 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004196 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004197 mAppsToBeHidden.remove(appToken);
4198 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004199 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004200 if (dismissKeyguard && !mKeyguardSecure) {
4201 mAppsThatDismissKeyguard.add(appToken);
4202 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004203 mWinShowWhenLocked = win;
4204 mHideLockScreen = true;
4205 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004206 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004207 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004208 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004209 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004210 mAppsToBeHidden.add(appToken);
4211 } else {
4212 mAppsToBeHidden.remove(appToken);
4213 }
4214 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004215 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004216 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004217 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004218 if (attrs.x == 0 && attrs.y == 0
4219 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4220 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4221 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4222 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004223 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4224 mTopFullscreenOpaqueOrDimmingWindowState = win;
4225 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004226 if (!mAppsThatDismissKeyguard.isEmpty() &&
4227 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4228 if (DEBUG_LAYOUT) Slog.v(TAG,
4229 "Setting mDismissKeyguard true by win " + win);
4230 mDismissKeyguard = mWinDismissingKeyguard == win ?
4231 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
4232 mWinDismissingKeyguard = win;
Jim Millerab954542014-10-10 18:21:49 -07004233 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004234 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4235 if (DEBUG_LAYOUT) Slog.v(TAG,
4236 "Setting mHideLockScreen to true by win " + win);
4237 mHideLockScreen = true;
4238 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004239 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004240 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004241 mAllowLockscreenWhenOn = true;
4242 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004243 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004244
4245 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004246 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4247 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004248 win.hideLw(false);
4249 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004250 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004251 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4252 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4253 // that is being hidden in an animation - keep the
4254 // keyguard hidden until the new window shows up and
4255 // we know whether to show the keyguard or not.
4256 if (win.isAnimatingLw() && appWindow && showWhenLocked) {
4257 mHideLockScreen = true;
4258 mWinShowWhenLocked = win;
4259 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004260 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004261 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4262 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4263 && win.isDimming()) {
4264 mTopFullscreenOpaqueOrDimmingWindowState = win;
4265 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004266 }
4267
4268 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004269 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004270 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004271 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4272 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4273 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004274 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4275 // fullscreen window.
4276 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4277 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4278 mTopFullscreenOpaqueWindowState.hideLw(false);
4279 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4280 }
4281
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004282 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004283 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004284
4285 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4286 ? mTopFullscreenOpaqueWindowState.getAttrs()
4287 : null;
4288
Jeff Brownc8018eb2012-10-29 21:33:27 -07004289 // If we are not currently showing a dream then remember the current
4290 // lockscreen state. We will use this to determine whether the dream
4291 // started while the lockscreen was showing and remember this state
4292 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004293 if (!mShowingDream) {
4294 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004295 if (mDreamingSleepTokenNeeded) {
4296 mDreamingSleepTokenNeeded = false;
4297 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4298 }
4299 } else {
4300 if (!mDreamingSleepTokenNeeded) {
4301 mDreamingSleepTokenNeeded = true;
4302 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4303 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004304 }
4305
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004306 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004307 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004308 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004309 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004310 boolean shouldBeTransparent = mForceStatusBarTransparent
4311 && !mForceStatusBar
4312 && !mForceStatusBarFromKeyguard;
4313 if (!shouldBeTransparent) {
4314 mStatusBarController.setShowTransparent(false /* transparent */);
4315 } else if (!mStatusBar.isVisibleLw()) {
4316 mStatusBarController.setShowTransparent(true /* transparent */);
4317 }
4318 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004319 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004320 if (mStatusBarController.setBarShowingLw(true)) {
4321 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4322 }
Craig Mautner81defc72013-10-29 11:10:42 -07004323 // Maintain fullscreen layout until incoming animation is complete.
4324 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004325 // Transient status bar on the lockscreen is not allowed
4326 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4327 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4328 mLastSystemUiFlags, mLastSystemUiFlags);
4329 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004330 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004331 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004332 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004333 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004334 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004335 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004336 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004337 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004338 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004339 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004340 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004341 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004342 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4343 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004344 if (mStatusBarController.isTransientShowing()) {
4345 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004346 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4347 }
4348 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004349 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004350 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004351 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004352 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004353 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004354 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004355 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004356 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004357 if (mStatusBarController.setBarShowingLw(true)) {
4358 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4359 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004360 }
4361 }
4362 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004363
Craig Mautner81defc72013-10-29 11:10:42 -07004364 if (mTopIsFullscreen != topIsFullscreen) {
4365 if (!topIsFullscreen) {
4366 // Force another layout when status bar becomes fully shown.
4367 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4368 }
4369 mTopIsFullscreen = topIsFullscreen;
4370 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004371
Craig Mautner39834192012-09-02 07:47:24 -07004372 // Hide the key guard if a visible window explicitly specifies that it wants to be
4373 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004374 if (mKeyguardDelegate != null && mStatusBar != null) {
4375 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4376 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004377 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004378 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004379 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004380 changes |= FINISH_LAYOUT_REDO_LAYOUT
4381 | FINISH_LAYOUT_REDO_CONFIG
4382 | FINISH_LAYOUT_REDO_WALLPAPER;
4383 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004384 if (mKeyguardDelegate.isShowing()) {
4385 mHandler.post(new Runnable() {
4386 @Override
4387 public void run() {
4388 mKeyguardDelegate.keyguardDone(false, false);
4389 }
4390 });
4391 }
4392 } else if (mHideLockScreen) {
4393 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004394 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004395 changes |= FINISH_LAYOUT_REDO_LAYOUT
4396 | FINISH_LAYOUT_REDO_CONFIG
4397 | FINISH_LAYOUT_REDO_WALLPAPER;
4398 }
4399 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
4400 // This is the case of keyguard isSecure() and not mHideLockScreen.
4401 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4402 // Only launch the next keyguard unlock window once per window.
4403 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004404 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004405 changes |= FINISH_LAYOUT_REDO_LAYOUT
4406 | FINISH_LAYOUT_REDO_CONFIG
4407 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004408 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004409 mHandler.post(new Runnable() {
4410 @Override
4411 public void run() {
4412 mKeyguardDelegate.dismiss();
4413 }
4414 });
4415 }
4416 } else {
4417 mWinDismissingKeyguard = null;
4418 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004419 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004420 changes |= FINISH_LAYOUT_REDO_LAYOUT
4421 | FINISH_LAYOUT_REDO_CONFIG
4422 | FINISH_LAYOUT_REDO_WALLPAPER;
4423 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004424 }
4425 }
Joe Onorato664644d2011-01-23 17:53:23 -08004426
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004427 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004428 // If the navigation bar has been hidden or shown, we need to do another
4429 // layout pass to update that window.
4430 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4431 }
Joe Onorato664644d2011-01-23 17:53:23 -08004432
Mike Lockwood28569302010-01-28 11:54:40 -05004433 // update since mAllowLockscreenWhenOn might have changed
4434 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004435 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004436 }
4437
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004438 /**
Jim Millerab954542014-10-10 18:21:49 -07004439 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004440 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004441 * @return Whether the flags have changed and we have to redo the layout.
4442 */
Jim Millerab954542014-10-10 18:21:49 -07004443 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4444 boolean wasOccluded = mKeyguardOccluded;
4445 boolean showing = mKeyguardDelegate.isShowing();
4446 if (wasOccluded && !isOccluded && showing) {
4447 mKeyguardOccluded = false;
4448 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004449 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4450 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4451 return true;
Jim Millerab954542014-10-10 18:21:49 -07004452 } else if (!wasOccluded && isOccluded && showing) {
4453 mKeyguardOccluded = true;
4454 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004455 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4456 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4457 return true;
4458 } else {
4459 return false;
4460 }
4461 }
4462
4463 private boolean isStatusBarKeyguard() {
4464 return mStatusBar != null
4465 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4466 }
4467
Jose Lima9546b202014-07-02 17:21:51 -07004468 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004469 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004470 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004471 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004472 return false;
4473 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004474 return true;
4475 }
4476
Jose Lima9546b202014-07-02 17:21:51 -07004477 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004478 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004479 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004480 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004481 // If the navigation bar has been hidden or shown, we need to do another
4482 // layout pass to update that window.
4483 return FINISH_LAYOUT_REDO_LAYOUT;
4484 }
4485 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004486 }
4487
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004488 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004489 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004490 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4491 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004492 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4493 if (newLidState == mLidState) {
4494 return;
4495 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004496
Jeff Brownc458ce92012-04-30 14:58:40 -07004497 mLidState = newLidState;
4498 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004499 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004500
4501 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004502 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004503 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004504 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004505 }
4506 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004507
Michael Wright3818c922014-09-02 13:59:07 -07004508 @Override
4509 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4510 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4511 if (mCameraLensCoverState == lensCoverState) {
4512 return;
4513 }
4514 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4515 lensCoverState == CAMERA_LENS_UNCOVERED) {
4516 Intent intent;
4517 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4518 mKeyguardDelegate.isShowing();
4519 if (keyguardActive) {
4520 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4521 } else {
4522 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4523 }
Bryce Lee584a4452014-10-21 15:55:55 -07004524 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004525 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004526 }
4527 mCameraLensCoverState = lensCoverState;
4528 }
4529
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004530 void setHdmiPlugged(boolean plugged) {
4531 if (mHdmiPlugged != plugged) {
4532 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004533 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004534 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004535 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004536 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004537 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004538 }
4539 }
4540
Joe Onoratoea495d42011-04-06 11:41:11 -07004541 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004542 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004543 // watch for HDMI plug messages if the hdmi switch exists
4544 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4545 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4546
Joe Onoratoea495d42011-04-06 11:41:11 -07004547 final String filename = "/sys/class/switch/hdmi/state";
4548 FileReader reader = null;
4549 try {
4550 reader = new FileReader(filename);
4551 char[] buf = new char[15];
4552 int n = reader.read(buf);
4553 if (n > 1) {
4554 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4555 }
4556 } catch (IOException ex) {
4557 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4558 } catch (NumberFormatException ex) {
4559 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4560 } finally {
4561 if (reader != null) {
4562 try {
4563 reader.close();
4564 } catch (IOException ex) {
4565 }
Joe Onoratodc100302011-01-11 17:07:41 -08004566 }
4567 }
4568 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004569 // This dance forces the code in setHdmiPlugged to run.
4570 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4571 mHdmiPlugged = !plugged;
4572 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004573 }
4574
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004575 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004576 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004577
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004578 final Runnable mScreenshotTimeout = new Runnable() {
4579 @Override public void run() {
4580 synchronized (mScreenshotLock) {
4581 if (mScreenshotConnection != null) {
4582 mContext.unbindService(mScreenshotConnection);
4583 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004584 }
Winson Chung9112ec32011-06-27 13:15:32 -07004585 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004586 }
4587 };
4588
4589 // Assume this is called from the Handler thread.
4590 private void takeScreenshot() {
4591 synchronized (mScreenshotLock) {
4592 if (mScreenshotConnection != null) {
4593 return;
4594 }
4595 ComponentName cn = new ComponentName("com.android.systemui",
4596 "com.android.systemui.screenshot.TakeScreenshotService");
4597 Intent intent = new Intent();
4598 intent.setComponent(cn);
4599 ServiceConnection conn = new ServiceConnection() {
4600 @Override
4601 public void onServiceConnected(ComponentName name, IBinder service) {
4602 synchronized (mScreenshotLock) {
4603 if (mScreenshotConnection != this) {
4604 return;
4605 }
4606 Messenger messenger = new Messenger(service);
4607 Message msg = Message.obtain(null, 1);
4608 final ServiceConnection myConn = this;
4609 Handler h = new Handler(mHandler.getLooper()) {
4610 @Override
4611 public void handleMessage(Message msg) {
4612 synchronized (mScreenshotLock) {
4613 if (mScreenshotConnection == myConn) {
4614 mContext.unbindService(mScreenshotConnection);
4615 mScreenshotConnection = null;
4616 mHandler.removeCallbacks(mScreenshotTimeout);
4617 }
4618 }
4619 }
4620 };
4621 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004622 msg.arg1 = msg.arg2 = 0;
4623 if (mStatusBar != null && mStatusBar.isVisibleLw())
4624 msg.arg1 = 1;
4625 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4626 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004627 try {
4628 messenger.send(msg);
4629 } catch (RemoteException e) {
4630 }
4631 }
4632 }
4633 @Override
4634 public void onServiceDisconnected(ComponentName name) {}
4635 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004636 if (mContext.bindServiceAsUser(
4637 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004638 mScreenshotConnection = conn;
4639 mHandler.postDelayed(mScreenshotTimeout, 10000);
4640 }
4641 }
Winson Chung9112ec32011-06-27 13:15:32 -07004642 }
4643
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004644 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004645 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004646 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004647 if (!mSystemBooted) {
4648 // If we have not yet booted, don't let key events do anything.
4649 return 0;
4650 }
4651
Jeff Brown037c33e2014-04-09 00:31:55 -07004652 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004653 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4654 final boolean canceled = event.isCanceled();
4655 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004656
Jeff Brown3122e442010-10-11 23:32:49 -07004657 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004658
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004659 // If screen is off then we treat the case where the keyguard is open but hidden
4660 // the same as if it were open and in front.
4661 // This will prevent any keys other than the power button from waking the screen
4662 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004663 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004664 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004665 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004666 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004667
Jeff Brown40013652012-05-16 21:22:36 -07004668 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004669 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004670 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004671 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004672 }
4673
Jeff Brown037c33e2014-04-09 00:31:55 -07004674 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004675 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004676 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4677 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004678 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004679 // When the device is interactive or the key is injected pass the
4680 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004681 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004682 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004683 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4684 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4685 // to the application but preserve its wake key status to make sure we still move
4686 // from dozing to fully interactive if we would normally go from off to fully
4687 // interactive.
4688 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004689 } else {
4690 // When the screen is off and the key is not injected, determine whether
4691 // to wake the device but don't pass the key to the application.
4692 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004693 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4694 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004695 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004696 }
4697
Justin Kohd378ad72013-04-01 12:18:26 -07004698 // If the key would be handled globally, just return the result, don't worry about special
4699 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004700 if (isValidGlobalKey(keyCode)
4701 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004702 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004703 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004704 }
Justin Kohd378ad72013-04-01 12:18:26 -07004705 return result;
4706 }
4707
Jeff Brownbae8e772014-06-12 19:59:45 -07004708 boolean useHapticFeedback = down
4709 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4710 && event.getRepeatCount() == 0;
4711
Jeff Brown4d396052010-10-29 21:50:21 -07004712 // Handle special keys.
4713 switch (keyCode) {
4714 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004715 case KeyEvent.KEYCODE_VOLUME_UP:
4716 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004717 if (mUseTvRouting) {
4718 // On TVs volume keys never go to the foreground app
4719 result &= ~ACTION_PASS_TO_USER;
4720 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004721 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4722 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004723 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004724 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004725 mScreenshotChordVolumeDownKeyTriggered = true;
4726 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4727 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004728 cancelPendingPowerKeyAction();
4729 interceptScreenshotChord();
4730 }
4731 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004732 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004733 cancelPendingScreenshotChordAction();
4734 }
4735 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4736 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004737 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004738 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004739 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004740 cancelPendingPowerKeyAction();
4741 cancelPendingScreenshotChordAction();
4742 }
4743 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004744 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004745 cancelPendingScreenshotChordAction();
4746 }
4747 }
Jeff Brown4d396052010-10-29 21:50:21 -07004748 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004749 TelecomManager telecomManager = getTelecommService();
4750 if (telecomManager != null) {
4751 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004752 // If an incoming call is ringing, either VOLUME key means
4753 // "silence ringer". We handle these keys here, rather than
4754 // in the InCallScreen, to make sure we'll respond to them
4755 // even if the InCallScreen hasn't come to the foreground yet.
4756 // Look for the DOWN event here, to agree with the "fallback"
4757 // behavior in the InCallScreen.
4758 Log.i(TAG, "interceptKeyBeforeQueueing:"
4759 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004760
Santos Cordon6848f722014-05-21 15:22:12 -07004761 // Silence the ringer. (It's safe to call this
4762 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004763 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004764
Santos Cordon6848f722014-05-21 15:22:12 -07004765 // And *don't* pass this key thru to the current activity
4766 // (which is probably the InCallScreen.)
4767 result &= ~ACTION_PASS_TO_USER;
4768 break;
4769 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004770 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004771 && (result & ACTION_PASS_TO_USER) == 0) {
4772 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004773 // the application, just pass it to the session service.
4774
4775 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004776 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004777 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004778 }
4779 }
4780
RoboErik430fc482014-06-12 15:49:20 -07004781 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004782 if (mUseTvRouting) {
4783 dispatchDirectAudioEvent(event);
4784 } else {
4785 // If we aren't passing to the user and no one else
4786 // handled it send it to the session manager to
4787 // figure out.
4788 MediaSessionLegacyHelper.getHelper(mContext)
4789 .sendVolumeKeyEvent(event, true);
4790 }
Jeff Brown4d396052010-10-29 21:50:21 -07004791 break;
4792 }
4793 }
4794 break;
4795 }
4796
4797 case KeyEvent.KEYCODE_ENDCALL: {
4798 result &= ~ACTION_PASS_TO_USER;
4799 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004800 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004801 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004802 if (telecomManager != null) {
4803 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004804 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004805 if (interactive && !hungUp) {
4806 mEndCallKeyHandled = false;
4807 mHandler.postDelayed(mEndCallLongPress,
4808 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4809 } else {
4810 mEndCallKeyHandled = true;
4811 }
Jeff Brown4d396052010-10-29 21:50:21 -07004812 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004813 if (!mEndCallKeyHandled) {
4814 mHandler.removeCallbacks(mEndCallLongPress);
4815 if (!canceled) {
4816 if ((mEndcallBehavior
4817 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4818 if (goHome()) {
4819 break;
4820 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004821 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004822 if ((mEndcallBehavior
4823 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4824 mPowerManager.goToSleep(event.getEventTime(),
4825 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4826 isWakeKey = false;
4827 }
Jeff Brown4d396052010-10-29 21:50:21 -07004828 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004829 }
Jeff Brown4d396052010-10-29 21:50:21 -07004830 }
4831 break;
4832 }
4833
4834 case KeyEvent.KEYCODE_POWER: {
4835 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004836 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004837 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004838 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004839 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004840 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004841 }
4842 break;
4843 }
4844
Jeff Brown6212a492014-03-07 13:58:47 -08004845 case KeyEvent.KEYCODE_SLEEP: {
4846 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004847 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004848 if (!mPowerManager.isInteractive()) {
4849 useHapticFeedback = false; // suppress feedback if already non-interactive
4850 }
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004851 sleepPress(event);
Jeff Brown6212a492014-03-07 13:58:47 -08004852 break;
4853 }
4854
4855 case KeyEvent.KEYCODE_WAKEUP: {
4856 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004857 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004858 break;
4859 }
4860
Jeff Brown4d396052010-10-29 21:50:21 -07004861 case KeyEvent.KEYCODE_MEDIA_PLAY:
4862 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4863 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004864 case KeyEvent.KEYCODE_HEADSETHOOK:
4865 case KeyEvent.KEYCODE_MUTE:
4866 case KeyEvent.KEYCODE_MEDIA_STOP:
4867 case KeyEvent.KEYCODE_MEDIA_NEXT:
4868 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4869 case KeyEvent.KEYCODE_MEDIA_REWIND:
4870 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004871 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4872 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004873 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4874 // If the global session is active pass all media keys to it
4875 // instead of the active window.
4876 result &= ~ACTION_PASS_TO_USER;
4877 }
Jeff Brown4d396052010-10-29 21:50:21 -07004878 if ((result & ACTION_PASS_TO_USER) == 0) {
4879 // Only do this if we would otherwise not pass it to the user. In that
4880 // case, the PhoneWindow class will do the same thing, except it will
4881 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004882 // Note that we need to make a copy of the key event here because the
4883 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004884 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004885 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4886 new KeyEvent(event));
4887 msg.setAsynchronous(true);
4888 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004889 }
4890 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004891 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004892
Jeff Brown4d396052010-10-29 21:50:21 -07004893 case KeyEvent.KEYCODE_CALL: {
4894 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004895 TelecomManager telecomManager = getTelecommService();
4896 if (telecomManager != null) {
4897 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004898 Log.i(TAG, "interceptKeyBeforeQueueing:"
4899 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004900 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004901
Santos Cordon6848f722014-05-21 15:22:12 -07004902 // And *don't* pass this key thru to the current activity
4903 // (which is presumably the InCallScreen.)
4904 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004905 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004906 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004907 }
Jeff Brown4d396052010-10-29 21:50:21 -07004908 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004909 }
Michael Wright869a67c2014-08-26 19:33:06 -07004910 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4911 // Only do this if we would otherwise not pass it to the user. In that case,
4912 // interceptKeyBeforeDispatching would apply a similar but different policy in
4913 // order to invoke voice assist actions. Note that we need to make a copy of the
4914 // key event here because the original key event will be recycled when we return.
4915 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4916 mBroadcastWakeLock.acquire();
4917 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4918 keyguardActive ? 1 : 0, 0);
4919 msg.setAsynchronous(true);
4920 msg.sendToTarget();
4921 }
4922 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004923 }
Jeff Brown26875502014-01-30 21:47:47 -08004924
Jeff Brownbae8e772014-06-12 19:59:45 -07004925 if (useHapticFeedback) {
4926 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4927 }
4928
Jeff Brown26875502014-01-30 21:47:47 -08004929 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004930 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004931 }
Bryce Lee584a4452014-10-21 15:55:55 -07004932
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004933 return result;
4934 }
4935
Jeff Brown1c2e4942012-11-06 16:32:01 -08004936 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004937 * Returns true if the key can have global actions attached to it.
4938 * We reserve all power management keys for the system since they require
4939 * very careful handling.
4940 */
4941 private static boolean isValidGlobalKey(int keyCode) {
4942 switch (keyCode) {
4943 case KeyEvent.KEYCODE_POWER:
4944 case KeyEvent.KEYCODE_WAKEUP:
4945 case KeyEvent.KEYCODE_SLEEP:
4946 return false;
4947 default:
4948 return true;
4949 }
4950 }
4951
4952 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08004953 * When the screen is off we ignore some keys that might otherwise typically
4954 * be considered wake keys. We filter them out here.
4955 *
4956 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4957 * is always considered a wake key.
4958 */
4959 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4960 switch (keyCode) {
4961 // ignore volume keys unless docked
4962 case KeyEvent.KEYCODE_VOLUME_UP:
4963 case KeyEvent.KEYCODE_VOLUME_DOWN:
4964 case KeyEvent.KEYCODE_VOLUME_MUTE:
4965 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4966
4967 // ignore media and camera keys
4968 case KeyEvent.KEYCODE_MUTE:
4969 case KeyEvent.KEYCODE_HEADSETHOOK:
4970 case KeyEvent.KEYCODE_MEDIA_PLAY:
4971 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4972 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4973 case KeyEvent.KEYCODE_MEDIA_STOP:
4974 case KeyEvent.KEYCODE_MEDIA_NEXT:
4975 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4976 case KeyEvent.KEYCODE_MEDIA_REWIND:
4977 case KeyEvent.KEYCODE_MEDIA_RECORD:
4978 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004979 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004980 case KeyEvent.KEYCODE_CAMERA:
4981 return false;
4982 }
4983 return true;
4984 }
4985
4986
Jeff Brown56194eb2011-03-02 19:23:13 -08004987 /** {@inheritDoc} */
4988 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004989 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4990 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08004991 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
4992 return 0;
4993 }
Michael Wright70af00a2014-09-03 19:30:20 -07004994 }
Bryce Lee5c138322014-11-03 08:26:09 -08004995
Michael Wright70af00a2014-09-03 19:30:20 -07004996 if (shouldDispatchInputWhenNonInteractive()) {
4997 return ACTION_PASS_TO_USER;
4998 }
Bryce Lee5c138322014-11-03 08:26:09 -08004999
Bryce Lee812d7022014-11-10 13:33:28 -08005000 // If we have not passed the action up and we are in theater mode without dreaming,
5001 // there will be no dream to intercept the touch and wake into ambient. The device should
5002 // wake up in this case.
5003 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
5004 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
5005 }
5006
Jeff Brown037c33e2014-04-09 00:31:55 -07005007 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005008 }
5009
Michael Wright70af00a2014-09-03 19:30:20 -07005010 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08005011 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07005012 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5013 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005014 return true;
5015 }
5016
5017 // Send events to a dozing dream even if the screen is off since the dream
5018 // is in control of the state of the screen.
5019 IDreamManager dreamManager = getDreamManager();
5020
5021 try {
5022 if (dreamManager != null && dreamManager.isDreaming()) {
5023 return true;
5024 }
5025 } catch (RemoteException e) {
5026 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5027 }
5028
5029 // Otherwise, consume events since the user can't see what is being
5030 // interacted with.
5031 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005032 }
5033
RoboErik001c59c2015-01-26 15:53:51 -08005034 private void dispatchDirectAudioEvent(KeyEvent event) {
5035 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5036 return;
5037 }
5038 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005039 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5040 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005041 String pkgName = mContext.getOpPackageName();
5042 switch (keyCode) {
5043 case KeyEvent.KEYCODE_VOLUME_UP:
5044 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005045 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005046 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005047 } catch (RemoteException e) {
5048 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5049 }
5050 break;
5051 case KeyEvent.KEYCODE_VOLUME_DOWN:
5052 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005053 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005054 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005055 } catch (RemoteException e) {
5056 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5057 }
5058 break;
5059 case KeyEvent.KEYCODE_VOLUME_MUTE:
5060 try {
5061 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005062 getAudioService().adjustSuggestedStreamVolume(
5063 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005064 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005065 }
5066 } catch (RemoteException e) {
5067 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5068 }
5069 break;
5070 }
5071 }
5072
Jeff Brown40013652012-05-16 21:22:36 -07005073 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5074 if (DEBUG_INPUT) {
5075 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005076 }
5077
Jeff Brown40013652012-05-16 21:22:36 -07005078 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5079 if (DEBUG_INPUT) {
5080 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5081 }
5082
5083 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5084 mHavePendingMediaKeyRepeatWithWakeLock = false;
5085 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5086 }
5087
5088 dispatchMediaKeyWithWakeLockToAudioService(event);
5089
5090 if (event.getAction() == KeyEvent.ACTION_DOWN
5091 && event.getRepeatCount() == 0) {
5092 mHavePendingMediaKeyRepeatWithWakeLock = true;
5093
5094 Message msg = mHandler.obtainMessage(
5095 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5096 msg.setAsynchronous(true);
5097 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5098 } else {
5099 mBroadcastWakeLock.release();
5100 }
5101 }
5102
5103 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5104 mHavePendingMediaKeyRepeatWithWakeLock = false;
5105
5106 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5107 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5108 if (DEBUG_INPUT) {
5109 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5110 }
5111
5112 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5113 mBroadcastWakeLock.release();
5114 }
5115
5116 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5117 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005118 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005119 }
5120 }
5121
Michael Wright869a67c2014-08-26 19:33:06 -07005122 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
5123 Intent voiceIntent =
5124 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5125 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005126 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005127 mBroadcastWakeLock.release();
5128 }
5129
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005130 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005131 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005132 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005133 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5134 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5135 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005136 } else {
5137 try {
5138 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5139 ServiceManager.getService(Context.UI_MODE_SERVICE));
5140 mUiMode = uiModeService.getCurrentModeType();
5141 } catch (RemoteException e) {
5142 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005143 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005144 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005145 synchronized (mLock) {
5146 updateOrientationListenerLp();
5147 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005148 }
5149 };
5150
Jeff Brown6aaf2952012-10-05 16:01:08 -07005151 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5152 @Override
5153 public void onReceive(Context context, Intent intent) {
5154 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005155 if (mKeyguardDelegate != null) {
5156 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005157 }
5158 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005159 if (mKeyguardDelegate != null) {
5160 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005161 }
5162 }
5163 }
5164 };
5165
Christopher Tate5e08af02012-09-21 17:17:22 -07005166 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5167 @Override
5168 public void onReceive(Context context, Intent intent) {
5169 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5170 // tickle the settings observer: this first ensures that we're
5171 // observing the relevant settings for the newly-active user,
5172 // and then updates our own bookkeeping based on the now-
5173 // current user.
5174 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005175
5176 // force a re-application of focused window sysui visibility.
5177 // the window may never have been shown for this user
5178 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005179 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005180 mLastSystemUiFlags = 0;
5181 updateSystemUiVisibilityLw();
5182 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005183 }
5184 }
5185 };
5186
John Spurlockd9b70bd2014-02-06 17:02:44 -05005187 private final Runnable mRequestTransientNav = new Runnable() {
5188 @Override
5189 public void run() {
5190 requestTransientBars(mNavigationBar);
5191 }
5192 };
5193
John Spurlocke1f366f2013-08-05 12:22:40 -04005194 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005195 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005196 if (!isUserSetupComplete()) {
5197 // Swipe-up for navigation bar is disabled during setup
5198 return;
5199 }
John Spurlock27735a42013-08-14 17:57:38 -04005200 boolean sb = mStatusBarController.checkShowTransientBarLw();
5201 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005202 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005203 // Don't show status bar when swiping on already visible navigation bar
5204 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005205 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005206 return;
5207 }
John Spurlock27735a42013-08-14 17:57:38 -04005208 if (sb) mStatusBarController.showTransient();
5209 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005210 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005211 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005212 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005213 }
5214 }
5215
Jeff Brown3ee549c2014-09-22 20:14:39 -07005216 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005217 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07005218 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005219 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07005220 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005221
5222 // We must get this work done here because the power manager will drop
5223 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005224 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005225 mAwake = false;
5226 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005227 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005228 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005229 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005230 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005231
5232 if (mKeyguardDelegate != null) {
5233 mKeyguardDelegate.onScreenTurnedOff(why);
5234 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005235 }
5236
Jeff Brown13f00f02014-10-31 14:45:50 -07005237 private void wakeUpFromPowerKey(long eventTime) {
5238 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5239 }
5240
Bryce Lee5c138322014-11-03 08:26:09 -08005241 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Lee584a4452014-10-21 15:55:55 -07005242 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005243 return false;
Bryce Lee584a4452014-10-21 15:55:55 -07005244 }
5245
5246 mPowerManager.wakeUp(wakeTime);
Bryce Lee5c138322014-11-03 08:26:09 -08005247 return true;
Bryce Lee584a4452014-10-21 15:55:55 -07005248 }
5249
Jeff Brown3ee549c2014-09-22 20:14:39 -07005250 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005251 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07005252 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005253 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07005254 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005255
Jeff Brown3ee549c2014-09-22 20:14:39 -07005256 // Since goToSleep performs these functions synchronously, we must
5257 // do the same here. We cannot post this work to a handler because
5258 // that might cause it to become reordered with respect to what
5259 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005260 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005261 mAwake = true;
5262 mKeyguardDrawComplete = false;
5263 if (mKeyguardDelegate != null) {
5264 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5265 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5266 }
5267
Jeff Browna20dda42014-05-27 20:57:24 -07005268 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005269 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005270 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005271 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005272
Jim Miller5ecd8112013-01-09 18:50:26 -08005273 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07005274 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005275 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005276 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005277 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005278 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005279 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005280 }
5281
Jeff Brown36c4db82014-09-19 12:05:31 -07005282 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005283 synchronized (mLock) {
5284 if (!mAwake || mKeyguardDrawComplete) {
5285 return; // spurious
5286 }
5287
Jeff Brown36c4db82014-09-19 12:05:31 -07005288 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005289 if (mKeyguardDelegate != null) {
5290 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5291 }
5292 }
5293
5294 finishScreenTurningOn();
5295 }
5296
5297 // Called on the DisplayManager's DisplayPowerController thread.
5298 @Override
5299 public void screenTurnedOff() {
5300 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5301
5302 synchronized (mLock) {
5303 mScreenOnEarly = false;
5304 mScreenOnFully = false;
5305 mWindowManagerDrawComplete = false;
5306 mScreenOnListener = null;
5307 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005308 }
5309 }
5310
Jeff Brown3ee549c2014-09-22 20:14:39 -07005311 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005312 @Override
5313 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005314 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005315
Jeff Brown3ee549c2014-09-22 20:14:39 -07005316 synchronized (mLock) {
5317 mScreenOnEarly = true;
5318 mScreenOnFully = false;
5319 mWindowManagerDrawComplete = false;
5320 mScreenOnListener = screenOnListener;
5321 updateOrientationListenerLp();
5322 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005323
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005324 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5325 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005326 // ... eventually calls finishWindowsDrawn
5327 }
5328
Jeff Brown36c4db82014-09-19 12:05:31 -07005329 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005330 synchronized (mLock) {
5331 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5332 return; // spurious
5333 }
5334
Jeff Brown36c4db82014-09-19 12:05:31 -07005335 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005336 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005337
5338 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005339 }
5340
Craig Mautner8a0da012014-05-31 15:13:37 -07005341 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005342 final ScreenOnListener listener;
5343 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005344 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005345 if (DEBUG_WAKEUP) Slog.d(TAG,
5346 "finishScreenTurningOn: mAwake=" + mAwake
5347 + ", mScreenOnEarly=" + mScreenOnEarly
5348 + ", mScreenOnFully=" + mScreenOnFully
5349 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5350 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5351
5352 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5353 || (mAwake && !mKeyguardDrawComplete)) {
5354 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005355 }
5356
Jeff Brown3ee549c2014-09-22 20:14:39 -07005357 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5358 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005359 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005360 mScreenOnFully = true;
5361
5362 // Remember the first time we draw the keyguard so we know when we're done with
5363 // the main part of booting and can enable the screen and hide boot messages.
5364 if (!mKeyguardDrawnOnce && mAwake) {
5365 mKeyguardDrawnOnce = true;
5366 enableScreen = true;
5367 if (mBootMessageNeedsHiding) {
5368 mBootMessageNeedsHiding = false;
5369 hideBootMessages();
5370 }
5371 } else {
5372 enableScreen = false;
5373 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005374 }
5375
Jeff Brown3ee549c2014-09-22 20:14:39 -07005376 if (listener != null) {
5377 listener.onScreenOn();
5378 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005379
Jeff Brown3ee549c2014-09-22 20:14:39 -07005380 if (enableScreen) {
5381 try {
5382 mWindowManager.enableScreenIfNeeded();
5383 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005384 }
Craig Mautnera631d492014-08-05 15:16:01 -07005385 }
5386 }
5387
5388 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005389 synchronized (mLock) {
5390 if (!mKeyguardDrawnOnce) {
5391 mBootMessageNeedsHiding = true;
5392 return; // keyguard hasn't drawn the first time yet, not done booting
5393 }
Craig Mautnera631d492014-08-05 15:16:01 -07005394 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005395
5396 if (mBootMsgDialog != null) {
5397 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5398 mBootMsgDialog.dismiss();
5399 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005400 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005401 }
5402
5403 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005404 public boolean isScreenOn() {
5405 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005406 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005407
Dianne Hackborn08743722009-12-21 12:16:51 -08005408 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005409 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005410 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005411 if (mKeyguardDelegate != null) {
5412 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005413 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005414 }
5415
5416 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005417 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005418 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005419 if (mKeyguardDelegate != null) {
5420 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005421 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005422 }
5423
Jim Millerab954542014-10-10 18:21:49 -07005424 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005425 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005426 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005427 }
5428
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005429 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005430 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005431 public boolean isKeyguardLocked() {
5432 return keyguardOn();
5433 }
5434
5435 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005436 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005437 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005438 if (mKeyguardDelegate == null) return false;
5439 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005440 }
5441
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005442 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005443 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005444 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005445 if (mKeyguardDelegate == null) return false;
5446 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005447 }
5448
Jose Lima9546b202014-07-02 17:21:51 -07005449 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005450 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005451 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005452 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005453 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005454 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005455 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005456 // ask the keyguard to prompt the user to authenticate if necessary
5457 mKeyguardDelegate.dismiss();
5458 }
5459 });
5460 }
5461 }
5462
5463 public void notifyActivityDrawnForKeyguardLw() {
5464 if (mKeyguardDelegate != null) {
5465 mHandler.post(new Runnable() {
5466 @Override
5467 public void run() {
5468 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005469 }
5470 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005471 }
5472 }
5473
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005474 @Override
5475 public boolean isKeyguardDrawnLw() {
5476 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005477 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005478 }
5479 }
5480
Jorim Jaggi0d674622014-05-21 01:34:15 +02005481 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005482 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005483 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005484 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005485 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005486 }
5487 }
5488
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005489 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005490 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005491 }
5492
5493 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005494 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005495 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005496
Jeff Brown01a98dd2011-09-20 15:08:29 -07005497 @Override
5498 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005499 if (false) {
5500 Slog.v(TAG, "rotationForOrientationLw(orient="
5501 + orientation + ", last=" + lastRotation
5502 + "); user=" + mUserRotation + " "
5503 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5504 ? "USER_ROTATION_LOCKED" : "")
5505 );
5506 }
5507
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005508 if (mForceDefaultOrientation) {
5509 return Surface.ROTATION_0;
5510 }
5511
The Android Open Source Project0727d222009-03-11 12:11:58 -07005512 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005513 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5514 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005515 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005516 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005517
Jeff Browndec6cf42011-11-15 14:08:20 -08005518 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005519 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005520 // Ignore sensor when lid switch is open and rotation is forced.
5521 preferredRotation = mLidOpenRotation;
5522 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005523 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005524 // Ignore sensor when in car dock unless explicitly enabled.
5525 // This case can override the behavior of NOSENSOR, and can also
5526 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005527 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005528 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005529 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5530 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5531 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005532 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005533 // Ignore sensor when in desk dock unless explicitly enabled.
5534 // This case can override the behavior of NOSENSOR, and can also
5535 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005536 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005537 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005538 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5539 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005540 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005541 preferredRotation = mDemoHdmiRotation;
5542 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5543 && mUndockedHdmiRotation >= 0) {
5544 // Ignore sensor when plugged into HDMI and an undocked orientation has
5545 // been specified in the configuration (only for legacy devices without
5546 // full multi-display support).
5547 // Note that the dock orientation overrides the HDMI orientation.
5548 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005549 } else if (mDemoRotationLock) {
5550 // Ignore sensor when demo rotation lock is enabled.
5551 // Note that the dock orientation and HDMI rotation lock override this.
5552 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005553 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5554 // Application just wants to remain locked in the last rotation.
5555 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005556 } else if (!mSupportAutoRotation) {
5557 // If we don't support auto-rotation then bail out here and ignore
5558 // the sensor and any rotation lock settings.
5559 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005560 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005561 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005562 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5563 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5564 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5565 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005566 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5567 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5568 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5569 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5570 // Otherwise, use sensor only if requested by the application or enabled
5571 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005572 if (mAllowAllRotations < 0) {
5573 // Can't read this during init() because the context doesn't
5574 // have display metrics at that time so we cannot determine
5575 // tablet vs. phone then.
5576 mAllowAllRotations = mContext.getResources().getBoolean(
5577 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5578 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005579 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005580 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005581 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5582 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005583 preferredRotation = sensorRotation;
5584 } else {
5585 preferredRotation = lastRotation;
5586 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005587 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5588 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5589 // Apply rotation lock. Does not apply to NOSENSOR.
5590 // The idea is that the user rotation expresses a weak preference for the direction
5591 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5592 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005593 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005594 } else {
5595 // No overriding preference.
5596 // We will do exactly what the application asked us to do.
5597 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005598 }
5599
Dianne Hackborne5439f22010-10-02 16:53:50 -07005600 switch (orientation) {
5601 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005602 // Return portrait unless overridden.
5603 if (isAnyPortrait(preferredRotation)) {
5604 return preferredRotation;
5605 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005606 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005607
Jeff Brown01a98dd2011-09-20 15:08:29 -07005608 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005609 // Return landscape unless overridden.
5610 if (isLandscapeOrSeascape(preferredRotation)) {
5611 return preferredRotation;
5612 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005613 return mLandscapeRotation;
5614
5615 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005616 // Return reverse portrait unless overridden.
5617 if (isAnyPortrait(preferredRotation)) {
5618 return preferredRotation;
5619 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005620 return mUpsideDownRotation;
5621
5622 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005623 // Return seascape unless overridden.
5624 if (isLandscapeOrSeascape(preferredRotation)) {
5625 return preferredRotation;
5626 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005627 return mSeascapeRotation;
5628
5629 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005630 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005631 // Return either landscape rotation.
5632 if (isLandscapeOrSeascape(preferredRotation)) {
5633 return preferredRotation;
5634 }
5635 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005636 return lastRotation;
5637 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005638 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005639
Jeff Brown01a98dd2011-09-20 15:08:29 -07005640 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005641 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005642 // Return either portrait rotation.
5643 if (isAnyPortrait(preferredRotation)) {
5644 return preferredRotation;
5645 }
5646 if (isAnyPortrait(lastRotation)) {
5647 return lastRotation;
5648 }
5649 return mPortraitRotation;
5650
5651 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005652 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5653 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005654 if (preferredRotation >= 0) {
5655 return preferredRotation;
5656 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005657 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005658 }
5659 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005660 }
5661
Jeff Brown01a98dd2011-09-20 15:08:29 -07005662 @Override
5663 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5664 switch (orientation) {
5665 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5666 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5667 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5668 return isAnyPortrait(rotation);
5669
5670 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5671 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5672 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5673 return isLandscapeOrSeascape(rotation);
5674
5675 default:
5676 return true;
5677 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005678 }
5679
Jeff Brownc0347aa2011-09-23 17:26:09 -07005680 @Override
5681 public void setRotationLw(int rotation) {
5682 mOrientationListener.setCurrentRotation(rotation);
5683 }
5684
Jeff Brown01a98dd2011-09-20 15:08:29 -07005685 private boolean isLandscapeOrSeascape(int rotation) {
5686 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005687 }
5688
Jeff Brown01a98dd2011-09-20 15:08:29 -07005689 private boolean isAnyPortrait(int rotation) {
5690 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005691 }
5692
Jose Lima9546b202014-07-02 17:21:51 -07005693 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005694 public int getUserRotationMode() {
5695 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005696 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5697 WindowManagerPolicy.USER_ROTATION_FREE :
5698 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005699 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005700
5701 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005702 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005703 public void setUserRotationMode(int mode, int rot) {
5704 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005705
5706 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005707 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005708 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005709 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005710 rot,
5711 UserHandle.USER_CURRENT);
5712 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005713 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005714 0,
5715 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005716 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005717 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005718 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005719 1,
5720 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005721 }
5722 }
5723
Jose Lima9546b202014-07-02 17:21:51 -07005724 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005725 public void setSafeMode(boolean safeMode) {
5726 mSafeMode = safeMode;
5727 performHapticFeedbackLw(null, safeMode
5728 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5729 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005730 }
Craig Mautnereda67292013-04-28 13:50:14 -07005731
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005732 static long[] getLongIntArray(Resources r, int resid) {
5733 int[] ar = r.getIntArray(resid);
5734 if (ar == null) {
5735 return null;
5736 }
5737 long[] out = new long[ar.length];
5738 for (int i=0; i<ar.length; i++) {
5739 out[i] = ar[i];
5740 }
5741 return out;
5742 }
Craig Mautnereda67292013-04-28 13:50:14 -07005743
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005744 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005745 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005746 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005747 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005748 mKeyguardDelegate.onSystemReady();
5749
Michael Wright3818c922014-09-02 13:59:07 -07005750 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005751 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005752 synchronized (mLock) {
5753 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005754 mSystemReady = true;
5755 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005756 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005757 public void run() {
5758 updateSettings();
5759 }
5760 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005761 }
5762 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005763
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005764 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005765 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005766 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005767 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005768 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005769 mKeyguardDelegate.onBootCompleted();
5770 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005771 synchronized (mLock) {
5772 mSystemBooted = true;
5773 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005774 wakingUp();
5775 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005776 }
5777
Dianne Hackborn661cd522011-08-22 00:26:20 -07005778 ProgressDialog mBootMsgDialog = null;
5779
5780 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005781 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005782 public void showBootMessage(final CharSequence msg, final boolean always) {
5783 mHandler.post(new Runnable() {
5784 @Override public void run() {
5785 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005786 int theme;
5787 if (mContext.getPackageManager().hasSystemFeature(
5788 PackageManager.FEATURE_WATCH)) {
5789 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5790 } else if (mContext.getPackageManager().hasSystemFeature(
5791 PackageManager.FEATURE_TELEVISION)) {
5792 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5793 } else {
5794 theme = 0;
5795 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005796
5797 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005798 // This dialog will consume all events coming in to
5799 // it, to avoid it trying to do things too early in boot.
5800 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5801 return true;
5802 }
5803 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5804 return true;
5805 }
5806 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5807 return true;
5808 }
5809 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5810 return true;
5811 }
5812 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5813 return true;
5814 }
5815 @Override public boolean dispatchPopulateAccessibilityEvent(
5816 AccessibilityEvent event) {
5817 return true;
5818 }
5819 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005820 if (mContext.getPackageManager().isUpgrade()) {
5821 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5822 } else {
5823 mBootMsgDialog.setTitle(R.string.android_start_title);
5824 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005825 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5826 mBootMsgDialog.setIndeterminate(true);
5827 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005828 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005829 mBootMsgDialog.getWindow().addFlags(
5830 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5831 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5832 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005833 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5834 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5835 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005836 mBootMsgDialog.setCancelable(false);
5837 mBootMsgDialog.show();
5838 }
5839 mBootMsgDialog.setMessage(msg);
5840 }
5841 });
5842 }
5843
5844 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005845 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005846 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005847 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005848 }
5849
Mike Lockwood28569302010-01-28 11:54:40 -05005850 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005851 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005852 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005853 // ***************************************
5854 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5855 // ***************************************
5856 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5857 // WITH ITS LOCKS HELD.
5858 //
5859 // This code must be VERY careful about the locks
5860 // it acquires.
5861 // In fact, the current code acquires way too many,
5862 // and probably has lurking deadlocks.
5863
Mike Lockwood28569302010-01-28 11:54:40 -05005864 synchronized (mScreenLockTimeout) {
5865 if (mLockScreenTimerActive) {
5866 // reset the timer
5867 mHandler.removeCallbacks(mScreenLockTimeout);
5868 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5869 }
5870 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005871 }
5872
Adam Cohenf7522022012-10-03 20:03:18 -07005873 class ScreenLockTimeout implements Runnable {
5874 Bundle options;
5875
5876 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005877 public void run() {
5878 synchronized (this) {
5879 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005880 if (mKeyguardDelegate != null) {
5881 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005882 }
Mike Lockwood28569302010-01-28 11:54:40 -05005883 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005884 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005885 }
5886 }
Mike Lockwood28569302010-01-28 11:54:40 -05005887
Adam Cohenf7522022012-10-03 20:03:18 -07005888 public void setLockOptions(Bundle options) {
5889 this.options = options;
5890 }
5891 }
5892
5893 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5894
Jose Lima9546b202014-07-02 17:21:51 -07005895 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005896 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005897 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5898 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005899 if (options != null) {
5900 // In case multiple calls are made to lockNow, we don't wipe out the options
5901 // until the runnable actually executes.
5902 mScreenLockTimeout.setLockOptions(options);
5903 }
Jim Miller93c518e2012-01-17 15:55:31 -08005904 mHandler.post(mScreenLockTimeout);
5905 }
5906
Mike Lockwood28569302010-01-28 11:54:40 -05005907 private void updateLockScreenTimeout() {
5908 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005909 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005910 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005911 if (mLockScreenTimerActive != enable) {
5912 if (enable) {
5913 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5914 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5915 } else {
5916 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5917 mHandler.removeCallbacks(mScreenLockTimeout);
5918 }
5919 mLockScreenTimerActive = enable;
5920 }
5921 }
5922 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005923
Jeff Brown061ea992015-04-17 19:55:47 -07005924 private void updateDreamingSleepToken(boolean acquire) {
5925 if (acquire) {
5926 if (mDreamingSleepToken == null) {
5927 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
5928 }
5929 } else {
5930 if (mDreamingSleepToken != null) {
5931 mDreamingSleepToken.release();
5932 }
5933 }
5934 }
5935
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005936 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005937 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005938 public void enableScreenAfterBoot() {
5939 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005940 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005941 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005942 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005943
Jeff Brownc458ce92012-04-30 14:58:40 -07005944 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005945 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005946 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005947 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005948 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005949 }
Jeff Browna20dda42014-05-27 20:57:24 -07005950
5951 synchronized (mLock) {
5952 updateWakeGestureListenerLp();
5953 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005954 }
5955
Jeff Brown4f5fa282014-06-12 19:19:15 -07005956 void updateUiMode() {
5957 if (mUiModeManager == null) {
5958 mUiModeManager = IUiModeManager.Stub.asInterface(
5959 ServiceManager.getService(Context.UI_MODE_SERVICE));
5960 }
5961 try {
5962 mUiMode = mUiModeManager.getCurrentModeType();
5963 } catch (RemoteException e) {
5964 }
5965 }
5966
Jeff Brown01a98dd2011-09-20 15:08:29 -07005967 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005968 try {
5969 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005970 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5971 } catch (RemoteException e) {
5972 // Ignore
5973 }
5974 }
5975
5976 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5977 try {
5978 //set orientation on WindowManager
5979 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005980 } catch (RemoteException e) {
5981 // Ignore
5982 }
5983 }
5984
Daniel Sandler6396c722013-04-16 20:19:09 -04005985 /**
5986 * Return an Intent to launch the currently active dock app as home. Returns
5987 * null if the standard home should be launched, which is the case if any of the following is
5988 * true:
5989 * <ul>
5990 * <li>The device is not in either car mode or desk mode
5991 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5992 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5993 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5994 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5995 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005996 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005997 */
5998 Intent createHomeDockIntent() {
5999 Intent intent = null;
6000
6001 // What home does is based on the mode, not the dock state. That
6002 // is, when in car mode you should be taken to car home regardless
6003 // of whether we are actually in a car dock.
6004 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6005 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
6006 intent = mCarDockIntent;
6007 }
6008 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6009 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6010 intent = mDeskDockIntent;
6011 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006012 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6013 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6014 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6015 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6016 // Always launch dock home from home when watch is docked, if it exists.
6017 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006018 }
6019
6020 if (intent == null) {
6021 return null;
6022 }
6023
6024 ActivityInfo ai = null;
6025 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6026 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006027 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006028 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006029 if (info != null) {
6030 ai = info.activityInfo;
6031 }
6032 if (ai != null
6033 && ai.metaData != null
6034 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6035 intent = new Intent(intent);
6036 intent.setClassName(ai.packageName, ai.name);
6037 return intent;
6038 }
6039
6040 return null;
6041 }
6042
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006043 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6044 if (awakenFromDreams) {
6045 awakenDreams();
6046 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006047
6048 Intent dock = createHomeDockIntent();
6049 if (dock != null) {
6050 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006051 if (fromHomeKey) {
6052 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6053 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006054 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006055 return;
6056 } catch (ActivityNotFoundException e) {
6057 }
6058 }
6059
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006060 Intent intent;
6061
6062 if (fromHomeKey) {
6063 intent = new Intent(mHomeIntent);
6064 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6065 } else {
6066 intent = mHomeIntent;
6067 }
6068
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006069 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006070 }
Craig Mautnereda67292013-04-28 13:50:14 -07006071
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006072 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006073 * goes to the home screen
6074 * @return whether it did anything
6075 */
6076 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006077 if (!isUserSetupComplete()) {
6078 Slog.i(TAG, "Not going home because user setup is in progress.");
6079 return false;
6080 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006081 if (false) {
6082 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006083 try {
6084 ActivityManagerNative.getDefault().stopAppSwitches();
6085 } catch (RemoteException e) {
6086 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006087 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006088 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006089 } else {
6090 // This code brings home to the front or, if it is already
6091 // at the front, puts the device to sleep.
6092 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006093 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6094 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6095 Log.d(TAG, "UTS-TEST-MODE");
6096 } else {
6097 ActivityManagerNative.getDefault().stopAppSwitches();
6098 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006099 Intent dock = createHomeDockIntent();
6100 if (dock != null) {
6101 int result = ActivityManagerNative.getDefault()
6102 .startActivityAsUser(null, null, dock,
6103 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6104 null, null, 0,
6105 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006106 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006107 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6108 return false;
6109 }
6110 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006111 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006112 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006113 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006114 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006115 null, null, 0,
6116 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006117 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006118 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006119 return false;
6120 }
6121 } catch (RemoteException ex) {
6122 // bummer, the activity manager, which is in this process, is dead
6123 }
6124 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006125 return true;
6126 }
Craig Mautnereda67292013-04-28 13:50:14 -07006127
6128 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006129 public void setCurrentOrientationLw(int newOrientation) {
6130 synchronized (mLock) {
6131 if (newOrientation != mCurrentAppOrientation) {
6132 mCurrentAppOrientation = newOrientation;
6133 updateOrientationListenerLp();
6134 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006135 }
6136 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006137
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006138 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6139 if (!isGlobalAccessibilityGestureEnabled()) {
6140 return;
6141 }
6142 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6143 Context.AUDIO_SERVICE);
6144 if (audioManager.isSilentMode()) {
6145 return;
6146 }
6147 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6148 Settings.System.DEFAULT_NOTIFICATION_URI);
6149 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6150 ringTone.play();
6151 }
Craig Mautnereda67292013-04-28 13:50:14 -07006152
Bryce Lee584a4452014-10-21 15:55:55 -07006153 private boolean isTheaterModeEnabled() {
6154 return Settings.Global.getInt(mContext.getContentResolver(),
6155 Settings.Global.THEATER_MODE_ON, 0) == 1;
6156 }
6157
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006158 private boolean isGlobalAccessibilityGestureEnabled() {
6159 return Settings.Global.getInt(mContext.getContentResolver(),
6160 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6161 }
6162
Craig Mautnereda67292013-04-28 13:50:14 -07006163 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006164 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006165 if (!mVibrator.hasVibrator()) {
6166 return false;
6167 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006168 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6169 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006170 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006171 return false;
6172 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006173 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006174 switch (effectId) {
6175 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006176 pattern = mLongPressVibePattern;
6177 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006178 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006179 pattern = mVirtualKeyVibePattern;
6180 break;
6181 case HapticFeedbackConstants.KEYBOARD_TAP:
6182 pattern = mKeyboardTapVibePattern;
6183 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006184 case HapticFeedbackConstants.CLOCK_TICK:
6185 pattern = mClockTickVibePattern;
6186 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006187 case HapticFeedbackConstants.CALENDAR_DATE:
6188 pattern = mCalendarDateVibePattern;
6189 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006190 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006191 pattern = mSafeModeDisabledVibePattern;
6192 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006193 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006194 pattern = mSafeModeEnabledVibePattern;
6195 break;
Mady Mellore82067b2015-04-30 09:58:35 -07006196 case HapticFeedbackConstants.STYLUS_BUTTON_PRESS:
6197 pattern = mStylusButtonPressVibePattern;
6198 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006199 default:
6200 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006201 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006202 int owningUid;
6203 String owningPackage;
6204 if (win != null) {
6205 owningUid = win.getOwningUid();
6206 owningPackage = win.getOwningPackage();
6207 } else {
6208 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006209 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006210 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006211 if (pattern.length == 1) {
6212 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006213 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006214 } else {
6215 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006216 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006217 }
6218 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006219 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006220
6221 @Override
6222 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006223 }
6224
Jeff Brownc38c9be2012-10-04 13:16:19 -07006225 @Override
6226 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006227 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006228 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006229 }
6230 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006231
Dianne Hackborndf89e652011-10-06 22:35:11 -07006232 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006233 // If there is no window focused, there will be nobody to handle the events
6234 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006235 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6236 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006237 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006238 return 0;
6239 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006240 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006241 // We are updating at a point where the keyguard has gotten
6242 // focus, but we were last in a state where the top window is
6243 // hiding it. This is probably because the keyguard as been
6244 // shown while the top window was displayed, so we want to ignore
6245 // it here because this is just a very transient change and it
6246 // will quickly lose focus once it correctly gets hidden.
6247 return 0;
6248 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006249
John Spurlock1db8b682014-02-18 11:18:59 -05006250 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006251 & ~mResettingSystemUiFlags
6252 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006253 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006254 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006255 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006256 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006257 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006258 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006259 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006260 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006261 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006262 return 0;
6263 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006264 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006265 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006266 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006267 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006268 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006269 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006270 try {
6271 IStatusBarService statusbar = getStatusBarService();
6272 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006273 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006274 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006275 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006276 } catch (RemoteException e) {
6277 // re-acquire status bar service next time it is needed.
6278 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006279 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006280 }
6281 });
6282 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006283 }
6284
Adrian Rooscd3884d2015-02-18 17:25:23 +01006285 private int updateLightStatusBarLw(int vis) {
6286 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6287 ? mStatusBar
6288 : mTopFullscreenOpaqueOrDimmingWindowState;
6289
6290 if (statusColorWin != null) {
6291 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6292 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6293 // its light flag.
6294 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6295 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6296 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6297 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6298 // Otherwise if it's dimming, clear the light flag.
6299 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6300 }
6301 }
6302 return vis;
6303 }
6304
John Spurlock79da8332013-09-20 12:04:47 -04006305 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006306 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006307 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6308 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006309 : mTopFullscreenOpaqueWindowState;
6310 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6311 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6312
John Spurlock27735a42013-08-14 17:57:38 -04006313 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04006314 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006315 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006316 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6317 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006318 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006319 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6320 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006321 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006322 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6323 }
John Spurlockbd957402013-10-03 11:38:39 -04006324 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006325 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006326
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006327 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006328 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6329 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006330 }
6331
John Spurlock27735a42013-08-14 17:57:38 -04006332 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006333 boolean immersiveSticky =
6334 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006335 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006336 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006337 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006338 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6339 boolean hideStatusBarSysui =
6340 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006341 boolean hideNavBarSysui =
6342 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006343
John Spurlock27735a42013-08-14 17:57:38 -04006344 boolean transientStatusBarAllowed =
6345 mStatusBar != null && (
6346 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006347 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006348 || statusBarHasFocus);
6349
John Spurlockf1a36642013-10-12 17:50:42 -04006350 boolean transientNavBarAllowed =
6351 mNavigationBar != null &&
6352 hideNavBarSysui && immersiveSticky;
6353
John Spurlockf25706f2013-11-07 18:02:43 -05006354 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006355 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006356 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006357 && !transientNavBarAllowed;
6358 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006359 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006360 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006361 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006362 }
John Spurlock27735a42013-08-14 17:57:38 -04006363
6364 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6365
6366 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006367 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6368 boolean newImmersiveMode = isImmersiveMode(vis);
6369 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006370 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006371 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6372 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006373 }
John Spurlock27735a42013-08-14 17:57:38 -04006374
John Spurlockf1a36642013-10-12 17:50:42 -04006375 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6376
John Spurlocke1f366f2013-08-05 12:22:40 -04006377 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006378 }
6379
John Spurlockf1a36642013-10-12 17:50:42 -04006380 private void clearClearableFlagsLw() {
6381 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6382 if (newVal != mResettingSystemUiFlags) {
6383 mResettingSystemUiFlags = newVal;
6384 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6385 }
6386 }
6387
6388 private boolean isImmersiveMode(int vis) {
6389 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006390 return mNavigationBar != null
6391 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006392 && (vis & flags) != 0
6393 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006394 }
6395
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006396 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006397 * @return whether the navigation or status bar can be made translucent
6398 *
6399 * This should return true unless touch exploration is not enabled or
6400 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006401 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006402 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006403 return mTranslucentDecorEnabled
6404 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006405 }
6406
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006407 // Use this instead of checking config_showNavigationBar so that it can be consistently
6408 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006409 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006410 public boolean hasNavigationBar() {
6411 return mHasNavigationBar;
6412 }
6413
satok1bc0a492012-04-25 22:47:12 +09006414 @Override
6415 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6416 mLastInputMethodWindow = ime;
6417 mLastInputMethodTargetWindow = target;
6418 }
6419
Craig Mautnerf1b67412012-09-19 13:18:29 -07006420 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006421 public int getInputMethodWindowVisibleHeightLw() {
6422 return mDockBottom - mCurBottom;
6423 }
6424
6425 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006426 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006427 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006428 if (mKeyguardDelegate != null) {
6429 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006430 }
John Spurlock13451a22012-09-28 14:40:41 -04006431 if (mStatusBarService != null) {
6432 try {
6433 mStatusBarService.setCurrentUser(newUserId);
6434 } catch (RemoteException e) {
6435 // oh well
6436 }
6437 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006438 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006439 }
6440
6441 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006442 public boolean canMagnifyWindow(int windowType) {
6443 switch (windowType) {
6444 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6445 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6446 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6447 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6448 return false;
6449 }
6450 }
6451 return true;
6452 }
6453
6454 @Override
6455 public boolean isTopLevelWindow(int windowType) {
6456 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6457 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6458 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6459 }
6460 return true;
6461 }
6462
Jim Miller4eeb4f62012-11-08 00:04:29 -08006463 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006464 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006465 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006466 pw.print(" mSystemReady="); pw.print(mSystemReady);
6467 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006468 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006469 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006470 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006471 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006472 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6473 || mForceClearedSystemUiFlags != 0) {
6474 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6475 pw.print(Integer.toHexString(mLastSystemUiFlags));
6476 pw.print(" mResettingSystemUiFlags=0x");
6477 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6478 pw.print(" mForceClearedSystemUiFlags=0x");
6479 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006480 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006481 if (mLastFocusNeedsMenu) {
6482 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6483 pw.println(mLastFocusNeedsMenu);
6484 }
Jeff Browna20dda42014-05-27 20:57:24 -07006485 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6486 pw.println(mWakeGestureEnabledSetting);
6487
Jeff Brownbcdfc622014-03-06 19:13:04 -08006488 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006489 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6490 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006491 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6492 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6493 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6494 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006495 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006496 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006497 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6498 pw.print(mCarDockEnablesAccelerometer);
6499 pw.print(" mDeskDockEnablesAccelerometer=");
6500 pw.println(mDeskDockEnablesAccelerometer);
6501 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6502 pw.print(mLidKeyboardAccessibility);
6503 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006504 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006505 pw.print(prefix);
6506 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6507 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006508 pw.print(prefix);
6509 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6510 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006511 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006512 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6513 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6514 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6515 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6516 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6517 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6518 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006519 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6520 pw.print(","); pw.print(mOverscanScreenTop);
6521 pw.print(") "); pw.print(mOverscanScreenWidth);
6522 pw.print("x"); pw.println(mOverscanScreenHeight);
6523 if (mOverscanLeft != 0 || mOverscanTop != 0
6524 || mOverscanRight != 0 || mOverscanBottom != 0) {
6525 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6526 pw.print(" top="); pw.print(mOverscanTop);
6527 pw.print(" right="); pw.print(mOverscanRight);
6528 pw.print(" bottom="); pw.println(mOverscanBottom);
6529 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006530 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6531 pw.print(mRestrictedOverscanScreenLeft);
6532 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6533 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6534 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006535 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6536 pw.print(","); pw.print(mUnrestrictedScreenTop);
6537 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6538 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6539 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6540 pw.print(","); pw.print(mRestrictedScreenTop);
6541 pw.print(") "); pw.print(mRestrictedScreenWidth);
6542 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006543 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6544 pw.print(","); pw.print(mStableFullscreenTop);
6545 pw.print(")-("); pw.print(mStableFullscreenRight);
6546 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006547 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6548 pw.print(","); pw.print(mStableTop);
6549 pw.print(")-("); pw.print(mStableRight);
6550 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006551 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6552 pw.print(","); pw.print(mSystemTop);
6553 pw.print(")-("); pw.print(mSystemRight);
6554 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006555 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6556 pw.print(","); pw.print(mCurTop);
6557 pw.print(")-("); pw.print(mCurRight);
6558 pw.print(","); pw.print(mCurBottom); pw.println(")");
6559 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6560 pw.print(","); pw.print(mContentTop);
6561 pw.print(")-("); pw.print(mContentRight);
6562 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006563 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6564 pw.print(","); pw.print(mVoiceContentTop);
6565 pw.print(")-("); pw.print(mVoiceContentRight);
6566 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006567 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6568 pw.print(","); pw.print(mDockTop);
6569 pw.print(")-("); pw.print(mDockRight);
6570 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006571 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6572 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006573 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6574 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006575 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6576 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006577 if (mLastInputMethodWindow != null) {
6578 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6579 pw.println(mLastInputMethodWindow);
6580 }
6581 if (mLastInputMethodTargetWindow != null) {
6582 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6583 pw.println(mLastInputMethodTargetWindow);
6584 }
6585 if (mStatusBar != null) {
6586 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006587 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6588 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006589 }
6590 if (mNavigationBar != null) {
6591 pw.print(prefix); pw.print("mNavigationBar=");
6592 pw.println(mNavigationBar);
6593 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006594 if (mFocusedWindow != null) {
6595 pw.print(prefix); pw.print("mFocusedWindow=");
6596 pw.println(mFocusedWindow);
6597 }
6598 if (mFocusedApp != null) {
6599 pw.print(prefix); pw.print("mFocusedApp=");
6600 pw.println(mFocusedApp);
6601 }
6602 if (mWinDismissingKeyguard != null) {
6603 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6604 pw.println(mWinDismissingKeyguard);
6605 }
6606 if (mTopFullscreenOpaqueWindowState != null) {
6607 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6608 pw.println(mTopFullscreenOpaqueWindowState);
6609 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006610 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6611 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6612 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6613 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006614 if (mForcingShowNavBar) {
6615 pw.print(prefix); pw.print("mForcingShowNavBar=");
6616 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6617 pw.println(mForcingShowNavBarLayer);
6618 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006619 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006620 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006621 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6622 pw.print(" mForceStatusBarFromKeyguard=");
6623 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006624 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006625 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006626 pw.print(" mHomePressed="); pw.println(mHomePressed);
6627 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6628 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6629 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6630 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6631 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6632 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6633 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6634 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6635 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6636 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006637 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6638 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6639 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006640
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006641 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006642 mStatusBarController.dump(pw, prefix);
6643 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006644 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006645
Jeff Browna20dda42014-05-27 20:57:24 -07006646 if (mWakeGestureListener != null) {
6647 mWakeGestureListener.dump(pw, prefix);
6648 }
Jeff Brown600f0032014-05-22 17:06:00 -07006649 if (mOrientationListener != null) {
6650 mOrientationListener.dump(pw, prefix);
6651 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006652 if (mBurnInProtectionHelper != null) {
6653 mBurnInProtectionHelper.dump(prefix, pw);
6654 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006655 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006656}