blob: 7036408eb0195a77d0b0f2afe5e18b1c64c25617 [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
Jeff Brown37df39a92015-02-25 15:42:31 -08002 * Copyright (C) 2006 The Android Open Source Project
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jorim Jaggib10e33f2015-02-04 21:57:40 +010017package com.android.server.policy;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080018
Dianne Hackborna4972e92012-03-14 10:38:05 -070019import android.app.ActivityManager;
Jeff Brown061ea992015-04-17 19:55:47 -070020import android.app.ActivityManagerInternal;
21import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080022import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080023import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040024import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070025import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070026import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040027import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080028import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070029import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080030import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040031import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080032import android.content.ContentResolver;
33import android.content.Context;
34import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070035import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070036import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080037import android.content.pm.ActivityInfo;
38import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040039import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070040import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.content.res.Configuration;
42import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070043import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080044import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080045import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080046import android.graphics.Rect;
John Spurlock7b414672014-07-18 13:02:39 -040047import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080048import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050049import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080050import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070051import android.media.Ringtone;
52import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070053import android.media.session.MediaSessionLegacyHelper;
Mark Renoufc1256912015-03-11 14:38:23 -040054import android.os.Build;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070055import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080056import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070057import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080058import android.os.Handler;
59import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080060import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070061import android.os.Message;
62import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080063import android.os.PowerManager;
64import android.os.RemoteException;
65import android.os.ServiceManager;
66import android.os.SystemClock;
67import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080068import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070069import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080070import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070071import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080072import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070073import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040074import android.service.dreams.DreamService;
75import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070076import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070077import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070078import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080079import android.util.EventLog;
80import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070081import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080082import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070083import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080084import android.view.Gravity;
85import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080086import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080087import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070088import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070089import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080090import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080091import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080092import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080093import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080094import android.view.KeyEvent;
95import android.view.MotionEvent;
Adam Powell6711f3b2015-05-06 15:57:09 -070096import com.android.internal.policy.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080097import android.view.Surface;
98import android.view.View;
99import android.view.ViewConfiguration;
Mark Renoufc1256912015-03-11 14:38:23 -0400100import android.view.ViewRootImpl;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800101import android.view.Window;
102import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800103import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700104import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800105import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800106import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800107import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800108import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200109import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800110import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800111import com.android.internal.R;
Craig Mautnerae446592012-12-06 19:05:05 -0800112import com.android.internal.statusbar.IStatusBarService;
Craig Mautnerae446592012-12-06 19:05:05 -0800113import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700114import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100115import com.android.server.policy.keyguard.KeyguardServiceDelegate;
116import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800117
118import java.io.File;
119import java.io.FileReader;
120import java.io.IOException;
121import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700122import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800123import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800124
Dianne Hackbornc652de82013-02-15 16:32:56 -0800125import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700126import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
127import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
128import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700129import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
130import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
131import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800132
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800133/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700134 * WindowManagerPolicy implementation for the Android phone UI. This
135 * introduces a new method suffix, Lp, for an internal lock of the
136 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400137 * can be acquired with either the Lw and Li lock held, so has the restrictions
The Android Open Source Project0727d222009-03-11 12:11:58 -0700138 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800139 */
140public class PhoneWindowManager implements WindowManagerPolicy {
141 static final String TAG = "WindowManager";
142 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700143 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700144 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700145 static final boolean DEBUG_KEYGUARD = false;
146 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700147 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700148 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800149 static final boolean SHOW_STARTING_ANIMATIONS = true;
150 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400151
Daniel Sandler6396c722013-04-16 20:19:09 -0400152 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
153 // No longer recommended for desk docks; still useful in car docks.
154 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
155 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
156
Jeff Brown6d8fd272014-05-20 21:24:38 -0700157 static final int SHORT_PRESS_POWER_NOTHING = 0;
158 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
159 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
160 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800161 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700162
Joe Onoratod208e702010-10-08 16:22:43 -0400163 static final int LONG_PRESS_POWER_NOTHING = 0;
164 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
165 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700166 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700167
Jeff Brown13f00f02014-10-31 14:45:50 -0700168 static final int MULTI_PRESS_POWER_NOTHING = 0;
169 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
170 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
171
Michael Jurka3b1fc472011-06-13 10:54:40 -0700172 // These need to match the documentation/constant in
173 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800174 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800175 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700176 static final int LONG_PRESS_HOME_ASSIST = 2;
177
178 static final int DOUBLE_TAP_HOME_NOTHING = 0;
179 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800180
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000181 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
182 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
183
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700184 static final int APPLICATION_MEDIA_SUBLAYER = -2;
185 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800186 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800187 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700188 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700189
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800190 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
191 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
192 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500193 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700194 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800195
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700196 /**
197 * These are the system UI flags that, when changing, can cause the layout
198 * of the screen to change.
199 */
200 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400201 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400202 | View.SYSTEM_UI_FLAG_FULLSCREEN
203 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200204 | View.NAVIGATION_BAR_TRANSLUCENT
205 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700206
John Spurlock7b414672014-07-18 13:02:39 -0400207 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
208 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
209 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
210 .build();
211
Jim Miller5ecd8112013-01-09 18:50:26 -0800212 /**
213 * Keyguard stuff
214 */
215 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100216 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700217 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800218
Jeff Brown6651a632011-11-28 12:59:11 -0800219 /* Table of Application Launch keys. Maps from key codes to intent categories.
220 *
221 * These are special keys that are used to launch particular kinds of applications,
222 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
223 * usage page. We don't support quite that many yet...
224 */
225 static SparseArray<String> sApplicationLaunchKeyCategories;
226 static {
227 sApplicationLaunchKeyCategories = new SparseArray<String>();
228 sApplicationLaunchKeyCategories.append(
229 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
230 sApplicationLaunchKeyCategories.append(
231 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
232 sApplicationLaunchKeyCategories.append(
233 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
234 sApplicationLaunchKeyCategories.append(
235 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
236 sApplicationLaunchKeyCategories.append(
237 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
238 sApplicationLaunchKeyCategories.append(
239 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
240 }
241
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700242 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
243 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
244
Dianne Hackborndf89e652011-10-06 22:35:11 -0700245 /**
246 * Lock protecting internal state. Must not call out into window
247 * manager with lock held. (This lock will be acquired in places
248 * where the window manager is calling in with its own lock held.)
249 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800250 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700251
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800252 Context mContext;
253 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700254 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700255 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700256 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700257 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700258 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400259 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700260 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700261 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800262 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700263 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800264 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000265 BurnInProtectionHelper mBurnInProtectionHelper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800266
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700267 // Vibrator pattern for haptic feedback of a long press.
268 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700269
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700270 // Vibrator pattern for haptic feedback of virtual key press.
271 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700272
Amith Yamasanic33cb712010-02-10 15:21:49 -0800273 // Vibrator pattern for a short vibration.
274 long[] mKeyboardTapVibePattern;
275
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700276 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
277 long[] mClockTickVibePattern;
278
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700279 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
280 long[] mCalendarDateVibePattern;
281
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700282 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
283 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700284
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700285 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
286 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700287
Mady Mellore82067b2015-04-30 09:58:35 -0700288 // Vibrator pattern for haptic feedback of a stylus button press.
289 long[] mStylusButtonPressVibePattern;
290
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800291 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
292 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400293
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800294 boolean mSafeMode;
295 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700296 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400297 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400298 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700299 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400300 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
301 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
302 int[] mNavigationBarHeightForRotation = new int[4];
303 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400304
Craig Mautnera631d492014-08-05 15:16:01 -0700305 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800306 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700307 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700308 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700309 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700310 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
311 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
312 }
313 };
314 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
315 @Override
316 public void onShown(IBinder windowToken) {
317 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
318 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
319 }
320 };
321
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800322 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800323 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900324 WindowState mLastInputMethodWindow = null;
325 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800326
Jeff Brown13f00f02014-10-31 14:45:50 -0700327 // FIXME This state is shared between the input reader and handler thread.
328 // Technically it's broken and buggy but it has been like this for many years
329 // and we have not yet seen any problems. Someday we'll rewrite this logic
330 // so that only one thread is involved in handling input policy. Unfortunately
331 // it's on a critical path for power management so we can't just post the work to the
332 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
333 // to hold wakelocks during dispatch and eliminating the critical path.
334 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800335 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700336 volatile int mPowerKeyPressCounter;
337 volatile boolean mEndCallKeyHandled;
338
Winson Chungd42a6cf2014-06-03 16:24:04 -0700339 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700340 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700341 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800342
Jeff Brown2e7760e2012-04-11 15:14:55 -0700343 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700344 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700345 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800346
Dianne Hackbornc777e072010-02-12 13:07:59 -0800347 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700348 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800349 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700350 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400351 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700352 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700353 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400354 int mCarDockRotation;
355 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700356 int mUndockedHdmiRotation;
357 int mDemoHdmiRotation;
358 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800359 int mDemoRotation;
360 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400361
Jeff Browna20dda42014-05-27 20:57:24 -0700362 boolean mWakeGestureEnabledSetting;
363 MyWakeGestureListener mWakeGestureListener;
364
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700365 // Default display does not rotate, apps that require non-default orientation will have to
366 // have the orientation emulated.
367 private boolean mForceDefaultOrientation = false;
368
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400369 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
370 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700371 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400372
Jeff Brownbcdfc622014-03-06 19:13:04 -0800373 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700374 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400375 boolean mCarDockEnablesAccelerometer;
376 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700377 int mLidKeyboardAccessibility;
378 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700379 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700380 int mShortPressOnPowerBehavior;
381 int mLongPressOnPowerBehavior;
382 int mDoublePressOnPowerBehavior;
383 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000384 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700385 boolean mAwake;
386 boolean mScreenOnEarly;
387 boolean mScreenOnFully;
388 ScreenOnListener mScreenOnListener;
389 boolean mKeyguardDrawComplete;
390 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800391 boolean mOrientationSensorEnabled = false;
392 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800393 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400394 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800395 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700396
Jeff Brown70825162012-03-28 17:27:48 -0700397 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800398
399 // The last window we were told about in focusChanged.
400 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800401 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800402
Jeff Brown70825162012-03-28 17:27:48 -0700403 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800404
Dianne Hackbornc652de82013-02-15 16:32:56 -0800405 // The current size of the screen; really; extends into the overscan area of
406 // the screen and doesn't account for any system elements like the status bar.
407 int mOverscanScreenLeft, mOverscanScreenTop;
408 int mOverscanScreenWidth, mOverscanScreenHeight;
409 // The current visible size of the screen; really; (ir)regardless of whether the status
410 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800411 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
412 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800413 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
414 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
415 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700416 // The current size of the screen; these may be different than (0,0)-(dw,dh)
417 // if the status bar can't be hidden; in that case it effectively carves out
418 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800419 int mRestrictedScreenLeft, mRestrictedScreenTop;
420 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700421 // During layout, the current screen borders accounting for any currently
422 // visible system UI elements.
423 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700424 // For applications requesting stable content insets, these are them.
425 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700426 // For applications requesting stable content insets but have also set the
427 // fullscreen window flag, these are the stable dimensions without the status bar.
428 int mStableFullscreenLeft, mStableFullscreenTop;
429 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800430 // During layout, the current screen borders with all outer decoration
431 // (status bar, input method dock) accounted for.
432 int mCurLeft, mCurTop, mCurRight, mCurBottom;
433 // During layout, the frame in which content should be displayed
434 // to the user, accounting for all screen decoration except for any
435 // space they deem as available for other content. This is usually
436 // the same as mCur*, but may be larger if the screen decor has supplied
437 // content insets.
438 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700439 // During layout, the frame in which voice content should be displayed
440 // to the user, accounting for all screen decoration except for any
441 // space they deem as available for other content.
442 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800443 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800444 // windows are placed.
445 int mDockLeft, mDockTop, mDockRight, mDockBottom;
446 // During layout, the layer at which the doc window is placed.
447 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700448 // During layout, this is the layer of the status bar.
449 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700450 int mLastSystemUiFlags;
451 // Bits that we are in the process of clearing, so we want to prevent
452 // them from being set by applications until everything has been updated
453 // to have them clear.
454 int mResettingSystemUiFlags = 0;
455 // Bits that we are currently always keeping cleared.
456 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800457 // What we last reported to system UI about whether the compatibility
458 // menu needs to be displayed.
459 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700460
461 FakeWindow mHideNavFakeWindow = null;
462
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800463 static final Rect mTmpParentFrame = new Rect();
464 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800465 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800466 static final Rect mTmpContentFrame = new Rect();
467 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400468 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700469 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700470 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700471
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800472 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100473 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700474 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200475 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400476 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800477 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700478 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700479 private boolean mForceStatusBarTransparent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700480 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800481 boolean mForcingShowNavBar;
482 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700483
484 // States of keyguard dismiss.
485 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
486 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
487 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
488 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
489
490 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
491 * be done once per window. */
492 private WindowState mWinDismissingKeyguard;
493
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700494 /** The window that is currently showing "over" the keyguard. If there is an app window
495 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
496 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
497 * the wallpaper. */
498 private WindowState mWinShowWhenLocked;
499
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700500 boolean mShowingLockscreen;
501 boolean mShowingDream;
502 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700503 boolean mDreamingSleepTokenNeeded;
504 SleepToken mDreamingSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700505 boolean mKeyguardSecure;
506 boolean mKeyguardSecureIncludingHidden;
507 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800508 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700509 boolean mHomeConsumed;
510 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800511 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700512 Intent mCarDockIntent;
513 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700514 boolean mSearchKeyShortcutPending;
515 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700516 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700517 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800518
Mike Lockwood28569302010-01-28 11:54:40 -0500519 // support for activating the lock screen while the screen is on
520 boolean mAllowLockscreenWhenOn;
521 int mLockScreenTimeout;
522 boolean mLockScreenTimerActive;
523
David Brownbaf8d092010-03-08 21:52:59 -0800524 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800525 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800526
527 // Behavior of POWER button while in-call and screen on.
528 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
529 int mIncallPowerBehavior;
530
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700531 Display mDisplay;
532
Dianne Hackborn9d132642011-04-21 17:26:39 -0700533 int mLandscapeRotation = 0; // default landscape rotation
534 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
535 int mPortraitRotation = 0; // default portrait rotation
536 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700537
Dianne Hackbornc652de82013-02-15 16:32:56 -0800538 int mOverscanLeft = 0;
539 int mOverscanTop = 0;
540 int mOverscanRight = 0;
541 int mOverscanBottom = 0;
542
Joe Onorato46b0d682010-11-22 17:37:27 -0800543 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700544 private int mLongPressOnHomeBehavior;
545
546 // What we do when the user double-taps on home
547 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800548
Bryce Lee584a4452014-10-21 15:55:55 -0700549 // Allowed theater mode wake actions
550 private boolean mAllowTheaterModeWakeFromKey;
551 private boolean mAllowTheaterModeWakeFromPowerKey;
552 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800553 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700554 private boolean mAllowTheaterModeWakeFromCameraLens;
555 private boolean mAllowTheaterModeWakeFromLidSwitch;
556 private boolean mAllowTheaterModeWakeFromWakeGesture;
557
Bryce Leed3b28402015-03-09 15:49:13 +0000558 // Whether to support long press from power button in non-interactive mode
559 private boolean mSupportLongPressPowerWhenNonInteractive;
560
Bryce Lee55e846d2014-11-04 12:43:44 -0800561 // Whether to go to sleep entering theater mode from power button
562 private boolean mGoToSleepOnButtonPressTheaterMode;
563
Winson Chung9112ec32011-06-27 13:15:32 -0700564 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700565 // Time to volume and power must be pressed within this interval of each other.
566 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700567 // Increase the chord delay when taking a screenshot from the keyguard
568 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800569 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700570 private boolean mScreenshotChordVolumeDownKeyTriggered;
571 private long mScreenshotChordVolumeDownKeyTime;
572 private boolean mScreenshotChordVolumeDownKeyConsumed;
573 private boolean mScreenshotChordVolumeUpKeyTriggered;
574 private boolean mScreenshotChordPowerKeyTriggered;
575 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700576
Michael Wrightb854e242013-02-05 17:54:02 -0800577 /* The number of steps between min and max brightness */
578 private static final int BRIGHTNESS_STEPS = 10;
579
Christopher Tate5e08af02012-09-21 17:17:22 -0700580 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800581 ShortcutManager mShortcutManager;
582 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700583 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700584 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800585
Craig Mautnerd625ab22013-09-06 13:40:31 -0700586 private int mCurrentUserId;
587
Justin Kohd378ad72013-04-01 12:18:26 -0700588 // Maps global key codes to the components that will handle them.
589 private GlobalKeyManager mGlobalKeyManager;
590
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700591 // Fallback actions by key code.
592 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
593 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800594
Jorim Jaggi76a16232014-08-08 17:00:47 +0200595 private final LogDecelerateInterpolator mLogDecelerateInterpolator
596 = new LogDecelerateInterpolator(100, 0);
597
Jeff Brown70825162012-03-28 17:27:48 -0700598 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
599 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700600 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
601 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700602 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
603 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
604 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700605 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700606 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700607 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700608 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700609 private static final int MSG_POWER_DELAYED_PRESS = 13;
610 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700611 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jeff Brown70825162012-03-28 17:27:48 -0700612
613 private class PolicyHandler extends Handler {
614 @Override
615 public void handleMessage(Message msg) {
616 switch (msg.what) {
617 case MSG_ENABLE_POINTER_LOCATION:
618 enablePointerLocation();
619 break;
620 case MSG_DISABLE_POINTER_LOCATION:
621 disablePointerLocation();
622 break;
Jeff Brown40013652012-05-16 21:22:36 -0700623 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
624 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
625 break;
626 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
627 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
628 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700629 case MSG_DISPATCH_SHOW_RECENTS:
630 showRecentApps(false);
631 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700632 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
633 showGlobalActionsInternal();
634 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700635 case MSG_KEYGUARD_DRAWN_COMPLETE:
636 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700637 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700638 break;
639 case MSG_KEYGUARD_DRAWN_TIMEOUT:
640 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700641 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700642 break;
643 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
644 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700645 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700646 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700647 case MSG_HIDE_BOOT_MESSAGE:
648 handleHideBootMessage();
649 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700650 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
651 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
652 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700653 case MSG_POWER_DELAYED_PRESS:
654 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
655 finishPowerKeyPress();
656 break;
657 case MSG_POWER_LONG_PRESS:
658 powerLongPress();
659 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700660 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
661 updateDreamingSleepToken(msg.arg1 != 0);
662 break;
Jeff Brown70825162012-03-28 17:27:48 -0700663 }
664 }
665 }
666
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800667 private UEventObserver mHDMIObserver = new UEventObserver() {
668 @Override
669 public void onUEvent(UEventObserver.UEvent event) {
670 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
671 }
672 };
673
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800674 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800675 SettingsObserver(Handler handler) {
676 super(handler);
677 }
David Brownbaf8d092010-03-08 21:52:59 -0800678
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800679 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700680 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800681 ContentResolver resolver = mContext.getContentResolver();
682 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700683 Settings.System.END_BUTTON_BEHAVIOR), false, this,
684 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800685 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700686 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
687 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700688 resolver.registerContentObserver(Settings.Secure.getUriFor(
689 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
690 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800691 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700692 Settings.System.ACCELEROMETER_ROTATION), false, this,
693 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500694 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700695 Settings.System.USER_ROTATION), false, this,
696 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400697 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700698 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
699 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800700 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700701 Settings.System.POINTER_LOCATION), false, this,
702 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800703 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700704 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
705 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500706 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400707 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700708 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500709 resolver.registerContentObserver(Settings.Global.getUriFor(
710 Settings.Global.POLICY_CONTROL), false, this,
711 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800712 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800713 }
714
715 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800716 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700717 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800718 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800719 }
Craig Mautner967212c2013-04-13 21:10:58 -0700720
Jeff Browna20dda42014-05-27 20:57:24 -0700721 class MyWakeGestureListener extends WakeGestureListener {
722 MyWakeGestureListener(Context context, Handler handler) {
723 super(context, handler);
724 }
725
726 @Override
727 public void onWakeUp() {
728 synchronized (mLock) {
729 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700730 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700731 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700732 }
733 }
734 }
735 }
736
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800737 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800738 MyOrientationListener(Context context, Handler handler) {
739 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800740 }
Craig Mautner967212c2013-04-13 21:10:58 -0700741
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800742 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700743 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700744 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700745 updateRotation(false);
746 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800747 }
748 MyOrientationListener mOrientationListener;
749
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100750 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400751
John Spurlock27735a42013-08-14 17:57:38 -0400752 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400753 View.NAVIGATION_BAR_TRANSIENT,
754 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400755 View.NAVIGATION_BAR_TRANSLUCENT,
756 StatusBarManager.WINDOW_NAVIGATION_BAR,
757 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400758
John Spurlockf1a36642013-10-12 17:50:42 -0400759 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400760
Craig Mautner037aa8d2013-06-07 10:35:44 -0700761 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400762
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700763 IStatusBarService getStatusBarService() {
764 synchronized (mServiceAquireLock) {
765 if (mStatusBarService == null) {
766 mStatusBarService = IStatusBarService.Stub.asInterface(
767 ServiceManager.getService("statusbar"));
768 }
769 return mStatusBarService;
770 }
771 }
772
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700773 /*
774 * We always let the sensor be switched on by default except when
775 * the user has explicitly disabled sensor based rotation or when the
776 * screen is switched off.
777 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700778 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800779 if (mSupportAutoRotation) {
780 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
781 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
782 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
783 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
784 // If the application has explicitly requested to follow the
785 // orientation, then we need to turn the sensor on.
786 return true;
787 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800788 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700789 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800790 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
791 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
792 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400793 // enable accelerometer if we are docked in a dock that enables accelerometer
794 // orientation management,
795 return true;
796 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700797 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800798 // If the setting for using the sensor by default is enabled, then
799 // we will always leave it on. Note that the user could go to
800 // a window that forces an orientation that does not use the
801 // sensor and in theory we could turn it off... however, when next
802 // turning it on we won't have a good value for the current
803 // orientation for a little bit, which can cause orientation
804 // changes to lag, so we'd like to keep it always on. (It will
805 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700806 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800807 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800808 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800809 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700810
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800811 /*
812 * Various use cases for invoking this function
813 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700814 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800815 * if not already enabled
816 * screen turned on and current app does not have sensor orientation, disable listeners if
817 * already enabled
818 * screen turning on and current app has sensor based orientation, enable listeners if needed
819 * screen turning on and current app has nosensor based orientation, do nothing
820 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700821 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800822 if (!mOrientationListener.canDetectOrientation()) {
823 // If sensor is turned off or nonexistent for some reason
824 return;
825 }
826 //Could have been invoked due to screen turning on or off or
827 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700828 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
829 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
830 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800831 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700832 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700833 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800834 disable = false;
835 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700836 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800837 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700838 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800839 mOrientationSensorEnabled = true;
840 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700841 }
842 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800843 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700844 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800845 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700846 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800847 mOrientationSensorEnabled = false;
848 }
849 }
850
Jeff Brown13f00f02014-10-31 14:45:50 -0700851 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
852 // Hold a wake lock until the power key is released.
853 if (!mPowerKeyWakeLock.isHeld()) {
854 mPowerKeyWakeLock.acquire();
855 }
856
857 // Cancel multi-press detection timeout.
858 if (mPowerKeyPressCounter != 0) {
859 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
860 }
861
862 // Detect user pressing the power button in panic when an application has
863 // taken over the whole screen.
864 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800865 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700866 if (panic) {
867 mHandler.post(mRequestTransientNav);
868 }
869
870 // Latch power key state to detect screenshot chord.
871 if (interactive && !mScreenshotChordPowerKeyTriggered
872 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
873 mScreenshotChordPowerKeyTriggered = true;
874 mScreenshotChordPowerKeyTime = event.getDownTime();
875 interceptScreenshotChord();
876 }
877
878 // Stop ringing or end call if configured to do so when power is pressed.
879 TelecomManager telecomManager = getTelecommService();
880 boolean hungUp = false;
881 if (telecomManager != null) {
882 if (telecomManager.isRinging()) {
883 // Pressing Power while there's a ringing incoming
884 // call should silence the ringer.
885 telecomManager.silenceRinger();
886 } else if ((mIncallPowerBehavior
887 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
888 && telecomManager.isInCall() && interactive) {
889 // Otherwise, if "Power button ends call" is enabled,
890 // the Power button will hang up any current active call.
891 hungUp = telecomManager.endCall();
892 }
893 }
894
895 // If the power key has still not yet been handled, then detect short
896 // press, long press, or multi press and decide what to do.
897 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
898 || mScreenshotChordVolumeUpKeyTriggered;
899 if (!mPowerKeyHandled) {
900 if (interactive) {
901 // When interactive, we're already awake.
902 // Wait for a long press or for the button to be released to decide what to do.
903 if (hasLongPressOnPowerBehavior()) {
904 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
905 msg.setAsynchronous(true);
906 mHandler.sendMessageDelayed(msg,
907 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
908 }
909 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800910 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800911
Bryce Leed3b28402015-03-09 15:49:13 +0000912 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
913 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
914 msg.setAsynchronous(true);
915 mHandler.sendMessageDelayed(msg,
916 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800917 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000918 } else {
919 final int maxCount = getMaxMultiPressPowerCount();
920
921 if (maxCount <= 1) {
922 mPowerKeyHandled = true;
923 } else {
924 mBeganFromNonInteractive = true;
925 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700926 }
927 }
Jeff Brown4d396052010-10-29 21:50:21 -0700928 }
929 }
930
Jeff Brown13f00f02014-10-31 14:45:50 -0700931 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
932 final boolean handled = canceled || mPowerKeyHandled;
933 mScreenshotChordPowerKeyTriggered = false;
934 cancelPendingScreenshotChordAction();
935 cancelPendingPowerKeyAction();
936
937 if (!handled) {
938 // Figure out how to handle the key now that it has been released.
939 mPowerKeyPressCounter += 1;
940
941 final int maxCount = getMaxMultiPressPowerCount();
942 final long eventTime = event.getDownTime();
943 if (mPowerKeyPressCounter < maxCount) {
944 // This could be a multi-press. Wait a little bit longer to confirm.
945 // Continue holding the wake lock.
946 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
947 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
948 msg.setAsynchronous(true);
949 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
950 return;
951 }
952
953 // No other actions. Handle it immediately.
954 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700955 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700956
957 // Done. Reset our state.
958 finishPowerKeyPress();
959 }
960
961 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800962 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700963 mPowerKeyPressCounter = 0;
964 if (mPowerKeyWakeLock.isHeld()) {
965 mPowerKeyWakeLock.release();
966 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700967 }
968
969 private void cancelPendingPowerKeyAction() {
970 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700971 mPowerKeyHandled = true;
972 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700973 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700974 }
975
976 private void powerPress(long eventTime, boolean interactive, int count) {
977 if (mScreenOnEarly && !mScreenOnFully) {
978 Slog.i(TAG, "Suppressed redundant power key press while "
979 + "already in the process of turning the screen on.");
980 return;
Jeff Brownff204712011-10-25 21:27:54 -0700981 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700982
983 if (count == 2) {
984 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
985 } else if (count == 3) {
986 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -0800987 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700988 switch (mShortPressOnPowerBehavior) {
989 case SHORT_PRESS_POWER_NOTHING:
990 break;
991 case SHORT_PRESS_POWER_GO_TO_SLEEP:
992 mPowerManager.goToSleep(eventTime,
993 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
994 break;
995 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
996 mPowerManager.goToSleep(eventTime,
997 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
998 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
999 break;
1000 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1001 mPowerManager.goToSleep(eventTime,
1002 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1003 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1004 launchHomeFromHotKey();
1005 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001006 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001007 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001008 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001009 }
1010 }
1011 }
1012
1013 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1014 switch (behavior) {
1015 case MULTI_PRESS_POWER_NOTHING:
1016 break;
1017 case MULTI_PRESS_POWER_THEATER_MODE:
1018 if (isTheaterModeEnabled()) {
1019 Slog.i(TAG, "Toggling theater mode off.");
1020 Settings.Global.putInt(mContext.getContentResolver(),
1021 Settings.Global.THEATER_MODE_ON, 0);
1022 if (!interactive) {
1023 wakeUpFromPowerKey(eventTime);
1024 }
1025 } else {
1026 Slog.i(TAG, "Toggling theater mode on.");
1027 Settings.Global.putInt(mContext.getContentResolver(),
1028 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001029
1030 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001031 mPowerManager.goToSleep(eventTime,
1032 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1033 }
1034 }
1035 break;
1036 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001037 Slog.i(TAG, "Starting brightness boost.");
1038 if (!interactive) {
1039 wakeUpFromPowerKey(eventTime);
1040 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001041 mPowerManager.boostScreenBrightness(eventTime);
1042 break;
1043 }
1044 }
1045
1046 private int getMaxMultiPressPowerCount() {
1047 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1048 return 3;
1049 }
1050 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1051 return 2;
1052 }
1053 return 1;
1054 }
1055
1056 private void powerLongPress() {
1057 final int behavior = getResolvedLongPressOnPowerBehavior();
1058 switch (behavior) {
1059 case LONG_PRESS_POWER_NOTHING:
1060 break;
1061 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1062 mPowerKeyHandled = true;
1063 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1064 performAuditoryFeedbackForAccessibilityIfNeed();
1065 }
1066 showGlobalActionsInternal();
1067 break;
1068 case LONG_PRESS_POWER_SHUT_OFF:
1069 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1070 mPowerKeyHandled = true;
1071 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1072 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1073 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1074 break;
1075 }
1076 }
1077
Nick Vaccarob593a812015-05-15 11:23:05 -07001078 private void sleepPress(long eventTime) {
1079 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1080 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1081 }
1082 }
1083
1084 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001085 switch (mShortPressOnSleepBehavior) {
1086 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001087 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001088 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1089 mPowerManager.goToSleep(eventTime,
1090 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001091 break;
1092 }
1093 }
1094
Jeff Brown13f00f02014-10-31 14:45:50 -07001095 private int getResolvedLongPressOnPowerBehavior() {
1096 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1097 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1098 }
1099 return mLongPressOnPowerBehavior;
1100 }
1101
1102 private boolean hasLongPressOnPowerBehavior() {
1103 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001104 }
1105
1106 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001107 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001108 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1109 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001110 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001111 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1112 && now <= mScreenshotChordPowerKeyTime
1113 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1114 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001115 cancelPendingPowerKeyAction();
1116
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001117 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001118 }
1119 }
1120 }
1121
Winson Chung1cea2f32012-10-08 20:42:01 -07001122 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001123 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001124 // Double the time it takes to take a screenshot from the keyguard
1125 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001126 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001127 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001128 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001129 }
1130
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001131 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001132 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001133 }
1134
Jeff Brown13f00f02014-10-31 14:45:50 -07001135 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001136 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001137 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001138 mEndCallKeyHandled = true;
1139 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1140 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001141 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001142 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001143 }
1144 };
1145
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001146 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001147 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001148 public void run() {
1149 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001150 }
1151 };
1152
Alan Viverettee34560b22014-07-10 14:50:06 -07001153 @Override
1154 public void showGlobalActions() {
1155 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1156 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1157 }
1158
1159 void showGlobalActionsInternal() {
1160 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001161 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001162 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001163 }
Jim Millerab954542014-10-10 18:21:49 -07001164 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001165 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1166 if (keyguardShowing) {
1167 // since it took two seconds of long press to bring this up,
1168 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001169 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001170 }
1171 }
1172
1173 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001174 return Settings.Global.getInt(
1175 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001176 }
1177
Maurice Lam99c6e072014-04-28 18:24:28 -07001178 boolean isUserSetupComplete() {
1179 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1180 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1181 }
1182
Jeff Brown13f00f02014-10-31 14:45:50 -07001183 private void handleShortPressOnHome() {
1184 // If there's a dream running then use home to escape the dream
1185 // but don't actually go home.
1186 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1187 mDreamManagerInternal.stopDream(false /*immediate*/);
1188 return;
1189 }
1190
1191 // Go home!
1192 launchHomeFromHotKey();
1193 }
1194
Patrick Dubroyece94522011-02-23 18:35:01 -08001195 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -08001196 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001197 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001198 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001199
Jeff Browncaca8812013-05-09 13:34:33 -07001200 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1201 toggleRecentApps();
1202 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1203 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -07001204 }
1205 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001206 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001207
Jeff Browncaca8812013-05-09 13:34:33 -07001208 private void handleDoubleTapOnHome() {
1209 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1210 mHomeConsumed = true;
1211 toggleRecentApps();
1212 }
1213 }
1214
1215 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1216 @Override
1217 public void run() {
1218 if (mHomeDoubleTapPending) {
1219 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001220 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001221 }
1222 }
1223 };
1224
Mark Renoufc1256912015-03-11 14:38:23 -04001225 private boolean isRoundWindow() {
1226 return mContext.getResources().getBoolean(com.android.internal.R.bool.config_windowIsRound)
1227 || (Build.HARDWARE.contains("goldfish")
1228 && SystemProperties.getBoolean(ViewRootImpl.PROPERTY_EMULATOR_CIRCULAR, false));
1229 }
1230
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001231 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001232 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001233 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001234 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001235 mContext = context;
1236 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001237 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001238 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001239 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001240 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Mark Renoufc1256912015-03-11 14:38:23 -04001241
1242 // Init display burn-in protection
1243 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1244 com.android.internal.R.bool.config_enableBurnInProtection);
1245 // Allow a system property to override this. Used by developer settings.
1246 boolean burnInProtectionDevMode =
1247 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1248 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1249 final int minHorizontal;
1250 final int maxHorizontal;
1251 final int minVertical;
1252 final int maxVertical;
1253 final int maxRadius;
1254 if (burnInProtectionDevMode) {
1255 minHorizontal = -8;
1256 maxHorizontal = 8;
1257 minVertical = -8;
1258 maxVertical = -4;
1259 maxRadius = (isRoundWindow()) ? 6 : -1;
1260 } else {
1261 Resources resources = context.getResources();
1262 minHorizontal = resources.getInteger(
1263 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1264 maxHorizontal = resources.getInteger(
1265 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1266 minVertical = resources.getInteger(
1267 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1268 maxVertical = resources.getInteger(
1269 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1270 maxRadius = resources.getInteger(
1271 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1272 }
1273 mBurnInProtectionHelper = new BurnInProtectionHelper(
1274 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001275 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001276
Jeff Brown70825162012-03-28 17:27:48 -07001277 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001278 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001279 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001280 try {
1281 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1282 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001283 mSettingsObserver = new SettingsObserver(mHandler);
1284 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001285 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001286 mUiMode = context.getResources().getInteger(
1287 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001288 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1289 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1290 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1291 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001292 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1293 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1294 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1295 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1296 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1297 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1298 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1299 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001300
Jeff Brown96307042012-07-27 15:51:34 -07001301 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1302 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001303 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001304 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1305 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001306 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001307 mSupportAutoRotation = mContext.getResources().getBoolean(
1308 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001309 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001310 com.android.internal.R.integer.config_lidOpenRotation);
1311 mCarDockRotation = readRotation(
1312 com.android.internal.R.integer.config_carDockRotation);
1313 mDeskDockRotation = readRotation(
1314 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001315 mUndockedHdmiRotation = readRotation(
1316 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001317 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1318 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1319 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1320 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001321 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1322 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1323 mLidNavigationAccessibility = mContext.getResources().getInteger(
1324 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001325 mLidControlsSleep = mContext.getResources().getBoolean(
1326 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001327 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1328 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001329
1330 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1331 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1332 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1333 || mContext.getResources().getBoolean(
1334 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1335 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1336 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001337 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1338 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001339 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1340 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1341 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1342 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1343 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1344 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1345
Bryce Lee55e846d2014-11-04 12:43:44 -08001346 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1347 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1348
Bryce Leed3b28402015-03-09 15:49:13 +00001349 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1350 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1351
Jeff Brown13f00f02014-10-31 14:45:50 -07001352 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1353 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1354 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1355 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1356 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1357 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1358 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1359 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001360 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1361 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001362
John Spurlock61560172015-02-06 19:46:04 -05001363 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001364
Jeff Brownf71343d2013-05-31 17:59:11 -07001365 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001366
Svetoslav8e3feb12014-02-24 13:46:47 -08001367 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1368 Context.ACCESSIBILITY_SERVICE);
1369
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001370 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001371 IntentFilter filter = new IntentFilter();
1372 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1373 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1374 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1375 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001376 filter.addAction(Intent.ACTION_DOCK_EVENT);
1377 Intent intent = context.registerReceiver(mDockReceiver, filter);
1378 if (intent != null) {
1379 // Retrieve current sticky dock event broadcast.
1380 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1381 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1382 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001383
Jeff Brown6aaf2952012-10-05 16:01:08 -07001384 // register for dream-related broadcasts
1385 filter = new IntentFilter();
1386 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1387 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1388 context.registerReceiver(mDreamReceiver, filter);
1389
Christopher Tate5e08af02012-09-21 17:17:22 -07001390 // register for multiuser-relevant broadcasts
1391 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1392 context.registerReceiver(mMultiuserReceiver, filter);
1393
John Spurlock57306e62013-04-22 09:48:49 -04001394 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001395 mSystemGestures = new SystemGesturesPointerEventListener(context,
1396 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001397 @Override
1398 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001399 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001400 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001401 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001402 }
1403 @Override
1404 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001405 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001406 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001407 }
1408 }
1409 @Override
1410 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001411 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001412 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001413 }
1414 }
1415 @Override
1416 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001417 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001418 }
Adrian Roos3595be42015-03-05 16:31:15 +01001419 @Override
1420 public void onDown() {
1421 mOrientationListener.onTouchStart();
1422 }
1423 @Override
1424 public void onUpOrCancel() {
1425 mOrientationListener.onTouchEnd();
1426 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001427 });
John Spurlockf1a36642013-10-12 17:50:42 -04001428 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001429 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001430
Jeff Brownc2346132012-04-13 01:55:38 -07001431 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001432 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1433 com.android.internal.R.array.config_longPressVibePattern);
1434 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1435 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001436 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1437 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001438 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1439 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001440 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1441 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001442 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1443 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1444 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1445 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore82067b2015-04-30 09:58:35 -07001446 mStylusButtonPressVibePattern = getLongIntArray(mContext.getResources(),
1447 com.android.internal.R.array.config_stylusButtonPressVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001448
Christopher Tatee90585f2012-03-05 18:56:25 -08001449 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1450 com.android.internal.R.bool.config_enableScreenshotChord);
1451
Justin Kohd378ad72013-04-01 12:18:26 -07001452 mGlobalKeyManager = new GlobalKeyManager(mContext);
1453
Joe Onoratoea495d42011-04-06 11:41:11 -07001454 // Controls rotation and the like.
1455 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001456
1457 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001458 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001459 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001460 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001461
1462 mWindowManagerInternal.registerAppTransitionListener(
1463 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001464 }
1465
Jeff Brownf71343d2013-05-31 17:59:11 -07001466 /**
1467 * Read values from config.xml that may be overridden depending on
1468 * the configuration of the device.
1469 * eg. Disable long press on home goes to recents on sw600dp.
1470 */
1471 private void readConfigurationDependentBehaviors() {
1472 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1473 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1474 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1475 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1476 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1477 }
1478
1479 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1480 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1481 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1482 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1483 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1484 }
1485 }
1486
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001487 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001488 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001489 // This method might be called before the policy has been fully initialized
1490 // or for other displays we don't care about.
1491 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1492 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001493 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001494 mDisplay = display;
1495
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001496 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001497 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001498 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001499 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001500 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001501 mLandscapeRotation = Surface.ROTATION_0;
1502 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001503 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001504 mPortraitRotation = Surface.ROTATION_90;
1505 mUpsideDownRotation = Surface.ROTATION_270;
1506 } else {
1507 mPortraitRotation = Surface.ROTATION_270;
1508 mUpsideDownRotation = Surface.ROTATION_90;
1509 }
1510 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001511 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001512 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001513 mPortraitRotation = Surface.ROTATION_0;
1514 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001515 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001516 mLandscapeRotation = Surface.ROTATION_270;
1517 mSeascapeRotation = Surface.ROTATION_90;
1518 } else {
1519 mLandscapeRotation = Surface.ROTATION_90;
1520 mSeascapeRotation = Surface.ROTATION_270;
1521 }
1522 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001523
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001524 mStatusBarHeight =
1525 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001526
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001527 // Height of the navigation bar when presented horizontally at bottom
1528 mNavigationBarHeightForRotation[mPortraitRotation] =
1529 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001530 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001531 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001532 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1533 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001534
1535 // Width of the navigation bar when presented vertically along one side
1536 mNavigationBarWidthForRotation[mPortraitRotation] =
1537 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1538 mNavigationBarWidthForRotation[mLandscapeRotation] =
1539 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001540 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001541
1542 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001543 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001544 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001545
Devin Kimd7b12b42014-05-05 14:34:58 -07001546 // Allow the navigation bar to move on non-square small devices (phones).
1547 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001548
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001549 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001550 // Allow a system property to override this. Used by the emulator.
1551 // See also hasNavigationBar().
1552 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1553 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001554 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001555 } else if ("0".equals(navBarOverride)) {
1556 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001557 }
1558
Jeff Brown27f1d672012-10-17 18:32:34 -07001559 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1560 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001561 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001562 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001563 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001564 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001565 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001566 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001567
Chong Zhangae6119ff2014-11-11 18:54:39 -08001568 // For demo purposes, allow the rotation of the remote display to be controlled.
1569 // By default, remote display locks rotation to landscape.
1570 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1571 mDemoRotation = mPortraitRotation;
1572 } else {
1573 mDemoRotation = mLandscapeRotation;
1574 }
1575 mDemoRotationLock = SystemProperties.getBoolean(
1576 "persist.demo.rotationlock", false);
1577
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001578 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1579 // http://developer.android.com/guide/practices/screens_support.html#range
1580 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1581 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1582 // For debug purposes the next line turns this feature off with:
1583 // $ adb shell setprop config.override_forced_orient true
1584 // $ adb shell wm size reset
1585 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1586 }
1587
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001588 /**
1589 * @return whether the navigation bar can be hidden, e.g. the device has a
1590 * navigation bar and touch exploration is not enabled
1591 */
1592 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001593 return mHasNavigationBar
1594 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001595 }
1596
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001597 @Override
1598 public boolean isDefaultOrientationForced() {
1599 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001600 }
1601
Dianne Hackbornc652de82013-02-15 16:32:56 -08001602 @Override
1603 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1604 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1605 mOverscanLeft = left;
1606 mOverscanTop = top;
1607 mOverscanRight = right;
1608 mOverscanBottom = bottom;
1609 }
1610 }
1611
Dianne Hackbornc777e072010-02-12 13:07:59 -08001612 public void updateSettings() {
1613 ContentResolver resolver = mContext.getContentResolver();
1614 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001615 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001616 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001617 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001618 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1619 UserHandle.USER_CURRENT);
1620 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001621 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001622 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1623 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001624
Jeff Browna20dda42014-05-27 20:57:24 -07001625 // Configure wake gesture.
1626 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1627 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1628 UserHandle.USER_CURRENT) != 0;
1629 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1630 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1631 updateWakeGestureListenerLp();
1632 }
1633
Jeff Brown207673cd2012-06-05 17:47:11 -07001634 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001635 int userRotation = Settings.System.getIntForUser(resolver,
1636 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1637 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001638 if (mUserRotation != userRotation) {
1639 mUserRotation = userRotation;
1640 updateRotation = true;
1641 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001642 int userRotationMode = Settings.System.getIntForUser(resolver,
1643 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001644 WindowManagerPolicy.USER_ROTATION_FREE :
1645 WindowManagerPolicy.USER_ROTATION_LOCKED;
1646 if (mUserRotationMode != userRotationMode) {
1647 mUserRotationMode = userRotationMode;
1648 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001649 updateOrientationListenerLp();
1650 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001651
Dianne Hackbornc777e072010-02-12 13:07:59 -08001652 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001653 int pointerLocation = Settings.System.getIntForUser(resolver,
1654 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001655 if (mPointerLocationMode != pointerLocation) {
1656 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001657 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1658 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001659 }
1660 }
1661 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001662 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1663 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1664 String imId = Settings.Secure.getStringForUser(resolver,
1665 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001666 boolean hasSoftInput = imId != null && imId.length() > 0;
1667 if (mHasSoftInput != hasSoftInput) {
1668 mHasSoftInput = hasSoftInput;
1669 updateRotation = true;
1670 }
John Spurlockf1a36642013-10-12 17:50:42 -04001671 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001672 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001673 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001674 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001675 }
1676 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001677 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001678 }
Jeff Brown70825162012-03-28 17:27:48 -07001679 }
1680
Jeff Browna20dda42014-05-27 20:57:24 -07001681 private void updateWakeGestureListenerLp() {
1682 if (shouldEnableWakeGestureLp()) {
1683 mWakeGestureListener.requestWakeUpTrigger();
1684 } else {
1685 mWakeGestureListener.cancelWakeUpTrigger();
1686 }
1687 }
1688
1689 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001690 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001691 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1692 && mWakeGestureListener.isSupported();
1693 }
1694
Jeff Brown70825162012-03-28 17:27:48 -07001695 private void enablePointerLocation() {
1696 if (mPointerLocationView == null) {
1697 mPointerLocationView = new PointerLocationView(mContext);
1698 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001699 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1700 WindowManager.LayoutParams.MATCH_PARENT,
1701 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001702 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001703 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1704 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1705 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1706 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001707 if (ActivityManager.isHighEndGfx()) {
1708 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1709 lp.privateFlags |=
1710 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1711 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001712 lp.format = PixelFormat.TRANSLUCENT;
1713 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001714 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001715 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001716 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001717 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001718 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001719 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001720 }
Jeff Brown70825162012-03-28 17:27:48 -07001721
1722 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001723 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001724 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1725 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001726 wm.removeView(mPointerLocationView);
1727 mPointerLocationView = null;
1728 }
1729 }
1730
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001731 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001732 try {
1733 int rotation = mContext.getResources().getInteger(resID);
1734 switch (rotation) {
1735 case 0:
1736 return Surface.ROTATION_0;
1737 case 90:
1738 return Surface.ROTATION_90;
1739 case 180:
1740 return Surface.ROTATION_180;
1741 case 270:
1742 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001743 }
1744 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001745 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001746 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001747 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001748 }
1749
1750 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001751 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001752 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001753 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001754
1755 outAppOp[0] = AppOpsManager.OP_NONE;
1756
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001757 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1758 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1759 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1760 return WindowManagerGlobal.ADD_INVALID_TYPE;
1761 }
1762
1763 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1764 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001765 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001766 }
1767 String permission = null;
1768 switch (type) {
1769 case TYPE_TOAST:
1770 // XXX right now the app process has complete control over
1771 // this... should introduce a token to let the system
1772 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001773 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001774 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001775 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001776 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001777 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001778 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001779 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001780 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001781 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001782 break;
1783 case TYPE_PHONE:
1784 case TYPE_PRIORITY_PHONE:
1785 case TYPE_SYSTEM_ALERT:
1786 case TYPE_SYSTEM_ERROR:
1787 case TYPE_SYSTEM_OVERLAY:
1788 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001789 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001790 break;
1791 default:
1792 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1793 }
1794 if (permission != null) {
1795 if (mContext.checkCallingOrSelfPermission(permission)
1796 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001797 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001798 }
1799 }
Jeff Brown98365d72012-08-19 20:30:52 -07001800 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001801 }
Craig Mautner88400d32012-09-30 12:35:45 -07001802
1803 @Override
1804 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1805
1806 // If this switch statement is modified, modify the comment in the declarations of
1807 // the type in {@link WindowManager.LayoutParams} as well.
1808 switch (attrs.type) {
1809 default:
1810 // These are the windows that by default are shown only to the user that created
1811 // them. If this needs to be overridden, set
1812 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1813 // {@link WindowManager.LayoutParams}. Note that permission
1814 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1815 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1816 return true;
1817 }
1818 break;
1819
1820 // These are the windows that by default are shown to all users. However, to
1821 // protect against spoofing, check permissions below.
1822 case TYPE_APPLICATION_STARTING:
1823 case TYPE_BOOT_PROGRESS:
1824 case TYPE_DISPLAY_OVERLAY:
1825 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001826 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001827 case TYPE_KEYGUARD_DIALOG:
1828 case TYPE_MAGNIFICATION_OVERLAY:
1829 case TYPE_NAVIGATION_BAR:
1830 case TYPE_NAVIGATION_BAR_PANEL:
1831 case TYPE_PHONE:
1832 case TYPE_POINTER:
1833 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001834 case TYPE_SEARCH_BAR:
1835 case TYPE_STATUS_BAR:
1836 case TYPE_STATUS_BAR_PANEL:
1837 case TYPE_STATUS_BAR_SUB_PANEL:
1838 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001839 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001840 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001841 break;
1842 }
1843
1844 // Check if third party app has set window to system window type.
1845 return mContext.checkCallingOrSelfPermission(
1846 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1847 != PackageManager.PERMISSION_GRANTED;
1848 }
1849
Craig Mautner967212c2013-04-13 21:10:58 -07001850 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001851 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1852 switch (attrs.type) {
1853 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001854 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001855 // These types of windows can't receive input events.
1856 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1857 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001858 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001859 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001860 case TYPE_STATUS_BAR:
1861
1862 // If the Keyguard is in a hidden state (occluded by another window), we force to
1863 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1864 // the keyguard as occluded wouldn't set these flags again.
1865 // See {@link #processKeyguardSetHiddenResultLw}.
1866 if (mKeyguardHidden) {
1867 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1868 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1869 }
1870 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001871 }
Adrian Roos38502112014-04-09 21:04:11 +02001872
1873 if (attrs.type != TYPE_STATUS_BAR) {
1874 // The status bar is the only window allowed to exhibit keyguard behavior.
1875 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1876 }
Adrian Roosea562512014-05-05 13:33:03 +02001877
1878 if (ActivityManager.isHighEndGfx()
1879 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001880 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001881 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1882 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001883 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001884
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001885 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001886 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001887 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001888
Michael Wright3818c922014-09-02 13:59:07 -07001889 private void readCameraLensCoverState() {
1890 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1891 }
1892
Jeff Browndaa37532012-05-01 15:54:03 -07001893 private boolean isHidden(int accessibilityMode) {
1894 switch (accessibilityMode) {
1895 case 1:
1896 return mLidState == LID_CLOSED;
1897 case 2:
1898 return mLidState == LID_OPEN;
1899 default:
1900 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001901 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001902 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001903
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001904 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001905 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001906 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1907 int navigationPresence) {
1908 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1909
Jeff Brownf71343d2013-05-31 17:59:11 -07001910 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001911 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001912 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001913
Jeff Browndaa37532012-05-01 15:54:03 -07001914 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1915 || (keyboardPresence == PRESENCE_INTERNAL
1916 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001917 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001918 if (!mHasSoftInput) {
1919 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1920 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001921 }
1922
Jeff Browndaa37532012-05-01 15:54:03 -07001923 if (config.navigation == Configuration.NAVIGATION_NONAV
1924 || (navigationPresence == PRESENCE_INTERNAL
1925 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001926 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001927 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001928 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001929
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001930 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001931 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001932 public int windowTypeToLayerLw(int type) {
1933 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001934 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001935 }
1936 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001937 case TYPE_PRIVATE_PRESENTATION:
1938 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001939 case TYPE_WALLPAPER:
1940 // wallpaper is at the bottom, though the window manager may move it.
1941 return 2;
1942 case TYPE_PHONE:
1943 return 3;
1944 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07001945 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001946 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001947 case TYPE_VOICE_INTERACTION:
1948 // voice interaction layer is almost immediately above apps.
1949 return 5;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001950 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001951 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001952 case TYPE_TOAST:
1953 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001954 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001955 case TYPE_PRIORITY_PHONE:
1956 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001957 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001958 case TYPE_DREAM:
1959 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001960 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001961 case TYPE_SYSTEM_ALERT:
1962 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001963 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001964 case TYPE_INPUT_METHOD:
1965 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001966 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001967 case TYPE_INPUT_METHOD_DIALOG:
1968 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001969 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001970 case TYPE_KEYGUARD_SCRIM:
1971 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001972 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001973 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001974 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001975 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001976 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001977 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001978 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001979 case TYPE_KEYGUARD_DIALOG:
1980 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001981 case TYPE_VOLUME_OVERLAY:
1982 // the on-screen volume indicator and controller shown when the user
1983 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001984 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001985 case TYPE_SYSTEM_OVERLAY:
1986 // the on-screen volume indicator and controller shown when the user
1987 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001988 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001989 case TYPE_NAVIGATION_BAR:
1990 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001991 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001992 case TYPE_NAVIGATION_BAR_PANEL:
1993 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001994 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001995 case TYPE_SYSTEM_ERROR:
1996 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001997 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001998 case TYPE_MAGNIFICATION_OVERLAY:
1999 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002000 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002001 case TYPE_DISPLAY_OVERLAY:
2002 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002003 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002004 case TYPE_DRAG:
2005 // the drag layer: input for drag-and-drop is associated with this window,
2006 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002007 return 25;
Svetoslav3a5c7212014-10-14 09:54:26 -07002008 case TYPE_ACCESSIBILITY_OVERLAY:
2009 // overlay put by accessibility services to intercept user interaction
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002010 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002011 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002012 return 27;
Svetoslav3a5c7212014-10-14 09:54:26 -07002013 case TYPE_BOOT_PROGRESS:
2014 return 28;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002015 case TYPE_POINTER:
2016 // the (mouse) pointer layer
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002017 return 29;
Svetoslav3a5c7212014-10-14 09:54:26 -07002018 case TYPE_HIDDEN_NAV_CONSUMER:
2019 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002020 }
2021 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002022 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002023 }
2024
2025 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002026 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002027 public int subWindowTypeToLayerLw(int type) {
2028 switch (type) {
2029 case TYPE_APPLICATION_PANEL:
2030 case TYPE_APPLICATION_ATTACHED_DIALOG:
2031 return APPLICATION_PANEL_SUBLAYER;
2032 case TYPE_APPLICATION_MEDIA:
2033 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002034 case TYPE_APPLICATION_MEDIA_OVERLAY:
2035 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002036 case TYPE_APPLICATION_SUB_PANEL:
2037 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002038 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2039 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002040 }
2041 Log.e(TAG, "Unknown sub-window type: " + type);
2042 return 0;
2043 }
2044
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002045 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002046 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002047 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002048 }
2049
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002050 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002051 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002052 if (mHasNavigationBar) {
2053 // For a basic navigation bar, when we are in landscape mode we place
2054 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002055 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2056 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002057 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002058 }
2059 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002060 }
2061
Jose Lima9546b202014-07-02 17:21:51 -07002062 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002063 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002064 if (mHasNavigationBar) {
2065 // For a basic navigation bar, when we are in portrait mode we place
2066 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002067 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2068 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002069 }
2070 }
2071 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002072 }
2073
Jose Lima9546b202014-07-02 17:21:51 -07002074 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002075 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2076 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002077 }
2078
Jose Lima9546b202014-07-02 17:21:51 -07002079 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002080 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002081 // There is a separate status bar at the top of the display. We don't count that as part
2082 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002083 // we do want to exclude it since applications can't generally use that part
2084 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002085 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002086 }
2087
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002088 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002089 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2090 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002091 (isKeyguardHostWindow(attrs) &&
2092 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002093 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002094 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002095
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002096 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002097 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2098 return attrs.type == TYPE_STATUS_BAR;
2099 }
2100
2101 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002102 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002103 switch (attrs.type) {
2104 case TYPE_STATUS_BAR:
2105 case TYPE_NAVIGATION_BAR:
2106 case TYPE_WALLPAPER:
2107 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002108 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002109 return false;
2110 default:
2111 return true;
2112 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002113 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002114
Craig Mautner7d7808f2014-09-11 18:02:38 -07002115 @Override
2116 public WindowState getWinShowWhenLockedLw() {
2117 return mWinShowWhenLocked;
2118 }
2119
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002120 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002121 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002122 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2123 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002124 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002125 if (!SHOW_STARTING_ANIMATIONS) {
2126 return null;
2127 }
2128 if (packageName == null) {
2129 return null;
2130 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002131
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002132 WindowManager wm = null;
2133 View view = null;
2134
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002135 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002136 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002137 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2138 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2139 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002140 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002141 try {
2142 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002143 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002144 } catch (PackageManager.NameNotFoundException e) {
2145 // Ignore
2146 }
2147 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002148
Jorim Jaggib10e33f2015-02-04 21:57:40 +01002149 Window win = new PhoneWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002150 final TypedArray ta = win.getWindowStyle();
2151 if (ta.getBoolean(
2152 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2153 || ta.getBoolean(
2154 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002155 return null;
2156 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002157
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002158 Resources r = context.getResources();
2159 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002160
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002161 win.setType(
2162 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002163
2164 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2165 // Assumes it's safe to show starting windows of launched apps while
2166 // the keyguard is being hidden. This is okay because starting windows never show
2167 // secret information.
2168 if (mKeyguardHidden) {
2169 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2170 }
2171 }
2172
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002173 // Force the window flags: this is a fake window, so it is not really
2174 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2175 // flag because we do know that the next window will take input
2176 // focus, so we want to get the IME window up on top of us right away.
2177 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002178 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002179 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2180 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2181 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002182 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002183 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2184 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2185 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002186
Adam Powell04fe6eb2013-05-31 14:39:48 -07002187 win.setDefaultIcon(icon);
2188 win.setDefaultLogo(logo);
2189
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002190 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002191 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002192
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002193 final WindowManager.LayoutParams params = win.getAttributes();
2194 params.token = appToken;
2195 params.packageName = packageName;
2196 params.windowAnimations = win.getWindowStyle().getResourceId(
2197 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002198 params.privateFlags |=
2199 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002200 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002201
2202 if (!compatInfo.supportsScreen()) {
2203 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2204 }
2205
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002206 params.setTitle("Starting " + packageName);
2207
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002208 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2209 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002210
2211 if (win.isFloating()) {
2212 // Whoops, there is no way to display an animation/preview
2213 // of such a thing! After all that work... let's skip it.
2214 // (Note that we must do this here because it is in
2215 // getDecorView() where the theme is evaluated... maybe
2216 // we should peek the floating attribute from the theme
2217 // earlier.)
2218 return null;
2219 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002220
Craig Mautner6fbda632012-07-03 09:26:39 -07002221 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002222 TAG, "Adding starting window for " + packageName
2223 + " / " + appToken + ": "
2224 + (view.getParent() != null ? view : null));
2225
2226 wm.addView(view, params);
2227
2228 // Only return the view if it was successfully added to the
2229 // window manager... which we can tell by it having a parent.
2230 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002231 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002232 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002233 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2234 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002235 } catch (RuntimeException e) {
2236 // don't crash if something else bad happens, for example a
2237 // failure loading resources because we are loading from an app
2238 // on external storage that has been unmounted.
2239 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002240 } finally {
2241 if (view != null && view.getParent() == null) {
2242 Log.w(TAG, "view not successfully added to wm, removing view");
2243 wm.removeViewImmediate(view);
2244 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002245 }
2246
2247 return null;
2248 }
2249
2250 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002251 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002252 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002253 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2254 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002255
2256 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002257 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002258 wm.removeView(window);
2259 }
2260 }
2261
2262 /**
2263 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002264 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002265 * Currently enforces that three window types are singletons:
2266 * <ul>
2267 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002268 * <li>KEYGUARD_TYPE</li>
2269 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002270 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002271 * @param win The window to be added
2272 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002273 *
Jeff Brown98365d72012-08-19 20:30:52 -07002274 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2275 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002276 */
Jose Lima9546b202014-07-02 17:21:51 -07002277 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002278 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2279 switch (attrs.type) {
2280 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002281 mContext.enforceCallingOrSelfPermission(
2282 android.Manifest.permission.STATUS_BAR_SERVICE,
2283 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002284 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002285 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002286 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002287 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002288 }
2289 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002290 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002291 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002292 case TYPE_NAVIGATION_BAR:
2293 mContext.enforceCallingOrSelfPermission(
2294 android.Manifest.permission.STATUS_BAR_SERVICE,
2295 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002296 if (mNavigationBar != null) {
2297 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002298 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002299 }
2300 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002301 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002302 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002303 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002304 break;
Jim Millere898ac52012-04-06 17:10:57 -07002305 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002306 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002307 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002308 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002309 mContext.enforceCallingOrSelfPermission(
2310 android.Manifest.permission.STATUS_BAR_SERVICE,
2311 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002312 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002313 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002314 if (mKeyguardScrim != null) {
2315 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2316 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002317 mKeyguardScrim = win;
2318 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002319 }
Jeff Brown98365d72012-08-19 20:30:52 -07002320 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002321 }
2322
2323 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002324 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002325 public void removeWindowLw(WindowState win) {
2326 if (mStatusBar == win) {
2327 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002328 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002329 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002330 } else if (mKeyguardScrim == win) {
2331 Log.v(TAG, "Removing keyguard scrim");
2332 mKeyguardScrim = null;
2333 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002334 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002335 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002336 }
2337 }
2338
2339 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002340
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002341 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002342 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002343 public int selectAnimationLw(WindowState win, int transit) {
2344 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2345 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002346 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002347 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002348 if (transit == TRANSIT_EXIT
2349 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002350 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002351 } else if (transit == TRANSIT_ENTER
2352 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002353 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002354 }
2355 } else if (win == mNavigationBar) {
2356 // This can be on either the bottom or the right.
2357 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002358 if (transit == TRANSIT_EXIT
2359 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002360 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002361 } else if (transit == TRANSIT_ENTER
2362 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002363 return R.anim.dock_bottom_enter;
2364 }
2365 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002366 if (transit == TRANSIT_EXIT
2367 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002368 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002369 } else if (transit == TRANSIT_ENTER
2370 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002371 return R.anim.dock_right_enter;
2372 }
2373 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002374 }
2375
2376 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002377 if (win.hasAppShownWindows()) {
2378 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2379 return com.android.internal.R.anim.app_starting_exit;
2380 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002381 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002382 && transit == TRANSIT_ENTER) {
2383 // Special case: we are animating in a dream, while the keyguard
2384 // is shown. We don't want an animation on the dream, because
2385 // we need it shown immediately with the keyguard animating away
2386 // to reveal it.
2387 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002388 }
2389
2390 return 0;
2391 }
2392
Craig Mautner3c174372013-02-21 17:54:37 -08002393 @Override
2394 public void selectRotationAnimationLw(int anim[]) {
2395 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2396 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2397 + (mTopFullscreenOpaqueWindowState == null ?
2398 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2399 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2400 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2401 case ROTATION_ANIMATION_CROSSFADE:
2402 anim[0] = R.anim.rotation_animation_xfade_exit;
2403 anim[1] = R.anim.rotation_animation_enter;
2404 break;
2405 case ROTATION_ANIMATION_JUMPCUT:
2406 anim[0] = R.anim.rotation_animation_jump_exit;
2407 anim[1] = R.anim.rotation_animation_enter;
2408 break;
2409 case ROTATION_ANIMATION_ROTATE:
2410 default:
2411 anim[0] = anim[1] = 0;
2412 break;
2413 }
2414 } else {
2415 anim[0] = anim[1] = 0;
2416 }
2417 }
2418
2419 @Override
2420 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2421 boolean forceDefault) {
2422 switch (exitAnimId) {
2423 case R.anim.rotation_animation_xfade_exit:
2424 case R.anim.rotation_animation_jump_exit:
2425 // These are the only cases that matter.
2426 if (forceDefault) {
2427 return false;
2428 }
2429 int anim[] = new int[2];
2430 selectRotationAnimationLw(anim);
2431 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2432 default:
2433 return true;
2434 }
2435 }
2436
2437 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002438 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2439 boolean goingToNotificationShade) {
2440 if (goingToNotificationShade) {
2441 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002442 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002443
2444 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2445 R.anim.lock_screen_behind_enter_wallpaper :
2446 R.anim.lock_screen_behind_enter);
2447
2448 // TODO: Use XML interpolators when we have log interpolators available in XML.
2449 final List<Animation> animations = set.getAnimations();
2450 for (int i = animations.size() - 1; i >= 0; --i) {
2451 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2452 }
2453
2454 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002455 }
2456
2457
2458 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002459 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2460 if (goingToNotificationShade) {
2461 return null;
2462 } else {
2463 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2464 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002465 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002466
2467 private static void awakenDreams() {
2468 IDreamManager dreamManager = getDreamManager();
2469 if (dreamManager != null) {
2470 try {
2471 dreamManager.awaken();
2472 } catch (RemoteException e) {
2473 // fine, stay asleep then
2474 }
2475 }
2476 }
2477
2478 static IDreamManager getDreamManager() {
2479 return IDreamManager.Stub.asInterface(
2480 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2481 }
2482
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002483 TelecomManager getTelecommService() {
2484 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002485 }
2486
Jeff Brown4d396052010-10-29 21:50:21 -07002487 static IAudioService getAudioService() {
2488 IAudioService audioService = IAudioService.Stub.asInterface(
2489 ServiceManager.checkService(Context.AUDIO_SERVICE));
2490 if (audioService == null) {
2491 Log.w(TAG, "Unable to find IAudioService interface.");
2492 }
2493 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002494 }
2495
2496 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002497 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002498 }
2499
2500 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2501 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2502 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2503 };
2504
2505 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002506 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002507 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002508 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002509 final int keyCode = event.getKeyCode();
2510 final int repeatCount = event.getRepeatCount();
2511 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002512 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002513 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2514 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002515
Jeff Brown40013652012-05-16 21:22:36 -07002516 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002517 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002518 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2519 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002520 }
2521
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002522 // If we think we might have a volume down & power key chord on the way
2523 // but we're not sure, then tell the dispatcher to wait a little while and
2524 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002525 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002526 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002527 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002528 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2529 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002530 if (now < timeoutTime) {
2531 return timeoutTime - now;
2532 }
2533 }
2534 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002535 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002536 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002537 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002538 }
2539 return -1;
2540 }
2541 }
2542
Michael Wright6a62e552014-06-03 19:19:48 -07002543 // Cancel any pending meta actions if we see any other keys being pressed between the down
2544 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002545 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002546 mPendingMetaAction = false;
2547 }
2548
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002549 // First we always handle the home key here, so applications
2550 // can never break it, although if keyguard is on, we do let
2551 // it handle it, because that gives us the correct 5 second
2552 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002553 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002554
Jeff Brown49ed71d2010-12-06 17:13:33 -08002555 // If we have released the home key, and didn't do anything else
2556 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002557 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002558 cancelPreloadRecentApps();
2559
Jeff Brown49ed71d2010-12-06 17:13:33 -08002560 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002561 if (mHomeConsumed) {
2562 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002563 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002564 }
Jeff Browncaca8812013-05-09 13:34:33 -07002565
2566 if (canceled) {
2567 Log.i(TAG, "Ignoring HOME; event canceled.");
2568 return -1;
2569 }
2570
Yorke Lee4f803242014-12-15 23:22:06 +00002571 // If an incoming call is ringing, HOME is totally disabled.
2572 // (The user is already on the InCallUI at this point,
2573 // and his ONLY options are to answer or reject the call.)
2574 TelecomManager telecomManager = getTelecommService();
2575 if (telecomManager != null && telecomManager.isRinging()) {
2576 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2577 return -1;
2578 }
2579
Jeff Browncaca8812013-05-09 13:34:33 -07002580 // Delay handling home if a double-tap is possible.
2581 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2582 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2583 mHomeDoubleTapPending = true;
2584 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2585 ViewConfiguration.getDoubleTapTimeout());
2586 return -1;
2587 }
2588
Jeff Brown13f00f02014-10-31 14:45:50 -07002589 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002590 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002591 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002592
2593 // If a system window has focus, then it doesn't make sense
2594 // right now to interact with applications.
2595 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2596 if (attrs != null) {
2597 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002598 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2599 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2600 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002601 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002602 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002603 }
2604 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2605 for (int i=0; i<typeCount; i++) {
2606 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2607 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002608 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002609 }
2610 }
2611 }
Jeff Browncaca8812013-05-09 13:34:33 -07002612
2613 // Remember that home is pressed and handle special actions.
2614 if (repeatCount == 0) {
2615 mHomePressed = true;
2616 if (mHomeDoubleTapPending) {
2617 mHomeDoubleTapPending = false;
2618 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2619 handleDoubleTapOnHome();
2620 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2621 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2622 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002623 }
Jeff Browncaca8812013-05-09 13:34:33 -07002624 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2625 if (!keyguardOn) {
2626 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002627 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002628 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002629 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002630 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002631 // Hijack modified menu keys for debugging features
2632 final int chordBug = KeyEvent.META_SHIFT_ON;
2633
2634 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002635 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002636 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002637 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2638 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002639 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002640 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002641 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002642 Intent service = new Intent();
2643 service.setClassName(mContext, "com.android.server.LoadAverageService");
2644 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002645 boolean shown = Settings.Global.getInt(
2646 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002647 if (!shown) {
2648 mContext.startService(service);
2649 } else {
2650 mContext.stopService(service);
2651 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002652 Settings.Global.putInt(
2653 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002654 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002655 }
2656 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002657 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002658 if (down) {
2659 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002660 mSearchKeyShortcutPending = true;
2661 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002662 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002663 } else {
2664 mSearchKeyShortcutPending = false;
2665 if (mConsumeSearchKeyUp) {
2666 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002667 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002668 }
2669 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002670 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002671 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002672 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002673 if (down && repeatCount == 0) {
2674 preloadRecentApps();
2675 } else if (!down) {
2676 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002677 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002678 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002679 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002680 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2681 if (down) {
2682 IStatusBarService service = getStatusBarService();
2683 if (service != null) {
2684 try {
2685 service.expandNotificationsPanel();
2686 } catch (RemoteException e) {
2687 // do nothing.
2688 }
2689 }
2690 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002691 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2692 if (down) {
2693 if (repeatCount == 0) {
2694 mAssistKeyLongPressed = false;
2695 } else if (repeatCount == 1) {
2696 mAssistKeyLongPressed = true;
2697 if (!keyguardOn) {
2698 launchAssistLongPressAction();
2699 }
2700 }
2701 } else {
2702 if (mAssistKeyLongPressed) {
2703 mAssistKeyLongPressed = false;
2704 } else {
2705 if (!keyguardOn) {
2706 launchAssistAction();
2707 }
2708 }
2709 }
2710 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002711 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2712 if (!down) {
2713 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002714 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002715 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2716 } else {
2717 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002718 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002719 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002720 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002721 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002722 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2723 if (down && repeatCount == 0) {
2724 mHandler.post(mScreenshotRunnable);
2725 }
2726 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002727 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2728 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2729 if (down) {
2730 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2731
2732 // Disable autobrightness if it's on
2733 int auto = Settings.System.getIntForUser(
2734 mContext.getContentResolver(),
2735 Settings.System.SCREEN_BRIGHTNESS_MODE,
2736 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2737 UserHandle.USER_CURRENT_OR_SELF);
2738 if (auto != 0) {
2739 Settings.System.putIntForUser(mContext.getContentResolver(),
2740 Settings.System.SCREEN_BRIGHTNESS_MODE,
2741 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2742 UserHandle.USER_CURRENT_OR_SELF);
2743 }
2744
2745 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2746 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2747 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2748 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2749 Settings.System.SCREEN_BRIGHTNESS,
2750 mPowerManager.getDefaultScreenBrightnessSetting(),
2751 UserHandle.USER_CURRENT_OR_SELF);
2752 brightness += step;
2753 // Make sure we don't go beyond the limits.
2754 brightness = Math.min(max, brightness);
2755 brightness = Math.max(min, brightness);
2756
2757 Settings.System.putIntForUser(mContext.getContentResolver(),
2758 Settings.System.SCREEN_BRIGHTNESS, brightness,
2759 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002760 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002761 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002762 }
2763 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002764 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002765 if (down) {
2766 mPendingMetaAction = true;
2767 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002768 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002769 }
2770 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002771 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002772
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002773 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002774 // Any printing key that is chorded with Search should be consumed
2775 // even if no shortcut was invoked. This prevents text from being
2776 // inadvertently inserted when using a keyboard that has built-in macro
2777 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002778 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002779 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2780 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002781 mConsumeSearchKeyUp = true;
2782 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002783 if (down && repeatCount == 0 && !keyguardOn) {
2784 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2785 if (shortcutIntent != null) {
2786 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002787 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002788 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002789 } catch (ActivityNotFoundException ex) {
2790 Slog.w(TAG, "Dropping shortcut key combination because "
2791 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002792 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002793 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002794 } else {
2795 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002796 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002797 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002798 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002799 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002800 }
2801 }
2802
Jeff Brown68b909d2011-12-07 16:36:01 -08002803 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002804 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002805 && (metaState & KeyEvent.META_META_ON) != 0) {
2806 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002807 if (kcm.isPrintingKey(keyCode)) {
2808 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2809 metaState & ~(KeyEvent.META_META_ON
2810 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2811 if (shortcutIntent != null) {
2812 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2813 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002814 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002815 } catch (ActivityNotFoundException ex) {
2816 Slog.w(TAG, "Dropping shortcut key combination because "
2817 + "the activity to which it is registered was not found: "
2818 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2819 }
2820 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002821 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002822 }
2823 }
2824
Jeff Brown6651a632011-11-28 12:59:11 -08002825 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002826 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002827 String category = sApplicationLaunchKeyCategories.get(keyCode);
2828 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002829 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002830 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2831 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002832 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002833 } catch (ActivityNotFoundException ex) {
2834 Slog.w(TAG, "Dropping application launch key because "
2835 + "the activity to which it is registered was not found: "
2836 + "keyCode=" + keyCode + ", category=" + category, ex);
2837 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002838 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002839 }
2840 }
2841
Michael Wright61c46752014-08-21 16:57:33 -07002842 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002843 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002844 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002845 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002846 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002847 mRecentAppsHeldModifiers = shiftlessModifiers;
2848 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002849 return -1;
2850 }
2851 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002852 } else if (!down && mRecentAppsHeldModifiers != 0
2853 && (metaState & mRecentAppsHeldModifiers) == 0) {
2854 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002855 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002856 }
2857
Jeff Browncf39bdf2012-05-18 14:41:19 -07002858 // Handle keyboard language switching.
2859 if (down && repeatCount == 0
2860 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2861 || (keyCode == KeyEvent.KEYCODE_SPACE
2862 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2863 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2864 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2865 return -1;
2866 }
2867 if (mLanguageSwitchKeyPressed && !down
2868 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2869 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2870 mLanguageSwitchKeyPressed = false;
2871 return -1;
2872 }
2873
Jeff Brown13f00f02014-10-31 14:45:50 -07002874 if (isValidGlobalKey(keyCode)
2875 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002876 return -1;
2877 }
2878
Michael Wright6a62e552014-06-03 19:19:48 -07002879 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002880 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002881 return -1;
2882 }
2883
Jeff Brown68b909d2011-12-07 16:36:01 -08002884 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002885 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002886 }
2887
Jeff Brown3915bb82010-11-05 15:02:16 -07002888 /** {@inheritDoc} */
2889 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002890 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002891 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002892 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002893 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2894 + ", flags=" + event.getFlags()
2895 + ", keyCode=" + event.getKeyCode()
2896 + ", scanCode=" + event.getScanCode()
2897 + ", metaState=" + event.getMetaState()
2898 + ", repeatCount=" + event.getRepeatCount()
2899 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002900 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002901
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002902 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002903 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2904 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002905 final int keyCode = event.getKeyCode();
2906 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002907 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2908 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002909
Jeff Brown54875002011-04-06 15:33:01 -07002910 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002911 final FallbackAction fallbackAction;
2912 if (initialDown) {
2913 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2914 } else {
2915 fallbackAction = mFallbackActions.get(keyCode);
2916 }
2917
2918 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002919 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002920 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2921 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002922 }
2923
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002924 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2925 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002926 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002927 event.getAction(), fallbackAction.keyCode,
2928 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002929 event.getDeviceId(), event.getScanCode(),
2930 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002931
2932 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2933 fallbackEvent.recycle();
2934 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002935 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002936
2937 if (initialDown) {
2938 mFallbackActions.put(keyCode, fallbackAction);
2939 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2940 mFallbackActions.remove(keyCode);
2941 fallbackAction.recycle();
2942 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002943 }
2944 }
2945
Jeff Brown40013652012-05-16 21:22:36 -07002946 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002947 if (fallbackEvent == null) {
2948 Slog.d(TAG, "No fallback.");
2949 } else {
2950 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2951 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002952 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002953 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002954 }
2955
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002956 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002957 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002958 if ((actions & ACTION_PASS_TO_USER) != 0) {
2959 long delayMillis = interceptKeyBeforeDispatching(
2960 win, fallbackEvent, policyFlags);
2961 if (delayMillis == 0) {
2962 return true;
2963 }
2964 }
2965 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002966 }
2967
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002968 private void launchAssistLongPressAction() {
2969 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2970 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2971
2972 // launch the search activity
2973 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2974 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2975 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002976 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002977 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002978 SearchManager searchManager = getSearchManager();
2979 if (searchManager != null) {
2980 searchManager.stopSearch();
2981 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002982 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002983 } catch (ActivityNotFoundException e) {
2984 Slog.w(TAG, "No activity to handle assist long press action.", e);
2985 }
2986 }
2987
2988 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002989 launchAssistAction(null);
2990 }
2991
2992 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002993 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002994 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002995 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002996 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002997 if (hint != null) {
2998 intent.putExtra(hint, true);
2999 }
Jim Miller45308b12012-06-18 19:23:39 -07003000 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
3001 | Intent.FLAG_ACTIVITY_SINGLE_TOP
3002 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
3003 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003004 startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07003005 } catch (ActivityNotFoundException e) {
3006 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003007 }
3008 }
3009 }
3010
Bart Sears8b1c27c2015-03-18 23:51:02 +00003011 private void startActivityAsUser(Intent intent, UserHandle handle) {
3012 if (isUserSetupComplete()) {
3013 mContext.startActivityAsUser(intent, handle);
3014 } else {
3015 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3016 }
3017 }
3018
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003019 private SearchManager getSearchManager() {
3020 if (mSearchManager == null) {
3021 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3022 }
3023 return mSearchManager;
3024 }
3025
Jeff Browncaca8812013-05-09 13:34:33 -07003026 private void preloadRecentApps() {
3027 mPreloadedRecentApps = true;
3028 try {
3029 IStatusBarService statusbar = getStatusBarService();
3030 if (statusbar != null) {
3031 statusbar.preloadRecentApps();
3032 }
3033 } catch (RemoteException e) {
3034 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3035 // re-acquire status bar service next time it is needed.
3036 mStatusBarService = null;
3037 }
3038 }
3039
3040 private void cancelPreloadRecentApps() {
3041 if (mPreloadedRecentApps) {
3042 mPreloadedRecentApps = false;
3043 try {
3044 IStatusBarService statusbar = getStatusBarService();
3045 if (statusbar != null) {
3046 statusbar.cancelPreloadRecentApps();
3047 }
3048 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003049 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003050 // re-acquire status bar service next time it is needed.
3051 mStatusBarService = null;
3052 }
3053 }
3054 }
3055
3056 private void toggleRecentApps() {
3057 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003058 try {
3059 IStatusBarService statusbar = getStatusBarService();
3060 if (statusbar != null) {
3061 statusbar.toggleRecentApps();
3062 }
3063 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003064 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3065 // re-acquire status bar service next time it is needed.
3066 mStatusBarService = null;
3067 }
3068 }
3069
Craig Mautner84984fa2014-06-19 11:19:20 -07003070 @Override
3071 public void showRecentApps() {
3072 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3073 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3074 }
3075
Winson Chung1e8d71b2014-05-16 17:05:22 -07003076 private void showRecentApps(boolean triggeredFromAltTab) {
3077 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3078 try {
3079 IStatusBarService statusbar = getStatusBarService();
3080 if (statusbar != null) {
3081 statusbar.showRecentApps(triggeredFromAltTab);
3082 }
3083 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003084 Slog.e(TAG, "RemoteException when showing recent apps", e);
3085 // re-acquire status bar service next time it is needed.
3086 mStatusBarService = null;
3087 }
3088 }
3089
Winson Chungcdcd4872014-08-05 18:00:13 -07003090 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003091 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3092 try {
3093 IStatusBarService statusbar = getStatusBarService();
3094 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003095 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003096 }
3097 } catch (RemoteException e) {
3098 Slog.e(TAG, "RemoteException when closing recent apps", e);
3099 // re-acquire status bar service next time it is needed.
3100 mStatusBarService = null;
3101 }
3102 }
3103
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003104 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003105 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003106 }
3107
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003108 /**
3109 * A home key -> launch home action was detected. Take the appropriate action
3110 * given the situation with the keyguard.
3111 */
Bryce Lee662ed802015-04-10 20:11:39 +00003112 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3113 if (respectKeyguard) {
3114 if (isKeyguardShowingAndNotOccluded()) {
3115 // don't launch home if keyguard showing
3116 return;
3117 }
3118
3119 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3120 // when in keyguard restricted mode, must first verify unlock
3121 // before launching home
3122 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3123 @Override
3124 public void onKeyguardExitResult(boolean success) {
3125 if (success) {
3126 try {
3127 ActivityManagerNative.getDefault().stopAppSwitches();
3128 } catch (RemoteException e) {
3129 }
3130 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3131 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003132 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003133 }
Bryce Lee662ed802015-04-10 20:11:39 +00003134 });
3135 return;
3136 }
3137 }
3138
3139 // no keyguard stuff to worry about, just launch home!
3140 try {
3141 ActivityManagerNative.getDefault().stopAppSwitches();
3142 } catch (RemoteException e) {
3143 }
3144 if (mRecentsVisible) {
3145 // Hide Recents and notify it to launch Home
3146 if (awakenFromDreams) {
3147 awakenDreams();
3148 }
3149 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3150 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003151 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003152 // Otherwise, just launch Home
3153 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3154 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003155 }
3156 }
3157
John Spurlock04db1762013-05-13 12:46:41 -04003158 private final Runnable mClearHideNavigationFlag = new Runnable() {
3159 @Override
3160 public void run() {
3161 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3162 // Clear flags.
3163 mForceClearedSystemUiFlags &=
3164 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3165 }
3166 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003167 }
3168 };
3169
3170 /**
3171 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3172 * to determine when the nav bar should be shown and prevent applications from
3173 * receiving those touches.
3174 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003175 final class HideNavInputEventReceiver extends InputEventReceiver {
3176 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3177 super(inputChannel, looper);
3178 }
3179
Dianne Hackborndf89e652011-10-06 22:35:11 -07003180 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003181 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003182 boolean handled = false;
3183 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003184 if (event instanceof MotionEvent
3185 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3186 final MotionEvent motionEvent = (MotionEvent)event;
3187 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003188 // When the user taps down, we re-show the nav bar.
3189 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003190 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003191 // Any user activity always causes us to show the
3192 // navigation controls, if they had been hidden.
3193 // We also clear the low profile and only content
3194 // flags so that tapping on the screen will atomically
3195 // restore all currently hidden screen decorations.
3196 int newVal = mResettingSystemUiFlags |
3197 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3198 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3199 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003200 if (mResettingSystemUiFlags != newVal) {
3201 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003202 changed = true;
3203 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003204 // We don't allow the system's nav bar to be hidden
3205 // again for 1 second, to prevent applications from
3206 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003207 newVal = mForceClearedSystemUiFlags |
3208 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003209 if (mForceClearedSystemUiFlags != newVal) {
3210 mForceClearedSystemUiFlags = newVal;
3211 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003212 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003213 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003214 }
3215 if (changed) {
3216 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3217 }
3218 }
3219 }
3220 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003221 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003222 }
3223 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003224 }
3225 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3226 new InputEventReceiver.Factory() {
3227 @Override
3228 public InputEventReceiver createInputEventReceiver(
3229 InputChannel inputChannel, Looper looper) {
3230 return new HideNavInputEventReceiver(inputChannel, looper);
3231 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003232 };
3233
3234 @Override
3235 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003236 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3237 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003238 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003239
Dianne Hackborndf89e652011-10-06 22:35:11 -07003240 // Reset any bits in mForceClearingStatusBarVisibility that
3241 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003242 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003243 // Clear any bits in the new visibility that are currently being
3244 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003245 return visibility & ~mResettingSystemUiFlags
3246 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003247 }
3248
Craig Mautner69b08182012-09-05 13:07:13 -07003249 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003250 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3251 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003252 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003253 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3254 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003255
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003256 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003257 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003258 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003259 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003260 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003261 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3262 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3263 } else {
3264 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3265 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3266 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003267 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3268 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003269 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003270 availRight - mStableFullscreenRight,
3271 availBottom - mStableFullscreenBottom);
3272 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003273 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003274 availRight - mStableRight, availBottom - mStableBottom);
3275 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003276 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003277 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003278 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003279 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
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 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003283 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003284 availRight - mCurRight, availBottom - mCurBottom);
3285 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003286
3287 outStableInsets.set(mStableLeft, mStableTop,
3288 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003289 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003290 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003291 outContentInsets.setEmpty();
3292 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003293 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003294
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003295 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003296 @Override
3297 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3298 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003299 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3300 if (isDefaultDisplay) {
3301 switch (displayRotation) {
3302 case Surface.ROTATION_90:
3303 overscanLeft = mOverscanTop;
3304 overscanTop = mOverscanRight;
3305 overscanRight = mOverscanBottom;
3306 overscanBottom = mOverscanLeft;
3307 break;
3308 case Surface.ROTATION_180:
3309 overscanLeft = mOverscanRight;
3310 overscanTop = mOverscanBottom;
3311 overscanRight = mOverscanLeft;
3312 overscanBottom = mOverscanTop;
3313 break;
3314 case Surface.ROTATION_270:
3315 overscanLeft = mOverscanBottom;
3316 overscanTop = mOverscanLeft;
3317 overscanRight = mOverscanTop;
3318 overscanBottom = mOverscanRight;
3319 break;
3320 default:
3321 overscanLeft = mOverscanLeft;
3322 overscanTop = mOverscanTop;
3323 overscanRight = mOverscanRight;
3324 overscanBottom = mOverscanBottom;
3325 break;
3326 }
3327 } else {
3328 overscanLeft = 0;
3329 overscanTop = 0;
3330 overscanRight = 0;
3331 overscanBottom = 0;
3332 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003333 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3334 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3335 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3336 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003337 mSystemLeft = 0;
3338 mSystemTop = 0;
3339 mSystemRight = displayWidth;
3340 mSystemBottom = displayHeight;
3341 mUnrestrictedScreenLeft = overscanLeft;
3342 mUnrestrictedScreenTop = overscanTop;
3343 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3344 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3345 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3346 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003347 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3348 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003349 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003350 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003351 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003352 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003353 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003354 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003355 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003356 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003357 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003358 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003359
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003360 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3361 final Rect pf = mTmpParentFrame;
3362 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003363 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003364 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003365 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003366 pf.left = df.left = of.left = vf.left = mDockLeft;
3367 pf.top = df.top = of.top = vf.top = mDockTop;
3368 pf.right = df.right = of.right = vf.right = mDockRight;
3369 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003370 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003371
Craig Mautner69b08182012-09-05 13:07:13 -07003372 if (isDefaultDisplay) {
3373 // For purposes of putting out fake window up to steal focus, we will
3374 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003375 final int sysui = mLastSystemUiFlags;
3376 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003377 boolean navTranslucent = (sysui
3378 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003379 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3380 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3381 boolean navAllowedHidden = immersive || immersiveSticky;
3382 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003383 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3384 if (!isKeyguardShowing) {
3385 navTranslucent &= areTranslucentBarsAllowed();
3386 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003387
Craig Mautner69b08182012-09-05 13:07:13 -07003388 // When the navigation bar isn't visible, we put up a fake
3389 // input window to catch all touch events. This way we can
3390 // detect when the user presses anywhere to bring back the nav
3391 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003392 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07003393 if (mHideNavFakeWindow != null) {
3394 mHideNavFakeWindow.dismiss();
3395 mHideNavFakeWindow = null;
3396 }
3397 } else if (mHideNavFakeWindow == null) {
3398 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
3399 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07003400 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07003401 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003402 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003403
Craig Mautner69b08182012-09-05 13:07:13 -07003404 // For purposes of positioning and showing the nav bar, if we have
3405 // decided that it can't be hidden (because of the screen aspect ratio),
3406 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003407 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003408
John Spurlockad3e6cb2013-04-30 08:47:43 -04003409 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003410 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003411 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003412 // Force the navigation bar to its appropriate place and
3413 // size. We need to do this directly, instead of relying on
3414 // it to bubble up from the nav bar, because this needs to
3415 // change atomically with screen rotations.
3416 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3417 if (mNavigationBarOnBottom) {
3418 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003419 int top = displayHeight - overscanBottom
3420 - mNavigationBarHeightForRotation[displayRotation];
3421 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003422 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003423 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003424 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003425 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003426 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003427 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003428 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3429 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003430 } else {
3431 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003432 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003433 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003434 if (navVisible && !navTranslucent && !navAllowedHidden
3435 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003436 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003437 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003438 // and not in the process of animating on or off, then
3439 // we can tell the app that it is covered by it.
3440 mSystemBottom = mTmpNavigationFrame.top;
3441 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003442 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003443 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003444 int left = displayWidth - overscanRight
3445 - mNavigationBarWidthForRotation[displayRotation];
3446 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003447 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003448 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003449 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003450 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003451 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003452 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003453 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3454 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003455 } else {
3456 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003457 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003458 }
John Spurlockbd957402013-10-03 11:38:39 -04003459 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3460 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003461 // If the nav bar is currently requested to be visible,
3462 // and not in the process of animating on or off, then
3463 // we can tell the app that it is covered by it.
3464 mSystemRight = mTmpNavigationFrame.left;
3465 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003466 }
Craig Mautner69b08182012-09-05 13:07:13 -07003467 // Make sure the content and current rectangles are updated to
3468 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003469 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3470 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3471 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3472 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003473 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3474 // And compute the final frame.
3475 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003476 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3477 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003478 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003479 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003480 updateSysUiVisibility = true;
3481 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003482 }
Craig Mautnereda67292013-04-28 13:50:14 -07003483 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003484 mDockLeft, mDockTop, mDockRight, mDockBottom));
3485
3486 // decide where the status bar goes ahead of time
3487 if (mStatusBar != null) {
3488 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003489 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3490 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3491 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3492 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3493 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003494 vf.left = mStableLeft;
3495 vf.top = mStableTop;
3496 vf.right = mStableRight;
3497 vf.bottom = mStableBottom;
3498
3499 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3500
3501 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003502 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003503
3504 // For layout, the status bar is always at the top with our fixed height.
3505 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3506
John Spurlocke1f366f2013-08-05 12:22:40 -04003507 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003508 boolean statusBarTranslucent = (sysui
3509 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003510 if (!isKeyguardShowing) {
3511 statusBarTranslucent &= areTranslucentBarsAllowed();
3512 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003513
Craig Mautner69b08182012-09-05 13:07:13 -07003514 // If the status bar is hidden, we don't want to cause
3515 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003516 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003517 // Status bar may go away, so the screen area it occupies
3518 // is available to apps but just covering them when the
3519 // status bar is visible.
3520 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3521
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003522 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3523 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3524 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3525 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003526
Craig Mautnereda67292013-04-28 13:50:14 -07003527 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003528 String.format(
3529 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3530 mDockLeft, mDockTop, mDockRight, mDockBottom,
3531 mContentLeft, mContentTop, mContentRight, mContentBottom,
3532 mCurLeft, mCurTop, mCurRight, mCurBottom));
3533 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003534 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003535 && !statusBarTransient && !statusBarTranslucent
3536 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003537 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003538 // and not in the process of animating on or off, then
3539 // we can tell the app that it is covered by it.
3540 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3541 }
John Spurlock27735a42013-08-14 17:57:38 -04003542 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003543 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003544 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003545 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003546 if (updateSysUiVisibility) {
3547 updateSystemUiVisibilityLw();
3548 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003549 }
3550 }
3551
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003552 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003553 @Override
John Spurlock46646232013-09-30 22:32:42 -04003554 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003555 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3556 return mStatusBar.getSurfaceLayer();
3557 }
3558
3559 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3560 return mNavigationBar.getSurfaceLayer();
3561 }
3562
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003563 return 0;
3564 }
3565
Craig Mautner967212c2013-04-13 21:10:58 -07003566 @Override
3567 public void getContentRectLw(Rect r) {
3568 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3569 }
3570
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003571 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3572 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003573 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3574 // Here's a special case: if this attached window is a panel that is
3575 // above the dock window, and the window it is attached to is below
3576 // the dock window, then the frames we computed for the window it is
3577 // attached to can not be used because the dock is effectively part
3578 // of the underlying window and the attached window is floating on top
3579 // of the whole thing. So, we ignore the attached window and explicitly
3580 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003581 df.left = of.left = cf.left = vf.left = mDockLeft;
3582 df.top = of.top = cf.top = vf.top = mDockTop;
3583 df.right = of.right = cf.right = vf.right = mDockRight;
3584 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003585 } else {
3586 // The effective display frame of the attached window depends on
3587 // whether it is taking care of insetting its content. If not,
3588 // we need to use the parent's content frame so that the entire
3589 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003590 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003591 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003592 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003593 // Set the content frame of the attached window to the parent's decor frame
3594 // (same as content frame when IME isn't present) if specifically requested by
3595 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3596 // Otherwise, use the overscan frame.
3597 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3598 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003599 } else {
3600 // If the window is resizing, then we want to base the content
3601 // frame on our attached content frame to resize... however,
3602 // things can be tricky if the attached window is NOT in resize
3603 // mode, in which case its content frame will be larger.
3604 // Ungh. So to deal with that, make sure the content frame
3605 // we end up using is not covering the IM dock.
3606 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003607 if (attached.isVoiceInteraction()) {
3608 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3609 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3610 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3611 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3612 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003613 if (cf.left < mContentLeft) cf.left = mContentLeft;
3614 if (cf.top < mContentTop) cf.top = mContentTop;
3615 if (cf.right > mContentRight) cf.right = mContentRight;
3616 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3617 }
3618 }
3619 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003620 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003621 vf.set(attached.getVisibleFrameLw());
3622 }
3623 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3624 // window should be positioned relative to its parent or the entire
3625 // screen.
3626 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3627 ? attached.getFrameLw() : df);
3628 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003629
3630 private void applyStableConstraints(int sysui, int fl, Rect r) {
3631 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3632 // If app is requesting a stable layout, don't let the
3633 // content insets go below the stable values.
3634 if ((fl & FLAG_FULLSCREEN) != 0) {
3635 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3636 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3637 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3638 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3639 } else {
3640 if (r.left < mStableLeft) r.left = mStableLeft;
3641 if (r.top < mStableTop) r.top = mStableTop;
3642 if (r.right > mStableRight) r.right = mStableRight;
3643 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3644 }
3645 }
3646 }
3647
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003648 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003649 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003650 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003651 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003652 final WindowManager.LayoutParams attrs = win.getAttrs();
3653 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3654 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003655 return;
3656 }
Craig Mautner69b08182012-09-05 13:07:13 -07003657 final boolean isDefaultDisplay = win.isDefaultDisplay();
3658 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003659 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3660 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003661 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003662 offsetInputMethodWindowLw(mLastInputMethodWindow);
3663 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003664
John Spurlockc6d1c602014-01-17 15:22:06 -05003665 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003666 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003667 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003668
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003669 final Rect pf = mTmpParentFrame;
3670 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003671 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003672 final Rect cf = mTmpContentFrame;
3673 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003674 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003675 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003676 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003677
3678 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003679 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003680
Craig Mautnerf683b562012-10-02 11:10:57 -07003681 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3682
Adrian Roosfa104232014-06-20 16:10:14 -07003683 if (isDefaultDisplay) {
3684 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3685 } else {
3686 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3687 }
3688
Craig Mautner69b08182012-09-05 13:07:13 -07003689 if (!isDefaultDisplay) {
3690 if (attached != null) {
3691 // If this window is attached to another, our display
3692 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003693 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003694 } else {
3695 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003696 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3697 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3698 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003699 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003700 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003701 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003702 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003703 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003704 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3705 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3706 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003707 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003708 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003709 // ...with content insets above the nav bar
3710 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003711 // IM dock windows always go to the bottom of the screen.
3712 attrs.gravity = Gravity.BOTTOM;
3713 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003714 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
3715 pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft;
3716 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3717 pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft
3718 + mUnrestrictedScreenWidth;
3719 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3720 + mUnrestrictedScreenHeight;
3721 cf.bottom = vf.bottom = mStableBottom;
3722 cf.top = vf.top = mStableTop;
Jorim Jaggie0700182014-08-21 01:12:37 +02003723 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3724 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3725 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3726 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3727 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3728 cf.left = vf.left = mStableLeft;
3729 cf.top = vf.top = mStableTop;
3730 cf.right = vf.right = mStableRight;
3731 vf.bottom = mStableBottom;
3732 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003733 } else {
John Spurlock46646232013-09-30 22:32:42 -04003734
3735 // Default policy decor for the default display
3736 dcf.left = mSystemLeft;
3737 dcf.top = mSystemTop;
3738 dcf.right = mSystemRight;
3739 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003740 final boolean inheritTranslucentDecor = (attrs.privateFlags
3741 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003742 final boolean isAppWindow =
3743 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3744 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3745 final boolean topAtRest =
3746 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3747 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003748 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3749 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003750 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3751 && (fl & WindowManager.LayoutParams.
3752 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003753 // Ensure policy decor includes status bar
3754 dcf.top = mStableTop;
3755 }
John Spurlockbd957402013-10-03 11:38:39 -04003756 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003757 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3758 && (fl & WindowManager.LayoutParams.
3759 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003760 // Ensure policy decor includes navigation bar
3761 dcf.bottom = mStableBottom;
3762 dcf.right = mStableRight;
3763 }
3764 }
3765
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003766 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3767 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003768 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003769 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003770 // This is the case for a normal activity window: we want it
3771 // to cover all of the screen space, and it can take care of
3772 // moving its contents to account for screen decorations that
3773 // intrude into that space.
3774 if (attached != null) {
3775 // If this window is attached to another, our display
3776 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003777 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003778 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003779 if (attrs.type == TYPE_STATUS_BAR_PANEL
3780 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003781 // Status bar panels are the only windows who can go on top of
3782 // the status bar. They are protected by the STATUS_BAR_SERVICE
3783 // permission, so they have the same privileges as the status
3784 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003785 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003786 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003787
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003788 pf.left = df.left = of.left = hasNavBar
3789 ? mDockLeft : mUnrestrictedScreenLeft;
3790 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3791 pf.right = df.right = of.right = hasNavBar
3792 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3793 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3794 pf.bottom = df.bottom = of.bottom = hasNavBar
3795 ? mRestrictedScreenTop+mRestrictedScreenHeight
3796 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003797
Craig Mautnereda67292013-04-28 13:50:14 -07003798 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003799 "Laying out status bar window: (%d,%d - %d,%d)",
3800 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003801 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003802 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3803 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3804 // Asking to layout into the overscan region, so give it that pure
3805 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003806 pf.left = df.left = of.left = mOverscanScreenLeft;
3807 pf.top = df.top = of.top = mOverscanScreenTop;
3808 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3809 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3810 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003811 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003812 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003813 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3814 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003815 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003816 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003817 // only do this for application windows to ensure no window that
3818 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003819 pf.left = df.left = mOverscanScreenLeft;
3820 pf.top = df.top = mOverscanScreenTop;
3821 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3822 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003823 // We need to tell the app about where the frame inside the overscan
3824 // is, so it can inset its content by that amount -- it didn't ask
3825 // to actually extend itself into the overscan region.
3826 of.left = mUnrestrictedScreenLeft;
3827 of.top = mUnrestrictedScreenTop;
3828 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3829 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003830 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003831 pf.left = df.left = mRestrictedOverscanScreenLeft;
3832 pf.top = df.top = mRestrictedOverscanScreenTop;
3833 pf.right = df.right = mRestrictedOverscanScreenLeft
3834 + mRestrictedOverscanScreenWidth;
3835 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3836 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003837 // We need to tell the app about where the frame inside the overscan
3838 // is, so it can inset its content by that amount -- it didn't ask
3839 // to actually extend itself into the overscan region.
3840 of.left = mUnrestrictedScreenLeft;
3841 of.top = mUnrestrictedScreenTop;
3842 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3843 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003844 }
Craig Mautner69b08182012-09-05 13:07:13 -07003845
John Spurlock46646232013-09-30 22:32:42 -04003846 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003847 if (win.isVoiceInteraction()) {
3848 cf.left = mVoiceContentLeft;
3849 cf.top = mVoiceContentTop;
3850 cf.right = mVoiceContentRight;
3851 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003852 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003853 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3854 cf.left = mDockLeft;
3855 cf.top = mDockTop;
3856 cf.right = mDockRight;
3857 cf.bottom = mDockBottom;
3858 } else {
3859 cf.left = mContentLeft;
3860 cf.top = mContentTop;
3861 cf.right = mContentRight;
3862 cf.bottom = mContentBottom;
3863 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003864 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003865 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003866 // Full screen windows are always given a layout that is as if the
3867 // status bar and other transient decors are gone. This is to avoid
3868 // bad states when moving from a window that is not hding the
3869 // status bar to one that is.
3870 cf.left = mRestrictedScreenLeft;
3871 cf.top = mRestrictedScreenTop;
3872 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3873 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003874 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003875 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003876 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3877 vf.left = mCurLeft;
3878 vf.top = mCurTop;
3879 vf.right = mCurRight;
3880 vf.bottom = mCurBottom;
3881 } else {
3882 vf.set(cf);
3883 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003884 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003885 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3886 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3887 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003888 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3889 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003890 // A window that has requested to fill the entire screen just
3891 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003892 if (attrs.type == TYPE_STATUS_BAR_PANEL
3893 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003894 pf.left = df.left = of.left = cf.left = hasNavBar
3895 ? mDockLeft : mUnrestrictedScreenLeft;
3896 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3897 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003898 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003899 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003900 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003901 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003902 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003903 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003904 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3905 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003906 } else if (attrs.type == TYPE_NAVIGATION_BAR
3907 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003908 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003909 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3910 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3911 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3912 + mUnrestrictedScreenWidth;
3913 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3914 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003915 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003916 "Laying out navigation bar window: (%d,%d - %d,%d)",
3917 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003918 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3919 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003920 && ((fl & FLAG_FULLSCREEN) != 0)) {
3921 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003922 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3923 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3924 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3925 + mOverscanScreenWidth;
3926 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3927 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003928 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003929 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003930 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3931 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3932 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3933 + mOverscanScreenWidth;
3934 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3935 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003936 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003937 // The wallpaper also has Real Ultimate Power, but we want to tell
3938 // it about the overscan area.
3939 pf.left = df.left = mOverscanScreenLeft;
3940 pf.top = df.top = mOverscanScreenTop;
3941 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3942 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3943 of.left = cf.left = mUnrestrictedScreenLeft;
3944 of.top = cf.top = mUnrestrictedScreenTop;
3945 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3946 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003947 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003948 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3949 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3950 // Asking to layout into the overscan region, so give it that pure
3951 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003952 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3953 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3954 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003955 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003956 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003957 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003958 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003959 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003960 && (attrs.type == TYPE_STATUS_BAR
3961 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07003962 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04003963 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3964 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003965 // Asking for layout as if the nav bar is hidden, lets the
3966 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003967 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003968 // can be above the nav bar can do this.
3969 // XXX This assumes that an app asking for this will also
3970 // ask for layout in only content. We can't currently figure out
3971 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003972 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3973 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3974 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3975 + mUnrestrictedScreenWidth;
3976 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3977 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003978 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003979 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3980 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3981 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3982 + mRestrictedScreenWidth;
3983 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3984 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003985 }
Craig Mautner69b08182012-09-05 13:07:13 -07003986
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003987 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003988
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003989 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3990 vf.left = mCurLeft;
3991 vf.top = mCurTop;
3992 vf.right = mCurRight;
3993 vf.bottom = mCurBottom;
3994 } else {
3995 vf.set(cf);
3996 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003997 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003998 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3999 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004000 // A child window should be placed inside of the same visible
4001 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004002 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004003 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004004 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4005 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004006 // Otherwise, a normal window must be placed inside the content
4007 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07004008 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
4009 // Status bar panels are the only windows who can go on top of
4010 // the status bar. They are protected by the STATUS_BAR_SERVICE
4011 // permission, so they have the same privileges as the status
4012 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004013 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4014 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4015 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4016 + mRestrictedScreenWidth;
4017 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4018 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05004019 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
4020 || attrs.type == TYPE_VOLUME_OVERLAY) {
4021 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004022 pf.left = df.left = of.left = cf.left = mStableLeft;
4023 pf.top = df.top = of.top = cf.top = mStableTop;
4024 pf.right = df.right = of.right = cf.right = mStableRight;
4025 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004026 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004027 pf.left = mContentLeft;
4028 pf.top = mContentTop;
4029 pf.right = mContentRight;
4030 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004031 if (win.isVoiceInteraction()) {
4032 df.left = of.left = cf.left = mVoiceContentLeft;
4033 df.top = of.top = cf.top = mVoiceContentTop;
4034 df.right = of.right = cf.right = mVoiceContentRight;
4035 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4036 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004037 df.left = of.left = cf.left = mDockLeft;
4038 df.top = of.top = cf.top = mDockTop;
4039 df.right = of.right = cf.right = mDockRight;
4040 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004041 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004042 df.left = of.left = cf.left = mContentLeft;
4043 df.top = of.top = cf.top = mContentTop;
4044 df.right = of.right = cf.right = mContentRight;
4045 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004046 }
4047 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4048 vf.left = mCurLeft;
4049 vf.top = mCurTop;
4050 vf.right = mCurRight;
4051 vf.bottom = mCurBottom;
4052 } else {
4053 vf.set(cf);
4054 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004055 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004056 }
4057 }
Craig Mautner69b08182012-09-05 13:07:13 -07004058
Craig Mautnerb816bed2013-07-23 10:26:17 -07004059 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4060 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004061 df.left = df.top = -10000;
4062 df.right = df.bottom = 10000;
4063 if (attrs.type != TYPE_WALLPAPER) {
4064 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4065 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4066 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004067 }
4068
Craig Mautnereda67292013-04-28 13:50:14 -07004069 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004070 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004071 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004072 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004073 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004074 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004075 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004076 + " dcf=" + dcf.toShortString()
4077 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07004078
Adrian Roosfa104232014-06-20 16:10:14 -07004079 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07004080
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004081 // Dock windows carve out the bottom of the screen, so normal windows
4082 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004083 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4084 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004085 setLastInputMethodWindowLw(null, null);
4086 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004087 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004088 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4089 && !win.getGivenInsetsPendingLw()) {
4090 offsetVoiceInputWindowLw(win);
4091 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004092 }
4093
satok1bc0a492012-04-25 22:47:12 +09004094 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004095 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004096 top += win.getGivenContentInsetsLw().top;
4097 if (mContentBottom > top) {
4098 mContentBottom = top;
4099 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004100 if (mVoiceContentBottom > top) {
4101 mVoiceContentBottom = top;
4102 }
satok1bc0a492012-04-25 22:47:12 +09004103 top = win.getVisibleFrameLw().top;
4104 top += win.getGivenVisibleInsetsLw().top;
4105 if (mCurBottom > top) {
4106 mCurBottom = top;
4107 }
Craig Mautnereda67292013-04-28 13:50:14 -07004108 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004109 + mDockBottom + " mContentBottom="
4110 + mContentBottom + " mCurBottom=" + mCurBottom);
4111 }
4112
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004113 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004114 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004115 top += win.getGivenContentInsetsLw().top;
4116 if (mVoiceContentBottom > top) {
4117 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004118 }
4119 }
4120
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004121 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004122 @Override
4123 public void finishLayoutLw() {
4124 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004125 }
4126
4127 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004128 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004129 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004130 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004131 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004132 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004133 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004134 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004135 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004136 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004137 mForcingShowNavBar = false;
4138 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004139
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004140 mHideLockScreen = false;
4141 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004142 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004143 mShowingLockscreen = false;
4144 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004145 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004146 mKeyguardSecure = isKeyguardSecure();
4147 mKeyguardSecureIncludingHidden = mKeyguardSecure
4148 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004149 }
4150
4151 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004152 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004153 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004154 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4155 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004156 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004157 if (mTopFullscreenOpaqueWindowState == null
4158 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4159 mForcingShowNavBar = true;
4160 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004161 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004162 if (attrs.type == TYPE_STATUS_BAR) {
4163 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4164 mForceStatusBarFromKeyguard = true;
4165 }
4166 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4167 mForceStatusBarTransparent = true;
4168 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004169 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004170
4171 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4172 && attrs.type < FIRST_SYSTEM_WINDOW;
4173 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4174 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4175
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004176 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004177 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004178 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004179 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004180 mForceStatusBarFromKeyguard = true;
4181 } else {
4182 mForceStatusBar = true;
4183 }
4184 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004185 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004186 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004187 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004188 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004189 // If the lockscreen was showing when the dream started then wait
4190 // for the dream to draw before hiding the lockscreen.
4191 if (!mDreamingLockscreen
4192 || (win.isVisibleLw() && win.hasDrawnLw())) {
4193 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004194 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004195 }
4196 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004197
Craig Mautnerab55e522014-03-03 13:26:03 -08004198 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004199 final IApplicationToken appToken = win.getAppToken();
4200 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004201 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004202 mAppsToBeHidden.remove(appToken);
4203 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004204 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004205 if (dismissKeyguard && !mKeyguardSecure) {
4206 mAppsThatDismissKeyguard.add(appToken);
4207 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004208 mWinShowWhenLocked = win;
4209 mHideLockScreen = true;
4210 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004211 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004212 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004213 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004214 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004215 mAppsToBeHidden.add(appToken);
4216 } else {
4217 mAppsToBeHidden.remove(appToken);
4218 }
4219 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004220 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004221 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004222 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004223 if (attrs.x == 0 && attrs.y == 0
4224 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4225 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4226 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4227 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004228 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4229 mTopFullscreenOpaqueOrDimmingWindowState = win;
4230 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004231 if (!mAppsThatDismissKeyguard.isEmpty() &&
4232 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4233 if (DEBUG_LAYOUT) Slog.v(TAG,
4234 "Setting mDismissKeyguard true by win " + win);
4235 mDismissKeyguard = mWinDismissingKeyguard == win ?
4236 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
4237 mWinDismissingKeyguard = win;
Jim Millerab954542014-10-10 18:21:49 -07004238 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004239 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4240 if (DEBUG_LAYOUT) Slog.v(TAG,
4241 "Setting mHideLockScreen to true by win " + win);
4242 mHideLockScreen = true;
4243 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004244 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004245 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004246 mAllowLockscreenWhenOn = true;
4247 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004248 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004249
4250 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004251 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4252 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004253 win.hideLw(false);
4254 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004255 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004256 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4257 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4258 // that is being hidden in an animation - keep the
4259 // keyguard hidden until the new window shows up and
4260 // we know whether to show the keyguard or not.
4261 if (win.isAnimatingLw() && appWindow && showWhenLocked) {
4262 mHideLockScreen = true;
4263 mWinShowWhenLocked = win;
4264 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004265 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004266 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4267 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4268 && win.isDimming()) {
4269 mTopFullscreenOpaqueOrDimmingWindowState = win;
4270 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004271 }
4272
4273 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004274 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004275 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004276 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4277 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4278 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004279 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4280 // fullscreen window.
4281 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4282 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4283 mTopFullscreenOpaqueWindowState.hideLw(false);
4284 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4285 }
4286
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004287 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004288 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004289
4290 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4291 ? mTopFullscreenOpaqueWindowState.getAttrs()
4292 : null;
4293
Jeff Brownc8018eb2012-10-29 21:33:27 -07004294 // If we are not currently showing a dream then remember the current
4295 // lockscreen state. We will use this to determine whether the dream
4296 // started while the lockscreen was showing and remember this state
4297 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004298 if (!mShowingDream) {
4299 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004300 if (mDreamingSleepTokenNeeded) {
4301 mDreamingSleepTokenNeeded = false;
4302 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4303 }
4304 } else {
4305 if (!mDreamingSleepTokenNeeded) {
4306 mDreamingSleepTokenNeeded = true;
4307 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4308 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004309 }
4310
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004311 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004312 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004313 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004314 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004315 boolean shouldBeTransparent = mForceStatusBarTransparent
4316 && !mForceStatusBar
4317 && !mForceStatusBarFromKeyguard;
4318 if (!shouldBeTransparent) {
4319 mStatusBarController.setShowTransparent(false /* transparent */);
4320 } else if (!mStatusBar.isVisibleLw()) {
4321 mStatusBarController.setShowTransparent(true /* transparent */);
4322 }
4323 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004324 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004325 if (mStatusBarController.setBarShowingLw(true)) {
4326 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4327 }
Craig Mautner81defc72013-10-29 11:10:42 -07004328 // Maintain fullscreen layout until incoming animation is complete.
4329 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004330 // Transient status bar on the lockscreen is not allowed
4331 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4332 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4333 mLastSystemUiFlags, mLastSystemUiFlags);
4334 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004335 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004336 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004337 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004338 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004339 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004340 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004341 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004342 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004343 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004344 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004345 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004346 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004347 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4348 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004349 if (mStatusBarController.isTransientShowing()) {
4350 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004351 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4352 }
4353 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004354 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004355 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004356 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004357 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004358 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004359 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004360 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004361 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004362 if (mStatusBarController.setBarShowingLw(true)) {
4363 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4364 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004365 }
4366 }
4367 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004368
Craig Mautner81defc72013-10-29 11:10:42 -07004369 if (mTopIsFullscreen != topIsFullscreen) {
4370 if (!topIsFullscreen) {
4371 // Force another layout when status bar becomes fully shown.
4372 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4373 }
4374 mTopIsFullscreen = topIsFullscreen;
4375 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004376
Craig Mautner39834192012-09-02 07:47:24 -07004377 // Hide the key guard if a visible window explicitly specifies that it wants to be
4378 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004379 if (mKeyguardDelegate != null && mStatusBar != null) {
4380 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4381 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004382 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004383 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004384 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004385 changes |= FINISH_LAYOUT_REDO_LAYOUT
4386 | FINISH_LAYOUT_REDO_CONFIG
4387 | FINISH_LAYOUT_REDO_WALLPAPER;
4388 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004389 if (mKeyguardDelegate.isShowing()) {
4390 mHandler.post(new Runnable() {
4391 @Override
4392 public void run() {
4393 mKeyguardDelegate.keyguardDone(false, false);
4394 }
4395 });
4396 }
4397 } else if (mHideLockScreen) {
4398 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004399 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004400 changes |= FINISH_LAYOUT_REDO_LAYOUT
4401 | FINISH_LAYOUT_REDO_CONFIG
4402 | FINISH_LAYOUT_REDO_WALLPAPER;
4403 }
4404 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
4405 // This is the case of keyguard isSecure() and not mHideLockScreen.
4406 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4407 // Only launch the next keyguard unlock window once per window.
4408 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004409 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004410 changes |= FINISH_LAYOUT_REDO_LAYOUT
4411 | FINISH_LAYOUT_REDO_CONFIG
4412 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004413 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004414 mHandler.post(new Runnable() {
4415 @Override
4416 public void run() {
4417 mKeyguardDelegate.dismiss();
4418 }
4419 });
4420 }
4421 } else {
4422 mWinDismissingKeyguard = null;
4423 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004424 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004425 changes |= FINISH_LAYOUT_REDO_LAYOUT
4426 | FINISH_LAYOUT_REDO_CONFIG
4427 | FINISH_LAYOUT_REDO_WALLPAPER;
4428 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004429 }
4430 }
Joe Onorato664644d2011-01-23 17:53:23 -08004431
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004432 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004433 // If the navigation bar has been hidden or shown, we need to do another
4434 // layout pass to update that window.
4435 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4436 }
Joe Onorato664644d2011-01-23 17:53:23 -08004437
Mike Lockwood28569302010-01-28 11:54:40 -05004438 // update since mAllowLockscreenWhenOn might have changed
4439 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004440 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004441 }
4442
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004443 /**
Jim Millerab954542014-10-10 18:21:49 -07004444 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004445 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004446 * @return Whether the flags have changed and we have to redo the layout.
4447 */
Jim Millerab954542014-10-10 18:21:49 -07004448 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4449 boolean wasOccluded = mKeyguardOccluded;
4450 boolean showing = mKeyguardDelegate.isShowing();
4451 if (wasOccluded && !isOccluded && showing) {
4452 mKeyguardOccluded = false;
4453 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004454 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4455 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4456 return true;
Jim Millerab954542014-10-10 18:21:49 -07004457 } else if (!wasOccluded && isOccluded && showing) {
4458 mKeyguardOccluded = true;
4459 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004460 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4461 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4462 return true;
4463 } else {
4464 return false;
4465 }
4466 }
4467
4468 private boolean isStatusBarKeyguard() {
4469 return mStatusBar != null
4470 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4471 }
4472
Jose Lima9546b202014-07-02 17:21:51 -07004473 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004474 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004475 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004476 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004477 return false;
4478 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004479 return true;
4480 }
4481
Jose Lima9546b202014-07-02 17:21:51 -07004482 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004483 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004484 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004485 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004486 // If the navigation bar has been hidden or shown, we need to do another
4487 // layout pass to update that window.
4488 return FINISH_LAYOUT_REDO_LAYOUT;
4489 }
4490 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004491 }
4492
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004493 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004494 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004495 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4496 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004497 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4498 if (newLidState == mLidState) {
4499 return;
4500 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004501
Jeff Brownc458ce92012-04-30 14:58:40 -07004502 mLidState = newLidState;
4503 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004504 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004505
4506 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004507 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004508 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004509 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004510 }
4511 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004512
Michael Wright3818c922014-09-02 13:59:07 -07004513 @Override
4514 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4515 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4516 if (mCameraLensCoverState == lensCoverState) {
4517 return;
4518 }
4519 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4520 lensCoverState == CAMERA_LENS_UNCOVERED) {
4521 Intent intent;
4522 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4523 mKeyguardDelegate.isShowing();
4524 if (keyguardActive) {
4525 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4526 } else {
4527 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4528 }
Bryce Lee584a4452014-10-21 15:55:55 -07004529 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004530 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004531 }
4532 mCameraLensCoverState = lensCoverState;
4533 }
4534
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004535 void setHdmiPlugged(boolean plugged) {
4536 if (mHdmiPlugged != plugged) {
4537 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004538 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004539 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004540 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004541 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004542 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004543 }
4544 }
4545
Joe Onoratoea495d42011-04-06 11:41:11 -07004546 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004547 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004548 // watch for HDMI plug messages if the hdmi switch exists
4549 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4550 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4551
Joe Onoratoea495d42011-04-06 11:41:11 -07004552 final String filename = "/sys/class/switch/hdmi/state";
4553 FileReader reader = null;
4554 try {
4555 reader = new FileReader(filename);
4556 char[] buf = new char[15];
4557 int n = reader.read(buf);
4558 if (n > 1) {
4559 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4560 }
4561 } catch (IOException ex) {
4562 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4563 } catch (NumberFormatException ex) {
4564 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4565 } finally {
4566 if (reader != null) {
4567 try {
4568 reader.close();
4569 } catch (IOException ex) {
4570 }
Joe Onoratodc100302011-01-11 17:07:41 -08004571 }
4572 }
4573 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004574 // This dance forces the code in setHdmiPlugged to run.
4575 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4576 mHdmiPlugged = !plugged;
4577 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004578 }
4579
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004580 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004581 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004582
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004583 final Runnable mScreenshotTimeout = new Runnable() {
4584 @Override public void run() {
4585 synchronized (mScreenshotLock) {
4586 if (mScreenshotConnection != null) {
4587 mContext.unbindService(mScreenshotConnection);
4588 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004589 }
Winson Chung9112ec32011-06-27 13:15:32 -07004590 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004591 }
4592 };
4593
4594 // Assume this is called from the Handler thread.
4595 private void takeScreenshot() {
4596 synchronized (mScreenshotLock) {
4597 if (mScreenshotConnection != null) {
4598 return;
4599 }
4600 ComponentName cn = new ComponentName("com.android.systemui",
4601 "com.android.systemui.screenshot.TakeScreenshotService");
4602 Intent intent = new Intent();
4603 intent.setComponent(cn);
4604 ServiceConnection conn = new ServiceConnection() {
4605 @Override
4606 public void onServiceConnected(ComponentName name, IBinder service) {
4607 synchronized (mScreenshotLock) {
4608 if (mScreenshotConnection != this) {
4609 return;
4610 }
4611 Messenger messenger = new Messenger(service);
4612 Message msg = Message.obtain(null, 1);
4613 final ServiceConnection myConn = this;
4614 Handler h = new Handler(mHandler.getLooper()) {
4615 @Override
4616 public void handleMessage(Message msg) {
4617 synchronized (mScreenshotLock) {
4618 if (mScreenshotConnection == myConn) {
4619 mContext.unbindService(mScreenshotConnection);
4620 mScreenshotConnection = null;
4621 mHandler.removeCallbacks(mScreenshotTimeout);
4622 }
4623 }
4624 }
4625 };
4626 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004627 msg.arg1 = msg.arg2 = 0;
4628 if (mStatusBar != null && mStatusBar.isVisibleLw())
4629 msg.arg1 = 1;
4630 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4631 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004632 try {
4633 messenger.send(msg);
4634 } catch (RemoteException e) {
4635 }
4636 }
4637 }
4638 @Override
4639 public void onServiceDisconnected(ComponentName name) {}
4640 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004641 if (mContext.bindServiceAsUser(
4642 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004643 mScreenshotConnection = conn;
4644 mHandler.postDelayed(mScreenshotTimeout, 10000);
4645 }
4646 }
Winson Chung9112ec32011-06-27 13:15:32 -07004647 }
4648
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004649 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004650 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004651 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004652 if (!mSystemBooted) {
4653 // If we have not yet booted, don't let key events do anything.
4654 return 0;
4655 }
4656
Jeff Brown037c33e2014-04-09 00:31:55 -07004657 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004658 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4659 final boolean canceled = event.isCanceled();
4660 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004661
Jeff Brown3122e442010-10-11 23:32:49 -07004662 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004663
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004664 // If screen is off then we treat the case where the keyguard is open but hidden
4665 // the same as if it were open and in front.
4666 // This will prevent any keys other than the power button from waking the screen
4667 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004668 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004669 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004670 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004671 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004672
Jeff Brown40013652012-05-16 21:22:36 -07004673 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004674 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004675 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004676 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004677 }
4678
Jeff Brown037c33e2014-04-09 00:31:55 -07004679 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004680 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004681 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4682 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004683 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004684 // When the device is interactive or the key is injected pass the
4685 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004686 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004687 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004688 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4689 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4690 // to the application but preserve its wake key status to make sure we still move
4691 // from dozing to fully interactive if we would normally go from off to fully
4692 // interactive.
4693 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004694 } else {
4695 // When the screen is off and the key is not injected, determine whether
4696 // to wake the device but don't pass the key to the application.
4697 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004698 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4699 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004700 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004701 }
4702
Justin Kohd378ad72013-04-01 12:18:26 -07004703 // If the key would be handled globally, just return the result, don't worry about special
4704 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004705 if (isValidGlobalKey(keyCode)
4706 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004707 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004708 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004709 }
Justin Kohd378ad72013-04-01 12:18:26 -07004710 return result;
4711 }
4712
Jeff Brownbae8e772014-06-12 19:59:45 -07004713 boolean useHapticFeedback = down
4714 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4715 && event.getRepeatCount() == 0;
4716
Jeff Brown4d396052010-10-29 21:50:21 -07004717 // Handle special keys.
4718 switch (keyCode) {
4719 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004720 case KeyEvent.KEYCODE_VOLUME_UP:
4721 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004722 if (mUseTvRouting) {
4723 // On TVs volume keys never go to the foreground app
4724 result &= ~ACTION_PASS_TO_USER;
4725 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004726 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4727 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004728 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004729 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004730 mScreenshotChordVolumeDownKeyTriggered = true;
4731 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4732 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004733 cancelPendingPowerKeyAction();
4734 interceptScreenshotChord();
4735 }
4736 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004737 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004738 cancelPendingScreenshotChordAction();
4739 }
4740 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4741 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004742 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004743 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004744 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004745 cancelPendingPowerKeyAction();
4746 cancelPendingScreenshotChordAction();
4747 }
4748 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004749 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004750 cancelPendingScreenshotChordAction();
4751 }
4752 }
Jeff Brown4d396052010-10-29 21:50:21 -07004753 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004754 TelecomManager telecomManager = getTelecommService();
4755 if (telecomManager != null) {
4756 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004757 // If an incoming call is ringing, either VOLUME key means
4758 // "silence ringer". We handle these keys here, rather than
4759 // in the InCallScreen, to make sure we'll respond to them
4760 // even if the InCallScreen hasn't come to the foreground yet.
4761 // Look for the DOWN event here, to agree with the "fallback"
4762 // behavior in the InCallScreen.
4763 Log.i(TAG, "interceptKeyBeforeQueueing:"
4764 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004765
Santos Cordon6848f722014-05-21 15:22:12 -07004766 // Silence the ringer. (It's safe to call this
4767 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004768 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004769
Santos Cordon6848f722014-05-21 15:22:12 -07004770 // And *don't* pass this key thru to the current activity
4771 // (which is probably the InCallScreen.)
4772 result &= ~ACTION_PASS_TO_USER;
4773 break;
4774 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004775 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004776 && (result & ACTION_PASS_TO_USER) == 0) {
4777 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004778 // the application, just pass it to the session service.
4779
4780 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004781 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004782 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004783 }
4784 }
4785
RoboErik430fc482014-06-12 15:49:20 -07004786 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004787 if (mUseTvRouting) {
4788 dispatchDirectAudioEvent(event);
4789 } else {
4790 // If we aren't passing to the user and no one else
4791 // handled it send it to the session manager to
4792 // figure out.
4793 MediaSessionLegacyHelper.getHelper(mContext)
4794 .sendVolumeKeyEvent(event, true);
4795 }
Jeff Brown4d396052010-10-29 21:50:21 -07004796 break;
4797 }
4798 }
4799 break;
4800 }
4801
4802 case KeyEvent.KEYCODE_ENDCALL: {
4803 result &= ~ACTION_PASS_TO_USER;
4804 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004805 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004806 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004807 if (telecomManager != null) {
4808 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004809 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004810 if (interactive && !hungUp) {
4811 mEndCallKeyHandled = false;
4812 mHandler.postDelayed(mEndCallLongPress,
4813 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4814 } else {
4815 mEndCallKeyHandled = true;
4816 }
Jeff Brown4d396052010-10-29 21:50:21 -07004817 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004818 if (!mEndCallKeyHandled) {
4819 mHandler.removeCallbacks(mEndCallLongPress);
4820 if (!canceled) {
4821 if ((mEndcallBehavior
4822 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4823 if (goHome()) {
4824 break;
4825 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004826 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004827 if ((mEndcallBehavior
4828 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4829 mPowerManager.goToSleep(event.getEventTime(),
4830 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4831 isWakeKey = false;
4832 }
Jeff Brown4d396052010-10-29 21:50:21 -07004833 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004834 }
Jeff Brown4d396052010-10-29 21:50:21 -07004835 }
4836 break;
4837 }
4838
4839 case KeyEvent.KEYCODE_POWER: {
4840 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004841 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004842 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004843 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004844 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004845 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004846 }
4847 break;
4848 }
4849
Jeff Brown6212a492014-03-07 13:58:47 -08004850 case KeyEvent.KEYCODE_SLEEP: {
4851 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004852 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004853 if (!mPowerManager.isInteractive()) {
4854 useHapticFeedback = false; // suppress feedback if already non-interactive
4855 }
Nick Vaccarob593a812015-05-15 11:23:05 -07004856 if (down) {
4857 sleepPress(event.getEventTime());
4858 } else {
4859 sleepRelease(event.getEventTime());
4860 }
Jeff Brown6212a492014-03-07 13:58:47 -08004861 break;
4862 }
4863
4864 case KeyEvent.KEYCODE_WAKEUP: {
4865 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004866 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004867 break;
4868 }
4869
Jeff Brown4d396052010-10-29 21:50:21 -07004870 case KeyEvent.KEYCODE_MEDIA_PLAY:
4871 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4872 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004873 case KeyEvent.KEYCODE_HEADSETHOOK:
4874 case KeyEvent.KEYCODE_MUTE:
4875 case KeyEvent.KEYCODE_MEDIA_STOP:
4876 case KeyEvent.KEYCODE_MEDIA_NEXT:
4877 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4878 case KeyEvent.KEYCODE_MEDIA_REWIND:
4879 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004880 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4881 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004882 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4883 // If the global session is active pass all media keys to it
4884 // instead of the active window.
4885 result &= ~ACTION_PASS_TO_USER;
4886 }
Jeff Brown4d396052010-10-29 21:50:21 -07004887 if ((result & ACTION_PASS_TO_USER) == 0) {
4888 // Only do this if we would otherwise not pass it to the user. In that
4889 // case, the PhoneWindow class will do the same thing, except it will
4890 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004891 // Note that we need to make a copy of the key event here because the
4892 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004893 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004894 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4895 new KeyEvent(event));
4896 msg.setAsynchronous(true);
4897 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004898 }
4899 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004900 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004901
Jeff Brown4d396052010-10-29 21:50:21 -07004902 case KeyEvent.KEYCODE_CALL: {
4903 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004904 TelecomManager telecomManager = getTelecommService();
4905 if (telecomManager != null) {
4906 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004907 Log.i(TAG, "interceptKeyBeforeQueueing:"
4908 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004909 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004910
Santos Cordon6848f722014-05-21 15:22:12 -07004911 // And *don't* pass this key thru to the current activity
4912 // (which is presumably the InCallScreen.)
4913 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004914 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004915 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004916 }
Jeff Brown4d396052010-10-29 21:50:21 -07004917 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004918 }
Michael Wright869a67c2014-08-26 19:33:06 -07004919 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4920 // Only do this if we would otherwise not pass it to the user. In that case,
4921 // interceptKeyBeforeDispatching would apply a similar but different policy in
4922 // order to invoke voice assist actions. Note that we need to make a copy of the
4923 // key event here because the original key event will be recycled when we return.
4924 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4925 mBroadcastWakeLock.acquire();
4926 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4927 keyguardActive ? 1 : 0, 0);
4928 msg.setAsynchronous(true);
4929 msg.sendToTarget();
4930 }
4931 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004932 }
Jeff Brown26875502014-01-30 21:47:47 -08004933
Jeff Brownbae8e772014-06-12 19:59:45 -07004934 if (useHapticFeedback) {
4935 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4936 }
4937
Jeff Brown26875502014-01-30 21:47:47 -08004938 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004939 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004940 }
Bryce Lee584a4452014-10-21 15:55:55 -07004941
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004942 return result;
4943 }
4944
Jeff Brown1c2e4942012-11-06 16:32:01 -08004945 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004946 * Returns true if the key can have global actions attached to it.
4947 * We reserve all power management keys for the system since they require
4948 * very careful handling.
4949 */
4950 private static boolean isValidGlobalKey(int keyCode) {
4951 switch (keyCode) {
4952 case KeyEvent.KEYCODE_POWER:
4953 case KeyEvent.KEYCODE_WAKEUP:
4954 case KeyEvent.KEYCODE_SLEEP:
4955 return false;
4956 default:
4957 return true;
4958 }
4959 }
4960
4961 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08004962 * When the screen is off we ignore some keys that might otherwise typically
4963 * be considered wake keys. We filter them out here.
4964 *
4965 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4966 * is always considered a wake key.
4967 */
4968 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4969 switch (keyCode) {
4970 // ignore volume keys unless docked
4971 case KeyEvent.KEYCODE_VOLUME_UP:
4972 case KeyEvent.KEYCODE_VOLUME_DOWN:
4973 case KeyEvent.KEYCODE_VOLUME_MUTE:
4974 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4975
4976 // ignore media and camera keys
4977 case KeyEvent.KEYCODE_MUTE:
4978 case KeyEvent.KEYCODE_HEADSETHOOK:
4979 case KeyEvent.KEYCODE_MEDIA_PLAY:
4980 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4981 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4982 case KeyEvent.KEYCODE_MEDIA_STOP:
4983 case KeyEvent.KEYCODE_MEDIA_NEXT:
4984 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4985 case KeyEvent.KEYCODE_MEDIA_REWIND:
4986 case KeyEvent.KEYCODE_MEDIA_RECORD:
4987 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004988 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004989 case KeyEvent.KEYCODE_CAMERA:
4990 return false;
4991 }
4992 return true;
4993 }
4994
4995
Jeff Brown56194eb2011-03-02 19:23:13 -08004996 /** {@inheritDoc} */
4997 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004998 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4999 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08005000 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
5001 return 0;
5002 }
Michael Wright70af00a2014-09-03 19:30:20 -07005003 }
Bryce Lee5c138322014-11-03 08:26:09 -08005004
Michael Wright70af00a2014-09-03 19:30:20 -07005005 if (shouldDispatchInputWhenNonInteractive()) {
5006 return ACTION_PASS_TO_USER;
5007 }
Bryce Lee5c138322014-11-03 08:26:09 -08005008
Bryce Lee812d7022014-11-10 13:33:28 -08005009 // If we have not passed the action up and we are in theater mode without dreaming,
5010 // there will be no dream to intercept the touch and wake into ambient. The device should
5011 // wake up in this case.
5012 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
5013 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
5014 }
5015
Jeff Brown037c33e2014-04-09 00:31:55 -07005016 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005017 }
5018
Michael Wright70af00a2014-09-03 19:30:20 -07005019 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08005020 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07005021 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5022 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005023 return true;
5024 }
5025
5026 // Send events to a dozing dream even if the screen is off since the dream
5027 // is in control of the state of the screen.
5028 IDreamManager dreamManager = getDreamManager();
5029
5030 try {
5031 if (dreamManager != null && dreamManager.isDreaming()) {
5032 return true;
5033 }
5034 } catch (RemoteException e) {
5035 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5036 }
5037
5038 // Otherwise, consume events since the user can't see what is being
5039 // interacted with.
5040 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005041 }
5042
RoboErik001c59c2015-01-26 15:53:51 -08005043 private void dispatchDirectAudioEvent(KeyEvent event) {
5044 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5045 return;
5046 }
5047 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005048 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5049 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005050 String pkgName = mContext.getOpPackageName();
5051 switch (keyCode) {
5052 case KeyEvent.KEYCODE_VOLUME_UP:
5053 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005054 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005055 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005056 } catch (RemoteException e) {
5057 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5058 }
5059 break;
5060 case KeyEvent.KEYCODE_VOLUME_DOWN:
5061 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005062 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005063 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005064 } catch (RemoteException e) {
5065 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5066 }
5067 break;
5068 case KeyEvent.KEYCODE_VOLUME_MUTE:
5069 try {
5070 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005071 getAudioService().adjustSuggestedStreamVolume(
5072 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005073 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005074 }
5075 } catch (RemoteException e) {
5076 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5077 }
5078 break;
5079 }
5080 }
5081
Jeff Brown40013652012-05-16 21:22:36 -07005082 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5083 if (DEBUG_INPUT) {
5084 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005085 }
5086
Jeff Brown40013652012-05-16 21:22:36 -07005087 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5088 if (DEBUG_INPUT) {
5089 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5090 }
5091
5092 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5093 mHavePendingMediaKeyRepeatWithWakeLock = false;
5094 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5095 }
5096
5097 dispatchMediaKeyWithWakeLockToAudioService(event);
5098
5099 if (event.getAction() == KeyEvent.ACTION_DOWN
5100 && event.getRepeatCount() == 0) {
5101 mHavePendingMediaKeyRepeatWithWakeLock = true;
5102
5103 Message msg = mHandler.obtainMessage(
5104 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5105 msg.setAsynchronous(true);
5106 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5107 } else {
5108 mBroadcastWakeLock.release();
5109 }
5110 }
5111
5112 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5113 mHavePendingMediaKeyRepeatWithWakeLock = false;
5114
5115 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5116 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5117 if (DEBUG_INPUT) {
5118 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5119 }
5120
5121 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5122 mBroadcastWakeLock.release();
5123 }
5124
5125 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5126 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005127 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005128 }
5129 }
5130
Michael Wright869a67c2014-08-26 19:33:06 -07005131 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
5132 Intent voiceIntent =
5133 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5134 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005135 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005136 mBroadcastWakeLock.release();
5137 }
5138
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005139 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005140 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005141 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005142 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5143 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5144 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005145 } else {
5146 try {
5147 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5148 ServiceManager.getService(Context.UI_MODE_SERVICE));
5149 mUiMode = uiModeService.getCurrentModeType();
5150 } catch (RemoteException e) {
5151 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005152 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005153 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005154 synchronized (mLock) {
5155 updateOrientationListenerLp();
5156 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005157 }
5158 };
5159
Jeff Brown6aaf2952012-10-05 16:01:08 -07005160 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5161 @Override
5162 public void onReceive(Context context, Intent intent) {
5163 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005164 if (mKeyguardDelegate != null) {
5165 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005166 }
5167 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005168 if (mKeyguardDelegate != null) {
5169 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005170 }
5171 }
5172 }
5173 };
5174
Christopher Tate5e08af02012-09-21 17:17:22 -07005175 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5176 @Override
5177 public void onReceive(Context context, Intent intent) {
5178 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5179 // tickle the settings observer: this first ensures that we're
5180 // observing the relevant settings for the newly-active user,
5181 // and then updates our own bookkeeping based on the now-
5182 // current user.
5183 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005184
5185 // force a re-application of focused window sysui visibility.
5186 // the window may never have been shown for this user
5187 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005188 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005189 mLastSystemUiFlags = 0;
5190 updateSystemUiVisibilityLw();
5191 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005192 }
5193 }
5194 };
5195
John Spurlockd9b70bd2014-02-06 17:02:44 -05005196 private final Runnable mRequestTransientNav = new Runnable() {
5197 @Override
5198 public void run() {
5199 requestTransientBars(mNavigationBar);
5200 }
5201 };
5202
John Spurlocke1f366f2013-08-05 12:22:40 -04005203 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005204 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005205 if (!isUserSetupComplete()) {
5206 // Swipe-up for navigation bar is disabled during setup
5207 return;
5208 }
John Spurlock27735a42013-08-14 17:57:38 -04005209 boolean sb = mStatusBarController.checkShowTransientBarLw();
5210 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005211 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005212 // Don't show status bar when swiping on already visible navigation bar
5213 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005214 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005215 return;
5216 }
John Spurlock27735a42013-08-14 17:57:38 -04005217 if (sb) mStatusBarController.showTransient();
5218 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005219 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005220 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005221 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005222 }
5223 }
5224
Jeff Brown3ee549c2014-09-22 20:14:39 -07005225 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005226 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07005227 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005228 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07005229 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005230
5231 // We must get this work done here because the power manager will drop
5232 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005233 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005234 mAwake = false;
5235 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005236 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005237 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005238 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005239 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005240
5241 if (mKeyguardDelegate != null) {
5242 mKeyguardDelegate.onScreenTurnedOff(why);
5243 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005244 }
5245
Jeff Brown13f00f02014-10-31 14:45:50 -07005246 private void wakeUpFromPowerKey(long eventTime) {
5247 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5248 }
5249
Bryce Lee5c138322014-11-03 08:26:09 -08005250 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Lee584a4452014-10-21 15:55:55 -07005251 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005252 return false;
Bryce Lee584a4452014-10-21 15:55:55 -07005253 }
5254
5255 mPowerManager.wakeUp(wakeTime);
Bryce Lee5c138322014-11-03 08:26:09 -08005256 return true;
Bryce Lee584a4452014-10-21 15:55:55 -07005257 }
5258
Jeff Brown3ee549c2014-09-22 20:14:39 -07005259 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005260 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07005261 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005262 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07005263 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005264
Jeff Brown3ee549c2014-09-22 20:14:39 -07005265 // Since goToSleep performs these functions synchronously, we must
5266 // do the same here. We cannot post this work to a handler because
5267 // that might cause it to become reordered with respect to what
5268 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005269 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005270 mAwake = true;
5271 mKeyguardDrawComplete = false;
5272 if (mKeyguardDelegate != null) {
5273 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5274 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5275 }
5276
Jeff Browna20dda42014-05-27 20:57:24 -07005277 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005278 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005279 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005280 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005281
Jim Miller5ecd8112013-01-09 18:50:26 -08005282 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07005283 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005284 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005285 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005286 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005287 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005288 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005289 }
5290
Jeff Brown36c4db82014-09-19 12:05:31 -07005291 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005292 synchronized (mLock) {
5293 if (!mAwake || mKeyguardDrawComplete) {
5294 return; // spurious
5295 }
5296
Jeff Brown36c4db82014-09-19 12:05:31 -07005297 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005298 if (mKeyguardDelegate != null) {
5299 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5300 }
5301 }
5302
5303 finishScreenTurningOn();
5304 }
5305
5306 // Called on the DisplayManager's DisplayPowerController thread.
5307 @Override
5308 public void screenTurnedOff() {
5309 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5310
5311 synchronized (mLock) {
5312 mScreenOnEarly = false;
5313 mScreenOnFully = false;
5314 mWindowManagerDrawComplete = false;
5315 mScreenOnListener = null;
5316 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005317 }
5318 }
5319
Jeff Brown3ee549c2014-09-22 20:14:39 -07005320 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005321 @Override
5322 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005323 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005324
Jeff Brown3ee549c2014-09-22 20:14:39 -07005325 synchronized (mLock) {
5326 mScreenOnEarly = true;
5327 mScreenOnFully = false;
5328 mWindowManagerDrawComplete = false;
5329 mScreenOnListener = screenOnListener;
5330 updateOrientationListenerLp();
5331 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005332
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005333 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5334 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005335 // ... eventually calls finishWindowsDrawn
5336 }
5337
Jeff Brown36c4db82014-09-19 12:05:31 -07005338 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005339 synchronized (mLock) {
5340 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5341 return; // spurious
5342 }
5343
Jeff Brown36c4db82014-09-19 12:05:31 -07005344 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005345 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005346
5347 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005348 }
5349
Craig Mautner8a0da012014-05-31 15:13:37 -07005350 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005351 final ScreenOnListener listener;
5352 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005353 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005354 if (DEBUG_WAKEUP) Slog.d(TAG,
5355 "finishScreenTurningOn: mAwake=" + mAwake
5356 + ", mScreenOnEarly=" + mScreenOnEarly
5357 + ", mScreenOnFully=" + mScreenOnFully
5358 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5359 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5360
5361 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5362 || (mAwake && !mKeyguardDrawComplete)) {
5363 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005364 }
5365
Jeff Brown3ee549c2014-09-22 20:14:39 -07005366 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5367 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005368 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005369 mScreenOnFully = true;
5370
5371 // Remember the first time we draw the keyguard so we know when we're done with
5372 // the main part of booting and can enable the screen and hide boot messages.
5373 if (!mKeyguardDrawnOnce && mAwake) {
5374 mKeyguardDrawnOnce = true;
5375 enableScreen = true;
5376 if (mBootMessageNeedsHiding) {
5377 mBootMessageNeedsHiding = false;
5378 hideBootMessages();
5379 }
5380 } else {
5381 enableScreen = false;
5382 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005383 }
5384
Jeff Brown3ee549c2014-09-22 20:14:39 -07005385 if (listener != null) {
5386 listener.onScreenOn();
5387 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005388
Jeff Brown3ee549c2014-09-22 20:14:39 -07005389 if (enableScreen) {
5390 try {
5391 mWindowManager.enableScreenIfNeeded();
5392 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005393 }
Craig Mautnera631d492014-08-05 15:16:01 -07005394 }
5395 }
5396
5397 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005398 synchronized (mLock) {
5399 if (!mKeyguardDrawnOnce) {
5400 mBootMessageNeedsHiding = true;
5401 return; // keyguard hasn't drawn the first time yet, not done booting
5402 }
Craig Mautnera631d492014-08-05 15:16:01 -07005403 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005404
5405 if (mBootMsgDialog != null) {
5406 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5407 mBootMsgDialog.dismiss();
5408 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005409 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005410 }
5411
5412 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005413 public boolean isScreenOn() {
5414 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005415 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005416
Dianne Hackborn08743722009-12-21 12:16:51 -08005417 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005418 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005419 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005420 if (mKeyguardDelegate != null) {
5421 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005422 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005423 }
5424
5425 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005426 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005427 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005428 if (mKeyguardDelegate != null) {
5429 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005430 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005431 }
5432
Jim Millerab954542014-10-10 18:21:49 -07005433 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005434 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005435 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005436 }
5437
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005438 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005439 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005440 public boolean isKeyguardLocked() {
5441 return keyguardOn();
5442 }
5443
5444 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005445 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005446 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005447 if (mKeyguardDelegate == null) return false;
5448 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005449 }
5450
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005451 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005452 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005453 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005454 if (mKeyguardDelegate == null) return false;
5455 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005456 }
5457
Jose Lima9546b202014-07-02 17:21:51 -07005458 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005459 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005460 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005461 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005462 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005463 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005464 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005465 // ask the keyguard to prompt the user to authenticate if necessary
5466 mKeyguardDelegate.dismiss();
5467 }
5468 });
5469 }
5470 }
5471
5472 public void notifyActivityDrawnForKeyguardLw() {
5473 if (mKeyguardDelegate != null) {
5474 mHandler.post(new Runnable() {
5475 @Override
5476 public void run() {
5477 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005478 }
5479 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005480 }
5481 }
5482
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005483 @Override
5484 public boolean isKeyguardDrawnLw() {
5485 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005486 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005487 }
5488 }
5489
Jorim Jaggi0d674622014-05-21 01:34:15 +02005490 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005491 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005492 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005493 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005494 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005495 }
5496 }
5497
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005498 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005499 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005500 }
5501
5502 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005503 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005504 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005505
Jeff Brown01a98dd2011-09-20 15:08:29 -07005506 @Override
5507 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005508 if (false) {
5509 Slog.v(TAG, "rotationForOrientationLw(orient="
5510 + orientation + ", last=" + lastRotation
5511 + "); user=" + mUserRotation + " "
5512 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5513 ? "USER_ROTATION_LOCKED" : "")
5514 );
5515 }
5516
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005517 if (mForceDefaultOrientation) {
5518 return Surface.ROTATION_0;
5519 }
5520
The Android Open Source Project0727d222009-03-11 12:11:58 -07005521 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005522 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5523 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005524 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005525 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005526
Jeff Browndec6cf42011-11-15 14:08:20 -08005527 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005528 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005529 // Ignore sensor when lid switch is open and rotation is forced.
5530 preferredRotation = mLidOpenRotation;
5531 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005532 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005533 // Ignore sensor when in car dock unless explicitly enabled.
5534 // This case can override the behavior of NOSENSOR, and can also
5535 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005536 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005537 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005538 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5539 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5540 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005541 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005542 // Ignore sensor when in desk dock unless explicitly enabled.
5543 // This case can override the behavior of NOSENSOR, and can also
5544 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005545 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005546 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005547 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5548 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005549 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005550 preferredRotation = mDemoHdmiRotation;
5551 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5552 && mUndockedHdmiRotation >= 0) {
5553 // Ignore sensor when plugged into HDMI and an undocked orientation has
5554 // been specified in the configuration (only for legacy devices without
5555 // full multi-display support).
5556 // Note that the dock orientation overrides the HDMI orientation.
5557 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005558 } else if (mDemoRotationLock) {
5559 // Ignore sensor when demo rotation lock is enabled.
5560 // Note that the dock orientation and HDMI rotation lock override this.
5561 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005562 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5563 // Application just wants to remain locked in the last rotation.
5564 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005565 } else if (!mSupportAutoRotation) {
5566 // If we don't support auto-rotation then bail out here and ignore
5567 // the sensor and any rotation lock settings.
5568 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005569 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005570 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005571 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5572 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5573 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5574 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005575 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5576 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5577 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5578 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5579 // Otherwise, use sensor only if requested by the application or enabled
5580 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005581 if (mAllowAllRotations < 0) {
5582 // Can't read this during init() because the context doesn't
5583 // have display metrics at that time so we cannot determine
5584 // tablet vs. phone then.
5585 mAllowAllRotations = mContext.getResources().getBoolean(
5586 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5587 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005588 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005589 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005590 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5591 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005592 preferredRotation = sensorRotation;
5593 } else {
5594 preferredRotation = lastRotation;
5595 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005596 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5597 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5598 // Apply rotation lock. Does not apply to NOSENSOR.
5599 // The idea is that the user rotation expresses a weak preference for the direction
5600 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5601 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005602 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005603 } else {
5604 // No overriding preference.
5605 // We will do exactly what the application asked us to do.
5606 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005607 }
5608
Dianne Hackborne5439f22010-10-02 16:53:50 -07005609 switch (orientation) {
5610 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005611 // Return portrait unless overridden.
5612 if (isAnyPortrait(preferredRotation)) {
5613 return preferredRotation;
5614 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005615 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005616
Jeff Brown01a98dd2011-09-20 15:08:29 -07005617 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005618 // Return landscape unless overridden.
5619 if (isLandscapeOrSeascape(preferredRotation)) {
5620 return preferredRotation;
5621 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005622 return mLandscapeRotation;
5623
5624 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005625 // Return reverse portrait unless overridden.
5626 if (isAnyPortrait(preferredRotation)) {
5627 return preferredRotation;
5628 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005629 return mUpsideDownRotation;
5630
5631 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005632 // Return seascape unless overridden.
5633 if (isLandscapeOrSeascape(preferredRotation)) {
5634 return preferredRotation;
5635 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005636 return mSeascapeRotation;
5637
5638 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005639 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005640 // Return either landscape rotation.
5641 if (isLandscapeOrSeascape(preferredRotation)) {
5642 return preferredRotation;
5643 }
5644 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005645 return lastRotation;
5646 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005647 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005648
Jeff Brown01a98dd2011-09-20 15:08:29 -07005649 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005650 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005651 // Return either portrait rotation.
5652 if (isAnyPortrait(preferredRotation)) {
5653 return preferredRotation;
5654 }
5655 if (isAnyPortrait(lastRotation)) {
5656 return lastRotation;
5657 }
5658 return mPortraitRotation;
5659
5660 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005661 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5662 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005663 if (preferredRotation >= 0) {
5664 return preferredRotation;
5665 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005666 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005667 }
5668 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005669 }
5670
Jeff Brown01a98dd2011-09-20 15:08:29 -07005671 @Override
5672 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5673 switch (orientation) {
5674 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5675 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5676 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5677 return isAnyPortrait(rotation);
5678
5679 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5680 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5681 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5682 return isLandscapeOrSeascape(rotation);
5683
5684 default:
5685 return true;
5686 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005687 }
5688
Jeff Brownc0347aa2011-09-23 17:26:09 -07005689 @Override
5690 public void setRotationLw(int rotation) {
5691 mOrientationListener.setCurrentRotation(rotation);
5692 }
5693
Jeff Brown01a98dd2011-09-20 15:08:29 -07005694 private boolean isLandscapeOrSeascape(int rotation) {
5695 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005696 }
5697
Jeff Brown01a98dd2011-09-20 15:08:29 -07005698 private boolean isAnyPortrait(int rotation) {
5699 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005700 }
5701
Jose Lima9546b202014-07-02 17:21:51 -07005702 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005703 public int getUserRotationMode() {
5704 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005705 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5706 WindowManagerPolicy.USER_ROTATION_FREE :
5707 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005708 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005709
5710 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005711 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005712 public void setUserRotationMode(int mode, int rot) {
5713 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005714
5715 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005716 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005717 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005718 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005719 rot,
5720 UserHandle.USER_CURRENT);
5721 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005722 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005723 0,
5724 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005725 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005726 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005727 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005728 1,
5729 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005730 }
5731 }
5732
Jose Lima9546b202014-07-02 17:21:51 -07005733 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005734 public void setSafeMode(boolean safeMode) {
5735 mSafeMode = safeMode;
5736 performHapticFeedbackLw(null, safeMode
5737 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5738 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005739 }
Craig Mautnereda67292013-04-28 13:50:14 -07005740
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005741 static long[] getLongIntArray(Resources r, int resid) {
5742 int[] ar = r.getIntArray(resid);
5743 if (ar == null) {
5744 return null;
5745 }
5746 long[] out = new long[ar.length];
5747 for (int i=0; i<ar.length; i++) {
5748 out[i] = ar[i];
5749 }
5750 return out;
5751 }
Craig Mautnereda67292013-04-28 13:50:14 -07005752
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005753 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005754 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005755 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005756 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005757 mKeyguardDelegate.onSystemReady();
5758
Michael Wright3818c922014-09-02 13:59:07 -07005759 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005760 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005761 synchronized (mLock) {
5762 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005763 mSystemReady = true;
5764 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005765 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005766 public void run() {
5767 updateSettings();
5768 }
5769 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005770 }
5771 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005772
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005773 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005774 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005775 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005776 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005777 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005778 mKeyguardDelegate.onBootCompleted();
5779 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005780 synchronized (mLock) {
5781 mSystemBooted = true;
5782 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005783 wakingUp();
5784 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005785 }
5786
Dianne Hackborn661cd522011-08-22 00:26:20 -07005787 ProgressDialog mBootMsgDialog = null;
5788
5789 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005790 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005791 public void showBootMessage(final CharSequence msg, final boolean always) {
5792 mHandler.post(new Runnable() {
5793 @Override public void run() {
5794 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005795 int theme;
5796 if (mContext.getPackageManager().hasSystemFeature(
5797 PackageManager.FEATURE_WATCH)) {
5798 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5799 } else if (mContext.getPackageManager().hasSystemFeature(
5800 PackageManager.FEATURE_TELEVISION)) {
5801 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5802 } else {
5803 theme = 0;
5804 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005805
5806 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005807 // This dialog will consume all events coming in to
5808 // it, to avoid it trying to do things too early in boot.
5809 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5810 return true;
5811 }
5812 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5813 return true;
5814 }
5815 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5816 return true;
5817 }
5818 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5819 return true;
5820 }
5821 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5822 return true;
5823 }
5824 @Override public boolean dispatchPopulateAccessibilityEvent(
5825 AccessibilityEvent event) {
5826 return true;
5827 }
5828 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005829 if (mContext.getPackageManager().isUpgrade()) {
5830 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5831 } else {
5832 mBootMsgDialog.setTitle(R.string.android_start_title);
5833 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005834 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5835 mBootMsgDialog.setIndeterminate(true);
5836 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005837 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005838 mBootMsgDialog.getWindow().addFlags(
5839 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5840 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5841 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005842 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5843 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5844 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005845 mBootMsgDialog.setCancelable(false);
5846 mBootMsgDialog.show();
5847 }
5848 mBootMsgDialog.setMessage(msg);
5849 }
5850 });
5851 }
5852
5853 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005854 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005855 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005856 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005857 }
5858
Mike Lockwood28569302010-01-28 11:54:40 -05005859 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005860 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005861 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005862 // ***************************************
5863 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5864 // ***************************************
5865 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5866 // WITH ITS LOCKS HELD.
5867 //
5868 // This code must be VERY careful about the locks
5869 // it acquires.
5870 // In fact, the current code acquires way too many,
5871 // and probably has lurking deadlocks.
5872
Mike Lockwood28569302010-01-28 11:54:40 -05005873 synchronized (mScreenLockTimeout) {
5874 if (mLockScreenTimerActive) {
5875 // reset the timer
5876 mHandler.removeCallbacks(mScreenLockTimeout);
5877 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5878 }
5879 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005880 }
5881
Adam Cohenf7522022012-10-03 20:03:18 -07005882 class ScreenLockTimeout implements Runnable {
5883 Bundle options;
5884
5885 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005886 public void run() {
5887 synchronized (this) {
5888 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005889 if (mKeyguardDelegate != null) {
5890 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005891 }
Mike Lockwood28569302010-01-28 11:54:40 -05005892 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005893 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005894 }
5895 }
Mike Lockwood28569302010-01-28 11:54:40 -05005896
Adam Cohenf7522022012-10-03 20:03:18 -07005897 public void setLockOptions(Bundle options) {
5898 this.options = options;
5899 }
5900 }
5901
5902 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5903
Jose Lima9546b202014-07-02 17:21:51 -07005904 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005905 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005906 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5907 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005908 if (options != null) {
5909 // In case multiple calls are made to lockNow, we don't wipe out the options
5910 // until the runnable actually executes.
5911 mScreenLockTimeout.setLockOptions(options);
5912 }
Jim Miller93c518e2012-01-17 15:55:31 -08005913 mHandler.post(mScreenLockTimeout);
5914 }
5915
Mike Lockwood28569302010-01-28 11:54:40 -05005916 private void updateLockScreenTimeout() {
5917 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005918 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005919 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005920 if (mLockScreenTimerActive != enable) {
5921 if (enable) {
5922 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5923 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5924 } else {
5925 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5926 mHandler.removeCallbacks(mScreenLockTimeout);
5927 }
5928 mLockScreenTimerActive = enable;
5929 }
5930 }
5931 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005932
Jeff Brown061ea992015-04-17 19:55:47 -07005933 private void updateDreamingSleepToken(boolean acquire) {
5934 if (acquire) {
5935 if (mDreamingSleepToken == null) {
5936 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
5937 }
5938 } else {
5939 if (mDreamingSleepToken != null) {
5940 mDreamingSleepToken.release();
5941 }
5942 }
5943 }
5944
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005945 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005946 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005947 public void enableScreenAfterBoot() {
5948 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005949 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005950 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005951 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005952
Jeff Brownc458ce92012-04-30 14:58:40 -07005953 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005954 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005955 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005956 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005957 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005958 }
Jeff Browna20dda42014-05-27 20:57:24 -07005959
5960 synchronized (mLock) {
5961 updateWakeGestureListenerLp();
5962 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005963 }
5964
Jeff Brown4f5fa282014-06-12 19:19:15 -07005965 void updateUiMode() {
5966 if (mUiModeManager == null) {
5967 mUiModeManager = IUiModeManager.Stub.asInterface(
5968 ServiceManager.getService(Context.UI_MODE_SERVICE));
5969 }
5970 try {
5971 mUiMode = mUiModeManager.getCurrentModeType();
5972 } catch (RemoteException e) {
5973 }
5974 }
5975
Jeff Brown01a98dd2011-09-20 15:08:29 -07005976 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005977 try {
5978 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005979 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5980 } catch (RemoteException e) {
5981 // Ignore
5982 }
5983 }
5984
5985 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5986 try {
5987 //set orientation on WindowManager
5988 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005989 } catch (RemoteException e) {
5990 // Ignore
5991 }
5992 }
5993
Daniel Sandler6396c722013-04-16 20:19:09 -04005994 /**
5995 * Return an Intent to launch the currently active dock app as home. Returns
5996 * null if the standard home should be launched, which is the case if any of the following is
5997 * true:
5998 * <ul>
5999 * <li>The device is not in either car mode or desk mode
6000 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
6001 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6002 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6003 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6004 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006005 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006006 */
6007 Intent createHomeDockIntent() {
6008 Intent intent = null;
6009
6010 // What home does is based on the mode, not the dock state. That
6011 // is, when in car mode you should be taken to car home regardless
6012 // of whether we are actually in a car dock.
6013 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6014 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
6015 intent = mCarDockIntent;
6016 }
6017 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6018 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6019 intent = mDeskDockIntent;
6020 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006021 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6022 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6023 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6024 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6025 // Always launch dock home from home when watch is docked, if it exists.
6026 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006027 }
6028
6029 if (intent == null) {
6030 return null;
6031 }
6032
6033 ActivityInfo ai = null;
6034 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6035 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006036 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006037 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006038 if (info != null) {
6039 ai = info.activityInfo;
6040 }
6041 if (ai != null
6042 && ai.metaData != null
6043 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6044 intent = new Intent(intent);
6045 intent.setClassName(ai.packageName, ai.name);
6046 return intent;
6047 }
6048
6049 return null;
6050 }
6051
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006052 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6053 if (awakenFromDreams) {
6054 awakenDreams();
6055 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006056
6057 Intent dock = createHomeDockIntent();
6058 if (dock != null) {
6059 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006060 if (fromHomeKey) {
6061 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6062 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006063 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006064 return;
6065 } catch (ActivityNotFoundException e) {
6066 }
6067 }
6068
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006069 Intent intent;
6070
6071 if (fromHomeKey) {
6072 intent = new Intent(mHomeIntent);
6073 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6074 } else {
6075 intent = mHomeIntent;
6076 }
6077
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006078 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006079 }
Craig Mautnereda67292013-04-28 13:50:14 -07006080
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006081 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006082 * goes to the home screen
6083 * @return whether it did anything
6084 */
6085 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006086 if (!isUserSetupComplete()) {
6087 Slog.i(TAG, "Not going home because user setup is in progress.");
6088 return false;
6089 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006090 if (false) {
6091 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006092 try {
6093 ActivityManagerNative.getDefault().stopAppSwitches();
6094 } catch (RemoteException e) {
6095 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006096 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006097 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006098 } else {
6099 // This code brings home to the front or, if it is already
6100 // at the front, puts the device to sleep.
6101 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006102 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6103 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6104 Log.d(TAG, "UTS-TEST-MODE");
6105 } else {
6106 ActivityManagerNative.getDefault().stopAppSwitches();
6107 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006108 Intent dock = createHomeDockIntent();
6109 if (dock != null) {
6110 int result = ActivityManagerNative.getDefault()
6111 .startActivityAsUser(null, null, dock,
6112 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6113 null, null, 0,
6114 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006115 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006116 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6117 return false;
6118 }
6119 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006120 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006121 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006122 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006123 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006124 null, null, 0,
6125 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006126 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006127 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006128 return false;
6129 }
6130 } catch (RemoteException ex) {
6131 // bummer, the activity manager, which is in this process, is dead
6132 }
6133 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006134 return true;
6135 }
Craig Mautnereda67292013-04-28 13:50:14 -07006136
6137 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006138 public void setCurrentOrientationLw(int newOrientation) {
6139 synchronized (mLock) {
6140 if (newOrientation != mCurrentAppOrientation) {
6141 mCurrentAppOrientation = newOrientation;
6142 updateOrientationListenerLp();
6143 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006144 }
6145 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006146
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006147 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6148 if (!isGlobalAccessibilityGestureEnabled()) {
6149 return;
6150 }
6151 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6152 Context.AUDIO_SERVICE);
6153 if (audioManager.isSilentMode()) {
6154 return;
6155 }
6156 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6157 Settings.System.DEFAULT_NOTIFICATION_URI);
6158 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6159 ringTone.play();
6160 }
Craig Mautnereda67292013-04-28 13:50:14 -07006161
Bryce Lee584a4452014-10-21 15:55:55 -07006162 private boolean isTheaterModeEnabled() {
6163 return Settings.Global.getInt(mContext.getContentResolver(),
6164 Settings.Global.THEATER_MODE_ON, 0) == 1;
6165 }
6166
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006167 private boolean isGlobalAccessibilityGestureEnabled() {
6168 return Settings.Global.getInt(mContext.getContentResolver(),
6169 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6170 }
6171
Craig Mautnereda67292013-04-28 13:50:14 -07006172 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006173 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006174 if (!mVibrator.hasVibrator()) {
6175 return false;
6176 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006177 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6178 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006179 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006180 return false;
6181 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006182 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006183 switch (effectId) {
6184 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006185 pattern = mLongPressVibePattern;
6186 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006187 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006188 pattern = mVirtualKeyVibePattern;
6189 break;
6190 case HapticFeedbackConstants.KEYBOARD_TAP:
6191 pattern = mKeyboardTapVibePattern;
6192 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006193 case HapticFeedbackConstants.CLOCK_TICK:
6194 pattern = mClockTickVibePattern;
6195 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006196 case HapticFeedbackConstants.CALENDAR_DATE:
6197 pattern = mCalendarDateVibePattern;
6198 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006199 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006200 pattern = mSafeModeDisabledVibePattern;
6201 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006202 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006203 pattern = mSafeModeEnabledVibePattern;
6204 break;
Mady Mellore82067b2015-04-30 09:58:35 -07006205 case HapticFeedbackConstants.STYLUS_BUTTON_PRESS:
6206 pattern = mStylusButtonPressVibePattern;
6207 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006208 default:
6209 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006210 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006211 int owningUid;
6212 String owningPackage;
6213 if (win != null) {
6214 owningUid = win.getOwningUid();
6215 owningPackage = win.getOwningPackage();
6216 } else {
6217 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006218 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006219 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006220 if (pattern.length == 1) {
6221 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006222 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006223 } else {
6224 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006225 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006226 }
6227 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006228 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006229
6230 @Override
6231 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006232 }
6233
Jeff Brownc38c9be2012-10-04 13:16:19 -07006234 @Override
6235 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006236 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006237 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006238 }
6239 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006240
Dianne Hackborndf89e652011-10-06 22:35:11 -07006241 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006242 // If there is no window focused, there will be nobody to handle the events
6243 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006244 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6245 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006246 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006247 return 0;
6248 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006249 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006250 // We are updating at a point where the keyguard has gotten
6251 // focus, but we were last in a state where the top window is
6252 // hiding it. This is probably because the keyguard as been
6253 // shown while the top window was displayed, so we want to ignore
6254 // it here because this is just a very transient change and it
6255 // will quickly lose focus once it correctly gets hidden.
6256 return 0;
6257 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006258
John Spurlock1db8b682014-02-18 11:18:59 -05006259 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006260 & ~mResettingSystemUiFlags
6261 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006262 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006263 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006264 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006265 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006266 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006267 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006268 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006269 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006270 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006271 return 0;
6272 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006273 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006274 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006275 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006276 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006277 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006278 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006279 try {
6280 IStatusBarService statusbar = getStatusBarService();
6281 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006282 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006283 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006284 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006285 } catch (RemoteException e) {
6286 // re-acquire status bar service next time it is needed.
6287 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006288 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006289 }
6290 });
6291 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006292 }
6293
Adrian Rooscd3884d2015-02-18 17:25:23 +01006294 private int updateLightStatusBarLw(int vis) {
6295 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6296 ? mStatusBar
6297 : mTopFullscreenOpaqueOrDimmingWindowState;
6298
6299 if (statusColorWin != null) {
6300 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6301 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6302 // its light flag.
6303 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6304 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6305 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6306 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6307 // Otherwise if it's dimming, clear the light flag.
6308 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6309 }
6310 }
6311 return vis;
6312 }
6313
John Spurlock79da8332013-09-20 12:04:47 -04006314 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006315 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006316 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6317 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006318 : mTopFullscreenOpaqueWindowState;
6319 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6320 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6321
John Spurlock27735a42013-08-14 17:57:38 -04006322 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04006323 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006324 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006325 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6326 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006327 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006328 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6329 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006330 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006331 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6332 }
John Spurlockbd957402013-10-03 11:38:39 -04006333 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006334 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006335
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006336 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006337 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6338 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006339 }
6340
John Spurlock27735a42013-08-14 17:57:38 -04006341 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006342 boolean immersiveSticky =
6343 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006344 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006345 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006346 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006347 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6348 boolean hideStatusBarSysui =
6349 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006350 boolean hideNavBarSysui =
6351 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006352
John Spurlock27735a42013-08-14 17:57:38 -04006353 boolean transientStatusBarAllowed =
6354 mStatusBar != null && (
6355 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006356 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006357 || statusBarHasFocus);
6358
John Spurlockf1a36642013-10-12 17:50:42 -04006359 boolean transientNavBarAllowed =
6360 mNavigationBar != null &&
6361 hideNavBarSysui && immersiveSticky;
6362
John Spurlockf25706f2013-11-07 18:02:43 -05006363 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006364 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006365 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006366 && !transientNavBarAllowed;
6367 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006368 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006369 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006370 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006371 }
John Spurlock27735a42013-08-14 17:57:38 -04006372
6373 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6374
6375 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006376 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6377 boolean newImmersiveMode = isImmersiveMode(vis);
6378 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006379 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006380 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6381 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006382 }
John Spurlock27735a42013-08-14 17:57:38 -04006383
John Spurlockf1a36642013-10-12 17:50:42 -04006384 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6385
John Spurlocke1f366f2013-08-05 12:22:40 -04006386 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006387 }
6388
John Spurlockf1a36642013-10-12 17:50:42 -04006389 private void clearClearableFlagsLw() {
6390 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6391 if (newVal != mResettingSystemUiFlags) {
6392 mResettingSystemUiFlags = newVal;
6393 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6394 }
6395 }
6396
6397 private boolean isImmersiveMode(int vis) {
6398 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006399 return mNavigationBar != null
6400 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006401 && (vis & flags) != 0
6402 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006403 }
6404
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006405 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006406 * @return whether the navigation or status bar can be made translucent
6407 *
6408 * This should return true unless touch exploration is not enabled or
6409 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006410 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006411 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006412 return mTranslucentDecorEnabled
6413 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006414 }
6415
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006416 // Use this instead of checking config_showNavigationBar so that it can be consistently
6417 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006418 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006419 public boolean hasNavigationBar() {
6420 return mHasNavigationBar;
6421 }
6422
satok1bc0a492012-04-25 22:47:12 +09006423 @Override
6424 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6425 mLastInputMethodWindow = ime;
6426 mLastInputMethodTargetWindow = target;
6427 }
6428
Craig Mautnerf1b67412012-09-19 13:18:29 -07006429 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006430 public int getInputMethodWindowVisibleHeightLw() {
6431 return mDockBottom - mCurBottom;
6432 }
6433
6434 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006435 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006436 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006437 if (mKeyguardDelegate != null) {
6438 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006439 }
John Spurlock13451a22012-09-28 14:40:41 -04006440 if (mStatusBarService != null) {
6441 try {
6442 mStatusBarService.setCurrentUser(newUserId);
6443 } catch (RemoteException e) {
6444 // oh well
6445 }
6446 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006447 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006448 }
6449
6450 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006451 public boolean canMagnifyWindow(int windowType) {
6452 switch (windowType) {
6453 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6454 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6455 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6456 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6457 return false;
6458 }
6459 }
6460 return true;
6461 }
6462
6463 @Override
6464 public boolean isTopLevelWindow(int windowType) {
6465 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6466 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6467 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6468 }
6469 return true;
6470 }
6471
Jim Miller4eeb4f62012-11-08 00:04:29 -08006472 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006473 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006474 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006475 pw.print(" mSystemReady="); pw.print(mSystemReady);
6476 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006477 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006478 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006479 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006480 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006481 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6482 || mForceClearedSystemUiFlags != 0) {
6483 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6484 pw.print(Integer.toHexString(mLastSystemUiFlags));
6485 pw.print(" mResettingSystemUiFlags=0x");
6486 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6487 pw.print(" mForceClearedSystemUiFlags=0x");
6488 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006489 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006490 if (mLastFocusNeedsMenu) {
6491 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6492 pw.println(mLastFocusNeedsMenu);
6493 }
Jeff Browna20dda42014-05-27 20:57:24 -07006494 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6495 pw.println(mWakeGestureEnabledSetting);
6496
Jeff Brownbcdfc622014-03-06 19:13:04 -08006497 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006498 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6499 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006500 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6501 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6502 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6503 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006504 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006505 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006506 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6507 pw.print(mCarDockEnablesAccelerometer);
6508 pw.print(" mDeskDockEnablesAccelerometer=");
6509 pw.println(mDeskDockEnablesAccelerometer);
6510 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6511 pw.print(mLidKeyboardAccessibility);
6512 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006513 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006514 pw.print(prefix);
6515 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6516 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006517 pw.print(prefix);
6518 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6519 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006520 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006521 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6522 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6523 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6524 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6525 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6526 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6527 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006528 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6529 pw.print(","); pw.print(mOverscanScreenTop);
6530 pw.print(") "); pw.print(mOverscanScreenWidth);
6531 pw.print("x"); pw.println(mOverscanScreenHeight);
6532 if (mOverscanLeft != 0 || mOverscanTop != 0
6533 || mOverscanRight != 0 || mOverscanBottom != 0) {
6534 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6535 pw.print(" top="); pw.print(mOverscanTop);
6536 pw.print(" right="); pw.print(mOverscanRight);
6537 pw.print(" bottom="); pw.println(mOverscanBottom);
6538 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006539 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6540 pw.print(mRestrictedOverscanScreenLeft);
6541 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6542 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6543 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006544 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6545 pw.print(","); pw.print(mUnrestrictedScreenTop);
6546 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6547 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6548 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6549 pw.print(","); pw.print(mRestrictedScreenTop);
6550 pw.print(") "); pw.print(mRestrictedScreenWidth);
6551 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006552 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6553 pw.print(","); pw.print(mStableFullscreenTop);
6554 pw.print(")-("); pw.print(mStableFullscreenRight);
6555 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006556 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6557 pw.print(","); pw.print(mStableTop);
6558 pw.print(")-("); pw.print(mStableRight);
6559 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006560 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6561 pw.print(","); pw.print(mSystemTop);
6562 pw.print(")-("); pw.print(mSystemRight);
6563 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006564 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6565 pw.print(","); pw.print(mCurTop);
6566 pw.print(")-("); pw.print(mCurRight);
6567 pw.print(","); pw.print(mCurBottom); pw.println(")");
6568 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6569 pw.print(","); pw.print(mContentTop);
6570 pw.print(")-("); pw.print(mContentRight);
6571 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006572 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6573 pw.print(","); pw.print(mVoiceContentTop);
6574 pw.print(")-("); pw.print(mVoiceContentRight);
6575 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006576 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6577 pw.print(","); pw.print(mDockTop);
6578 pw.print(")-("); pw.print(mDockRight);
6579 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006580 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6581 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006582 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6583 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006584 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6585 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006586 if (mLastInputMethodWindow != null) {
6587 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6588 pw.println(mLastInputMethodWindow);
6589 }
6590 if (mLastInputMethodTargetWindow != null) {
6591 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6592 pw.println(mLastInputMethodTargetWindow);
6593 }
6594 if (mStatusBar != null) {
6595 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006596 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6597 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006598 }
6599 if (mNavigationBar != null) {
6600 pw.print(prefix); pw.print("mNavigationBar=");
6601 pw.println(mNavigationBar);
6602 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006603 if (mFocusedWindow != null) {
6604 pw.print(prefix); pw.print("mFocusedWindow=");
6605 pw.println(mFocusedWindow);
6606 }
6607 if (mFocusedApp != null) {
6608 pw.print(prefix); pw.print("mFocusedApp=");
6609 pw.println(mFocusedApp);
6610 }
6611 if (mWinDismissingKeyguard != null) {
6612 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6613 pw.println(mWinDismissingKeyguard);
6614 }
6615 if (mTopFullscreenOpaqueWindowState != null) {
6616 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6617 pw.println(mTopFullscreenOpaqueWindowState);
6618 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006619 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6620 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6621 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6622 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006623 if (mForcingShowNavBar) {
6624 pw.print(prefix); pw.print("mForcingShowNavBar=");
6625 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6626 pw.println(mForcingShowNavBarLayer);
6627 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006628 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006629 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006630 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6631 pw.print(" mForceStatusBarFromKeyguard=");
6632 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006633 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006634 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006635 pw.print(" mHomePressed="); pw.println(mHomePressed);
6636 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6637 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6638 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6639 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6640 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6641 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6642 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6643 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6644 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6645 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006646 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6647 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6648 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006649
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006650 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006651 mStatusBarController.dump(pw, prefix);
6652 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006653 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006654
Jeff Browna20dda42014-05-27 20:57:24 -07006655 if (mWakeGestureListener != null) {
6656 mWakeGestureListener.dump(pw, prefix);
6657 }
Jeff Brown600f0032014-05-22 17:06:00 -07006658 if (mOrientationListener != null) {
6659 mOrientationListener.dump(pw, prefix);
6660 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006661 if (mBurnInProtectionHelper != null) {
6662 mBurnInProtectionHelper.dump(prefix, pw);
6663 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006664 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006665}