blob: 5eee75da4caf3db1e2b6c1c5cf038ade1157c550 [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
Jeff Brown37df39a92015-02-25 15:42:31 -08002 * Copyright (C) 2006 The Android Open Source Project
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jorim Jaggib10e33f2015-02-04 21:57:40 +010017package com.android.server.policy;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080018
Dianne Hackborna4972e92012-03-14 10:38:05 -070019import android.app.ActivityManager;
Jeff Brown061ea992015-04-17 19:55:47 -070020import android.app.ActivityManagerInternal;
21import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080022import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080023import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040024import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070025import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070026import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040027import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080028import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070029import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080030import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040031import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080032import android.content.ContentResolver;
33import android.content.Context;
34import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070035import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070036import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080037import android.content.pm.ActivityInfo;
38import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040039import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070040import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.content.res.Configuration;
42import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070043import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080044import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080045import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080046import android.graphics.Rect;
John Spurlock7b414672014-07-18 13:02:39 -040047import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080048import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050049import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080050import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070051import android.media.Ringtone;
52import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070053import android.media.session.MediaSessionLegacyHelper;
Mark Renoufc1256912015-03-11 14:38:23 -040054import android.os.Build;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070055import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080056import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070057import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080058import android.os.Handler;
59import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080060import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070061import android.os.Message;
62import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080063import android.os.PowerManager;
64import android.os.RemoteException;
65import android.os.ServiceManager;
66import android.os.SystemClock;
67import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080068import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070069import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080070import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070071import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080072import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070073import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040074import android.service.dreams.DreamService;
75import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070076import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070077import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070078import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080079import android.util.EventLog;
80import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070081import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080082import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070083import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080084import android.view.Gravity;
85import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080086import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080087import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070088import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070089import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080090import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080091import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080092import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080093import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080094import android.view.KeyEvent;
95import android.view.MotionEvent;
Jorim Jaggib10e33f2015-02-04 21:57:40 +010096import android.view.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080097import android.view.Surface;
98import android.view.View;
99import android.view.ViewConfiguration;
Mark Renoufc1256912015-03-11 14:38:23 -0400100import android.view.ViewRootImpl;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800101import android.view.Window;
102import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800103import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700104import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800105import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800106import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800107import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800108import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200109import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800110import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800111import com.android.internal.R;
Craig Mautnerae446592012-12-06 19:05:05 -0800112import com.android.internal.statusbar.IStatusBarService;
Craig Mautnerae446592012-12-06 19:05:05 -0800113import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700114import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100115import com.android.server.policy.keyguard.KeyguardServiceDelegate;
116import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800117
118import java.io.File;
119import java.io.FileReader;
120import java.io.IOException;
121import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700122import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800123import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800124
Dianne Hackbornc652de82013-02-15 16:32:56 -0800125import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700126import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
127import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
128import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700129import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
130import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
131import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800132
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800133/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700134 * WindowManagerPolicy implementation for the Android phone UI. This
135 * introduces a new method suffix, Lp, for an internal lock of the
136 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400137 * can be acquired with either the Lw and Li lock held, so has the restrictions
The Android Open Source Project0727d222009-03-11 12:11:58 -0700138 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800139 */
140public class PhoneWindowManager implements WindowManagerPolicy {
141 static final String TAG = "WindowManager";
142 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700143 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700144 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700145 static final boolean DEBUG_KEYGUARD = false;
146 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700147 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700148 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800149 static final boolean SHOW_STARTING_ANIMATIONS = true;
150 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400151
Daniel Sandler6396c722013-04-16 20:19:09 -0400152 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
153 // No longer recommended for desk docks; still useful in car docks.
154 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
155 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
156
Jeff Brown6d8fd272014-05-20 21:24:38 -0700157 static final int SHORT_PRESS_POWER_NOTHING = 0;
158 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
159 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
160 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800161 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700162
Joe Onoratod208e702010-10-08 16:22:43 -0400163 static final int LONG_PRESS_POWER_NOTHING = 0;
164 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
165 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700166 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700167
Jeff Brown13f00f02014-10-31 14:45:50 -0700168 static final int MULTI_PRESS_POWER_NOTHING = 0;
169 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
170 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
171
Michael Jurka3b1fc472011-06-13 10:54:40 -0700172 // These need to match the documentation/constant in
173 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800174 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800175 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700176 static final int LONG_PRESS_HOME_ASSIST = 2;
177
178 static final int DOUBLE_TAP_HOME_NOTHING = 0;
179 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800180
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000181 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
182 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
183
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700184 static final int APPLICATION_MEDIA_SUBLAYER = -2;
185 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800186 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800187 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700188 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700189
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800190 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
191 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
192 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500193 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700194 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800195
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700196 /**
197 * These are the system UI flags that, when changing, can cause the layout
198 * of the screen to change.
199 */
200 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400201 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400202 | View.SYSTEM_UI_FLAG_FULLSCREEN
203 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200204 | View.NAVIGATION_BAR_TRANSLUCENT
205 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700206
John Spurlock7b414672014-07-18 13:02:39 -0400207 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
208 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
209 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
210 .build();
211
Jim Miller5ecd8112013-01-09 18:50:26 -0800212 /**
213 * Keyguard stuff
214 */
215 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100216 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700217 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800218
Jeff Brown6651a632011-11-28 12:59:11 -0800219 /* Table of Application Launch keys. Maps from key codes to intent categories.
220 *
221 * These are special keys that are used to launch particular kinds of applications,
222 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
223 * usage page. We don't support quite that many yet...
224 */
225 static SparseArray<String> sApplicationLaunchKeyCategories;
226 static {
227 sApplicationLaunchKeyCategories = new SparseArray<String>();
228 sApplicationLaunchKeyCategories.append(
229 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
230 sApplicationLaunchKeyCategories.append(
231 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
232 sApplicationLaunchKeyCategories.append(
233 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
234 sApplicationLaunchKeyCategories.append(
235 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
236 sApplicationLaunchKeyCategories.append(
237 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
238 sApplicationLaunchKeyCategories.append(
239 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
240 }
241
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700242 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
243 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
244
Dianne Hackborndf89e652011-10-06 22:35:11 -0700245 /**
246 * Lock protecting internal state. Must not call out into window
247 * manager with lock held. (This lock will be acquired in places
248 * where the window manager is calling in with its own lock held.)
249 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800250 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700251
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800252 Context mContext;
253 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700254 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700255 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700256 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700257 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700258 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400259 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700260 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700261 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800262 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700263 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800264 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000265 BurnInProtectionHelper mBurnInProtectionHelper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800266
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700267 // Vibrator pattern for haptic feedback of a long press.
268 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700269
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700270 // Vibrator pattern for haptic feedback of virtual key press.
271 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700272
Amith Yamasanic33cb712010-02-10 15:21:49 -0800273 // Vibrator pattern for a short vibration.
274 long[] mKeyboardTapVibePattern;
275
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700276 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
277 long[] mClockTickVibePattern;
278
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700279 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
280 long[] mCalendarDateVibePattern;
281
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700282 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
283 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700284
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700285 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
286 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700287
Mady Mellore82067b2015-04-30 09:58:35 -0700288 // Vibrator pattern for haptic feedback of a stylus button press.
289 long[] mStylusButtonPressVibePattern;
290
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800291 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
292 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400293
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800294 boolean mSafeMode;
295 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700296 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400297 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400298 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700299 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400300 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
301 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
302 int[] mNavigationBarHeightForRotation = new int[4];
303 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400304
Craig Mautnera631d492014-08-05 15:16:01 -0700305 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800306 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700307 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700308 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700309 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700310 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
311 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
312 }
313 };
314 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
315 @Override
316 public void onShown(IBinder windowToken) {
317 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
318 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
319 }
320 };
321
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800322 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800323 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900324 WindowState mLastInputMethodWindow = null;
325 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800326
Jeff Brown13f00f02014-10-31 14:45:50 -0700327 // FIXME This state is shared between the input reader and handler thread.
328 // Technically it's broken and buggy but it has been like this for many years
329 // and we have not yet seen any problems. Someday we'll rewrite this logic
330 // so that only one thread is involved in handling input policy. Unfortunately
331 // it's on a critical path for power management so we can't just post the work to the
332 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
333 // to hold wakelocks during dispatch and eliminating the critical path.
334 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800335 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700336 volatile int mPowerKeyPressCounter;
337 volatile boolean mEndCallKeyHandled;
338
Winson Chungd42a6cf2014-06-03 16:24:04 -0700339 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700340 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700341 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800342
Jeff Brown2e7760e2012-04-11 15:14:55 -0700343 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700344 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700345 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800346
Dianne Hackbornc777e072010-02-12 13:07:59 -0800347 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700348 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800349 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700350 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400351 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700352 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700353 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400354 int mCarDockRotation;
355 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700356 int mUndockedHdmiRotation;
357 int mDemoHdmiRotation;
358 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800359 int mDemoRotation;
360 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400361
Jeff Browna20dda42014-05-27 20:57:24 -0700362 boolean mWakeGestureEnabledSetting;
363 MyWakeGestureListener mWakeGestureListener;
364
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700365 // Default display does not rotate, apps that require non-default orientation will have to
366 // have the orientation emulated.
367 private boolean mForceDefaultOrientation = false;
368
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400369 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
370 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700371 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400372
Jeff Brownbcdfc622014-03-06 19:13:04 -0800373 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700374 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400375 boolean mCarDockEnablesAccelerometer;
376 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700377 int mLidKeyboardAccessibility;
378 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700379 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700380 int mShortPressOnPowerBehavior;
381 int mLongPressOnPowerBehavior;
382 int mDoublePressOnPowerBehavior;
383 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000384 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700385 boolean mAwake;
386 boolean mScreenOnEarly;
387 boolean mScreenOnFully;
388 ScreenOnListener mScreenOnListener;
389 boolean mKeyguardDrawComplete;
390 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800391 boolean mOrientationSensorEnabled = false;
392 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800393 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400394 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800395 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700396
Jeff Brown70825162012-03-28 17:27:48 -0700397 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800398
399 // The last window we were told about in focusChanged.
400 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800401 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800402
Jeff Brown70825162012-03-28 17:27:48 -0700403 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800404
Dianne Hackbornc652de82013-02-15 16:32:56 -0800405 // The current size of the screen; really; extends into the overscan area of
406 // the screen and doesn't account for any system elements like the status bar.
407 int mOverscanScreenLeft, mOverscanScreenTop;
408 int mOverscanScreenWidth, mOverscanScreenHeight;
409 // The current visible size of the screen; really; (ir)regardless of whether the status
410 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800411 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
412 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800413 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
414 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
415 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700416 // The current size of the screen; these may be different than (0,0)-(dw,dh)
417 // if the status bar can't be hidden; in that case it effectively carves out
418 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800419 int mRestrictedScreenLeft, mRestrictedScreenTop;
420 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700421 // During layout, the current screen borders accounting for any currently
422 // visible system UI elements.
423 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700424 // For applications requesting stable content insets, these are them.
425 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700426 // For applications requesting stable content insets but have also set the
427 // fullscreen window flag, these are the stable dimensions without the status bar.
428 int mStableFullscreenLeft, mStableFullscreenTop;
429 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800430 // During layout, the current screen borders with all outer decoration
431 // (status bar, input method dock) accounted for.
432 int mCurLeft, mCurTop, mCurRight, mCurBottom;
433 // During layout, the frame in which content should be displayed
434 // to the user, accounting for all screen decoration except for any
435 // space they deem as available for other content. This is usually
436 // the same as mCur*, but may be larger if the screen decor has supplied
437 // content insets.
438 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700439 // During layout, the frame in which voice content should be displayed
440 // to the user, accounting for all screen decoration except for any
441 // space they deem as available for other content.
442 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800443 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800444 // windows are placed.
445 int mDockLeft, mDockTop, mDockRight, mDockBottom;
446 // During layout, the layer at which the doc window is placed.
447 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700448 // During layout, this is the layer of the status bar.
449 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700450 int mLastSystemUiFlags;
451 // Bits that we are in the process of clearing, so we want to prevent
452 // them from being set by applications until everything has been updated
453 // to have them clear.
454 int mResettingSystemUiFlags = 0;
455 // Bits that we are currently always keeping cleared.
456 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800457 // What we last reported to system UI about whether the compatibility
458 // menu needs to be displayed.
459 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700460
461 FakeWindow mHideNavFakeWindow = null;
462
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800463 static final Rect mTmpParentFrame = new Rect();
464 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800465 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800466 static final Rect mTmpContentFrame = new Rect();
467 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400468 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700469 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700470 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700471
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800472 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100473 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700474 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200475 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400476 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800477 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700478 boolean mForceStatusBarFromKeyguard;
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() {
1223 return mContext.getResources().getBoolean(com.android.internal.R.bool.config_windowIsRound)
1224 || (Build.HARDWARE.contains("goldfish")
1225 && SystemProperties.getBoolean(ViewRootImpl.PROPERTY_EMULATOR_CIRCULAR, false));
1226 }
1227
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001228 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001229 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001230 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001231 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001232 mContext = context;
1233 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001234 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001235 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001236 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001237 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Mark Renoufc1256912015-03-11 14:38:23 -04001238
1239 // Init display burn-in protection
1240 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1241 com.android.internal.R.bool.config_enableBurnInProtection);
1242 // Allow a system property to override this. Used by developer settings.
1243 boolean burnInProtectionDevMode =
1244 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1245 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1246 final int minHorizontal;
1247 final int maxHorizontal;
1248 final int minVertical;
1249 final int maxVertical;
1250 final int maxRadius;
1251 if (burnInProtectionDevMode) {
1252 minHorizontal = -8;
1253 maxHorizontal = 8;
1254 minVertical = -8;
1255 maxVertical = -4;
1256 maxRadius = (isRoundWindow()) ? 6 : -1;
1257 } else {
1258 Resources resources = context.getResources();
1259 minHorizontal = resources.getInteger(
1260 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1261 maxHorizontal = resources.getInteger(
1262 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1263 minVertical = resources.getInteger(
1264 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1265 maxVertical = resources.getInteger(
1266 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1267 maxRadius = resources.getInteger(
1268 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1269 }
1270 mBurnInProtectionHelper = new BurnInProtectionHelper(
1271 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001272 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001273
Jeff Brown70825162012-03-28 17:27:48 -07001274 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001275 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001276 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001277 try {
1278 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1279 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001280 mSettingsObserver = new SettingsObserver(mHandler);
1281 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001282 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001283 mUiMode = context.getResources().getInteger(
1284 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001285 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1286 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1287 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1288 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001289 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1290 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1291 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1292 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1293 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1294 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1295 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1296 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001297
Jeff Brown96307042012-07-27 15:51:34 -07001298 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1299 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001300 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001301 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1302 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001303 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001304 mSupportAutoRotation = mContext.getResources().getBoolean(
1305 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001306 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001307 com.android.internal.R.integer.config_lidOpenRotation);
1308 mCarDockRotation = readRotation(
1309 com.android.internal.R.integer.config_carDockRotation);
1310 mDeskDockRotation = readRotation(
1311 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001312 mUndockedHdmiRotation = readRotation(
1313 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001314 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1315 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1316 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1317 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001318 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1319 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1320 mLidNavigationAccessibility = mContext.getResources().getInteger(
1321 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001322 mLidControlsSleep = mContext.getResources().getBoolean(
1323 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001324 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1325 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001326
1327 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1328 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1329 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1330 || mContext.getResources().getBoolean(
1331 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1332 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1333 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001334 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1335 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001336 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1337 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1338 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1339 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1340 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1341 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1342
Bryce Lee55e846d2014-11-04 12:43:44 -08001343 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1344 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1345
Bryce Leed3b28402015-03-09 15:49:13 +00001346 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1347 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1348
Jeff Brown13f00f02014-10-31 14:45:50 -07001349 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1350 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1351 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1352 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1353 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1354 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1355 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1356 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001357 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1358 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001359
John Spurlock61560172015-02-06 19:46:04 -05001360 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001361
Jeff Brownf71343d2013-05-31 17:59:11 -07001362 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001363
Svetoslav8e3feb12014-02-24 13:46:47 -08001364 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1365 Context.ACCESSIBILITY_SERVICE);
1366
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001367 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001368 IntentFilter filter = new IntentFilter();
1369 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1370 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1371 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1372 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001373 filter.addAction(Intent.ACTION_DOCK_EVENT);
1374 Intent intent = context.registerReceiver(mDockReceiver, filter);
1375 if (intent != null) {
1376 // Retrieve current sticky dock event broadcast.
1377 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1378 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1379 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001380
Jeff Brown6aaf2952012-10-05 16:01:08 -07001381 // register for dream-related broadcasts
1382 filter = new IntentFilter();
1383 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1384 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1385 context.registerReceiver(mDreamReceiver, filter);
1386
Christopher Tate5e08af02012-09-21 17:17:22 -07001387 // register for multiuser-relevant broadcasts
1388 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1389 context.registerReceiver(mMultiuserReceiver, filter);
1390
John Spurlock57306e62013-04-22 09:48:49 -04001391 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001392 mSystemGestures = new SystemGesturesPointerEventListener(context,
1393 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001394 @Override
1395 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001396 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001397 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001398 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001399 }
1400 @Override
1401 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001402 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001403 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001404 }
1405 }
1406 @Override
1407 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001408 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001409 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001410 }
1411 }
1412 @Override
1413 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001414 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001415 }
Adrian Roos3595be42015-03-05 16:31:15 +01001416 @Override
1417 public void onDown() {
1418 mOrientationListener.onTouchStart();
1419 }
1420 @Override
1421 public void onUpOrCancel() {
1422 mOrientationListener.onTouchEnd();
1423 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001424 });
John Spurlockf1a36642013-10-12 17:50:42 -04001425 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001426 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001427
Jeff Brownc2346132012-04-13 01:55:38 -07001428 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001429 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1430 com.android.internal.R.array.config_longPressVibePattern);
1431 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1432 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001433 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1434 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001435 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1436 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001437 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1438 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001439 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1440 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1441 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1442 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore82067b2015-04-30 09:58:35 -07001443 mStylusButtonPressVibePattern = getLongIntArray(mContext.getResources(),
1444 com.android.internal.R.array.config_stylusButtonPressVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001445
Christopher Tatee90585f2012-03-05 18:56:25 -08001446 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1447 com.android.internal.R.bool.config_enableScreenshotChord);
1448
Justin Kohd378ad72013-04-01 12:18:26 -07001449 mGlobalKeyManager = new GlobalKeyManager(mContext);
1450
Joe Onoratoea495d42011-04-06 11:41:11 -07001451 // Controls rotation and the like.
1452 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001453
1454 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001455 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001456 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001457 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001458
1459 mWindowManagerInternal.registerAppTransitionListener(
1460 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001461 }
1462
Jeff Brownf71343d2013-05-31 17:59:11 -07001463 /**
1464 * Read values from config.xml that may be overridden depending on
1465 * the configuration of the device.
1466 * eg. Disable long press on home goes to recents on sw600dp.
1467 */
1468 private void readConfigurationDependentBehaviors() {
1469 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1470 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1471 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1472 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1473 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1474 }
1475
1476 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1477 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1478 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1479 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1480 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1481 }
1482 }
1483
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001484 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001485 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001486 // This method might be called before the policy has been fully initialized
1487 // or for other displays we don't care about.
1488 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1489 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001490 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001491 mDisplay = display;
1492
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001493 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001494 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001495 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001496 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001497 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001498 mLandscapeRotation = Surface.ROTATION_0;
1499 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001500 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001501 mPortraitRotation = Surface.ROTATION_90;
1502 mUpsideDownRotation = Surface.ROTATION_270;
1503 } else {
1504 mPortraitRotation = Surface.ROTATION_270;
1505 mUpsideDownRotation = Surface.ROTATION_90;
1506 }
1507 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001508 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001509 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001510 mPortraitRotation = Surface.ROTATION_0;
1511 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001512 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001513 mLandscapeRotation = Surface.ROTATION_270;
1514 mSeascapeRotation = Surface.ROTATION_90;
1515 } else {
1516 mLandscapeRotation = Surface.ROTATION_90;
1517 mSeascapeRotation = Surface.ROTATION_270;
1518 }
1519 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001520
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001521 mStatusBarHeight =
1522 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001523
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001524 // Height of the navigation bar when presented horizontally at bottom
1525 mNavigationBarHeightForRotation[mPortraitRotation] =
1526 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001527 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001528 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001529 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1530 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001531
1532 // Width of the navigation bar when presented vertically along one side
1533 mNavigationBarWidthForRotation[mPortraitRotation] =
1534 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1535 mNavigationBarWidthForRotation[mLandscapeRotation] =
1536 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001537 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001538
1539 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001540 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001541 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001542
Devin Kimd7b12b42014-05-05 14:34:58 -07001543 // Allow the navigation bar to move on non-square small devices (phones).
1544 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001545
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001546 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001547 // Allow a system property to override this. Used by the emulator.
1548 // See also hasNavigationBar().
1549 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1550 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001551 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001552 } else if ("0".equals(navBarOverride)) {
1553 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001554 }
1555
Jeff Brown27f1d672012-10-17 18:32:34 -07001556 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1557 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001558 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001559 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001560 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001561 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001562 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001563 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001564
Chong Zhangae6119ff2014-11-11 18:54:39 -08001565 // For demo purposes, allow the rotation of the remote display to be controlled.
1566 // By default, remote display locks rotation to landscape.
1567 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1568 mDemoRotation = mPortraitRotation;
1569 } else {
1570 mDemoRotation = mLandscapeRotation;
1571 }
1572 mDemoRotationLock = SystemProperties.getBoolean(
1573 "persist.demo.rotationlock", false);
1574
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001575 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1576 // http://developer.android.com/guide/practices/screens_support.html#range
1577 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1578 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1579 // For debug purposes the next line turns this feature off with:
1580 // $ adb shell setprop config.override_forced_orient true
1581 // $ adb shell wm size reset
1582 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1583 }
1584
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001585 /**
1586 * @return whether the navigation bar can be hidden, e.g. the device has a
1587 * navigation bar and touch exploration is not enabled
1588 */
1589 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001590 return mHasNavigationBar
1591 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001592 }
1593
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001594 @Override
1595 public boolean isDefaultOrientationForced() {
1596 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001597 }
1598
Dianne Hackbornc652de82013-02-15 16:32:56 -08001599 @Override
1600 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1601 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1602 mOverscanLeft = left;
1603 mOverscanTop = top;
1604 mOverscanRight = right;
1605 mOverscanBottom = bottom;
1606 }
1607 }
1608
Dianne Hackbornc777e072010-02-12 13:07:59 -08001609 public void updateSettings() {
1610 ContentResolver resolver = mContext.getContentResolver();
1611 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001612 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001613 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001614 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001615 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1616 UserHandle.USER_CURRENT);
1617 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001618 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001619 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1620 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001621
Jeff Browna20dda42014-05-27 20:57:24 -07001622 // Configure wake gesture.
1623 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1624 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1625 UserHandle.USER_CURRENT) != 0;
1626 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1627 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1628 updateWakeGestureListenerLp();
1629 }
1630
Jeff Brown207673cd2012-06-05 17:47:11 -07001631 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001632 int userRotation = Settings.System.getIntForUser(resolver,
1633 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1634 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001635 if (mUserRotation != userRotation) {
1636 mUserRotation = userRotation;
1637 updateRotation = true;
1638 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001639 int userRotationMode = Settings.System.getIntForUser(resolver,
1640 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001641 WindowManagerPolicy.USER_ROTATION_FREE :
1642 WindowManagerPolicy.USER_ROTATION_LOCKED;
1643 if (mUserRotationMode != userRotationMode) {
1644 mUserRotationMode = userRotationMode;
1645 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001646 updateOrientationListenerLp();
1647 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001648
Dianne Hackbornc777e072010-02-12 13:07:59 -08001649 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001650 int pointerLocation = Settings.System.getIntForUser(resolver,
1651 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001652 if (mPointerLocationMode != pointerLocation) {
1653 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001654 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1655 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001656 }
1657 }
1658 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001659 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1660 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1661 String imId = Settings.Secure.getStringForUser(resolver,
1662 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001663 boolean hasSoftInput = imId != null && imId.length() > 0;
1664 if (mHasSoftInput != hasSoftInput) {
1665 mHasSoftInput = hasSoftInput;
1666 updateRotation = true;
1667 }
John Spurlockf1a36642013-10-12 17:50:42 -04001668 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001669 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001670 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001671 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001672 }
1673 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001674 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001675 }
Jeff Brown70825162012-03-28 17:27:48 -07001676 }
1677
Jeff Browna20dda42014-05-27 20:57:24 -07001678 private void updateWakeGestureListenerLp() {
1679 if (shouldEnableWakeGestureLp()) {
1680 mWakeGestureListener.requestWakeUpTrigger();
1681 } else {
1682 mWakeGestureListener.cancelWakeUpTrigger();
1683 }
1684 }
1685
1686 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001687 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001688 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1689 && mWakeGestureListener.isSupported();
1690 }
1691
Jeff Brown70825162012-03-28 17:27:48 -07001692 private void enablePointerLocation() {
1693 if (mPointerLocationView == null) {
1694 mPointerLocationView = new PointerLocationView(mContext);
1695 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001696 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1697 WindowManager.LayoutParams.MATCH_PARENT,
1698 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001699 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001700 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1701 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1702 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1703 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001704 if (ActivityManager.isHighEndGfx()) {
1705 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1706 lp.privateFlags |=
1707 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1708 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001709 lp.format = PixelFormat.TRANSLUCENT;
1710 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001711 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001712 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001713 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001714 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001715 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001716 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001717 }
Jeff Brown70825162012-03-28 17:27:48 -07001718
1719 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001720 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001721 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1722 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001723 wm.removeView(mPointerLocationView);
1724 mPointerLocationView = null;
1725 }
1726 }
1727
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001728 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001729 try {
1730 int rotation = mContext.getResources().getInteger(resID);
1731 switch (rotation) {
1732 case 0:
1733 return Surface.ROTATION_0;
1734 case 90:
1735 return Surface.ROTATION_90;
1736 case 180:
1737 return Surface.ROTATION_180;
1738 case 270:
1739 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001740 }
1741 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001742 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001743 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001744 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001745 }
1746
1747 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001748 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001749 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001750 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001751
1752 outAppOp[0] = AppOpsManager.OP_NONE;
1753
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001754 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1755 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1756 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1757 return WindowManagerGlobal.ADD_INVALID_TYPE;
1758 }
1759
1760 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1761 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001762 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001763 }
1764 String permission = null;
1765 switch (type) {
1766 case TYPE_TOAST:
1767 // XXX right now the app process has complete control over
1768 // this... should introduce a token to let the system
1769 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001770 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001771 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001772 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001773 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001774 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001775 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001776 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001777 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001778 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001779 break;
1780 case TYPE_PHONE:
1781 case TYPE_PRIORITY_PHONE:
1782 case TYPE_SYSTEM_ALERT:
1783 case TYPE_SYSTEM_ERROR:
1784 case TYPE_SYSTEM_OVERLAY:
1785 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001786 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001787 break;
1788 default:
1789 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1790 }
1791 if (permission != null) {
1792 if (mContext.checkCallingOrSelfPermission(permission)
1793 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001794 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001795 }
1796 }
Jeff Brown98365d72012-08-19 20:30:52 -07001797 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001798 }
Craig Mautner88400d32012-09-30 12:35:45 -07001799
1800 @Override
1801 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1802
1803 // If this switch statement is modified, modify the comment in the declarations of
1804 // the type in {@link WindowManager.LayoutParams} as well.
1805 switch (attrs.type) {
1806 default:
1807 // These are the windows that by default are shown only to the user that created
1808 // them. If this needs to be overridden, set
1809 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1810 // {@link WindowManager.LayoutParams}. Note that permission
1811 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1812 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1813 return true;
1814 }
1815 break;
1816
1817 // These are the windows that by default are shown to all users. However, to
1818 // protect against spoofing, check permissions below.
1819 case TYPE_APPLICATION_STARTING:
1820 case TYPE_BOOT_PROGRESS:
1821 case TYPE_DISPLAY_OVERLAY:
1822 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001823 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001824 case TYPE_KEYGUARD_DIALOG:
1825 case TYPE_MAGNIFICATION_OVERLAY:
1826 case TYPE_NAVIGATION_BAR:
1827 case TYPE_NAVIGATION_BAR_PANEL:
1828 case TYPE_PHONE:
1829 case TYPE_POINTER:
1830 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001831 case TYPE_SEARCH_BAR:
1832 case TYPE_STATUS_BAR:
1833 case TYPE_STATUS_BAR_PANEL:
1834 case TYPE_STATUS_BAR_SUB_PANEL:
1835 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001836 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001837 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001838 break;
1839 }
1840
1841 // Check if third party app has set window to system window type.
1842 return mContext.checkCallingOrSelfPermission(
1843 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1844 != PackageManager.PERMISSION_GRANTED;
1845 }
1846
Craig Mautner967212c2013-04-13 21:10:58 -07001847 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001848 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1849 switch (attrs.type) {
1850 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001851 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001852 // These types of windows can't receive input events.
1853 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1854 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001855 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001856 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001857 case TYPE_STATUS_BAR:
1858
1859 // If the Keyguard is in a hidden state (occluded by another window), we force to
1860 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1861 // the keyguard as occluded wouldn't set these flags again.
1862 // See {@link #processKeyguardSetHiddenResultLw}.
1863 if (mKeyguardHidden) {
1864 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1865 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1866 }
1867 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001868 }
Adrian Roos38502112014-04-09 21:04:11 +02001869
1870 if (attrs.type != TYPE_STATUS_BAR) {
1871 // The status bar is the only window allowed to exhibit keyguard behavior.
1872 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1873 }
Adrian Roosea562512014-05-05 13:33:03 +02001874
1875 if (ActivityManager.isHighEndGfx()
1876 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001877 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001878 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1879 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001880 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001881
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001882 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001883 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001884 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001885
Michael Wright3818c922014-09-02 13:59:07 -07001886 private void readCameraLensCoverState() {
1887 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1888 }
1889
Jeff Browndaa37532012-05-01 15:54:03 -07001890 private boolean isHidden(int accessibilityMode) {
1891 switch (accessibilityMode) {
1892 case 1:
1893 return mLidState == LID_CLOSED;
1894 case 2:
1895 return mLidState == LID_OPEN;
1896 default:
1897 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001898 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001899 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001900
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001901 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001902 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001903 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1904 int navigationPresence) {
1905 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1906
Jeff Brownf71343d2013-05-31 17:59:11 -07001907 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001908 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001909 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001910
Jeff Browndaa37532012-05-01 15:54:03 -07001911 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1912 || (keyboardPresence == PRESENCE_INTERNAL
1913 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001914 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001915 if (!mHasSoftInput) {
1916 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1917 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001918 }
1919
Jeff Browndaa37532012-05-01 15:54:03 -07001920 if (config.navigation == Configuration.NAVIGATION_NONAV
1921 || (navigationPresence == PRESENCE_INTERNAL
1922 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001923 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001924 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001925 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001926
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001927 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001928 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001929 public int windowTypeToLayerLw(int type) {
1930 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001931 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001932 }
1933 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001934 case TYPE_PRIVATE_PRESENTATION:
1935 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001936 case TYPE_WALLPAPER:
1937 // wallpaper is at the bottom, though the window manager may move it.
1938 return 2;
1939 case TYPE_PHONE:
1940 return 3;
1941 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07001942 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001943 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001944 case TYPE_VOICE_INTERACTION:
1945 // voice interaction layer is almost immediately above apps.
1946 return 5;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001947 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001948 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001949 case TYPE_TOAST:
1950 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001951 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001952 case TYPE_PRIORITY_PHONE:
1953 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001954 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001955 case TYPE_DREAM:
1956 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001957 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001958 case TYPE_SYSTEM_ALERT:
1959 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001960 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001961 case TYPE_INPUT_METHOD:
1962 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001963 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001964 case TYPE_INPUT_METHOD_DIALOG:
1965 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001966 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001967 case TYPE_KEYGUARD_SCRIM:
1968 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001969 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001970 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001971 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001972 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001973 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001974 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001975 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001976 case TYPE_KEYGUARD_DIALOG:
1977 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001978 case TYPE_VOLUME_OVERLAY:
1979 // the on-screen volume indicator and controller shown when the user
1980 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001981 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001982 case TYPE_SYSTEM_OVERLAY:
1983 // the on-screen volume indicator and controller shown when the user
1984 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001985 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001986 case TYPE_NAVIGATION_BAR:
1987 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001988 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001989 case TYPE_NAVIGATION_BAR_PANEL:
1990 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001991 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001992 case TYPE_SYSTEM_ERROR:
1993 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001994 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001995 case TYPE_MAGNIFICATION_OVERLAY:
1996 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001997 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001998 case TYPE_DISPLAY_OVERLAY:
1999 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002000 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002001 case TYPE_DRAG:
2002 // the drag layer: input for drag-and-drop is associated with this window,
2003 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002004 return 25;
Svetoslav3a5c7212014-10-14 09:54:26 -07002005 case TYPE_ACCESSIBILITY_OVERLAY:
2006 // overlay put by accessibility services to intercept user interaction
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002007 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002008 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002009 return 27;
Svetoslav3a5c7212014-10-14 09:54:26 -07002010 case TYPE_BOOT_PROGRESS:
2011 return 28;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002012 case TYPE_POINTER:
2013 // the (mouse) pointer layer
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002014 return 29;
Svetoslav3a5c7212014-10-14 09:54:26 -07002015 case TYPE_HIDDEN_NAV_CONSUMER:
2016 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002017 }
2018 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002019 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002020 }
2021
2022 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002023 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002024 public int subWindowTypeToLayerLw(int type) {
2025 switch (type) {
2026 case TYPE_APPLICATION_PANEL:
2027 case TYPE_APPLICATION_ATTACHED_DIALOG:
2028 return APPLICATION_PANEL_SUBLAYER;
2029 case TYPE_APPLICATION_MEDIA:
2030 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002031 case TYPE_APPLICATION_MEDIA_OVERLAY:
2032 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002033 case TYPE_APPLICATION_SUB_PANEL:
2034 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002035 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2036 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002037 }
2038 Log.e(TAG, "Unknown sub-window type: " + type);
2039 return 0;
2040 }
2041
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002042 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002043 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002044 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002045 }
2046
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002047 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002048 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002049 if (mHasNavigationBar) {
2050 // For a basic navigation bar, when we are in landscape mode we place
2051 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002052 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2053 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002054 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002055 }
2056 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002057 }
2058
Jose Lima9546b202014-07-02 17:21:51 -07002059 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002060 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002061 if (mHasNavigationBar) {
2062 // For a basic navigation bar, when we are in portrait mode we place
2063 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002064 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2065 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002066 }
2067 }
2068 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002069 }
2070
Jose Lima9546b202014-07-02 17:21:51 -07002071 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002072 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2073 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002074 }
2075
Jose Lima9546b202014-07-02 17:21:51 -07002076 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002077 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002078 // There is a separate status bar at the top of the display. We don't count that as part
2079 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002080 // we do want to exclude it since applications can't generally use that part
2081 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002082 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002083 }
2084
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002085 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002086 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2087 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002088 (isKeyguardHostWindow(attrs) &&
2089 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002090 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002091 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002092
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002093 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002094 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2095 return attrs.type == TYPE_STATUS_BAR;
2096 }
2097
2098 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002099 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002100 switch (attrs.type) {
2101 case TYPE_STATUS_BAR:
2102 case TYPE_NAVIGATION_BAR:
2103 case TYPE_WALLPAPER:
2104 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002105 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002106 return false;
2107 default:
2108 return true;
2109 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002110 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002111
Craig Mautner7d7808f2014-09-11 18:02:38 -07002112 @Override
2113 public WindowState getWinShowWhenLockedLw() {
2114 return mWinShowWhenLocked;
2115 }
2116
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002117 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002118 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002119 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2120 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002121 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002122 if (!SHOW_STARTING_ANIMATIONS) {
2123 return null;
2124 }
2125 if (packageName == null) {
2126 return null;
2127 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002128
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002129 WindowManager wm = null;
2130 View view = null;
2131
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002132 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002133 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002134 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2135 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2136 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002137 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002138 try {
2139 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002140 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002141 } catch (PackageManager.NameNotFoundException e) {
2142 // Ignore
2143 }
2144 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002145
Jorim Jaggib10e33f2015-02-04 21:57:40 +01002146 Window win = new PhoneWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002147 final TypedArray ta = win.getWindowStyle();
2148 if (ta.getBoolean(
2149 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2150 || ta.getBoolean(
2151 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002152 return null;
2153 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002154
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002155 Resources r = context.getResources();
2156 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002157
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002158 win.setType(
2159 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002160
2161 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2162 // Assumes it's safe to show starting windows of launched apps while
2163 // the keyguard is being hidden. This is okay because starting windows never show
2164 // secret information.
2165 if (mKeyguardHidden) {
2166 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2167 }
2168 }
2169
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002170 // Force the window flags: this is a fake window, so it is not really
2171 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2172 // flag because we do know that the next window will take input
2173 // focus, so we want to get the IME window up on top of us right away.
2174 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002175 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002176 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2177 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2178 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002179 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002180 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2181 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2182 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002183
Adam Powell04fe6eb2013-05-31 14:39:48 -07002184 win.setDefaultIcon(icon);
2185 win.setDefaultLogo(logo);
2186
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002187 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002188 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002189
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002190 final WindowManager.LayoutParams params = win.getAttributes();
2191 params.token = appToken;
2192 params.packageName = packageName;
2193 params.windowAnimations = win.getWindowStyle().getResourceId(
2194 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002195 params.privateFlags |=
2196 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002197 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002198
2199 if (!compatInfo.supportsScreen()) {
2200 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2201 }
2202
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002203 params.setTitle("Starting " + packageName);
2204
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002205 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2206 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002207
2208 if (win.isFloating()) {
2209 // Whoops, there is no way to display an animation/preview
2210 // of such a thing! After all that work... let's skip it.
2211 // (Note that we must do this here because it is in
2212 // getDecorView() where the theme is evaluated... maybe
2213 // we should peek the floating attribute from the theme
2214 // earlier.)
2215 return null;
2216 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002217
Craig Mautner6fbda632012-07-03 09:26:39 -07002218 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002219 TAG, "Adding starting window for " + packageName
2220 + " / " + appToken + ": "
2221 + (view.getParent() != null ? view : null));
2222
2223 wm.addView(view, params);
2224
2225 // Only return the view if it was successfully added to the
2226 // window manager... which we can tell by it having a parent.
2227 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002228 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002229 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002230 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2231 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002232 } catch (RuntimeException e) {
2233 // don't crash if something else bad happens, for example a
2234 // failure loading resources because we are loading from an app
2235 // on external storage that has been unmounted.
2236 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002237 } finally {
2238 if (view != null && view.getParent() == null) {
2239 Log.w(TAG, "view not successfully added to wm, removing view");
2240 wm.removeViewImmediate(view);
2241 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002242 }
2243
2244 return null;
2245 }
2246
2247 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002248 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002249 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002250 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2251 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002252
2253 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002254 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002255 wm.removeView(window);
2256 }
2257 }
2258
2259 /**
2260 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002261 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002262 * Currently enforces that three window types are singletons:
2263 * <ul>
2264 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002265 * <li>KEYGUARD_TYPE</li>
2266 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002267 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002268 * @param win The window to be added
2269 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002270 *
Jeff Brown98365d72012-08-19 20:30:52 -07002271 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2272 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002273 */
Jose Lima9546b202014-07-02 17:21:51 -07002274 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002275 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2276 switch (attrs.type) {
2277 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002278 mContext.enforceCallingOrSelfPermission(
2279 android.Manifest.permission.STATUS_BAR_SERVICE,
2280 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002281 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002282 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002283 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002284 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002285 }
2286 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002287 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002288 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002289 case TYPE_NAVIGATION_BAR:
2290 mContext.enforceCallingOrSelfPermission(
2291 android.Manifest.permission.STATUS_BAR_SERVICE,
2292 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002293 if (mNavigationBar != null) {
2294 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002295 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002296 }
2297 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002298 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002299 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002300 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002301 break;
Jim Millere898ac52012-04-06 17:10:57 -07002302 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002303 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002304 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002305 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002306 mContext.enforceCallingOrSelfPermission(
2307 android.Manifest.permission.STATUS_BAR_SERVICE,
2308 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002309 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002310 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002311 if (mKeyguardScrim != null) {
2312 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2313 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002314 mKeyguardScrim = win;
2315 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002316 }
Jeff Brown98365d72012-08-19 20:30:52 -07002317 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002318 }
2319
2320 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002321 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002322 public void removeWindowLw(WindowState win) {
2323 if (mStatusBar == win) {
2324 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002325 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002326 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002327 } else if (mKeyguardScrim == win) {
2328 Log.v(TAG, "Removing keyguard scrim");
2329 mKeyguardScrim = null;
2330 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002331 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002332 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002333 }
2334 }
2335
2336 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002337
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002338 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002339 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002340 public int selectAnimationLw(WindowState win, int transit) {
2341 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2342 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002343 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002344 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002345 if (transit == TRANSIT_EXIT
2346 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002347 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002348 } else if (transit == TRANSIT_ENTER
2349 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002350 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002351 }
2352 } else if (win == mNavigationBar) {
2353 // This can be on either the bottom or the right.
2354 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002355 if (transit == TRANSIT_EXIT
2356 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002357 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002358 } else if (transit == TRANSIT_ENTER
2359 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002360 return R.anim.dock_bottom_enter;
2361 }
2362 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002363 if (transit == TRANSIT_EXIT
2364 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002365 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002366 } else if (transit == TRANSIT_ENTER
2367 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002368 return R.anim.dock_right_enter;
2369 }
2370 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002371 }
2372
2373 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002374 if (win.hasAppShownWindows()) {
2375 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2376 return com.android.internal.R.anim.app_starting_exit;
2377 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002378 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002379 && transit == TRANSIT_ENTER) {
2380 // Special case: we are animating in a dream, while the keyguard
2381 // is shown. We don't want an animation on the dream, because
2382 // we need it shown immediately with the keyguard animating away
2383 // to reveal it.
2384 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002385 }
2386
2387 return 0;
2388 }
2389
Craig Mautner3c174372013-02-21 17:54:37 -08002390 @Override
2391 public void selectRotationAnimationLw(int anim[]) {
2392 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2393 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2394 + (mTopFullscreenOpaqueWindowState == null ?
2395 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2396 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2397 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2398 case ROTATION_ANIMATION_CROSSFADE:
2399 anim[0] = R.anim.rotation_animation_xfade_exit;
2400 anim[1] = R.anim.rotation_animation_enter;
2401 break;
2402 case ROTATION_ANIMATION_JUMPCUT:
2403 anim[0] = R.anim.rotation_animation_jump_exit;
2404 anim[1] = R.anim.rotation_animation_enter;
2405 break;
2406 case ROTATION_ANIMATION_ROTATE:
2407 default:
2408 anim[0] = anim[1] = 0;
2409 break;
2410 }
2411 } else {
2412 anim[0] = anim[1] = 0;
2413 }
2414 }
2415
2416 @Override
2417 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2418 boolean forceDefault) {
2419 switch (exitAnimId) {
2420 case R.anim.rotation_animation_xfade_exit:
2421 case R.anim.rotation_animation_jump_exit:
2422 // These are the only cases that matter.
2423 if (forceDefault) {
2424 return false;
2425 }
2426 int anim[] = new int[2];
2427 selectRotationAnimationLw(anim);
2428 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2429 default:
2430 return true;
2431 }
2432 }
2433
2434 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002435 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2436 boolean goingToNotificationShade) {
2437 if (goingToNotificationShade) {
2438 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002439 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002440
2441 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2442 R.anim.lock_screen_behind_enter_wallpaper :
2443 R.anim.lock_screen_behind_enter);
2444
2445 // TODO: Use XML interpolators when we have log interpolators available in XML.
2446 final List<Animation> animations = set.getAnimations();
2447 for (int i = animations.size() - 1; i >= 0; --i) {
2448 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2449 }
2450
2451 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002452 }
2453
2454
2455 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002456 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2457 if (goingToNotificationShade) {
2458 return null;
2459 } else {
2460 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2461 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002462 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002463
2464 private static void awakenDreams() {
2465 IDreamManager dreamManager = getDreamManager();
2466 if (dreamManager != null) {
2467 try {
2468 dreamManager.awaken();
2469 } catch (RemoteException e) {
2470 // fine, stay asleep then
2471 }
2472 }
2473 }
2474
2475 static IDreamManager getDreamManager() {
2476 return IDreamManager.Stub.asInterface(
2477 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2478 }
2479
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002480 TelecomManager getTelecommService() {
2481 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002482 }
2483
Jeff Brown4d396052010-10-29 21:50:21 -07002484 static IAudioService getAudioService() {
2485 IAudioService audioService = IAudioService.Stub.asInterface(
2486 ServiceManager.checkService(Context.AUDIO_SERVICE));
2487 if (audioService == null) {
2488 Log.w(TAG, "Unable to find IAudioService interface.");
2489 }
2490 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002491 }
2492
2493 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002494 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002495 }
2496
2497 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2498 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2499 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2500 };
2501
2502 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002503 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002504 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002505 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002506 final int keyCode = event.getKeyCode();
2507 final int repeatCount = event.getRepeatCount();
2508 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002509 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002510 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2511 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002512
Jeff Brown40013652012-05-16 21:22:36 -07002513 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002514 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002515 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2516 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002517 }
2518
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002519 // If we think we might have a volume down & power key chord on the way
2520 // but we're not sure, then tell the dispatcher to wait a little while and
2521 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002522 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002523 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002524 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002525 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2526 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002527 if (now < timeoutTime) {
2528 return timeoutTime - now;
2529 }
2530 }
2531 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002532 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002533 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002534 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002535 }
2536 return -1;
2537 }
2538 }
2539
Michael Wright6a62e552014-06-03 19:19:48 -07002540 // Cancel any pending meta actions if we see any other keys being pressed between the down
2541 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002542 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002543 mPendingMetaAction = false;
2544 }
2545
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002546 // First we always handle the home key here, so applications
2547 // can never break it, although if keyguard is on, we do let
2548 // it handle it, because that gives us the correct 5 second
2549 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002550 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002551
Jeff Brown49ed71d2010-12-06 17:13:33 -08002552 // If we have released the home key, and didn't do anything else
2553 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002554 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002555 cancelPreloadRecentApps();
2556
Jeff Brown49ed71d2010-12-06 17:13:33 -08002557 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002558 if (mHomeConsumed) {
2559 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002560 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002561 }
Jeff Browncaca8812013-05-09 13:34:33 -07002562
2563 if (canceled) {
2564 Log.i(TAG, "Ignoring HOME; event canceled.");
2565 return -1;
2566 }
2567
Yorke Lee4f803242014-12-15 23:22:06 +00002568 // If an incoming call is ringing, HOME is totally disabled.
2569 // (The user is already on the InCallUI at this point,
2570 // and his ONLY options are to answer or reject the call.)
2571 TelecomManager telecomManager = getTelecommService();
2572 if (telecomManager != null && telecomManager.isRinging()) {
2573 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2574 return -1;
2575 }
2576
Jeff Browncaca8812013-05-09 13:34:33 -07002577 // Delay handling home if a double-tap is possible.
2578 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2579 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2580 mHomeDoubleTapPending = true;
2581 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2582 ViewConfiguration.getDoubleTapTimeout());
2583 return -1;
2584 }
2585
Jeff Brown13f00f02014-10-31 14:45:50 -07002586 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002587 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002588 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002589
2590 // If a system window has focus, then it doesn't make sense
2591 // right now to interact with applications.
2592 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2593 if (attrs != null) {
2594 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002595 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2596 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2597 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002598 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002599 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002600 }
2601 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2602 for (int i=0; i<typeCount; i++) {
2603 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2604 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002605 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002606 }
2607 }
2608 }
Jeff Browncaca8812013-05-09 13:34:33 -07002609
2610 // Remember that home is pressed and handle special actions.
2611 if (repeatCount == 0) {
2612 mHomePressed = true;
2613 if (mHomeDoubleTapPending) {
2614 mHomeDoubleTapPending = false;
2615 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2616 handleDoubleTapOnHome();
2617 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2618 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2619 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002620 }
Jeff Browncaca8812013-05-09 13:34:33 -07002621 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2622 if (!keyguardOn) {
2623 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002624 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002625 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002626 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002627 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002628 // Hijack modified menu keys for debugging features
2629 final int chordBug = KeyEvent.META_SHIFT_ON;
2630
2631 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002632 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002633 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002634 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2635 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002636 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002637 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002638 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002639 Intent service = new Intent();
2640 service.setClassName(mContext, "com.android.server.LoadAverageService");
2641 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002642 boolean shown = Settings.Global.getInt(
2643 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002644 if (!shown) {
2645 mContext.startService(service);
2646 } else {
2647 mContext.stopService(service);
2648 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002649 Settings.Global.putInt(
2650 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002651 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002652 }
2653 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002654 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002655 if (down) {
2656 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002657 mSearchKeyShortcutPending = true;
2658 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002659 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002660 } else {
2661 mSearchKeyShortcutPending = false;
2662 if (mConsumeSearchKeyUp) {
2663 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002664 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002665 }
2666 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002667 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002668 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002669 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002670 if (down && repeatCount == 0) {
2671 preloadRecentApps();
2672 } else if (!down) {
2673 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002674 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002675 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002676 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002677 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2678 if (down) {
2679 IStatusBarService service = getStatusBarService();
2680 if (service != null) {
2681 try {
2682 service.expandNotificationsPanel();
2683 } catch (RemoteException e) {
2684 // do nothing.
2685 }
2686 }
2687 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002688 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2689 if (down) {
2690 if (repeatCount == 0) {
2691 mAssistKeyLongPressed = false;
2692 } else if (repeatCount == 1) {
2693 mAssistKeyLongPressed = true;
2694 if (!keyguardOn) {
2695 launchAssistLongPressAction();
2696 }
2697 }
2698 } else {
2699 if (mAssistKeyLongPressed) {
2700 mAssistKeyLongPressed = false;
2701 } else {
2702 if (!keyguardOn) {
2703 launchAssistAction();
2704 }
2705 }
2706 }
2707 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002708 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2709 if (!down) {
2710 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002711 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002712 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2713 } else {
2714 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002715 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002716 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002717 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002718 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002719 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2720 if (down && repeatCount == 0) {
2721 mHandler.post(mScreenshotRunnable);
2722 }
2723 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002724 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2725 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2726 if (down) {
2727 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2728
2729 // Disable autobrightness if it's on
2730 int auto = Settings.System.getIntForUser(
2731 mContext.getContentResolver(),
2732 Settings.System.SCREEN_BRIGHTNESS_MODE,
2733 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2734 UserHandle.USER_CURRENT_OR_SELF);
2735 if (auto != 0) {
2736 Settings.System.putIntForUser(mContext.getContentResolver(),
2737 Settings.System.SCREEN_BRIGHTNESS_MODE,
2738 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2739 UserHandle.USER_CURRENT_OR_SELF);
2740 }
2741
2742 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2743 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2744 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2745 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2746 Settings.System.SCREEN_BRIGHTNESS,
2747 mPowerManager.getDefaultScreenBrightnessSetting(),
2748 UserHandle.USER_CURRENT_OR_SELF);
2749 brightness += step;
2750 // Make sure we don't go beyond the limits.
2751 brightness = Math.min(max, brightness);
2752 brightness = Math.max(min, brightness);
2753
2754 Settings.System.putIntForUser(mContext.getContentResolver(),
2755 Settings.System.SCREEN_BRIGHTNESS, brightness,
2756 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002757 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002758 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002759 }
2760 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002761 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002762 if (down) {
2763 mPendingMetaAction = true;
2764 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002765 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002766 }
2767 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002768 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002769
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002770 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002771 // Any printing key that is chorded with Search should be consumed
2772 // even if no shortcut was invoked. This prevents text from being
2773 // inadvertently inserted when using a keyboard that has built-in macro
2774 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002775 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002776 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2777 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002778 mConsumeSearchKeyUp = true;
2779 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002780 if (down && repeatCount == 0 && !keyguardOn) {
2781 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2782 if (shortcutIntent != null) {
2783 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002784 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002785 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002786 } catch (ActivityNotFoundException ex) {
2787 Slog.w(TAG, "Dropping shortcut key combination because "
2788 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002789 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002790 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002791 } else {
2792 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002793 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002794 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002795 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002796 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002797 }
2798 }
2799
Jeff Brown68b909d2011-12-07 16:36:01 -08002800 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002801 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002802 && (metaState & KeyEvent.META_META_ON) != 0) {
2803 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002804 if (kcm.isPrintingKey(keyCode)) {
2805 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2806 metaState & ~(KeyEvent.META_META_ON
2807 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2808 if (shortcutIntent != null) {
2809 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2810 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002811 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002812 } catch (ActivityNotFoundException ex) {
2813 Slog.w(TAG, "Dropping shortcut key combination because "
2814 + "the activity to which it is registered was not found: "
2815 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2816 }
2817 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002818 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002819 }
2820 }
2821
Jeff Brown6651a632011-11-28 12:59:11 -08002822 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002823 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002824 String category = sApplicationLaunchKeyCategories.get(keyCode);
2825 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002826 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002827 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2828 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002829 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002830 } catch (ActivityNotFoundException ex) {
2831 Slog.w(TAG, "Dropping application launch key because "
2832 + "the activity to which it is registered was not found: "
2833 + "keyCode=" + keyCode + ", category=" + category, ex);
2834 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002835 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002836 }
2837 }
2838
Michael Wright61c46752014-08-21 16:57:33 -07002839 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002840 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002841 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002842 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002843 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002844 mRecentAppsHeldModifiers = shiftlessModifiers;
2845 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002846 return -1;
2847 }
2848 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002849 } else if (!down && mRecentAppsHeldModifiers != 0
2850 && (metaState & mRecentAppsHeldModifiers) == 0) {
2851 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002852 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002853 }
2854
Jeff Browncf39bdf2012-05-18 14:41:19 -07002855 // Handle keyboard language switching.
2856 if (down && repeatCount == 0
2857 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2858 || (keyCode == KeyEvent.KEYCODE_SPACE
2859 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2860 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2861 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2862 return -1;
2863 }
2864 if (mLanguageSwitchKeyPressed && !down
2865 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2866 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2867 mLanguageSwitchKeyPressed = false;
2868 return -1;
2869 }
2870
Jeff Brown13f00f02014-10-31 14:45:50 -07002871 if (isValidGlobalKey(keyCode)
2872 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002873 return -1;
2874 }
2875
Michael Wright6a62e552014-06-03 19:19:48 -07002876 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002877 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002878 return -1;
2879 }
2880
Jeff Brown68b909d2011-12-07 16:36:01 -08002881 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002882 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002883 }
2884
Jeff Brown3915bb82010-11-05 15:02:16 -07002885 /** {@inheritDoc} */
2886 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002887 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002888 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002889 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002890 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2891 + ", flags=" + event.getFlags()
2892 + ", keyCode=" + event.getKeyCode()
2893 + ", scanCode=" + event.getScanCode()
2894 + ", metaState=" + event.getMetaState()
2895 + ", repeatCount=" + event.getRepeatCount()
2896 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002897 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002898
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002899 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002900 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2901 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002902 final int keyCode = event.getKeyCode();
2903 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002904 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2905 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002906
Jeff Brown54875002011-04-06 15:33:01 -07002907 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002908 final FallbackAction fallbackAction;
2909 if (initialDown) {
2910 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2911 } else {
2912 fallbackAction = mFallbackActions.get(keyCode);
2913 }
2914
2915 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002916 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002917 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2918 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002919 }
2920
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002921 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2922 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002923 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002924 event.getAction(), fallbackAction.keyCode,
2925 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002926 event.getDeviceId(), event.getScanCode(),
2927 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002928
2929 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2930 fallbackEvent.recycle();
2931 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002932 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002933
2934 if (initialDown) {
2935 mFallbackActions.put(keyCode, fallbackAction);
2936 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2937 mFallbackActions.remove(keyCode);
2938 fallbackAction.recycle();
2939 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002940 }
2941 }
2942
Jeff Brown40013652012-05-16 21:22:36 -07002943 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002944 if (fallbackEvent == null) {
2945 Slog.d(TAG, "No fallback.");
2946 } else {
2947 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2948 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002949 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002950 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002951 }
2952
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002953 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002954 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002955 if ((actions & ACTION_PASS_TO_USER) != 0) {
2956 long delayMillis = interceptKeyBeforeDispatching(
2957 win, fallbackEvent, policyFlags);
2958 if (delayMillis == 0) {
2959 return true;
2960 }
2961 }
2962 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002963 }
2964
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002965 private void launchAssistLongPressAction() {
2966 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2967 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2968
2969 // launch the search activity
2970 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2971 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2972 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002973 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002974 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002975 SearchManager searchManager = getSearchManager();
2976 if (searchManager != null) {
2977 searchManager.stopSearch();
2978 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002979 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002980 } catch (ActivityNotFoundException e) {
2981 Slog.w(TAG, "No activity to handle assist long press action.", e);
2982 }
2983 }
2984
2985 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002986 launchAssistAction(null);
2987 }
2988
2989 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002990 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002991 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002992 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002993 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002994 if (hint != null) {
2995 intent.putExtra(hint, true);
2996 }
Jim Miller45308b12012-06-18 19:23:39 -07002997 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2998 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2999 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
3000 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003001 startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07003002 } catch (ActivityNotFoundException e) {
3003 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003004 }
3005 }
3006 }
3007
Bart Sears8b1c27c2015-03-18 23:51:02 +00003008 private void startActivityAsUser(Intent intent, UserHandle handle) {
3009 if (isUserSetupComplete()) {
3010 mContext.startActivityAsUser(intent, handle);
3011 } else {
3012 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3013 }
3014 }
3015
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003016 private SearchManager getSearchManager() {
3017 if (mSearchManager == null) {
3018 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3019 }
3020 return mSearchManager;
3021 }
3022
Jeff Browncaca8812013-05-09 13:34:33 -07003023 private void preloadRecentApps() {
3024 mPreloadedRecentApps = true;
3025 try {
3026 IStatusBarService statusbar = getStatusBarService();
3027 if (statusbar != null) {
3028 statusbar.preloadRecentApps();
3029 }
3030 } catch (RemoteException e) {
3031 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3032 // re-acquire status bar service next time it is needed.
3033 mStatusBarService = null;
3034 }
3035 }
3036
3037 private void cancelPreloadRecentApps() {
3038 if (mPreloadedRecentApps) {
3039 mPreloadedRecentApps = false;
3040 try {
3041 IStatusBarService statusbar = getStatusBarService();
3042 if (statusbar != null) {
3043 statusbar.cancelPreloadRecentApps();
3044 }
3045 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003046 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003047 // re-acquire status bar service next time it is needed.
3048 mStatusBarService = null;
3049 }
3050 }
3051 }
3052
3053 private void toggleRecentApps() {
3054 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003055 try {
3056 IStatusBarService statusbar = getStatusBarService();
3057 if (statusbar != null) {
3058 statusbar.toggleRecentApps();
3059 }
3060 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003061 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3062 // re-acquire status bar service next time it is needed.
3063 mStatusBarService = null;
3064 }
3065 }
3066
Craig Mautner84984fa2014-06-19 11:19:20 -07003067 @Override
3068 public void showRecentApps() {
3069 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3070 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3071 }
3072
Winson Chung1e8d71b2014-05-16 17:05:22 -07003073 private void showRecentApps(boolean triggeredFromAltTab) {
3074 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3075 try {
3076 IStatusBarService statusbar = getStatusBarService();
3077 if (statusbar != null) {
3078 statusbar.showRecentApps(triggeredFromAltTab);
3079 }
3080 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003081 Slog.e(TAG, "RemoteException when showing recent apps", e);
3082 // re-acquire status bar service next time it is needed.
3083 mStatusBarService = null;
3084 }
3085 }
3086
Winson Chungcdcd4872014-08-05 18:00:13 -07003087 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003088 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3089 try {
3090 IStatusBarService statusbar = getStatusBarService();
3091 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003092 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003093 }
3094 } catch (RemoteException e) {
3095 Slog.e(TAG, "RemoteException when closing recent apps", e);
3096 // re-acquire status bar service next time it is needed.
3097 mStatusBarService = null;
3098 }
3099 }
3100
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003101 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003102 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003103 }
3104
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003105 /**
3106 * A home key -> launch home action was detected. Take the appropriate action
3107 * given the situation with the keyguard.
3108 */
Bryce Lee662ed802015-04-10 20:11:39 +00003109 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3110 if (respectKeyguard) {
3111 if (isKeyguardShowingAndNotOccluded()) {
3112 // don't launch home if keyguard showing
3113 return;
3114 }
3115
3116 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3117 // when in keyguard restricted mode, must first verify unlock
3118 // before launching home
3119 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3120 @Override
3121 public void onKeyguardExitResult(boolean success) {
3122 if (success) {
3123 try {
3124 ActivityManagerNative.getDefault().stopAppSwitches();
3125 } catch (RemoteException e) {
3126 }
3127 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3128 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003129 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003130 }
Bryce Lee662ed802015-04-10 20:11:39 +00003131 });
3132 return;
3133 }
3134 }
3135
3136 // no keyguard stuff to worry about, just launch home!
3137 try {
3138 ActivityManagerNative.getDefault().stopAppSwitches();
3139 } catch (RemoteException e) {
3140 }
3141 if (mRecentsVisible) {
3142 // Hide Recents and notify it to launch Home
3143 if (awakenFromDreams) {
3144 awakenDreams();
3145 }
3146 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3147 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003148 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003149 // Otherwise, just launch Home
3150 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3151 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003152 }
3153 }
3154
John Spurlock04db1762013-05-13 12:46:41 -04003155 private final Runnable mClearHideNavigationFlag = new Runnable() {
3156 @Override
3157 public void run() {
3158 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3159 // Clear flags.
3160 mForceClearedSystemUiFlags &=
3161 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3162 }
3163 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003164 }
3165 };
3166
3167 /**
3168 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3169 * to determine when the nav bar should be shown and prevent applications from
3170 * receiving those touches.
3171 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003172 final class HideNavInputEventReceiver extends InputEventReceiver {
3173 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3174 super(inputChannel, looper);
3175 }
3176
Dianne Hackborndf89e652011-10-06 22:35:11 -07003177 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003178 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003179 boolean handled = false;
3180 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003181 if (event instanceof MotionEvent
3182 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3183 final MotionEvent motionEvent = (MotionEvent)event;
3184 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003185 // When the user taps down, we re-show the nav bar.
3186 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003187 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003188 // Any user activity always causes us to show the
3189 // navigation controls, if they had been hidden.
3190 // We also clear the low profile and only content
3191 // flags so that tapping on the screen will atomically
3192 // restore all currently hidden screen decorations.
3193 int newVal = mResettingSystemUiFlags |
3194 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3195 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3196 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003197 if (mResettingSystemUiFlags != newVal) {
3198 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003199 changed = true;
3200 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003201 // We don't allow the system's nav bar to be hidden
3202 // again for 1 second, to prevent applications from
3203 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003204 newVal = mForceClearedSystemUiFlags |
3205 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003206 if (mForceClearedSystemUiFlags != newVal) {
3207 mForceClearedSystemUiFlags = newVal;
3208 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003209 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003210 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003211 }
3212 if (changed) {
3213 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3214 }
3215 }
3216 }
3217 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003218 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003219 }
3220 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003221 }
3222 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3223 new InputEventReceiver.Factory() {
3224 @Override
3225 public InputEventReceiver createInputEventReceiver(
3226 InputChannel inputChannel, Looper looper) {
3227 return new HideNavInputEventReceiver(inputChannel, looper);
3228 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003229 };
3230
3231 @Override
3232 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003233 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3234 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003235 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003236
Dianne Hackborndf89e652011-10-06 22:35:11 -07003237 // Reset any bits in mForceClearingStatusBarVisibility that
3238 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003239 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003240 // Clear any bits in the new visibility that are currently being
3241 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003242 return visibility & ~mResettingSystemUiFlags
3243 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003244 }
3245
Craig Mautner69b08182012-09-05 13:07:13 -07003246 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003247 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3248 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003249 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003250 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3251 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003252
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003253 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003254 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003255 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003256 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003257 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003258 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3259 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3260 } else {
3261 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3262 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3263 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003264 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3265 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003266 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003267 availRight - mStableFullscreenRight,
3268 availBottom - mStableFullscreenBottom);
3269 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003270 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003271 availRight - mStableRight, availBottom - mStableBottom);
3272 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003273 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003274 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003275 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003276 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003277 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003278 availRight - mCurRight, availBottom - mCurBottom);
3279 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003280 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003281 availRight - mCurRight, availBottom - mCurBottom);
3282 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003283
3284 outStableInsets.set(mStableLeft, mStableTop,
3285 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003286 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003287 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003288 outContentInsets.setEmpty();
3289 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003290 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003291
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003292 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003293 @Override
3294 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3295 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003296 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3297 if (isDefaultDisplay) {
3298 switch (displayRotation) {
3299 case Surface.ROTATION_90:
3300 overscanLeft = mOverscanTop;
3301 overscanTop = mOverscanRight;
3302 overscanRight = mOverscanBottom;
3303 overscanBottom = mOverscanLeft;
3304 break;
3305 case Surface.ROTATION_180:
3306 overscanLeft = mOverscanRight;
3307 overscanTop = mOverscanBottom;
3308 overscanRight = mOverscanLeft;
3309 overscanBottom = mOverscanTop;
3310 break;
3311 case Surface.ROTATION_270:
3312 overscanLeft = mOverscanBottom;
3313 overscanTop = mOverscanLeft;
3314 overscanRight = mOverscanTop;
3315 overscanBottom = mOverscanRight;
3316 break;
3317 default:
3318 overscanLeft = mOverscanLeft;
3319 overscanTop = mOverscanTop;
3320 overscanRight = mOverscanRight;
3321 overscanBottom = mOverscanBottom;
3322 break;
3323 }
3324 } else {
3325 overscanLeft = 0;
3326 overscanTop = 0;
3327 overscanRight = 0;
3328 overscanBottom = 0;
3329 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003330 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3331 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3332 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3333 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003334 mSystemLeft = 0;
3335 mSystemTop = 0;
3336 mSystemRight = displayWidth;
3337 mSystemBottom = displayHeight;
3338 mUnrestrictedScreenLeft = overscanLeft;
3339 mUnrestrictedScreenTop = overscanTop;
3340 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3341 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3342 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3343 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003344 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3345 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003346 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003347 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003348 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003349 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003350 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003351 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003352 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003353 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003354 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003355 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003356
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003357 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3358 final Rect pf = mTmpParentFrame;
3359 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003360 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003361 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003362 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003363 pf.left = df.left = of.left = vf.left = mDockLeft;
3364 pf.top = df.top = of.top = vf.top = mDockTop;
3365 pf.right = df.right = of.right = vf.right = mDockRight;
3366 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003367 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003368
Craig Mautner69b08182012-09-05 13:07:13 -07003369 if (isDefaultDisplay) {
3370 // For purposes of putting out fake window up to steal focus, we will
3371 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003372 final int sysui = mLastSystemUiFlags;
3373 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003374 boolean navTranslucent = (sysui
3375 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003376 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3377 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3378 boolean navAllowedHidden = immersive || immersiveSticky;
3379 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003380 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3381 if (!isKeyguardShowing) {
3382 navTranslucent &= areTranslucentBarsAllowed();
3383 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003384
Craig Mautner69b08182012-09-05 13:07:13 -07003385 // When the navigation bar isn't visible, we put up a fake
3386 // input window to catch all touch events. This way we can
3387 // detect when the user presses anywhere to bring back the nav
3388 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003389 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07003390 if (mHideNavFakeWindow != null) {
3391 mHideNavFakeWindow.dismiss();
3392 mHideNavFakeWindow = null;
3393 }
3394 } else if (mHideNavFakeWindow == null) {
3395 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
3396 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07003397 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07003398 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003399 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003400
Craig Mautner69b08182012-09-05 13:07:13 -07003401 // For purposes of positioning and showing the nav bar, if we have
3402 // decided that it can't be hidden (because of the screen aspect ratio),
3403 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003404 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003405
John Spurlockad3e6cb2013-04-30 08:47:43 -04003406 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003407 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003408 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003409 // Force the navigation bar to its appropriate place and
3410 // size. We need to do this directly, instead of relying on
3411 // it to bubble up from the nav bar, because this needs to
3412 // change atomically with screen rotations.
3413 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3414 if (mNavigationBarOnBottom) {
3415 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003416 int top = displayHeight - overscanBottom
3417 - mNavigationBarHeightForRotation[displayRotation];
3418 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003419 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003420 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003421 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003422 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003423 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003424 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003425 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3426 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003427 } else {
3428 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003429 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003430 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003431 if (navVisible && !navTranslucent && !navAllowedHidden
3432 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003433 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003434 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003435 // and not in the process of animating on or off, then
3436 // we can tell the app that it is covered by it.
3437 mSystemBottom = mTmpNavigationFrame.top;
3438 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003439 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003440 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003441 int left = displayWidth - overscanRight
3442 - mNavigationBarWidthForRotation[displayRotation];
3443 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003444 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003445 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003446 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003447 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003448 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003449 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003450 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3451 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003452 } else {
3453 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003454 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003455 }
John Spurlockbd957402013-10-03 11:38:39 -04003456 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3457 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003458 // If the nav bar is currently requested to be visible,
3459 // and not in the process of animating on or off, then
3460 // we can tell the app that it is covered by it.
3461 mSystemRight = mTmpNavigationFrame.left;
3462 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003463 }
Craig Mautner69b08182012-09-05 13:07:13 -07003464 // Make sure the content and current rectangles are updated to
3465 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003466 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3467 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3468 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3469 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003470 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3471 // And compute the final frame.
3472 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003473 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3474 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003475 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003476 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003477 updateSysUiVisibility = true;
3478 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003479 }
Craig Mautnereda67292013-04-28 13:50:14 -07003480 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003481 mDockLeft, mDockTop, mDockRight, mDockBottom));
3482
3483 // decide where the status bar goes ahead of time
3484 if (mStatusBar != null) {
3485 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003486 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3487 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3488 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3489 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3490 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003491 vf.left = mStableLeft;
3492 vf.top = mStableTop;
3493 vf.right = mStableRight;
3494 vf.bottom = mStableBottom;
3495
3496 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3497
3498 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003499 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003500
3501 // For layout, the status bar is always at the top with our fixed height.
3502 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3503
John Spurlocke1f366f2013-08-05 12:22:40 -04003504 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003505 boolean statusBarTranslucent = (sysui
3506 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003507 if (!isKeyguardShowing) {
3508 statusBarTranslucent &= areTranslucentBarsAllowed();
3509 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003510
Craig Mautner69b08182012-09-05 13:07:13 -07003511 // If the status bar is hidden, we don't want to cause
3512 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003513 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003514 // Status bar may go away, so the screen area it occupies
3515 // is available to apps but just covering them when the
3516 // status bar is visible.
3517 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3518
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003519 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3520 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3521 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3522 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003523
Craig Mautnereda67292013-04-28 13:50:14 -07003524 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003525 String.format(
3526 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3527 mDockLeft, mDockTop, mDockRight, mDockBottom,
3528 mContentLeft, mContentTop, mContentRight, mContentBottom,
3529 mCurLeft, mCurTop, mCurRight, mCurBottom));
3530 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003531 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003532 && !statusBarTransient && !statusBarTranslucent
3533 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003534 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003535 // and not in the process of animating on or off, then
3536 // we can tell the app that it is covered by it.
3537 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3538 }
John Spurlock27735a42013-08-14 17:57:38 -04003539 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003540 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003541 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003542 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003543 if (updateSysUiVisibility) {
3544 updateSystemUiVisibilityLw();
3545 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003546 }
3547 }
3548
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003549 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003550 @Override
John Spurlock46646232013-09-30 22:32:42 -04003551 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003552 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3553 return mStatusBar.getSurfaceLayer();
3554 }
3555
3556 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3557 return mNavigationBar.getSurfaceLayer();
3558 }
3559
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003560 return 0;
3561 }
3562
Craig Mautner967212c2013-04-13 21:10:58 -07003563 @Override
3564 public void getContentRectLw(Rect r) {
3565 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3566 }
3567
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003568 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3569 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003570 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3571 // Here's a special case: if this attached window is a panel that is
3572 // above the dock window, and the window it is attached to is below
3573 // the dock window, then the frames we computed for the window it is
3574 // attached to can not be used because the dock is effectively part
3575 // of the underlying window and the attached window is floating on top
3576 // of the whole thing. So, we ignore the attached window and explicitly
3577 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003578 df.left = of.left = cf.left = vf.left = mDockLeft;
3579 df.top = of.top = cf.top = vf.top = mDockTop;
3580 df.right = of.right = cf.right = vf.right = mDockRight;
3581 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003582 } else {
3583 // The effective display frame of the attached window depends on
3584 // whether it is taking care of insetting its content. If not,
3585 // we need to use the parent's content frame so that the entire
3586 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003587 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003588 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003589 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003590 // Set the content frame of the attached window to the parent's decor frame
3591 // (same as content frame when IME isn't present) if specifically requested by
3592 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3593 // Otherwise, use the overscan frame.
3594 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3595 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003596 } else {
3597 // If the window is resizing, then we want to base the content
3598 // frame on our attached content frame to resize... however,
3599 // things can be tricky if the attached window is NOT in resize
3600 // mode, in which case its content frame will be larger.
3601 // Ungh. So to deal with that, make sure the content frame
3602 // we end up using is not covering the IM dock.
3603 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003604 if (attached.isVoiceInteraction()) {
3605 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3606 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3607 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3608 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3609 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003610 if (cf.left < mContentLeft) cf.left = mContentLeft;
3611 if (cf.top < mContentTop) cf.top = mContentTop;
3612 if (cf.right > mContentRight) cf.right = mContentRight;
3613 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3614 }
3615 }
3616 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003617 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003618 vf.set(attached.getVisibleFrameLw());
3619 }
3620 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3621 // window should be positioned relative to its parent or the entire
3622 // screen.
3623 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3624 ? attached.getFrameLw() : df);
3625 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003626
3627 private void applyStableConstraints(int sysui, int fl, Rect r) {
3628 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3629 // If app is requesting a stable layout, don't let the
3630 // content insets go below the stable values.
3631 if ((fl & FLAG_FULLSCREEN) != 0) {
3632 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3633 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3634 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3635 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3636 } else {
3637 if (r.left < mStableLeft) r.left = mStableLeft;
3638 if (r.top < mStableTop) r.top = mStableTop;
3639 if (r.right > mStableRight) r.right = mStableRight;
3640 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3641 }
3642 }
3643 }
3644
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003645 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003646 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003647 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003648 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003649 final WindowManager.LayoutParams attrs = win.getAttrs();
3650 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3651 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003652 return;
3653 }
Craig Mautner69b08182012-09-05 13:07:13 -07003654 final boolean isDefaultDisplay = win.isDefaultDisplay();
3655 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003656 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3657 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003658 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003659 offsetInputMethodWindowLw(mLastInputMethodWindow);
3660 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003661
John Spurlockc6d1c602014-01-17 15:22:06 -05003662 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003663 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003664 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003665
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003666 final Rect pf = mTmpParentFrame;
3667 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003668 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003669 final Rect cf = mTmpContentFrame;
3670 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003671 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003672 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003673 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003674
3675 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003676 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003677
Craig Mautnerf683b562012-10-02 11:10:57 -07003678 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3679
Adrian Roosfa104232014-06-20 16:10:14 -07003680 if (isDefaultDisplay) {
3681 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3682 } else {
3683 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3684 }
3685
Craig Mautner69b08182012-09-05 13:07:13 -07003686 if (!isDefaultDisplay) {
3687 if (attached != null) {
3688 // If this window is attached to another, our display
3689 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003690 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003691 } else {
3692 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003693 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3694 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3695 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003696 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003697 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003698 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003699 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003700 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003701 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3702 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3703 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003704 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003705 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003706 // ...with content insets above the nav bar
3707 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003708 // IM dock windows always go to the bottom of the screen.
3709 attrs.gravity = Gravity.BOTTOM;
3710 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003711 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
3712 pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft;
3713 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3714 pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft
3715 + mUnrestrictedScreenWidth;
3716 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3717 + mUnrestrictedScreenHeight;
3718 cf.bottom = vf.bottom = mStableBottom;
3719 cf.top = vf.top = mStableTop;
Jorim Jaggie0700182014-08-21 01:12:37 +02003720 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3721 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3722 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3723 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3724 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3725 cf.left = vf.left = mStableLeft;
3726 cf.top = vf.top = mStableTop;
3727 cf.right = vf.right = mStableRight;
3728 vf.bottom = mStableBottom;
3729 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003730 } else {
John Spurlock46646232013-09-30 22:32:42 -04003731
3732 // Default policy decor for the default display
3733 dcf.left = mSystemLeft;
3734 dcf.top = mSystemTop;
3735 dcf.right = mSystemRight;
3736 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003737 final boolean inheritTranslucentDecor = (attrs.privateFlags
3738 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003739 final boolean isAppWindow =
3740 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3741 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3742 final boolean topAtRest =
3743 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3744 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003745 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3746 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003747 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3748 && (fl & WindowManager.LayoutParams.
3749 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003750 // Ensure policy decor includes status bar
3751 dcf.top = mStableTop;
3752 }
John Spurlockbd957402013-10-03 11:38:39 -04003753 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003754 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3755 && (fl & WindowManager.LayoutParams.
3756 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003757 // Ensure policy decor includes navigation bar
3758 dcf.bottom = mStableBottom;
3759 dcf.right = mStableRight;
3760 }
3761 }
3762
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003763 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3764 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003765 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003766 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003767 // This is the case for a normal activity window: we want it
3768 // to cover all of the screen space, and it can take care of
3769 // moving its contents to account for screen decorations that
3770 // intrude into that space.
3771 if (attached != null) {
3772 // If this window is attached to another, our display
3773 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003774 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003775 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003776 if (attrs.type == TYPE_STATUS_BAR_PANEL
3777 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003778 // Status bar panels are the only windows who can go on top of
3779 // the status bar. They are protected by the STATUS_BAR_SERVICE
3780 // permission, so they have the same privileges as the status
3781 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003782 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003783 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003784
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003785 pf.left = df.left = of.left = hasNavBar
3786 ? mDockLeft : mUnrestrictedScreenLeft;
3787 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3788 pf.right = df.right = of.right = hasNavBar
3789 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3790 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3791 pf.bottom = df.bottom = of.bottom = hasNavBar
3792 ? mRestrictedScreenTop+mRestrictedScreenHeight
3793 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003794
Craig Mautnereda67292013-04-28 13:50:14 -07003795 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003796 "Laying out status bar window: (%d,%d - %d,%d)",
3797 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003798 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003799 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3800 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3801 // Asking to layout into the overscan region, so give it that pure
3802 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003803 pf.left = df.left = of.left = mOverscanScreenLeft;
3804 pf.top = df.top = of.top = mOverscanScreenTop;
3805 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3806 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3807 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003808 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003809 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003810 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3811 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003812 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003813 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003814 // only do this for application windows to ensure no window that
3815 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003816 pf.left = df.left = mOverscanScreenLeft;
3817 pf.top = df.top = mOverscanScreenTop;
3818 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3819 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003820 // We need to tell the app about where the frame inside the overscan
3821 // is, so it can inset its content by that amount -- it didn't ask
3822 // to actually extend itself into the overscan region.
3823 of.left = mUnrestrictedScreenLeft;
3824 of.top = mUnrestrictedScreenTop;
3825 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3826 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003827 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003828 pf.left = df.left = mRestrictedOverscanScreenLeft;
3829 pf.top = df.top = mRestrictedOverscanScreenTop;
3830 pf.right = df.right = mRestrictedOverscanScreenLeft
3831 + mRestrictedOverscanScreenWidth;
3832 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3833 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003834 // We need to tell the app about where the frame inside the overscan
3835 // is, so it can inset its content by that amount -- it didn't ask
3836 // to actually extend itself into the overscan region.
3837 of.left = mUnrestrictedScreenLeft;
3838 of.top = mUnrestrictedScreenTop;
3839 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3840 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003841 }
Craig Mautner69b08182012-09-05 13:07:13 -07003842
John Spurlock46646232013-09-30 22:32:42 -04003843 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003844 if (win.isVoiceInteraction()) {
3845 cf.left = mVoiceContentLeft;
3846 cf.top = mVoiceContentTop;
3847 cf.right = mVoiceContentRight;
3848 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003849 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003850 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3851 cf.left = mDockLeft;
3852 cf.top = mDockTop;
3853 cf.right = mDockRight;
3854 cf.bottom = mDockBottom;
3855 } else {
3856 cf.left = mContentLeft;
3857 cf.top = mContentTop;
3858 cf.right = mContentRight;
3859 cf.bottom = mContentBottom;
3860 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003861 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003862 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003863 // Full screen windows are always given a layout that is as if the
3864 // status bar and other transient decors are gone. This is to avoid
3865 // bad states when moving from a window that is not hding the
3866 // status bar to one that is.
3867 cf.left = mRestrictedScreenLeft;
3868 cf.top = mRestrictedScreenTop;
3869 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3870 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003871 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003872 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003873 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3874 vf.left = mCurLeft;
3875 vf.top = mCurTop;
3876 vf.right = mCurRight;
3877 vf.bottom = mCurBottom;
3878 } else {
3879 vf.set(cf);
3880 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003881 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003882 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3883 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3884 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003885 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3886 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003887 // A window that has requested to fill the entire screen just
3888 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003889 if (attrs.type == TYPE_STATUS_BAR_PANEL
3890 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003891 pf.left = df.left = of.left = cf.left = hasNavBar
3892 ? mDockLeft : mUnrestrictedScreenLeft;
3893 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3894 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003895 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003896 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003897 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003898 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003899 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003900 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003901 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3902 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003903 } else if (attrs.type == TYPE_NAVIGATION_BAR
3904 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003905 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003906 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3907 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3908 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3909 + mUnrestrictedScreenWidth;
3910 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3911 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003912 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003913 "Laying out navigation bar window: (%d,%d - %d,%d)",
3914 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003915 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3916 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003917 && ((fl & FLAG_FULLSCREEN) != 0)) {
3918 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003919 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3920 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3921 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3922 + mOverscanScreenWidth;
3923 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3924 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003925 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003926 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003927 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3928 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3929 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3930 + mOverscanScreenWidth;
3931 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3932 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003933 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003934 // The wallpaper also has Real Ultimate Power, but we want to tell
3935 // it about the overscan area.
3936 pf.left = df.left = mOverscanScreenLeft;
3937 pf.top = df.top = mOverscanScreenTop;
3938 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3939 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3940 of.left = cf.left = mUnrestrictedScreenLeft;
3941 of.top = cf.top = mUnrestrictedScreenTop;
3942 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3943 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003944 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003945 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3946 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3947 // Asking to layout into the overscan region, so give it that pure
3948 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003949 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3950 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3951 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003952 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003953 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003954 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003955 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003956 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003957 && (attrs.type == TYPE_STATUS_BAR
3958 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07003959 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04003960 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3961 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003962 // Asking for layout as if the nav bar is hidden, lets the
3963 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003964 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003965 // can be above the nav bar can do this.
3966 // XXX This assumes that an app asking for this will also
3967 // ask for layout in only content. We can't currently figure out
3968 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003969 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3970 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3971 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3972 + mUnrestrictedScreenWidth;
3973 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3974 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003975 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003976 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3977 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3978 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3979 + mRestrictedScreenWidth;
3980 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3981 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003982 }
Craig Mautner69b08182012-09-05 13:07:13 -07003983
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003984 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003985
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003986 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3987 vf.left = mCurLeft;
3988 vf.top = mCurTop;
3989 vf.right = mCurRight;
3990 vf.bottom = mCurBottom;
3991 } else {
3992 vf.set(cf);
3993 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003994 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003995 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3996 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003997 // A child window should be placed inside of the same visible
3998 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003999 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004000 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004001 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4002 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004003 // Otherwise, a normal window must be placed inside the content
4004 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07004005 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
4006 // Status bar panels are the only windows who can go on top of
4007 // the status bar. They are protected by the STATUS_BAR_SERVICE
4008 // permission, so they have the same privileges as the status
4009 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004010 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4011 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4012 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4013 + mRestrictedScreenWidth;
4014 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4015 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05004016 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
4017 || attrs.type == TYPE_VOLUME_OVERLAY) {
4018 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004019 pf.left = df.left = of.left = cf.left = mStableLeft;
4020 pf.top = df.top = of.top = cf.top = mStableTop;
4021 pf.right = df.right = of.right = cf.right = mStableRight;
4022 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004023 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004024 pf.left = mContentLeft;
4025 pf.top = mContentTop;
4026 pf.right = mContentRight;
4027 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004028 if (win.isVoiceInteraction()) {
4029 df.left = of.left = cf.left = mVoiceContentLeft;
4030 df.top = of.top = cf.top = mVoiceContentTop;
4031 df.right = of.right = cf.right = mVoiceContentRight;
4032 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4033 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004034 df.left = of.left = cf.left = mDockLeft;
4035 df.top = of.top = cf.top = mDockTop;
4036 df.right = of.right = cf.right = mDockRight;
4037 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004038 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004039 df.left = of.left = cf.left = mContentLeft;
4040 df.top = of.top = cf.top = mContentTop;
4041 df.right = of.right = cf.right = mContentRight;
4042 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004043 }
4044 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4045 vf.left = mCurLeft;
4046 vf.top = mCurTop;
4047 vf.right = mCurRight;
4048 vf.bottom = mCurBottom;
4049 } else {
4050 vf.set(cf);
4051 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004052 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004053 }
4054 }
Craig Mautner69b08182012-09-05 13:07:13 -07004055
Craig Mautnerb816bed2013-07-23 10:26:17 -07004056 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4057 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004058 df.left = df.top = -10000;
4059 df.right = df.bottom = 10000;
4060 if (attrs.type != TYPE_WALLPAPER) {
4061 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4062 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4063 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004064 }
4065
Craig Mautnereda67292013-04-28 13:50:14 -07004066 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004067 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004068 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004069 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004070 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004071 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004072 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004073 + " dcf=" + dcf.toShortString()
4074 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07004075
Adrian Roosfa104232014-06-20 16:10:14 -07004076 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07004077
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004078 // Dock windows carve out the bottom of the screen, so normal windows
4079 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004080 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4081 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004082 setLastInputMethodWindowLw(null, null);
4083 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004084 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004085 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4086 && !win.getGivenInsetsPendingLw()) {
4087 offsetVoiceInputWindowLw(win);
4088 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004089 }
4090
satok1bc0a492012-04-25 22:47:12 +09004091 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004092 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004093 top += win.getGivenContentInsetsLw().top;
4094 if (mContentBottom > top) {
4095 mContentBottom = top;
4096 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004097 if (mVoiceContentBottom > top) {
4098 mVoiceContentBottom = top;
4099 }
satok1bc0a492012-04-25 22:47:12 +09004100 top = win.getVisibleFrameLw().top;
4101 top += win.getGivenVisibleInsetsLw().top;
4102 if (mCurBottom > top) {
4103 mCurBottom = top;
4104 }
Craig Mautnereda67292013-04-28 13:50:14 -07004105 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004106 + mDockBottom + " mContentBottom="
4107 + mContentBottom + " mCurBottom=" + mCurBottom);
4108 }
4109
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004110 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004111 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004112 top += win.getGivenContentInsetsLw().top;
4113 if (mVoiceContentBottom > top) {
4114 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004115 }
4116 }
4117
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004118 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004119 @Override
4120 public void finishLayoutLw() {
4121 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004122 }
4123
4124 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004125 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004126 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004127 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004128 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004129 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004130 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004131 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004132 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004133 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004134 mForcingShowNavBar = false;
4135 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004136
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004137 mHideLockScreen = false;
4138 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004139 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004140 mShowingLockscreen = false;
4141 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004142 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004143 mKeyguardSecure = isKeyguardSecure();
4144 mKeyguardSecureIncludingHidden = mKeyguardSecure
4145 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004146 }
4147
4148 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004149 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004150 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004151 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4152 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004153 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004154 if (mTopFullscreenOpaqueWindowState == null
4155 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4156 mForcingShowNavBar = true;
4157 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004158 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004159 if (attrs.type == TYPE_STATUS_BAR) {
4160 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4161 mForceStatusBarFromKeyguard = true;
4162 }
4163 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4164 mForceStatusBarTransparent = true;
4165 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004166 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004167
4168 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4169 && attrs.type < FIRST_SYSTEM_WINDOW;
4170 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4171 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4172
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004173 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004174 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004175 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004176 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004177 mForceStatusBarFromKeyguard = true;
4178 } else {
4179 mForceStatusBar = true;
4180 }
4181 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004182 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004183 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004184 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004185 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004186 // If the lockscreen was showing when the dream started then wait
4187 // for the dream to draw before hiding the lockscreen.
4188 if (!mDreamingLockscreen
4189 || (win.isVisibleLw() && win.hasDrawnLw())) {
4190 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004191 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004192 }
4193 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004194
Craig Mautnerab55e522014-03-03 13:26:03 -08004195 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004196 final IApplicationToken appToken = win.getAppToken();
4197 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004198 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004199 mAppsToBeHidden.remove(appToken);
4200 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004201 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004202 if (dismissKeyguard && !mKeyguardSecure) {
4203 mAppsThatDismissKeyguard.add(appToken);
4204 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004205 mWinShowWhenLocked = win;
4206 mHideLockScreen = true;
4207 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004208 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004209 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004210 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004211 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004212 mAppsToBeHidden.add(appToken);
4213 } else {
4214 mAppsToBeHidden.remove(appToken);
4215 }
4216 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004217 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004218 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004219 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004220 if (attrs.x == 0 && attrs.y == 0
4221 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4222 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4223 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4224 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004225 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4226 mTopFullscreenOpaqueOrDimmingWindowState = win;
4227 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004228 if (!mAppsThatDismissKeyguard.isEmpty() &&
4229 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4230 if (DEBUG_LAYOUT) Slog.v(TAG,
4231 "Setting mDismissKeyguard true by win " + win);
4232 mDismissKeyguard = mWinDismissingKeyguard == win ?
4233 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
4234 mWinDismissingKeyguard = win;
Jim Millerab954542014-10-10 18:21:49 -07004235 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004236 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4237 if (DEBUG_LAYOUT) Slog.v(TAG,
4238 "Setting mHideLockScreen to true by win " + win);
4239 mHideLockScreen = true;
4240 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004241 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004242 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004243 mAllowLockscreenWhenOn = true;
4244 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004245 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004246
4247 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004248 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4249 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004250 win.hideLw(false);
4251 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004252 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004253 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4254 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4255 // that is being hidden in an animation - keep the
4256 // keyguard hidden until the new window shows up and
4257 // we know whether to show the keyguard or not.
4258 if (win.isAnimatingLw() && appWindow && showWhenLocked) {
4259 mHideLockScreen = true;
4260 mWinShowWhenLocked = win;
4261 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004262 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004263 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4264 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4265 && win.isDimming()) {
4266 mTopFullscreenOpaqueOrDimmingWindowState = win;
4267 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004268 }
4269
4270 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004271 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004272 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004273 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4274 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4275 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004276 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4277 // fullscreen window.
4278 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4279 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4280 mTopFullscreenOpaqueWindowState.hideLw(false);
4281 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4282 }
4283
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004284 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004285 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004286
4287 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4288 ? mTopFullscreenOpaqueWindowState.getAttrs()
4289 : null;
4290
Jeff Brownc8018eb2012-10-29 21:33:27 -07004291 // If we are not currently showing a dream then remember the current
4292 // lockscreen state. We will use this to determine whether the dream
4293 // started while the lockscreen was showing and remember this state
4294 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004295 if (!mShowingDream) {
4296 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004297 if (mDreamingSleepTokenNeeded) {
4298 mDreamingSleepTokenNeeded = false;
4299 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4300 }
4301 } else {
4302 if (!mDreamingSleepTokenNeeded) {
4303 mDreamingSleepTokenNeeded = true;
4304 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4305 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004306 }
4307
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004308 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004309 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004310 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004311 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004312 boolean shouldBeTransparent = mForceStatusBarTransparent
4313 && !mForceStatusBar
4314 && !mForceStatusBarFromKeyguard;
4315 if (!shouldBeTransparent) {
4316 mStatusBarController.setShowTransparent(false /* transparent */);
4317 } else if (!mStatusBar.isVisibleLw()) {
4318 mStatusBarController.setShowTransparent(true /* transparent */);
4319 }
4320 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004321 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004322 if (mStatusBarController.setBarShowingLw(true)) {
4323 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4324 }
Craig Mautner81defc72013-10-29 11:10:42 -07004325 // Maintain fullscreen layout until incoming animation is complete.
4326 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004327 // Transient status bar on the lockscreen is not allowed
4328 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4329 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4330 mLastSystemUiFlags, mLastSystemUiFlags);
4331 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004332 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004333 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004334 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004335 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004336 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004337 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004338 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004339 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004340 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004341 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004342 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004343 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004344 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4345 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004346 if (mStatusBarController.isTransientShowing()) {
4347 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004348 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4349 }
4350 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004351 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004352 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004353 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004354 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004355 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004356 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004357 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004358 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004359 if (mStatusBarController.setBarShowingLw(true)) {
4360 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4361 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004362 }
4363 }
4364 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004365
Craig Mautner81defc72013-10-29 11:10:42 -07004366 if (mTopIsFullscreen != topIsFullscreen) {
4367 if (!topIsFullscreen) {
4368 // Force another layout when status bar becomes fully shown.
4369 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4370 }
4371 mTopIsFullscreen = topIsFullscreen;
4372 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004373
Craig Mautner39834192012-09-02 07:47:24 -07004374 // Hide the key guard if a visible window explicitly specifies that it wants to be
4375 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004376 if (mKeyguardDelegate != null && mStatusBar != null) {
4377 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4378 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004379 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004380 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004381 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004382 changes |= FINISH_LAYOUT_REDO_LAYOUT
4383 | FINISH_LAYOUT_REDO_CONFIG
4384 | FINISH_LAYOUT_REDO_WALLPAPER;
4385 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004386 if (mKeyguardDelegate.isShowing()) {
4387 mHandler.post(new Runnable() {
4388 @Override
4389 public void run() {
4390 mKeyguardDelegate.keyguardDone(false, false);
4391 }
4392 });
4393 }
4394 } else if (mHideLockScreen) {
4395 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004396 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004397 changes |= FINISH_LAYOUT_REDO_LAYOUT
4398 | FINISH_LAYOUT_REDO_CONFIG
4399 | FINISH_LAYOUT_REDO_WALLPAPER;
4400 }
4401 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
4402 // This is the case of keyguard isSecure() and not mHideLockScreen.
4403 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4404 // Only launch the next keyguard unlock window once per window.
4405 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004406 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004407 changes |= FINISH_LAYOUT_REDO_LAYOUT
4408 | FINISH_LAYOUT_REDO_CONFIG
4409 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004410 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004411 mHandler.post(new Runnable() {
4412 @Override
4413 public void run() {
4414 mKeyguardDelegate.dismiss();
4415 }
4416 });
4417 }
4418 } else {
4419 mWinDismissingKeyguard = null;
4420 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004421 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004422 changes |= FINISH_LAYOUT_REDO_LAYOUT
4423 | FINISH_LAYOUT_REDO_CONFIG
4424 | FINISH_LAYOUT_REDO_WALLPAPER;
4425 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004426 }
4427 }
Joe Onorato664644d2011-01-23 17:53:23 -08004428
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004429 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004430 // If the navigation bar has been hidden or shown, we need to do another
4431 // layout pass to update that window.
4432 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4433 }
Joe Onorato664644d2011-01-23 17:53:23 -08004434
Mike Lockwood28569302010-01-28 11:54:40 -05004435 // update since mAllowLockscreenWhenOn might have changed
4436 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004437 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004438 }
4439
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004440 /**
Jim Millerab954542014-10-10 18:21:49 -07004441 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004442 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004443 * @return Whether the flags have changed and we have to redo the layout.
4444 */
Jim Millerab954542014-10-10 18:21:49 -07004445 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4446 boolean wasOccluded = mKeyguardOccluded;
4447 boolean showing = mKeyguardDelegate.isShowing();
4448 if (wasOccluded && !isOccluded && showing) {
4449 mKeyguardOccluded = false;
4450 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004451 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4452 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4453 return true;
Jim Millerab954542014-10-10 18:21:49 -07004454 } else if (!wasOccluded && isOccluded && showing) {
4455 mKeyguardOccluded = true;
4456 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004457 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4458 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4459 return true;
4460 } else {
4461 return false;
4462 }
4463 }
4464
4465 private boolean isStatusBarKeyguard() {
4466 return mStatusBar != null
4467 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4468 }
4469
Jose Lima9546b202014-07-02 17:21:51 -07004470 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004471 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004472 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004473 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004474 return false;
4475 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004476 return true;
4477 }
4478
Jose Lima9546b202014-07-02 17:21:51 -07004479 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004480 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004481 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004482 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004483 // If the navigation bar has been hidden or shown, we need to do another
4484 // layout pass to update that window.
4485 return FINISH_LAYOUT_REDO_LAYOUT;
4486 }
4487 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004488 }
4489
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004490 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004491 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004492 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4493 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004494 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4495 if (newLidState == mLidState) {
4496 return;
4497 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004498
Jeff Brownc458ce92012-04-30 14:58:40 -07004499 mLidState = newLidState;
4500 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004501 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004502
4503 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004504 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004505 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004506 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004507 }
4508 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004509
Michael Wright3818c922014-09-02 13:59:07 -07004510 @Override
4511 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4512 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4513 if (mCameraLensCoverState == lensCoverState) {
4514 return;
4515 }
4516 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4517 lensCoverState == CAMERA_LENS_UNCOVERED) {
4518 Intent intent;
4519 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4520 mKeyguardDelegate.isShowing();
4521 if (keyguardActive) {
4522 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4523 } else {
4524 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4525 }
Bryce Lee584a4452014-10-21 15:55:55 -07004526 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004527 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004528 }
4529 mCameraLensCoverState = lensCoverState;
4530 }
4531
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004532 void setHdmiPlugged(boolean plugged) {
4533 if (mHdmiPlugged != plugged) {
4534 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004535 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004536 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004537 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004538 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004539 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004540 }
4541 }
4542
Joe Onoratoea495d42011-04-06 11:41:11 -07004543 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004544 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004545 // watch for HDMI plug messages if the hdmi switch exists
4546 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4547 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4548
Joe Onoratoea495d42011-04-06 11:41:11 -07004549 final String filename = "/sys/class/switch/hdmi/state";
4550 FileReader reader = null;
4551 try {
4552 reader = new FileReader(filename);
4553 char[] buf = new char[15];
4554 int n = reader.read(buf);
4555 if (n > 1) {
4556 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4557 }
4558 } catch (IOException ex) {
4559 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4560 } catch (NumberFormatException ex) {
4561 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4562 } finally {
4563 if (reader != null) {
4564 try {
4565 reader.close();
4566 } catch (IOException ex) {
4567 }
Joe Onoratodc100302011-01-11 17:07:41 -08004568 }
4569 }
4570 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004571 // This dance forces the code in setHdmiPlugged to run.
4572 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4573 mHdmiPlugged = !plugged;
4574 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004575 }
4576
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004577 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004578 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004579
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004580 final Runnable mScreenshotTimeout = new Runnable() {
4581 @Override public void run() {
4582 synchronized (mScreenshotLock) {
4583 if (mScreenshotConnection != null) {
4584 mContext.unbindService(mScreenshotConnection);
4585 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004586 }
Winson Chung9112ec32011-06-27 13:15:32 -07004587 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004588 }
4589 };
4590
4591 // Assume this is called from the Handler thread.
4592 private void takeScreenshot() {
4593 synchronized (mScreenshotLock) {
4594 if (mScreenshotConnection != null) {
4595 return;
4596 }
4597 ComponentName cn = new ComponentName("com.android.systemui",
4598 "com.android.systemui.screenshot.TakeScreenshotService");
4599 Intent intent = new Intent();
4600 intent.setComponent(cn);
4601 ServiceConnection conn = new ServiceConnection() {
4602 @Override
4603 public void onServiceConnected(ComponentName name, IBinder service) {
4604 synchronized (mScreenshotLock) {
4605 if (mScreenshotConnection != this) {
4606 return;
4607 }
4608 Messenger messenger = new Messenger(service);
4609 Message msg = Message.obtain(null, 1);
4610 final ServiceConnection myConn = this;
4611 Handler h = new Handler(mHandler.getLooper()) {
4612 @Override
4613 public void handleMessage(Message msg) {
4614 synchronized (mScreenshotLock) {
4615 if (mScreenshotConnection == myConn) {
4616 mContext.unbindService(mScreenshotConnection);
4617 mScreenshotConnection = null;
4618 mHandler.removeCallbacks(mScreenshotTimeout);
4619 }
4620 }
4621 }
4622 };
4623 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004624 msg.arg1 = msg.arg2 = 0;
4625 if (mStatusBar != null && mStatusBar.isVisibleLw())
4626 msg.arg1 = 1;
4627 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4628 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004629 try {
4630 messenger.send(msg);
4631 } catch (RemoteException e) {
4632 }
4633 }
4634 }
4635 @Override
4636 public void onServiceDisconnected(ComponentName name) {}
4637 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004638 if (mContext.bindServiceAsUser(
4639 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004640 mScreenshotConnection = conn;
4641 mHandler.postDelayed(mScreenshotTimeout, 10000);
4642 }
4643 }
Winson Chung9112ec32011-06-27 13:15:32 -07004644 }
4645
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004646 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004647 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004648 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004649 if (!mSystemBooted) {
4650 // If we have not yet booted, don't let key events do anything.
4651 return 0;
4652 }
4653
Jeff Brown037c33e2014-04-09 00:31:55 -07004654 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004655 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4656 final boolean canceled = event.isCanceled();
4657 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004658
Jeff Brown3122e442010-10-11 23:32:49 -07004659 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004660
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004661 // If screen is off then we treat the case where the keyguard is open but hidden
4662 // the same as if it were open and in front.
4663 // This will prevent any keys other than the power button from waking the screen
4664 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004665 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004666 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004667 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004668 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004669
Jeff Brown40013652012-05-16 21:22:36 -07004670 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004671 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004672 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004673 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004674 }
4675
Jeff Brown037c33e2014-04-09 00:31:55 -07004676 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004677 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004678 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4679 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004680 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004681 // When the device is interactive or the key is injected pass the
4682 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004683 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004684 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004685 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4686 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4687 // to the application but preserve its wake key status to make sure we still move
4688 // from dozing to fully interactive if we would normally go from off to fully
4689 // interactive.
4690 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004691 } else {
4692 // When the screen is off and the key is not injected, determine whether
4693 // to wake the device but don't pass the key to the application.
4694 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004695 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4696 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004697 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004698 }
4699
Justin Kohd378ad72013-04-01 12:18:26 -07004700 // If the key would be handled globally, just return the result, don't worry about special
4701 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004702 if (isValidGlobalKey(keyCode)
4703 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004704 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004705 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004706 }
Justin Kohd378ad72013-04-01 12:18:26 -07004707 return result;
4708 }
4709
Jeff Brownbae8e772014-06-12 19:59:45 -07004710 boolean useHapticFeedback = down
4711 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4712 && event.getRepeatCount() == 0;
4713
Jeff Brown4d396052010-10-29 21:50:21 -07004714 // Handle special keys.
4715 switch (keyCode) {
4716 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004717 case KeyEvent.KEYCODE_VOLUME_UP:
4718 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004719 if (mUseTvRouting) {
4720 // On TVs volume keys never go to the foreground app
4721 result &= ~ACTION_PASS_TO_USER;
4722 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004723 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4724 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004725 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004726 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004727 mScreenshotChordVolumeDownKeyTriggered = true;
4728 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4729 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004730 cancelPendingPowerKeyAction();
4731 interceptScreenshotChord();
4732 }
4733 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004734 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004735 cancelPendingScreenshotChordAction();
4736 }
4737 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4738 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004739 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004740 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004741 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004742 cancelPendingPowerKeyAction();
4743 cancelPendingScreenshotChordAction();
4744 }
4745 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004746 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004747 cancelPendingScreenshotChordAction();
4748 }
4749 }
Jeff Brown4d396052010-10-29 21:50:21 -07004750 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004751 TelecomManager telecomManager = getTelecommService();
4752 if (telecomManager != null) {
4753 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004754 // If an incoming call is ringing, either VOLUME key means
4755 // "silence ringer". We handle these keys here, rather than
4756 // in the InCallScreen, to make sure we'll respond to them
4757 // even if the InCallScreen hasn't come to the foreground yet.
4758 // Look for the DOWN event here, to agree with the "fallback"
4759 // behavior in the InCallScreen.
4760 Log.i(TAG, "interceptKeyBeforeQueueing:"
4761 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004762
Santos Cordon6848f722014-05-21 15:22:12 -07004763 // Silence the ringer. (It's safe to call this
4764 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004765 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004766
Santos Cordon6848f722014-05-21 15:22:12 -07004767 // And *don't* pass this key thru to the current activity
4768 // (which is probably the InCallScreen.)
4769 result &= ~ACTION_PASS_TO_USER;
4770 break;
4771 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004772 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004773 && (result & ACTION_PASS_TO_USER) == 0) {
4774 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004775 // the application, just pass it to the session service.
4776
4777 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004778 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004779 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004780 }
4781 }
4782
RoboErik430fc482014-06-12 15:49:20 -07004783 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004784 if (mUseTvRouting) {
4785 dispatchDirectAudioEvent(event);
4786 } else {
4787 // If we aren't passing to the user and no one else
4788 // handled it send it to the session manager to
4789 // figure out.
4790 MediaSessionLegacyHelper.getHelper(mContext)
4791 .sendVolumeKeyEvent(event, true);
4792 }
Jeff Brown4d396052010-10-29 21:50:21 -07004793 break;
4794 }
4795 }
4796 break;
4797 }
4798
4799 case KeyEvent.KEYCODE_ENDCALL: {
4800 result &= ~ACTION_PASS_TO_USER;
4801 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004802 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004803 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004804 if (telecomManager != null) {
4805 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004806 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004807 if (interactive && !hungUp) {
4808 mEndCallKeyHandled = false;
4809 mHandler.postDelayed(mEndCallLongPress,
4810 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4811 } else {
4812 mEndCallKeyHandled = true;
4813 }
Jeff Brown4d396052010-10-29 21:50:21 -07004814 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004815 if (!mEndCallKeyHandled) {
4816 mHandler.removeCallbacks(mEndCallLongPress);
4817 if (!canceled) {
4818 if ((mEndcallBehavior
4819 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4820 if (goHome()) {
4821 break;
4822 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004823 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004824 if ((mEndcallBehavior
4825 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4826 mPowerManager.goToSleep(event.getEventTime(),
4827 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4828 isWakeKey = false;
4829 }
Jeff Brown4d396052010-10-29 21:50:21 -07004830 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004831 }
Jeff Brown4d396052010-10-29 21:50:21 -07004832 }
4833 break;
4834 }
4835
4836 case KeyEvent.KEYCODE_POWER: {
4837 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004838 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004839 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004840 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004841 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004842 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004843 }
4844 break;
4845 }
4846
Jeff Brown6212a492014-03-07 13:58:47 -08004847 case KeyEvent.KEYCODE_SLEEP: {
4848 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004849 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004850 if (!mPowerManager.isInteractive()) {
4851 useHapticFeedback = false; // suppress feedback if already non-interactive
4852 }
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004853 sleepPress(event);
Jeff Brown6212a492014-03-07 13:58:47 -08004854 break;
4855 }
4856
4857 case KeyEvent.KEYCODE_WAKEUP: {
4858 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004859 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004860 break;
4861 }
4862
Jeff Brown4d396052010-10-29 21:50:21 -07004863 case KeyEvent.KEYCODE_MEDIA_PLAY:
4864 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4865 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004866 case KeyEvent.KEYCODE_HEADSETHOOK:
4867 case KeyEvent.KEYCODE_MUTE:
4868 case KeyEvent.KEYCODE_MEDIA_STOP:
4869 case KeyEvent.KEYCODE_MEDIA_NEXT:
4870 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4871 case KeyEvent.KEYCODE_MEDIA_REWIND:
4872 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004873 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4874 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004875 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4876 // If the global session is active pass all media keys to it
4877 // instead of the active window.
4878 result &= ~ACTION_PASS_TO_USER;
4879 }
Jeff Brown4d396052010-10-29 21:50:21 -07004880 if ((result & ACTION_PASS_TO_USER) == 0) {
4881 // Only do this if we would otherwise not pass it to the user. In that
4882 // case, the PhoneWindow class will do the same thing, except it will
4883 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004884 // Note that we need to make a copy of the key event here because the
4885 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004886 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004887 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4888 new KeyEvent(event));
4889 msg.setAsynchronous(true);
4890 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004891 }
4892 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004893 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004894
Jeff Brown4d396052010-10-29 21:50:21 -07004895 case KeyEvent.KEYCODE_CALL: {
4896 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004897 TelecomManager telecomManager = getTelecommService();
4898 if (telecomManager != null) {
4899 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004900 Log.i(TAG, "interceptKeyBeforeQueueing:"
4901 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004902 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004903
Santos Cordon6848f722014-05-21 15:22:12 -07004904 // And *don't* pass this key thru to the current activity
4905 // (which is presumably the InCallScreen.)
4906 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004907 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004908 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004909 }
Jeff Brown4d396052010-10-29 21:50:21 -07004910 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004911 }
Michael Wright869a67c2014-08-26 19:33:06 -07004912 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4913 // Only do this if we would otherwise not pass it to the user. In that case,
4914 // interceptKeyBeforeDispatching would apply a similar but different policy in
4915 // order to invoke voice assist actions. Note that we need to make a copy of the
4916 // key event here because the original key event will be recycled when we return.
4917 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4918 mBroadcastWakeLock.acquire();
4919 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4920 keyguardActive ? 1 : 0, 0);
4921 msg.setAsynchronous(true);
4922 msg.sendToTarget();
4923 }
4924 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004925 }
Jeff Brown26875502014-01-30 21:47:47 -08004926
Jeff Brownbae8e772014-06-12 19:59:45 -07004927 if (useHapticFeedback) {
4928 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4929 }
4930
Jeff Brown26875502014-01-30 21:47:47 -08004931 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004932 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004933 }
Bryce Lee584a4452014-10-21 15:55:55 -07004934
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004935 return result;
4936 }
4937
Jeff Brown1c2e4942012-11-06 16:32:01 -08004938 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004939 * Returns true if the key can have global actions attached to it.
4940 * We reserve all power management keys for the system since they require
4941 * very careful handling.
4942 */
4943 private static boolean isValidGlobalKey(int keyCode) {
4944 switch (keyCode) {
4945 case KeyEvent.KEYCODE_POWER:
4946 case KeyEvent.KEYCODE_WAKEUP:
4947 case KeyEvent.KEYCODE_SLEEP:
4948 return false;
4949 default:
4950 return true;
4951 }
4952 }
4953
4954 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08004955 * When the screen is off we ignore some keys that might otherwise typically
4956 * be considered wake keys. We filter them out here.
4957 *
4958 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4959 * is always considered a wake key.
4960 */
4961 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4962 switch (keyCode) {
4963 // ignore volume keys unless docked
4964 case KeyEvent.KEYCODE_VOLUME_UP:
4965 case KeyEvent.KEYCODE_VOLUME_DOWN:
4966 case KeyEvent.KEYCODE_VOLUME_MUTE:
4967 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4968
4969 // ignore media and camera keys
4970 case KeyEvent.KEYCODE_MUTE:
4971 case KeyEvent.KEYCODE_HEADSETHOOK:
4972 case KeyEvent.KEYCODE_MEDIA_PLAY:
4973 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4974 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4975 case KeyEvent.KEYCODE_MEDIA_STOP:
4976 case KeyEvent.KEYCODE_MEDIA_NEXT:
4977 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4978 case KeyEvent.KEYCODE_MEDIA_REWIND:
4979 case KeyEvent.KEYCODE_MEDIA_RECORD:
4980 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004981 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004982 case KeyEvent.KEYCODE_CAMERA:
4983 return false;
4984 }
4985 return true;
4986 }
4987
4988
Jeff Brown56194eb2011-03-02 19:23:13 -08004989 /** {@inheritDoc} */
4990 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004991 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4992 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08004993 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
4994 return 0;
4995 }
Michael Wright70af00a2014-09-03 19:30:20 -07004996 }
Bryce Lee5c138322014-11-03 08:26:09 -08004997
Michael Wright70af00a2014-09-03 19:30:20 -07004998 if (shouldDispatchInputWhenNonInteractive()) {
4999 return ACTION_PASS_TO_USER;
5000 }
Bryce Lee5c138322014-11-03 08:26:09 -08005001
Bryce Lee812d7022014-11-10 13:33:28 -08005002 // If we have not passed the action up and we are in theater mode without dreaming,
5003 // there will be no dream to intercept the touch and wake into ambient. The device should
5004 // wake up in this case.
5005 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
5006 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
5007 }
5008
Jeff Brown037c33e2014-04-09 00:31:55 -07005009 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005010 }
5011
Michael Wright70af00a2014-09-03 19:30:20 -07005012 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08005013 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07005014 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5015 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005016 return true;
5017 }
5018
5019 // Send events to a dozing dream even if the screen is off since the dream
5020 // is in control of the state of the screen.
5021 IDreamManager dreamManager = getDreamManager();
5022
5023 try {
5024 if (dreamManager != null && dreamManager.isDreaming()) {
5025 return true;
5026 }
5027 } catch (RemoteException e) {
5028 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5029 }
5030
5031 // Otherwise, consume events since the user can't see what is being
5032 // interacted with.
5033 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005034 }
5035
RoboErik001c59c2015-01-26 15:53:51 -08005036 private void dispatchDirectAudioEvent(KeyEvent event) {
5037 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5038 return;
5039 }
5040 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005041 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5042 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005043 String pkgName = mContext.getOpPackageName();
5044 switch (keyCode) {
5045 case KeyEvent.KEYCODE_VOLUME_UP:
5046 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005047 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005048 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005049 } catch (RemoteException e) {
5050 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5051 }
5052 break;
5053 case KeyEvent.KEYCODE_VOLUME_DOWN:
5054 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005055 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005056 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005057 } catch (RemoteException e) {
5058 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5059 }
5060 break;
5061 case KeyEvent.KEYCODE_VOLUME_MUTE:
5062 try {
5063 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005064 getAudioService().adjustSuggestedStreamVolume(
5065 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005066 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005067 }
5068 } catch (RemoteException e) {
5069 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5070 }
5071 break;
5072 }
5073 }
5074
Jeff Brown40013652012-05-16 21:22:36 -07005075 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5076 if (DEBUG_INPUT) {
5077 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005078 }
5079
Jeff Brown40013652012-05-16 21:22:36 -07005080 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5081 if (DEBUG_INPUT) {
5082 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5083 }
5084
5085 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5086 mHavePendingMediaKeyRepeatWithWakeLock = false;
5087 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5088 }
5089
5090 dispatchMediaKeyWithWakeLockToAudioService(event);
5091
5092 if (event.getAction() == KeyEvent.ACTION_DOWN
5093 && event.getRepeatCount() == 0) {
5094 mHavePendingMediaKeyRepeatWithWakeLock = true;
5095
5096 Message msg = mHandler.obtainMessage(
5097 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5098 msg.setAsynchronous(true);
5099 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5100 } else {
5101 mBroadcastWakeLock.release();
5102 }
5103 }
5104
5105 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5106 mHavePendingMediaKeyRepeatWithWakeLock = false;
5107
5108 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5109 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5110 if (DEBUG_INPUT) {
5111 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5112 }
5113
5114 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5115 mBroadcastWakeLock.release();
5116 }
5117
5118 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5119 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005120 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005121 }
5122 }
5123
Michael Wright869a67c2014-08-26 19:33:06 -07005124 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
5125 Intent voiceIntent =
5126 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5127 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005128 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005129 mBroadcastWakeLock.release();
5130 }
5131
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005132 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005133 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005134 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005135 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5136 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5137 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005138 } else {
5139 try {
5140 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5141 ServiceManager.getService(Context.UI_MODE_SERVICE));
5142 mUiMode = uiModeService.getCurrentModeType();
5143 } catch (RemoteException e) {
5144 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005145 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005146 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005147 synchronized (mLock) {
5148 updateOrientationListenerLp();
5149 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005150 }
5151 };
5152
Jeff Brown6aaf2952012-10-05 16:01:08 -07005153 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5154 @Override
5155 public void onReceive(Context context, Intent intent) {
5156 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005157 if (mKeyguardDelegate != null) {
5158 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005159 }
5160 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005161 if (mKeyguardDelegate != null) {
5162 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005163 }
5164 }
5165 }
5166 };
5167
Christopher Tate5e08af02012-09-21 17:17:22 -07005168 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5169 @Override
5170 public void onReceive(Context context, Intent intent) {
5171 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5172 // tickle the settings observer: this first ensures that we're
5173 // observing the relevant settings for the newly-active user,
5174 // and then updates our own bookkeeping based on the now-
5175 // current user.
5176 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005177
5178 // force a re-application of focused window sysui visibility.
5179 // the window may never have been shown for this user
5180 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005181 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005182 mLastSystemUiFlags = 0;
5183 updateSystemUiVisibilityLw();
5184 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005185 }
5186 }
5187 };
5188
John Spurlockd9b70bd2014-02-06 17:02:44 -05005189 private final Runnable mRequestTransientNav = new Runnable() {
5190 @Override
5191 public void run() {
5192 requestTransientBars(mNavigationBar);
5193 }
5194 };
5195
John Spurlocke1f366f2013-08-05 12:22:40 -04005196 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005197 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005198 if (!isUserSetupComplete()) {
5199 // Swipe-up for navigation bar is disabled during setup
5200 return;
5201 }
John Spurlock27735a42013-08-14 17:57:38 -04005202 boolean sb = mStatusBarController.checkShowTransientBarLw();
5203 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005204 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005205 // Don't show status bar when swiping on already visible navigation bar
5206 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005207 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005208 return;
5209 }
John Spurlock27735a42013-08-14 17:57:38 -04005210 if (sb) mStatusBarController.showTransient();
5211 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005212 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005213 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005214 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005215 }
5216 }
5217
Jeff Brown3ee549c2014-09-22 20:14:39 -07005218 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005219 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07005220 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005221 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07005222 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005223
5224 // We must get this work done here because the power manager will drop
5225 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005226 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005227 mAwake = false;
5228 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005229 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005230 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005231 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005232 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005233
5234 if (mKeyguardDelegate != null) {
5235 mKeyguardDelegate.onScreenTurnedOff(why);
5236 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005237 }
5238
Jeff Brown13f00f02014-10-31 14:45:50 -07005239 private void wakeUpFromPowerKey(long eventTime) {
5240 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5241 }
5242
Bryce Lee5c138322014-11-03 08:26:09 -08005243 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Lee584a4452014-10-21 15:55:55 -07005244 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005245 return false;
Bryce Lee584a4452014-10-21 15:55:55 -07005246 }
5247
5248 mPowerManager.wakeUp(wakeTime);
Bryce Lee5c138322014-11-03 08:26:09 -08005249 return true;
Bryce Lee584a4452014-10-21 15:55:55 -07005250 }
5251
Jeff Brown3ee549c2014-09-22 20:14:39 -07005252 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005253 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07005254 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005255 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07005256 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005257
Jeff Brown3ee549c2014-09-22 20:14:39 -07005258 // Since goToSleep performs these functions synchronously, we must
5259 // do the same here. We cannot post this work to a handler because
5260 // that might cause it to become reordered with respect to what
5261 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005262 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005263 mAwake = true;
5264 mKeyguardDrawComplete = false;
5265 if (mKeyguardDelegate != null) {
5266 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5267 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5268 }
5269
Jeff Browna20dda42014-05-27 20:57:24 -07005270 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005271 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005272 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005273 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005274
Jim Miller5ecd8112013-01-09 18:50:26 -08005275 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07005276 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005277 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005278 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005279 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005280 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005281 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005282 }
5283
Jeff Brown36c4db82014-09-19 12:05:31 -07005284 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005285 synchronized (mLock) {
5286 if (!mAwake || mKeyguardDrawComplete) {
5287 return; // spurious
5288 }
5289
Jeff Brown36c4db82014-09-19 12:05:31 -07005290 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005291 if (mKeyguardDelegate != null) {
5292 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5293 }
5294 }
5295
5296 finishScreenTurningOn();
5297 }
5298
5299 // Called on the DisplayManager's DisplayPowerController thread.
5300 @Override
5301 public void screenTurnedOff() {
5302 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5303
5304 synchronized (mLock) {
5305 mScreenOnEarly = false;
5306 mScreenOnFully = false;
5307 mWindowManagerDrawComplete = false;
5308 mScreenOnListener = null;
5309 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005310 }
5311 }
5312
Jeff Brown3ee549c2014-09-22 20:14:39 -07005313 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005314 @Override
5315 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005316 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005317
Jeff Brown3ee549c2014-09-22 20:14:39 -07005318 synchronized (mLock) {
5319 mScreenOnEarly = true;
5320 mScreenOnFully = false;
5321 mWindowManagerDrawComplete = false;
5322 mScreenOnListener = screenOnListener;
5323 updateOrientationListenerLp();
5324 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005325
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005326 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5327 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005328 // ... eventually calls finishWindowsDrawn
5329 }
5330
Jeff Brown36c4db82014-09-19 12:05:31 -07005331 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005332 synchronized (mLock) {
5333 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5334 return; // spurious
5335 }
5336
Jeff Brown36c4db82014-09-19 12:05:31 -07005337 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005338 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005339
5340 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005341 }
5342
Craig Mautner8a0da012014-05-31 15:13:37 -07005343 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005344 final ScreenOnListener listener;
5345 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005346 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005347 if (DEBUG_WAKEUP) Slog.d(TAG,
5348 "finishScreenTurningOn: mAwake=" + mAwake
5349 + ", mScreenOnEarly=" + mScreenOnEarly
5350 + ", mScreenOnFully=" + mScreenOnFully
5351 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5352 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5353
5354 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5355 || (mAwake && !mKeyguardDrawComplete)) {
5356 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005357 }
5358
Jeff Brown3ee549c2014-09-22 20:14:39 -07005359 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5360 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005361 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005362 mScreenOnFully = true;
5363
5364 // Remember the first time we draw the keyguard so we know when we're done with
5365 // the main part of booting and can enable the screen and hide boot messages.
5366 if (!mKeyguardDrawnOnce && mAwake) {
5367 mKeyguardDrawnOnce = true;
5368 enableScreen = true;
5369 if (mBootMessageNeedsHiding) {
5370 mBootMessageNeedsHiding = false;
5371 hideBootMessages();
5372 }
5373 } else {
5374 enableScreen = false;
5375 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005376 }
5377
Jeff Brown3ee549c2014-09-22 20:14:39 -07005378 if (listener != null) {
5379 listener.onScreenOn();
5380 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005381
Jeff Brown3ee549c2014-09-22 20:14:39 -07005382 if (enableScreen) {
5383 try {
5384 mWindowManager.enableScreenIfNeeded();
5385 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005386 }
Craig Mautnera631d492014-08-05 15:16:01 -07005387 }
5388 }
5389
5390 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005391 synchronized (mLock) {
5392 if (!mKeyguardDrawnOnce) {
5393 mBootMessageNeedsHiding = true;
5394 return; // keyguard hasn't drawn the first time yet, not done booting
5395 }
Craig Mautnera631d492014-08-05 15:16:01 -07005396 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005397
5398 if (mBootMsgDialog != null) {
5399 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5400 mBootMsgDialog.dismiss();
5401 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005402 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005403 }
5404
5405 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005406 public boolean isScreenOn() {
5407 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005408 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005409
Dianne Hackborn08743722009-12-21 12:16:51 -08005410 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005411 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005412 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005413 if (mKeyguardDelegate != null) {
5414 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005415 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005416 }
5417
5418 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005419 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005420 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005421 if (mKeyguardDelegate != null) {
5422 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005423 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005424 }
5425
Jim Millerab954542014-10-10 18:21:49 -07005426 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005427 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005428 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005429 }
5430
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005431 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005432 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005433 public boolean isKeyguardLocked() {
5434 return keyguardOn();
5435 }
5436
5437 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005438 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005439 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005440 if (mKeyguardDelegate == null) return false;
5441 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005442 }
5443
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005444 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005445 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005446 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005447 if (mKeyguardDelegate == null) return false;
5448 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005449 }
5450
Jose Lima9546b202014-07-02 17:21:51 -07005451 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005452 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005453 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005454 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005455 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005456 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005457 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005458 // ask the keyguard to prompt the user to authenticate if necessary
5459 mKeyguardDelegate.dismiss();
5460 }
5461 });
5462 }
5463 }
5464
5465 public void notifyActivityDrawnForKeyguardLw() {
5466 if (mKeyguardDelegate != null) {
5467 mHandler.post(new Runnable() {
5468 @Override
5469 public void run() {
5470 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005471 }
5472 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005473 }
5474 }
5475
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005476 @Override
5477 public boolean isKeyguardDrawnLw() {
5478 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005479 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005480 }
5481 }
5482
Jorim Jaggi0d674622014-05-21 01:34:15 +02005483 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005484 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005485 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005486 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005487 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005488 }
5489 }
5490
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005491 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005492 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005493 }
5494
5495 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005496 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005497 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005498
Jeff Brown01a98dd2011-09-20 15:08:29 -07005499 @Override
5500 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005501 if (false) {
5502 Slog.v(TAG, "rotationForOrientationLw(orient="
5503 + orientation + ", last=" + lastRotation
5504 + "); user=" + mUserRotation + " "
5505 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5506 ? "USER_ROTATION_LOCKED" : "")
5507 );
5508 }
5509
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005510 if (mForceDefaultOrientation) {
5511 return Surface.ROTATION_0;
5512 }
5513
The Android Open Source Project0727d222009-03-11 12:11:58 -07005514 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005515 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5516 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005517 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005518 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005519
Jeff Browndec6cf42011-11-15 14:08:20 -08005520 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005521 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005522 // Ignore sensor when lid switch is open and rotation is forced.
5523 preferredRotation = mLidOpenRotation;
5524 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005525 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005526 // Ignore sensor when in car dock unless explicitly enabled.
5527 // This case can override the behavior of NOSENSOR, and can also
5528 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005529 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005530 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005531 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5532 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5533 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005534 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005535 // Ignore sensor when in desk dock unless explicitly enabled.
5536 // This case can override the behavior of NOSENSOR, and can also
5537 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005538 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005539 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005540 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5541 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005542 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005543 preferredRotation = mDemoHdmiRotation;
5544 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5545 && mUndockedHdmiRotation >= 0) {
5546 // Ignore sensor when plugged into HDMI and an undocked orientation has
5547 // been specified in the configuration (only for legacy devices without
5548 // full multi-display support).
5549 // Note that the dock orientation overrides the HDMI orientation.
5550 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005551 } else if (mDemoRotationLock) {
5552 // Ignore sensor when demo rotation lock is enabled.
5553 // Note that the dock orientation and HDMI rotation lock override this.
5554 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005555 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5556 // Application just wants to remain locked in the last rotation.
5557 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005558 } else if (!mSupportAutoRotation) {
5559 // If we don't support auto-rotation then bail out here and ignore
5560 // the sensor and any rotation lock settings.
5561 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005562 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005563 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005564 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5565 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5566 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5567 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005568 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5569 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5570 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5571 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5572 // Otherwise, use sensor only if requested by the application or enabled
5573 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005574 if (mAllowAllRotations < 0) {
5575 // Can't read this during init() because the context doesn't
5576 // have display metrics at that time so we cannot determine
5577 // tablet vs. phone then.
5578 mAllowAllRotations = mContext.getResources().getBoolean(
5579 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5580 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005581 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005582 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005583 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5584 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005585 preferredRotation = sensorRotation;
5586 } else {
5587 preferredRotation = lastRotation;
5588 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005589 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5590 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5591 // Apply rotation lock. Does not apply to NOSENSOR.
5592 // The idea is that the user rotation expresses a weak preference for the direction
5593 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5594 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005595 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005596 } else {
5597 // No overriding preference.
5598 // We will do exactly what the application asked us to do.
5599 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005600 }
5601
Dianne Hackborne5439f22010-10-02 16:53:50 -07005602 switch (orientation) {
5603 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005604 // Return portrait unless overridden.
5605 if (isAnyPortrait(preferredRotation)) {
5606 return preferredRotation;
5607 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005608 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005609
Jeff Brown01a98dd2011-09-20 15:08:29 -07005610 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005611 // Return landscape unless overridden.
5612 if (isLandscapeOrSeascape(preferredRotation)) {
5613 return preferredRotation;
5614 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005615 return mLandscapeRotation;
5616
5617 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005618 // Return reverse portrait unless overridden.
5619 if (isAnyPortrait(preferredRotation)) {
5620 return preferredRotation;
5621 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005622 return mUpsideDownRotation;
5623
5624 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005625 // Return seascape unless overridden.
5626 if (isLandscapeOrSeascape(preferredRotation)) {
5627 return preferredRotation;
5628 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005629 return mSeascapeRotation;
5630
5631 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005632 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005633 // Return either landscape rotation.
5634 if (isLandscapeOrSeascape(preferredRotation)) {
5635 return preferredRotation;
5636 }
5637 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005638 return lastRotation;
5639 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005640 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005641
Jeff Brown01a98dd2011-09-20 15:08:29 -07005642 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005643 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005644 // Return either portrait rotation.
5645 if (isAnyPortrait(preferredRotation)) {
5646 return preferredRotation;
5647 }
5648 if (isAnyPortrait(lastRotation)) {
5649 return lastRotation;
5650 }
5651 return mPortraitRotation;
5652
5653 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005654 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5655 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005656 if (preferredRotation >= 0) {
5657 return preferredRotation;
5658 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005659 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005660 }
5661 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005662 }
5663
Jeff Brown01a98dd2011-09-20 15:08:29 -07005664 @Override
5665 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5666 switch (orientation) {
5667 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5668 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5669 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5670 return isAnyPortrait(rotation);
5671
5672 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5673 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5674 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5675 return isLandscapeOrSeascape(rotation);
5676
5677 default:
5678 return true;
5679 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005680 }
5681
Jeff Brownc0347aa2011-09-23 17:26:09 -07005682 @Override
5683 public void setRotationLw(int rotation) {
5684 mOrientationListener.setCurrentRotation(rotation);
5685 }
5686
Jeff Brown01a98dd2011-09-20 15:08:29 -07005687 private boolean isLandscapeOrSeascape(int rotation) {
5688 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005689 }
5690
Jeff Brown01a98dd2011-09-20 15:08:29 -07005691 private boolean isAnyPortrait(int rotation) {
5692 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005693 }
5694
Jose Lima9546b202014-07-02 17:21:51 -07005695 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005696 public int getUserRotationMode() {
5697 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005698 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5699 WindowManagerPolicy.USER_ROTATION_FREE :
5700 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005701 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005702
5703 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005704 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005705 public void setUserRotationMode(int mode, int rot) {
5706 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005707
5708 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005709 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005710 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005711 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005712 rot,
5713 UserHandle.USER_CURRENT);
5714 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005715 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005716 0,
5717 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005718 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005719 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005720 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005721 1,
5722 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005723 }
5724 }
5725
Jose Lima9546b202014-07-02 17:21:51 -07005726 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005727 public void setSafeMode(boolean safeMode) {
5728 mSafeMode = safeMode;
5729 performHapticFeedbackLw(null, safeMode
5730 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5731 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005732 }
Craig Mautnereda67292013-04-28 13:50:14 -07005733
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005734 static long[] getLongIntArray(Resources r, int resid) {
5735 int[] ar = r.getIntArray(resid);
5736 if (ar == null) {
5737 return null;
5738 }
5739 long[] out = new long[ar.length];
5740 for (int i=0; i<ar.length; i++) {
5741 out[i] = ar[i];
5742 }
5743 return out;
5744 }
Craig Mautnereda67292013-04-28 13:50:14 -07005745
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005746 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005747 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005748 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005749 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005750 mKeyguardDelegate.onSystemReady();
5751
Michael Wright3818c922014-09-02 13:59:07 -07005752 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005753 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005754 synchronized (mLock) {
5755 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005756 mSystemReady = true;
5757 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005758 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005759 public void run() {
5760 updateSettings();
5761 }
5762 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005763 }
5764 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005765
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005766 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005767 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005768 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005769 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005770 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005771 mKeyguardDelegate.onBootCompleted();
5772 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005773 synchronized (mLock) {
5774 mSystemBooted = true;
5775 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005776 wakingUp();
5777 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005778 }
5779
Dianne Hackborn661cd522011-08-22 00:26:20 -07005780 ProgressDialog mBootMsgDialog = null;
5781
5782 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005783 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005784 public void showBootMessage(final CharSequence msg, final boolean always) {
5785 mHandler.post(new Runnable() {
5786 @Override public void run() {
5787 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005788 int theme;
5789 if (mContext.getPackageManager().hasSystemFeature(
5790 PackageManager.FEATURE_WATCH)) {
5791 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5792 } else if (mContext.getPackageManager().hasSystemFeature(
5793 PackageManager.FEATURE_TELEVISION)) {
5794 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5795 } else {
5796 theme = 0;
5797 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005798
5799 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005800 // This dialog will consume all events coming in to
5801 // it, to avoid it trying to do things too early in boot.
5802 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5803 return true;
5804 }
5805 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5806 return true;
5807 }
5808 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5809 return true;
5810 }
5811 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5812 return true;
5813 }
5814 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5815 return true;
5816 }
5817 @Override public boolean dispatchPopulateAccessibilityEvent(
5818 AccessibilityEvent event) {
5819 return true;
5820 }
5821 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005822 if (mContext.getPackageManager().isUpgrade()) {
5823 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5824 } else {
5825 mBootMsgDialog.setTitle(R.string.android_start_title);
5826 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005827 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5828 mBootMsgDialog.setIndeterminate(true);
5829 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005830 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005831 mBootMsgDialog.getWindow().addFlags(
5832 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5833 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5834 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005835 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5836 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5837 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005838 mBootMsgDialog.setCancelable(false);
5839 mBootMsgDialog.show();
5840 }
5841 mBootMsgDialog.setMessage(msg);
5842 }
5843 });
5844 }
5845
5846 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005847 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005848 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005849 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005850 }
5851
Mike Lockwood28569302010-01-28 11:54:40 -05005852 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005853 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005854 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005855 // ***************************************
5856 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5857 // ***************************************
5858 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5859 // WITH ITS LOCKS HELD.
5860 //
5861 // This code must be VERY careful about the locks
5862 // it acquires.
5863 // In fact, the current code acquires way too many,
5864 // and probably has lurking deadlocks.
5865
Mike Lockwood28569302010-01-28 11:54:40 -05005866 synchronized (mScreenLockTimeout) {
5867 if (mLockScreenTimerActive) {
5868 // reset the timer
5869 mHandler.removeCallbacks(mScreenLockTimeout);
5870 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5871 }
5872 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005873 }
5874
Adam Cohenf7522022012-10-03 20:03:18 -07005875 class ScreenLockTimeout implements Runnable {
5876 Bundle options;
5877
5878 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005879 public void run() {
5880 synchronized (this) {
5881 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005882 if (mKeyguardDelegate != null) {
5883 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005884 }
Mike Lockwood28569302010-01-28 11:54:40 -05005885 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005886 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005887 }
5888 }
Mike Lockwood28569302010-01-28 11:54:40 -05005889
Adam Cohenf7522022012-10-03 20:03:18 -07005890 public void setLockOptions(Bundle options) {
5891 this.options = options;
5892 }
5893 }
5894
5895 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5896
Jose Lima9546b202014-07-02 17:21:51 -07005897 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005898 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005899 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5900 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005901 if (options != null) {
5902 // In case multiple calls are made to lockNow, we don't wipe out the options
5903 // until the runnable actually executes.
5904 mScreenLockTimeout.setLockOptions(options);
5905 }
Jim Miller93c518e2012-01-17 15:55:31 -08005906 mHandler.post(mScreenLockTimeout);
5907 }
5908
Mike Lockwood28569302010-01-28 11:54:40 -05005909 private void updateLockScreenTimeout() {
5910 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005911 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005912 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005913 if (mLockScreenTimerActive != enable) {
5914 if (enable) {
5915 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5916 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5917 } else {
5918 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5919 mHandler.removeCallbacks(mScreenLockTimeout);
5920 }
5921 mLockScreenTimerActive = enable;
5922 }
5923 }
5924 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005925
Jeff Brown061ea992015-04-17 19:55:47 -07005926 private void updateDreamingSleepToken(boolean acquire) {
5927 if (acquire) {
5928 if (mDreamingSleepToken == null) {
5929 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
5930 }
5931 } else {
5932 if (mDreamingSleepToken != null) {
5933 mDreamingSleepToken.release();
5934 }
5935 }
5936 }
5937
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005938 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005939 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005940 public void enableScreenAfterBoot() {
5941 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005942 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005943 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005944 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005945
Jeff Brownc458ce92012-04-30 14:58:40 -07005946 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005947 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005948 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005949 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005950 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005951 }
Jeff Browna20dda42014-05-27 20:57:24 -07005952
5953 synchronized (mLock) {
5954 updateWakeGestureListenerLp();
5955 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005956 }
5957
Jeff Brown4f5fa282014-06-12 19:19:15 -07005958 void updateUiMode() {
5959 if (mUiModeManager == null) {
5960 mUiModeManager = IUiModeManager.Stub.asInterface(
5961 ServiceManager.getService(Context.UI_MODE_SERVICE));
5962 }
5963 try {
5964 mUiMode = mUiModeManager.getCurrentModeType();
5965 } catch (RemoteException e) {
5966 }
5967 }
5968
Jeff Brown01a98dd2011-09-20 15:08:29 -07005969 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005970 try {
5971 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005972 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5973 } catch (RemoteException e) {
5974 // Ignore
5975 }
5976 }
5977
5978 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5979 try {
5980 //set orientation on WindowManager
5981 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005982 } catch (RemoteException e) {
5983 // Ignore
5984 }
5985 }
5986
Daniel Sandler6396c722013-04-16 20:19:09 -04005987 /**
5988 * Return an Intent to launch the currently active dock app as home. Returns
5989 * null if the standard home should be launched, which is the case if any of the following is
5990 * true:
5991 * <ul>
5992 * <li>The device is not in either car mode or desk mode
5993 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5994 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5995 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5996 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5997 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005998 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005999 */
6000 Intent createHomeDockIntent() {
6001 Intent intent = null;
6002
6003 // What home does is based on the mode, not the dock state. That
6004 // is, when in car mode you should be taken to car home regardless
6005 // of whether we are actually in a car dock.
6006 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6007 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
6008 intent = mCarDockIntent;
6009 }
6010 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6011 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6012 intent = mDeskDockIntent;
6013 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006014 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6015 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6016 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6017 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6018 // Always launch dock home from home when watch is docked, if it exists.
6019 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006020 }
6021
6022 if (intent == null) {
6023 return null;
6024 }
6025
6026 ActivityInfo ai = null;
6027 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6028 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006029 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006030 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006031 if (info != null) {
6032 ai = info.activityInfo;
6033 }
6034 if (ai != null
6035 && ai.metaData != null
6036 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6037 intent = new Intent(intent);
6038 intent.setClassName(ai.packageName, ai.name);
6039 return intent;
6040 }
6041
6042 return null;
6043 }
6044
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006045 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6046 if (awakenFromDreams) {
6047 awakenDreams();
6048 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006049
6050 Intent dock = createHomeDockIntent();
6051 if (dock != null) {
6052 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006053 if (fromHomeKey) {
6054 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6055 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006056 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006057 return;
6058 } catch (ActivityNotFoundException e) {
6059 }
6060 }
6061
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006062 Intent intent;
6063
6064 if (fromHomeKey) {
6065 intent = new Intent(mHomeIntent);
6066 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6067 } else {
6068 intent = mHomeIntent;
6069 }
6070
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006071 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006072 }
Craig Mautnereda67292013-04-28 13:50:14 -07006073
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006074 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006075 * goes to the home screen
6076 * @return whether it did anything
6077 */
6078 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006079 if (!isUserSetupComplete()) {
6080 Slog.i(TAG, "Not going home because user setup is in progress.");
6081 return false;
6082 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006083 if (false) {
6084 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006085 try {
6086 ActivityManagerNative.getDefault().stopAppSwitches();
6087 } catch (RemoteException e) {
6088 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006089 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006090 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006091 } else {
6092 // This code brings home to the front or, if it is already
6093 // at the front, puts the device to sleep.
6094 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006095 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6096 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6097 Log.d(TAG, "UTS-TEST-MODE");
6098 } else {
6099 ActivityManagerNative.getDefault().stopAppSwitches();
6100 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006101 Intent dock = createHomeDockIntent();
6102 if (dock != null) {
6103 int result = ActivityManagerNative.getDefault()
6104 .startActivityAsUser(null, null, dock,
6105 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6106 null, null, 0,
6107 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006108 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006109 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6110 return false;
6111 }
6112 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006113 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006114 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006115 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006116 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006117 null, null, 0,
6118 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006119 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006120 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006121 return false;
6122 }
6123 } catch (RemoteException ex) {
6124 // bummer, the activity manager, which is in this process, is dead
6125 }
6126 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006127 return true;
6128 }
Craig Mautnereda67292013-04-28 13:50:14 -07006129
6130 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006131 public void setCurrentOrientationLw(int newOrientation) {
6132 synchronized (mLock) {
6133 if (newOrientation != mCurrentAppOrientation) {
6134 mCurrentAppOrientation = newOrientation;
6135 updateOrientationListenerLp();
6136 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006137 }
6138 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006139
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006140 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6141 if (!isGlobalAccessibilityGestureEnabled()) {
6142 return;
6143 }
6144 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6145 Context.AUDIO_SERVICE);
6146 if (audioManager.isSilentMode()) {
6147 return;
6148 }
6149 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6150 Settings.System.DEFAULT_NOTIFICATION_URI);
6151 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6152 ringTone.play();
6153 }
Craig Mautnereda67292013-04-28 13:50:14 -07006154
Bryce Lee584a4452014-10-21 15:55:55 -07006155 private boolean isTheaterModeEnabled() {
6156 return Settings.Global.getInt(mContext.getContentResolver(),
6157 Settings.Global.THEATER_MODE_ON, 0) == 1;
6158 }
6159
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006160 private boolean isGlobalAccessibilityGestureEnabled() {
6161 return Settings.Global.getInt(mContext.getContentResolver(),
6162 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6163 }
6164
Craig Mautnereda67292013-04-28 13:50:14 -07006165 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006166 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006167 if (!mVibrator.hasVibrator()) {
6168 return false;
6169 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006170 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6171 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006172 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006173 return false;
6174 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006175 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006176 switch (effectId) {
6177 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006178 pattern = mLongPressVibePattern;
6179 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006180 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006181 pattern = mVirtualKeyVibePattern;
6182 break;
6183 case HapticFeedbackConstants.KEYBOARD_TAP:
6184 pattern = mKeyboardTapVibePattern;
6185 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006186 case HapticFeedbackConstants.CLOCK_TICK:
6187 pattern = mClockTickVibePattern;
6188 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006189 case HapticFeedbackConstants.CALENDAR_DATE:
6190 pattern = mCalendarDateVibePattern;
6191 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006192 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006193 pattern = mSafeModeDisabledVibePattern;
6194 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006195 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006196 pattern = mSafeModeEnabledVibePattern;
6197 break;
Mady Mellore82067b2015-04-30 09:58:35 -07006198 case HapticFeedbackConstants.STYLUS_BUTTON_PRESS:
6199 pattern = mStylusButtonPressVibePattern;
6200 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006201 default:
6202 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006203 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006204 int owningUid;
6205 String owningPackage;
6206 if (win != null) {
6207 owningUid = win.getOwningUid();
6208 owningPackage = win.getOwningPackage();
6209 } else {
6210 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006211 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006212 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006213 if (pattern.length == 1) {
6214 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006215 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006216 } else {
6217 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006218 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006219 }
6220 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006221 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006222
6223 @Override
6224 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006225 }
6226
Jeff Brownc38c9be2012-10-04 13:16:19 -07006227 @Override
6228 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006229 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006230 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006231 }
6232 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006233
Dianne Hackborndf89e652011-10-06 22:35:11 -07006234 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006235 // If there is no window focused, there will be nobody to handle the events
6236 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006237 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6238 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006239 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006240 return 0;
6241 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006242 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006243 // We are updating at a point where the keyguard has gotten
6244 // focus, but we were last in a state where the top window is
6245 // hiding it. This is probably because the keyguard as been
6246 // shown while the top window was displayed, so we want to ignore
6247 // it here because this is just a very transient change and it
6248 // will quickly lose focus once it correctly gets hidden.
6249 return 0;
6250 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006251
John Spurlock1db8b682014-02-18 11:18:59 -05006252 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006253 & ~mResettingSystemUiFlags
6254 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006255 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006256 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006257 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006258 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006259 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006260 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006261 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006262 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006263 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006264 return 0;
6265 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006266 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006267 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006268 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006269 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006270 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006271 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006272 try {
6273 IStatusBarService statusbar = getStatusBarService();
6274 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006275 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006276 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006277 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006278 } catch (RemoteException e) {
6279 // re-acquire status bar service next time it is needed.
6280 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006281 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006282 }
6283 });
6284 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006285 }
6286
Adrian Rooscd3884d2015-02-18 17:25:23 +01006287 private int updateLightStatusBarLw(int vis) {
6288 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6289 ? mStatusBar
6290 : mTopFullscreenOpaqueOrDimmingWindowState;
6291
6292 if (statusColorWin != null) {
6293 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6294 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6295 // its light flag.
6296 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6297 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6298 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6299 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6300 // Otherwise if it's dimming, clear the light flag.
6301 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6302 }
6303 }
6304 return vis;
6305 }
6306
John Spurlock79da8332013-09-20 12:04:47 -04006307 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006308 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006309 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6310 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006311 : mTopFullscreenOpaqueWindowState;
6312 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6313 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6314
John Spurlock27735a42013-08-14 17:57:38 -04006315 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04006316 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006317 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006318 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6319 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006320 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006321 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6322 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006323 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006324 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6325 }
John Spurlockbd957402013-10-03 11:38:39 -04006326 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006327 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006328
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006329 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006330 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6331 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006332 }
6333
John Spurlock27735a42013-08-14 17:57:38 -04006334 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006335 boolean immersiveSticky =
6336 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006337 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006338 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006339 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006340 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6341 boolean hideStatusBarSysui =
6342 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006343 boolean hideNavBarSysui =
6344 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006345
John Spurlock27735a42013-08-14 17:57:38 -04006346 boolean transientStatusBarAllowed =
6347 mStatusBar != null && (
6348 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006349 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006350 || statusBarHasFocus);
6351
John Spurlockf1a36642013-10-12 17:50:42 -04006352 boolean transientNavBarAllowed =
6353 mNavigationBar != null &&
6354 hideNavBarSysui && immersiveSticky;
6355
John Spurlockf25706f2013-11-07 18:02:43 -05006356 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006357 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006358 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006359 && !transientNavBarAllowed;
6360 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006361 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006362 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006363 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006364 }
John Spurlock27735a42013-08-14 17:57:38 -04006365
6366 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6367
6368 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006369 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6370 boolean newImmersiveMode = isImmersiveMode(vis);
6371 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006372 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006373 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6374 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006375 }
John Spurlock27735a42013-08-14 17:57:38 -04006376
John Spurlockf1a36642013-10-12 17:50:42 -04006377 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6378
John Spurlocke1f366f2013-08-05 12:22:40 -04006379 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006380 }
6381
John Spurlockf1a36642013-10-12 17:50:42 -04006382 private void clearClearableFlagsLw() {
6383 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6384 if (newVal != mResettingSystemUiFlags) {
6385 mResettingSystemUiFlags = newVal;
6386 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6387 }
6388 }
6389
6390 private boolean isImmersiveMode(int vis) {
6391 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006392 return mNavigationBar != null
6393 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006394 && (vis & flags) != 0
6395 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006396 }
6397
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006398 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006399 * @return whether the navigation or status bar can be made translucent
6400 *
6401 * This should return true unless touch exploration is not enabled or
6402 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006403 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006404 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006405 return mTranslucentDecorEnabled
6406 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006407 }
6408
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006409 // Use this instead of checking config_showNavigationBar so that it can be consistently
6410 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006411 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006412 public boolean hasNavigationBar() {
6413 return mHasNavigationBar;
6414 }
6415
satok1bc0a492012-04-25 22:47:12 +09006416 @Override
6417 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6418 mLastInputMethodWindow = ime;
6419 mLastInputMethodTargetWindow = target;
6420 }
6421
Craig Mautnerf1b67412012-09-19 13:18:29 -07006422 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006423 public int getInputMethodWindowVisibleHeightLw() {
6424 return mDockBottom - mCurBottom;
6425 }
6426
6427 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006428 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006429 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006430 if (mKeyguardDelegate != null) {
6431 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006432 }
John Spurlock13451a22012-09-28 14:40:41 -04006433 if (mStatusBarService != null) {
6434 try {
6435 mStatusBarService.setCurrentUser(newUserId);
6436 } catch (RemoteException e) {
6437 // oh well
6438 }
6439 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006440 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006441 }
6442
6443 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006444 public boolean canMagnifyWindow(int windowType) {
6445 switch (windowType) {
6446 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6447 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6448 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6449 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6450 return false;
6451 }
6452 }
6453 return true;
6454 }
6455
6456 @Override
6457 public boolean isTopLevelWindow(int windowType) {
6458 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6459 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6460 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6461 }
6462 return true;
6463 }
6464
Jim Miller4eeb4f62012-11-08 00:04:29 -08006465 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006466 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006467 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006468 pw.print(" mSystemReady="); pw.print(mSystemReady);
6469 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006470 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006471 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006472 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006473 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006474 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6475 || mForceClearedSystemUiFlags != 0) {
6476 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6477 pw.print(Integer.toHexString(mLastSystemUiFlags));
6478 pw.print(" mResettingSystemUiFlags=0x");
6479 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6480 pw.print(" mForceClearedSystemUiFlags=0x");
6481 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006482 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006483 if (mLastFocusNeedsMenu) {
6484 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6485 pw.println(mLastFocusNeedsMenu);
6486 }
Jeff Browna20dda42014-05-27 20:57:24 -07006487 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6488 pw.println(mWakeGestureEnabledSetting);
6489
Jeff Brownbcdfc622014-03-06 19:13:04 -08006490 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006491 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6492 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006493 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6494 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6495 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6496 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006497 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006498 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006499 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6500 pw.print(mCarDockEnablesAccelerometer);
6501 pw.print(" mDeskDockEnablesAccelerometer=");
6502 pw.println(mDeskDockEnablesAccelerometer);
6503 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6504 pw.print(mLidKeyboardAccessibility);
6505 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006506 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006507 pw.print(prefix);
6508 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6509 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006510 pw.print(prefix);
6511 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6512 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006513 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006514 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6515 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6516 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6517 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6518 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6519 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6520 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006521 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6522 pw.print(","); pw.print(mOverscanScreenTop);
6523 pw.print(") "); pw.print(mOverscanScreenWidth);
6524 pw.print("x"); pw.println(mOverscanScreenHeight);
6525 if (mOverscanLeft != 0 || mOverscanTop != 0
6526 || mOverscanRight != 0 || mOverscanBottom != 0) {
6527 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6528 pw.print(" top="); pw.print(mOverscanTop);
6529 pw.print(" right="); pw.print(mOverscanRight);
6530 pw.print(" bottom="); pw.println(mOverscanBottom);
6531 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006532 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6533 pw.print(mRestrictedOverscanScreenLeft);
6534 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6535 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6536 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006537 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6538 pw.print(","); pw.print(mUnrestrictedScreenTop);
6539 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6540 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6541 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6542 pw.print(","); pw.print(mRestrictedScreenTop);
6543 pw.print(") "); pw.print(mRestrictedScreenWidth);
6544 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006545 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6546 pw.print(","); pw.print(mStableFullscreenTop);
6547 pw.print(")-("); pw.print(mStableFullscreenRight);
6548 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006549 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6550 pw.print(","); pw.print(mStableTop);
6551 pw.print(")-("); pw.print(mStableRight);
6552 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006553 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6554 pw.print(","); pw.print(mSystemTop);
6555 pw.print(")-("); pw.print(mSystemRight);
6556 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006557 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6558 pw.print(","); pw.print(mCurTop);
6559 pw.print(")-("); pw.print(mCurRight);
6560 pw.print(","); pw.print(mCurBottom); pw.println(")");
6561 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6562 pw.print(","); pw.print(mContentTop);
6563 pw.print(")-("); pw.print(mContentRight);
6564 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006565 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6566 pw.print(","); pw.print(mVoiceContentTop);
6567 pw.print(")-("); pw.print(mVoiceContentRight);
6568 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006569 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6570 pw.print(","); pw.print(mDockTop);
6571 pw.print(")-("); pw.print(mDockRight);
6572 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006573 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6574 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006575 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6576 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006577 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6578 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006579 if (mLastInputMethodWindow != null) {
6580 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6581 pw.println(mLastInputMethodWindow);
6582 }
6583 if (mLastInputMethodTargetWindow != null) {
6584 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6585 pw.println(mLastInputMethodTargetWindow);
6586 }
6587 if (mStatusBar != null) {
6588 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006589 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6590 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006591 }
6592 if (mNavigationBar != null) {
6593 pw.print(prefix); pw.print("mNavigationBar=");
6594 pw.println(mNavigationBar);
6595 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006596 if (mFocusedWindow != null) {
6597 pw.print(prefix); pw.print("mFocusedWindow=");
6598 pw.println(mFocusedWindow);
6599 }
6600 if (mFocusedApp != null) {
6601 pw.print(prefix); pw.print("mFocusedApp=");
6602 pw.println(mFocusedApp);
6603 }
6604 if (mWinDismissingKeyguard != null) {
6605 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6606 pw.println(mWinDismissingKeyguard);
6607 }
6608 if (mTopFullscreenOpaqueWindowState != null) {
6609 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6610 pw.println(mTopFullscreenOpaqueWindowState);
6611 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006612 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6613 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6614 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6615 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006616 if (mForcingShowNavBar) {
6617 pw.print(prefix); pw.print("mForcingShowNavBar=");
6618 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6619 pw.println(mForcingShowNavBarLayer);
6620 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006621 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006622 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006623 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6624 pw.print(" mForceStatusBarFromKeyguard=");
6625 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006626 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006627 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006628 pw.print(" mHomePressed="); pw.println(mHomePressed);
6629 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6630 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6631 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6632 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6633 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6634 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6635 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6636 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6637 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6638 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006639 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6640 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6641 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006642
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006643 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006644 mStatusBarController.dump(pw, prefix);
6645 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006646 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006647
Jeff Browna20dda42014-05-27 20:57:24 -07006648 if (mWakeGestureListener != null) {
6649 mWakeGestureListener.dump(pw, prefix);
6650 }
Jeff Brown600f0032014-05-22 17:06:00 -07006651 if (mOrientationListener != null) {
6652 mOrientationListener.dump(pw, prefix);
6653 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006654 if (mBurnInProtectionHelper != null) {
6655 mBurnInProtectionHelper.dump(prefix, pw);
6656 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006657 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006658}