blob: 25857c5d50620ff88f840f4536031a5e13d9c2f9 [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
Jeff Brown37df39a92015-02-25 15:42:31 -08002 * Copyright (C) 2006 The Android Open Source Project
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jorim Jaggib10e33f2015-02-04 21:57:40 +010017package com.android.server.policy;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080018
Dianne Hackborna4972e92012-03-14 10:38:05 -070019import android.app.ActivityManager;
Jeff Brown061ea992015-04-17 19:55:47 -070020import android.app.ActivityManagerInternal;
21import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080022import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080023import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040024import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070025import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070026import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040027import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080028import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070029import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080030import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040031import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080032import android.content.ContentResolver;
33import android.content.Context;
34import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070035import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070036import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080037import android.content.pm.ActivityInfo;
38import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040039import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070040import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.content.res.Configuration;
42import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070043import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080044import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080045import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080046import android.graphics.Rect;
John Spurlock7b414672014-07-18 13:02:39 -040047import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080048import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050049import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080050import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070051import android.media.Ringtone;
52import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070053import android.media.session.MediaSessionLegacyHelper;
Mark Renoufc1256912015-03-11 14:38:23 -040054import android.os.Build;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070055import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080056import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070057import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080058import android.os.Handler;
59import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080060import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070061import android.os.Message;
62import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080063import android.os.PowerManager;
64import android.os.RemoteException;
65import android.os.ServiceManager;
66import android.os.SystemClock;
67import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080068import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070069import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080070import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070071import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080072import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070073import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040074import android.service.dreams.DreamService;
75import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070076import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070077import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070078import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080079import android.util.EventLog;
80import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070081import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080082import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070083import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080084import android.view.Gravity;
85import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080086import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080087import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070088import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070089import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080090import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080091import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080092import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080093import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080094import android.view.KeyEvent;
95import android.view.MotionEvent;
Jorim Jaggib10e33f2015-02-04 21:57:40 +010096import android.view.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080097import android.view.Surface;
98import android.view.View;
99import android.view.ViewConfiguration;
Mark Renoufc1256912015-03-11 14:38:23 -0400100import android.view.ViewRootImpl;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800101import android.view.Window;
102import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800103import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700104import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800105import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800106import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800107import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800108import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200109import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800110import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800111import com.android.internal.R;
Craig Mautnerae446592012-12-06 19:05:05 -0800112import com.android.internal.statusbar.IStatusBarService;
Craig Mautnerae446592012-12-06 19:05:05 -0800113import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700114import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100115import com.android.server.policy.keyguard.KeyguardServiceDelegate;
116import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800117
118import java.io.File;
119import java.io.FileReader;
120import java.io.IOException;
121import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700122import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800123import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800124
Dianne Hackbornc652de82013-02-15 16:32:56 -0800125import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700126import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
127import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
128import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700129import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
130import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
131import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800132
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800133/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700134 * WindowManagerPolicy implementation for the Android phone UI. This
135 * introduces a new method suffix, Lp, for an internal lock of the
136 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400137 * can be acquired with either the Lw and Li lock held, so has the restrictions
The Android Open Source Project0727d222009-03-11 12:11:58 -0700138 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800139 */
140public class PhoneWindowManager implements WindowManagerPolicy {
141 static final String TAG = "WindowManager";
142 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700143 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700144 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700145 static final boolean DEBUG_KEYGUARD = false;
146 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700147 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700148 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800149 static final boolean SHOW_STARTING_ANIMATIONS = true;
150 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400151
Daniel Sandler6396c722013-04-16 20:19:09 -0400152 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
153 // No longer recommended for desk docks; still useful in car docks.
154 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
155 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
156
Jeff Brown6d8fd272014-05-20 21:24:38 -0700157 static final int SHORT_PRESS_POWER_NOTHING = 0;
158 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
159 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
160 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800161 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700162
Joe Onoratod208e702010-10-08 16:22:43 -0400163 static final int LONG_PRESS_POWER_NOTHING = 0;
164 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
165 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700166 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700167
Jeff Brown13f00f02014-10-31 14:45:50 -0700168 static final int MULTI_PRESS_POWER_NOTHING = 0;
169 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
170 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
171
Michael Jurka3b1fc472011-06-13 10:54:40 -0700172 // These need to match the documentation/constant in
173 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800174 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800175 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700176 static final int LONG_PRESS_HOME_ASSIST = 2;
177
178 static final int DOUBLE_TAP_HOME_NOTHING = 0;
179 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800180
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000181 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
182 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
183
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700184 static final int APPLICATION_MEDIA_SUBLAYER = -2;
185 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800186 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800187 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700188 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700189
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800190 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
191 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
192 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500193 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700194 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800195
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700196 /**
197 * These are the system UI flags that, when changing, can cause the layout
198 * of the screen to change.
199 */
200 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400201 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400202 | View.SYSTEM_UI_FLAG_FULLSCREEN
203 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200204 | View.NAVIGATION_BAR_TRANSLUCENT
205 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700206
John Spurlock7b414672014-07-18 13:02:39 -0400207 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
208 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
209 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
210 .build();
211
Jim Miller5ecd8112013-01-09 18:50:26 -0800212 /**
213 * Keyguard stuff
214 */
215 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100216 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700217 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800218
Jeff Brown6651a632011-11-28 12:59:11 -0800219 /* Table of Application Launch keys. Maps from key codes to intent categories.
220 *
221 * These are special keys that are used to launch particular kinds of applications,
222 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
223 * usage page. We don't support quite that many yet...
224 */
225 static SparseArray<String> sApplicationLaunchKeyCategories;
226 static {
227 sApplicationLaunchKeyCategories = new SparseArray<String>();
228 sApplicationLaunchKeyCategories.append(
229 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
230 sApplicationLaunchKeyCategories.append(
231 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
232 sApplicationLaunchKeyCategories.append(
233 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
234 sApplicationLaunchKeyCategories.append(
235 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
236 sApplicationLaunchKeyCategories.append(
237 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
238 sApplicationLaunchKeyCategories.append(
239 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
240 }
241
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700242 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
243 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
244
Dianne Hackborndf89e652011-10-06 22:35:11 -0700245 /**
246 * Lock protecting internal state. Must not call out into window
247 * manager with lock held. (This lock will be acquired in places
248 * where the window manager is calling in with its own lock held.)
249 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800250 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700251
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800252 Context mContext;
253 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700254 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700255 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700256 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700257 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700258 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400259 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700260 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700261 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800262 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700263 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800264 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000265 BurnInProtectionHelper mBurnInProtectionHelper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800266
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700267 // Vibrator pattern for haptic feedback of a long press.
268 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700269
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700270 // Vibrator pattern for haptic feedback of virtual key press.
271 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700272
Amith Yamasanic33cb712010-02-10 15:21:49 -0800273 // Vibrator pattern for a short vibration.
274 long[] mKeyboardTapVibePattern;
275
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700276 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
277 long[] mClockTickVibePattern;
278
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700279 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
280 long[] mCalendarDateVibePattern;
281
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700282 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
283 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700284
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700285 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
286 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700287
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800288 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
289 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400290
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800291 boolean mSafeMode;
292 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700293 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400294 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400295 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700296 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400297 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
298 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
299 int[] mNavigationBarHeightForRotation = new int[4];
300 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400301
Craig Mautnera631d492014-08-05 15:16:01 -0700302 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800303 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700304 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700305 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700306 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700307 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
308 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
309 }
310 };
311 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
312 @Override
313 public void onShown(IBinder windowToken) {
314 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
315 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
316 }
317 };
318
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800319 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800320 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900321 WindowState mLastInputMethodWindow = null;
322 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800323
Jeff Brown13f00f02014-10-31 14:45:50 -0700324 // FIXME This state is shared between the input reader and handler thread.
325 // Technically it's broken and buggy but it has been like this for many years
326 // and we have not yet seen any problems. Someday we'll rewrite this logic
327 // so that only one thread is involved in handling input policy. Unfortunately
328 // it's on a critical path for power management so we can't just post the work to the
329 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
330 // to hold wakelocks during dispatch and eliminating the critical path.
331 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800332 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700333 volatile int mPowerKeyPressCounter;
334 volatile boolean mEndCallKeyHandled;
335
Winson Chungd42a6cf2014-06-03 16:24:04 -0700336 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700337 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700338 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800339
Jeff Brown2e7760e2012-04-11 15:14:55 -0700340 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700341 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700342 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800343
Dianne Hackbornc777e072010-02-12 13:07:59 -0800344 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700345 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800346 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700347 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400348 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700349 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700350 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400351 int mCarDockRotation;
352 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700353 int mUndockedHdmiRotation;
354 int mDemoHdmiRotation;
355 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800356 int mDemoRotation;
357 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400358
Jeff Browna20dda42014-05-27 20:57:24 -0700359 boolean mWakeGestureEnabledSetting;
360 MyWakeGestureListener mWakeGestureListener;
361
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700362 // Default display does not rotate, apps that require non-default orientation will have to
363 // have the orientation emulated.
364 private boolean mForceDefaultOrientation = false;
365
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400366 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
367 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700368 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400369
Jeff Brownbcdfc622014-03-06 19:13:04 -0800370 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700371 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400372 boolean mCarDockEnablesAccelerometer;
373 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700374 int mLidKeyboardAccessibility;
375 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700376 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700377 int mShortPressOnPowerBehavior;
378 int mLongPressOnPowerBehavior;
379 int mDoublePressOnPowerBehavior;
380 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000381 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700382 boolean mAwake;
383 boolean mScreenOnEarly;
384 boolean mScreenOnFully;
385 ScreenOnListener mScreenOnListener;
386 boolean mKeyguardDrawComplete;
387 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800388 boolean mOrientationSensorEnabled = false;
389 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800390 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400391 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800392 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700393
Jeff Brown70825162012-03-28 17:27:48 -0700394 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800395
396 // The last window we were told about in focusChanged.
397 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800398 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800399
Jeff Brown70825162012-03-28 17:27:48 -0700400 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800401
Dianne Hackbornc652de82013-02-15 16:32:56 -0800402 // The current size of the screen; really; extends into the overscan area of
403 // the screen and doesn't account for any system elements like the status bar.
404 int mOverscanScreenLeft, mOverscanScreenTop;
405 int mOverscanScreenWidth, mOverscanScreenHeight;
406 // The current visible size of the screen; really; (ir)regardless of whether the status
407 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800408 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
409 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800410 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
411 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
412 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700413 // The current size of the screen; these may be different than (0,0)-(dw,dh)
414 // if the status bar can't be hidden; in that case it effectively carves out
415 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800416 int mRestrictedScreenLeft, mRestrictedScreenTop;
417 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700418 // During layout, the current screen borders accounting for any currently
419 // visible system UI elements.
420 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700421 // For applications requesting stable content insets, these are them.
422 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700423 // For applications requesting stable content insets but have also set the
424 // fullscreen window flag, these are the stable dimensions without the status bar.
425 int mStableFullscreenLeft, mStableFullscreenTop;
426 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800427 // During layout, the current screen borders with all outer decoration
428 // (status bar, input method dock) accounted for.
429 int mCurLeft, mCurTop, mCurRight, mCurBottom;
430 // During layout, the frame in which content should be displayed
431 // to the user, accounting for all screen decoration except for any
432 // space they deem as available for other content. This is usually
433 // the same as mCur*, but may be larger if the screen decor has supplied
434 // content insets.
435 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700436 // During layout, the frame in which voice content should be displayed
437 // to the user, accounting for all screen decoration except for any
438 // space they deem as available for other content.
439 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800440 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800441 // windows are placed.
442 int mDockLeft, mDockTop, mDockRight, mDockBottom;
443 // During layout, the layer at which the doc window is placed.
444 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700445 // During layout, this is the layer of the status bar.
446 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700447 int mLastSystemUiFlags;
448 // Bits that we are in the process of clearing, so we want to prevent
449 // them from being set by applications until everything has been updated
450 // to have them clear.
451 int mResettingSystemUiFlags = 0;
452 // Bits that we are currently always keeping cleared.
453 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800454 // What we last reported to system UI about whether the compatibility
455 // menu needs to be displayed.
456 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700457
458 FakeWindow mHideNavFakeWindow = null;
459
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800460 static final Rect mTmpParentFrame = new Rect();
461 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800462 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800463 static final Rect mTmpContentFrame = new Rect();
464 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400465 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700466 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700467 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700468
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800469 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100470 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700471 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200472 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400473 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800474 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700475 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700476 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800477 boolean mForcingShowNavBar;
478 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700479
480 // States of keyguard dismiss.
481 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
482 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
483 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
484 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
485
486 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
487 * be done once per window. */
488 private WindowState mWinDismissingKeyguard;
489
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700490 /** The window that is currently showing "over" the keyguard. If there is an app window
491 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
492 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
493 * the wallpaper. */
494 private WindowState mWinShowWhenLocked;
495
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700496 boolean mShowingLockscreen;
497 boolean mShowingDream;
498 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700499 boolean mDreamingSleepTokenNeeded;
500 SleepToken mDreamingSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700501 boolean mKeyguardSecure;
502 boolean mKeyguardSecureIncludingHidden;
503 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800504 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700505 boolean mHomeConsumed;
506 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800507 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700508 Intent mCarDockIntent;
509 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700510 boolean mSearchKeyShortcutPending;
511 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700512 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700513 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800514
Mike Lockwood28569302010-01-28 11:54:40 -0500515 // support for activating the lock screen while the screen is on
516 boolean mAllowLockscreenWhenOn;
517 int mLockScreenTimeout;
518 boolean mLockScreenTimerActive;
519
David Brownbaf8d092010-03-08 21:52:59 -0800520 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800521 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800522
523 // Behavior of POWER button while in-call and screen on.
524 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
525 int mIncallPowerBehavior;
526
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700527 Display mDisplay;
528
Dianne Hackborn9d132642011-04-21 17:26:39 -0700529 int mLandscapeRotation = 0; // default landscape rotation
530 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
531 int mPortraitRotation = 0; // default portrait rotation
532 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700533
Dianne Hackbornc652de82013-02-15 16:32:56 -0800534 int mOverscanLeft = 0;
535 int mOverscanTop = 0;
536 int mOverscanRight = 0;
537 int mOverscanBottom = 0;
538
Joe Onorato46b0d682010-11-22 17:37:27 -0800539 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700540 private int mLongPressOnHomeBehavior;
541
542 // What we do when the user double-taps on home
543 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800544
Bryce Lee584a4452014-10-21 15:55:55 -0700545 // Allowed theater mode wake actions
546 private boolean mAllowTheaterModeWakeFromKey;
547 private boolean mAllowTheaterModeWakeFromPowerKey;
548 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800549 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700550 private boolean mAllowTheaterModeWakeFromCameraLens;
551 private boolean mAllowTheaterModeWakeFromLidSwitch;
552 private boolean mAllowTheaterModeWakeFromWakeGesture;
553
Bryce Leed3b28402015-03-09 15:49:13 +0000554 // Whether to support long press from power button in non-interactive mode
555 private boolean mSupportLongPressPowerWhenNonInteractive;
556
Bryce Lee55e846d2014-11-04 12:43:44 -0800557 // Whether to go to sleep entering theater mode from power button
558 private boolean mGoToSleepOnButtonPressTheaterMode;
559
Winson Chung9112ec32011-06-27 13:15:32 -0700560 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700561 // Time to volume and power must be pressed within this interval of each other.
562 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700563 // Increase the chord delay when taking a screenshot from the keyguard
564 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800565 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700566 private boolean mScreenshotChordVolumeDownKeyTriggered;
567 private long mScreenshotChordVolumeDownKeyTime;
568 private boolean mScreenshotChordVolumeDownKeyConsumed;
569 private boolean mScreenshotChordVolumeUpKeyTriggered;
570 private boolean mScreenshotChordPowerKeyTriggered;
571 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700572
Michael Wrightb854e242013-02-05 17:54:02 -0800573 /* The number of steps between min and max brightness */
574 private static final int BRIGHTNESS_STEPS = 10;
575
Christopher Tate5e08af02012-09-21 17:17:22 -0700576 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800577 ShortcutManager mShortcutManager;
578 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700579 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700580 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800581
Craig Mautnerd625ab22013-09-06 13:40:31 -0700582 private int mCurrentUserId;
583
Justin Kohd378ad72013-04-01 12:18:26 -0700584 // Maps global key codes to the components that will handle them.
585 private GlobalKeyManager mGlobalKeyManager;
586
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700587 // Fallback actions by key code.
588 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
589 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800590
Jorim Jaggi76a16232014-08-08 17:00:47 +0200591 private final LogDecelerateInterpolator mLogDecelerateInterpolator
592 = new LogDecelerateInterpolator(100, 0);
593
Jeff Brown70825162012-03-28 17:27:48 -0700594 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
595 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700596 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
597 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700598 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
599 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
600 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700601 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700602 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700603 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700604 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700605 private static final int MSG_POWER_DELAYED_PRESS = 13;
606 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700607 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jeff Brown70825162012-03-28 17:27:48 -0700608
609 private class PolicyHandler extends Handler {
610 @Override
611 public void handleMessage(Message msg) {
612 switch (msg.what) {
613 case MSG_ENABLE_POINTER_LOCATION:
614 enablePointerLocation();
615 break;
616 case MSG_DISABLE_POINTER_LOCATION:
617 disablePointerLocation();
618 break;
Jeff Brown40013652012-05-16 21:22:36 -0700619 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
620 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
621 break;
622 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
623 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
624 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700625 case MSG_DISPATCH_SHOW_RECENTS:
626 showRecentApps(false);
627 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700628 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
629 showGlobalActionsInternal();
630 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700631 case MSG_KEYGUARD_DRAWN_COMPLETE:
632 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700633 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700634 break;
635 case MSG_KEYGUARD_DRAWN_TIMEOUT:
636 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700637 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700638 break;
639 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
640 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700641 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700642 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700643 case MSG_HIDE_BOOT_MESSAGE:
644 handleHideBootMessage();
645 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700646 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
647 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
648 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700649 case MSG_POWER_DELAYED_PRESS:
650 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
651 finishPowerKeyPress();
652 break;
653 case MSG_POWER_LONG_PRESS:
654 powerLongPress();
655 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700656 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
657 updateDreamingSleepToken(msg.arg1 != 0);
658 break;
Jeff Brown70825162012-03-28 17:27:48 -0700659 }
660 }
661 }
662
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800663 private UEventObserver mHDMIObserver = new UEventObserver() {
664 @Override
665 public void onUEvent(UEventObserver.UEvent event) {
666 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
667 }
668 };
669
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800670 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800671 SettingsObserver(Handler handler) {
672 super(handler);
673 }
David Brownbaf8d092010-03-08 21:52:59 -0800674
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800675 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700676 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800677 ContentResolver resolver = mContext.getContentResolver();
678 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700679 Settings.System.END_BUTTON_BEHAVIOR), false, this,
680 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800681 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700682 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
683 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700684 resolver.registerContentObserver(Settings.Secure.getUriFor(
685 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
686 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800687 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700688 Settings.System.ACCELEROMETER_ROTATION), false, this,
689 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500690 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700691 Settings.System.USER_ROTATION), false, this,
692 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400693 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700694 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
695 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800696 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700697 Settings.System.POINTER_LOCATION), false, this,
698 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800699 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700700 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
701 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500702 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400703 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700704 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500705 resolver.registerContentObserver(Settings.Global.getUriFor(
706 Settings.Global.POLICY_CONTROL), false, this,
707 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800708 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800709 }
710
711 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800712 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700713 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800714 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800715 }
Craig Mautner967212c2013-04-13 21:10:58 -0700716
Jeff Browna20dda42014-05-27 20:57:24 -0700717 class MyWakeGestureListener extends WakeGestureListener {
718 MyWakeGestureListener(Context context, Handler handler) {
719 super(context, handler);
720 }
721
722 @Override
723 public void onWakeUp() {
724 synchronized (mLock) {
725 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700726 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700727 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700728 }
729 }
730 }
731 }
732
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800733 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800734 MyOrientationListener(Context context, Handler handler) {
735 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800736 }
Craig Mautner967212c2013-04-13 21:10:58 -0700737
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800738 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700739 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700740 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700741 updateRotation(false);
742 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800743 }
744 MyOrientationListener mOrientationListener;
745
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100746 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400747
John Spurlock27735a42013-08-14 17:57:38 -0400748 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400749 View.NAVIGATION_BAR_TRANSIENT,
750 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400751 View.NAVIGATION_BAR_TRANSLUCENT,
752 StatusBarManager.WINDOW_NAVIGATION_BAR,
753 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400754
John Spurlockf1a36642013-10-12 17:50:42 -0400755 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400756
Craig Mautner037aa8d2013-06-07 10:35:44 -0700757 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400758
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700759 IStatusBarService getStatusBarService() {
760 synchronized (mServiceAquireLock) {
761 if (mStatusBarService == null) {
762 mStatusBarService = IStatusBarService.Stub.asInterface(
763 ServiceManager.getService("statusbar"));
764 }
765 return mStatusBarService;
766 }
767 }
768
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700769 /*
770 * We always let the sensor be switched on by default except when
771 * the user has explicitly disabled sensor based rotation or when the
772 * screen is switched off.
773 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700774 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800775 if (mSupportAutoRotation) {
776 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
777 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
778 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
779 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
780 // If the application has explicitly requested to follow the
781 // orientation, then we need to turn the sensor on.
782 return true;
783 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800784 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700785 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800786 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
787 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
788 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400789 // enable accelerometer if we are docked in a dock that enables accelerometer
790 // orientation management,
791 return true;
792 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700793 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800794 // If the setting for using the sensor by default is enabled, then
795 // we will always leave it on. Note that the user could go to
796 // a window that forces an orientation that does not use the
797 // sensor and in theory we could turn it off... however, when next
798 // turning it on we won't have a good value for the current
799 // orientation for a little bit, which can cause orientation
800 // changes to lag, so we'd like to keep it always on. (It will
801 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700802 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800803 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800804 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800805 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700806
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800807 /*
808 * Various use cases for invoking this function
809 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700810 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800811 * if not already enabled
812 * screen turned on and current app does not have sensor orientation, disable listeners if
813 * already enabled
814 * screen turning on and current app has sensor based orientation, enable listeners if needed
815 * screen turning on and current app has nosensor based orientation, do nothing
816 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700817 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800818 if (!mOrientationListener.canDetectOrientation()) {
819 // If sensor is turned off or nonexistent for some reason
820 return;
821 }
822 //Could have been invoked due to screen turning on or off or
823 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700824 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
825 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
826 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800827 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700828 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700829 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800830 disable = false;
831 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700832 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800833 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700834 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800835 mOrientationSensorEnabled = true;
836 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700837 }
838 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800839 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700840 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800841 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700842 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800843 mOrientationSensorEnabled = false;
844 }
845 }
846
Jeff Brown13f00f02014-10-31 14:45:50 -0700847 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
848 // Hold a wake lock until the power key is released.
849 if (!mPowerKeyWakeLock.isHeld()) {
850 mPowerKeyWakeLock.acquire();
851 }
852
853 // Cancel multi-press detection timeout.
854 if (mPowerKeyPressCounter != 0) {
855 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
856 }
857
858 // Detect user pressing the power button in panic when an application has
859 // taken over the whole screen.
860 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800861 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700862 if (panic) {
863 mHandler.post(mRequestTransientNav);
864 }
865
866 // Latch power key state to detect screenshot chord.
867 if (interactive && !mScreenshotChordPowerKeyTriggered
868 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
869 mScreenshotChordPowerKeyTriggered = true;
870 mScreenshotChordPowerKeyTime = event.getDownTime();
871 interceptScreenshotChord();
872 }
873
874 // Stop ringing or end call if configured to do so when power is pressed.
875 TelecomManager telecomManager = getTelecommService();
876 boolean hungUp = false;
877 if (telecomManager != null) {
878 if (telecomManager.isRinging()) {
879 // Pressing Power while there's a ringing incoming
880 // call should silence the ringer.
881 telecomManager.silenceRinger();
882 } else if ((mIncallPowerBehavior
883 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
884 && telecomManager.isInCall() && interactive) {
885 // Otherwise, if "Power button ends call" is enabled,
886 // the Power button will hang up any current active call.
887 hungUp = telecomManager.endCall();
888 }
889 }
890
891 // If the power key has still not yet been handled, then detect short
892 // press, long press, or multi press and decide what to do.
893 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
894 || mScreenshotChordVolumeUpKeyTriggered;
895 if (!mPowerKeyHandled) {
896 if (interactive) {
897 // When interactive, we're already awake.
898 // Wait for a long press or for the button to be released to decide what to do.
899 if (hasLongPressOnPowerBehavior()) {
900 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
901 msg.setAsynchronous(true);
902 mHandler.sendMessageDelayed(msg,
903 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
904 }
905 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800906 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800907
Bryce Leed3b28402015-03-09 15:49:13 +0000908 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
909 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
910 msg.setAsynchronous(true);
911 mHandler.sendMessageDelayed(msg,
912 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800913 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000914 } else {
915 final int maxCount = getMaxMultiPressPowerCount();
916
917 if (maxCount <= 1) {
918 mPowerKeyHandled = true;
919 } else {
920 mBeganFromNonInteractive = true;
921 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700922 }
923 }
Jeff Brown4d396052010-10-29 21:50:21 -0700924 }
925 }
926
Jeff Brown13f00f02014-10-31 14:45:50 -0700927 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
928 final boolean handled = canceled || mPowerKeyHandled;
929 mScreenshotChordPowerKeyTriggered = false;
930 cancelPendingScreenshotChordAction();
931 cancelPendingPowerKeyAction();
932
933 if (!handled) {
934 // Figure out how to handle the key now that it has been released.
935 mPowerKeyPressCounter += 1;
936
937 final int maxCount = getMaxMultiPressPowerCount();
938 final long eventTime = event.getDownTime();
939 if (mPowerKeyPressCounter < maxCount) {
940 // This could be a multi-press. Wait a little bit longer to confirm.
941 // Continue holding the wake lock.
942 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
943 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
944 msg.setAsynchronous(true);
945 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
946 return;
947 }
948
949 // No other actions. Handle it immediately.
950 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700951 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700952
953 // Done. Reset our state.
954 finishPowerKeyPress();
955 }
956
957 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800958 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700959 mPowerKeyPressCounter = 0;
960 if (mPowerKeyWakeLock.isHeld()) {
961 mPowerKeyWakeLock.release();
962 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700963 }
964
965 private void cancelPendingPowerKeyAction() {
966 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700967 mPowerKeyHandled = true;
968 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700969 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700970 }
971
972 private void powerPress(long eventTime, boolean interactive, int count) {
973 if (mScreenOnEarly && !mScreenOnFully) {
974 Slog.i(TAG, "Suppressed redundant power key press while "
975 + "already in the process of turning the screen on.");
976 return;
Jeff Brownff204712011-10-25 21:27:54 -0700977 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700978
979 if (count == 2) {
980 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
981 } else if (count == 3) {
982 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -0800983 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700984 switch (mShortPressOnPowerBehavior) {
985 case SHORT_PRESS_POWER_NOTHING:
986 break;
987 case SHORT_PRESS_POWER_GO_TO_SLEEP:
988 mPowerManager.goToSleep(eventTime,
989 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
990 break;
991 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
992 mPowerManager.goToSleep(eventTime,
993 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
994 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
995 break;
996 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
997 mPowerManager.goToSleep(eventTime,
998 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
999 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1000 launchHomeFromHotKey();
1001 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001002 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001003 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001004 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001005 }
1006 }
1007 }
1008
1009 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1010 switch (behavior) {
1011 case MULTI_PRESS_POWER_NOTHING:
1012 break;
1013 case MULTI_PRESS_POWER_THEATER_MODE:
1014 if (isTheaterModeEnabled()) {
1015 Slog.i(TAG, "Toggling theater mode off.");
1016 Settings.Global.putInt(mContext.getContentResolver(),
1017 Settings.Global.THEATER_MODE_ON, 0);
1018 if (!interactive) {
1019 wakeUpFromPowerKey(eventTime);
1020 }
1021 } else {
1022 Slog.i(TAG, "Toggling theater mode on.");
1023 Settings.Global.putInt(mContext.getContentResolver(),
1024 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001025
1026 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001027 mPowerManager.goToSleep(eventTime,
1028 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1029 }
1030 }
1031 break;
1032 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001033 Slog.i(TAG, "Starting brightness boost.");
1034 if (!interactive) {
1035 wakeUpFromPowerKey(eventTime);
1036 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001037 mPowerManager.boostScreenBrightness(eventTime);
1038 break;
1039 }
1040 }
1041
1042 private int getMaxMultiPressPowerCount() {
1043 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1044 return 3;
1045 }
1046 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1047 return 2;
1048 }
1049 return 1;
1050 }
1051
1052 private void powerLongPress() {
1053 final int behavior = getResolvedLongPressOnPowerBehavior();
1054 switch (behavior) {
1055 case LONG_PRESS_POWER_NOTHING:
1056 break;
1057 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1058 mPowerKeyHandled = true;
1059 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1060 performAuditoryFeedbackForAccessibilityIfNeed();
1061 }
1062 showGlobalActionsInternal();
1063 break;
1064 case LONG_PRESS_POWER_SHUT_OFF:
1065 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1066 mPowerKeyHandled = true;
1067 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1068 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1069 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1070 break;
1071 }
1072 }
1073
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001074 private void sleepPress(KeyEvent event) {
1075 switch (mShortPressOnSleepBehavior) {
1076 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
1077 mPowerManager.goToSleep(event.getEventTime(),
1078 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1079 break;
1080 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001081 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001082 mPowerManager.goToSleep(event.getEventTime(),
1083 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1084 break;
1085 }
1086 }
1087
Jeff Brown13f00f02014-10-31 14:45:50 -07001088 private int getResolvedLongPressOnPowerBehavior() {
1089 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1090 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1091 }
1092 return mLongPressOnPowerBehavior;
1093 }
1094
1095 private boolean hasLongPressOnPowerBehavior() {
1096 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001097 }
1098
1099 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001100 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001101 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1102 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001103 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001104 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1105 && now <= mScreenshotChordPowerKeyTime
1106 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1107 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001108 cancelPendingPowerKeyAction();
1109
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001110 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001111 }
1112 }
1113 }
1114
Winson Chung1cea2f32012-10-08 20:42:01 -07001115 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001116 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001117 // Double the time it takes to take a screenshot from the keyguard
1118 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001119 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001120 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001121 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001122 }
1123
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001124 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001125 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001126 }
1127
Jeff Brown13f00f02014-10-31 14:45:50 -07001128 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001129 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001130 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001131 mEndCallKeyHandled = true;
1132 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1133 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001134 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001135 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001136 }
1137 };
1138
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001139 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001140 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001141 public void run() {
1142 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001143 }
1144 };
1145
Alan Viverettee34560b22014-07-10 14:50:06 -07001146 @Override
1147 public void showGlobalActions() {
1148 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1149 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1150 }
1151
1152 void showGlobalActionsInternal() {
1153 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001154 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001155 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001156 }
Jim Millerab954542014-10-10 18:21:49 -07001157 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001158 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1159 if (keyguardShowing) {
1160 // since it took two seconds of long press to bring this up,
1161 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001162 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001163 }
1164 }
1165
1166 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001167 return Settings.Global.getInt(
1168 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001169 }
1170
Maurice Lam99c6e072014-04-28 18:24:28 -07001171 boolean isUserSetupComplete() {
1172 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1173 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1174 }
1175
Jeff Brown13f00f02014-10-31 14:45:50 -07001176 private void handleShortPressOnHome() {
1177 // If there's a dream running then use home to escape the dream
1178 // but don't actually go home.
1179 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1180 mDreamManagerInternal.stopDream(false /*immediate*/);
1181 return;
1182 }
1183
1184 // Go home!
1185 launchHomeFromHotKey();
1186 }
1187
Patrick Dubroyece94522011-02-23 18:35:01 -08001188 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -08001189 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001190 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001191 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001192
Jeff Browncaca8812013-05-09 13:34:33 -07001193 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1194 toggleRecentApps();
1195 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1196 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -07001197 }
1198 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001199 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001200
Jeff Browncaca8812013-05-09 13:34:33 -07001201 private void handleDoubleTapOnHome() {
1202 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1203 mHomeConsumed = true;
1204 toggleRecentApps();
1205 }
1206 }
1207
1208 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1209 @Override
1210 public void run() {
1211 if (mHomeDoubleTapPending) {
1212 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001213 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001214 }
1215 }
1216 };
1217
Mark Renoufc1256912015-03-11 14:38:23 -04001218 private boolean isRoundWindow() {
1219 return mContext.getResources().getBoolean(com.android.internal.R.bool.config_windowIsRound)
1220 || (Build.HARDWARE.contains("goldfish")
1221 && SystemProperties.getBoolean(ViewRootImpl.PROPERTY_EMULATOR_CIRCULAR, false));
1222 }
1223
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001224 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001225 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001226 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001227 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001228 mContext = context;
1229 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001230 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001231 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001232 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001233 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Mark Renoufc1256912015-03-11 14:38:23 -04001234
1235 // Init display burn-in protection
1236 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1237 com.android.internal.R.bool.config_enableBurnInProtection);
1238 // Allow a system property to override this. Used by developer settings.
1239 boolean burnInProtectionDevMode =
1240 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1241 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1242 final int minHorizontal;
1243 final int maxHorizontal;
1244 final int minVertical;
1245 final int maxVertical;
1246 final int maxRadius;
1247 if (burnInProtectionDevMode) {
1248 minHorizontal = -8;
1249 maxHorizontal = 8;
1250 minVertical = -8;
1251 maxVertical = -4;
1252 maxRadius = (isRoundWindow()) ? 6 : -1;
1253 } else {
1254 Resources resources = context.getResources();
1255 minHorizontal = resources.getInteger(
1256 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1257 maxHorizontal = resources.getInteger(
1258 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1259 minVertical = resources.getInteger(
1260 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1261 maxVertical = resources.getInteger(
1262 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1263 maxRadius = resources.getInteger(
1264 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1265 }
1266 mBurnInProtectionHelper = new BurnInProtectionHelper(
1267 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001268 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001269
Jeff Brown70825162012-03-28 17:27:48 -07001270 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001271 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001272 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001273 try {
1274 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1275 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001276 mSettingsObserver = new SettingsObserver(mHandler);
1277 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001278 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001279 mUiMode = context.getResources().getInteger(
1280 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001281 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1282 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1283 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1284 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001285 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1286 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1287 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1288 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1289 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1290 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1291 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1292 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001293
Jeff Brown96307042012-07-27 15:51:34 -07001294 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1295 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001296 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001297 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1298 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001299 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001300 mSupportAutoRotation = mContext.getResources().getBoolean(
1301 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001302 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001303 com.android.internal.R.integer.config_lidOpenRotation);
1304 mCarDockRotation = readRotation(
1305 com.android.internal.R.integer.config_carDockRotation);
1306 mDeskDockRotation = readRotation(
1307 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001308 mUndockedHdmiRotation = readRotation(
1309 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001310 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1311 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1312 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1313 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001314 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1315 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1316 mLidNavigationAccessibility = mContext.getResources().getInteger(
1317 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001318 mLidControlsSleep = mContext.getResources().getBoolean(
1319 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001320 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1321 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001322
1323 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1324 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1325 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1326 || mContext.getResources().getBoolean(
1327 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1328 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1329 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001330 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1331 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001332 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1333 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1334 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1335 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1336 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1337 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1338
Bryce Lee55e846d2014-11-04 12:43:44 -08001339 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1340 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1341
Bryce Leed3b28402015-03-09 15:49:13 +00001342 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1343 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1344
Jeff Brown13f00f02014-10-31 14:45:50 -07001345 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1346 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1347 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1348 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1349 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1350 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1351 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1352 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001353 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1354 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001355
John Spurlock61560172015-02-06 19:46:04 -05001356 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001357
Jeff Brownf71343d2013-05-31 17:59:11 -07001358 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001359
Svetoslav8e3feb12014-02-24 13:46:47 -08001360 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1361 Context.ACCESSIBILITY_SERVICE);
1362
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001363 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001364 IntentFilter filter = new IntentFilter();
1365 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1366 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1367 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1368 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001369 filter.addAction(Intent.ACTION_DOCK_EVENT);
1370 Intent intent = context.registerReceiver(mDockReceiver, filter);
1371 if (intent != null) {
1372 // Retrieve current sticky dock event broadcast.
1373 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1374 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1375 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001376
Jeff Brown6aaf2952012-10-05 16:01:08 -07001377 // register for dream-related broadcasts
1378 filter = new IntentFilter();
1379 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1380 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1381 context.registerReceiver(mDreamReceiver, filter);
1382
Christopher Tate5e08af02012-09-21 17:17:22 -07001383 // register for multiuser-relevant broadcasts
1384 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1385 context.registerReceiver(mMultiuserReceiver, filter);
1386
John Spurlock57306e62013-04-22 09:48:49 -04001387 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001388 mSystemGestures = new SystemGesturesPointerEventListener(context,
1389 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001390 @Override
1391 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001392 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001393 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001394 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001395 }
1396 @Override
1397 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001398 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001399 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001400 }
1401 }
1402 @Override
1403 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001404 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001405 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001406 }
1407 }
1408 @Override
1409 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001410 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001411 }
Adrian Roos3595be42015-03-05 16:31:15 +01001412 @Override
1413 public void onDown() {
1414 mOrientationListener.onTouchStart();
1415 }
1416 @Override
1417 public void onUpOrCancel() {
1418 mOrientationListener.onTouchEnd();
1419 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001420 });
John Spurlockf1a36642013-10-12 17:50:42 -04001421 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001422 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001423
Jeff Brownc2346132012-04-13 01:55:38 -07001424 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001425 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1426 com.android.internal.R.array.config_longPressVibePattern);
1427 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1428 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001429 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1430 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001431 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1432 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001433 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1434 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001435 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1436 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1437 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1438 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001439
Christopher Tatee90585f2012-03-05 18:56:25 -08001440 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1441 com.android.internal.R.bool.config_enableScreenshotChord);
1442
Justin Kohd378ad72013-04-01 12:18:26 -07001443 mGlobalKeyManager = new GlobalKeyManager(mContext);
1444
Joe Onoratoea495d42011-04-06 11:41:11 -07001445 // Controls rotation and the like.
1446 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001447
1448 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001449 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001450 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001451 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001452
1453 mWindowManagerInternal.registerAppTransitionListener(
1454 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001455 }
1456
Jeff Brownf71343d2013-05-31 17:59:11 -07001457 /**
1458 * Read values from config.xml that may be overridden depending on
1459 * the configuration of the device.
1460 * eg. Disable long press on home goes to recents on sw600dp.
1461 */
1462 private void readConfigurationDependentBehaviors() {
1463 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1464 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1465 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1466 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1467 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1468 }
1469
1470 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1471 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1472 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1473 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1474 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1475 }
1476 }
1477
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001478 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001479 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001480 // This method might be called before the policy has been fully initialized
1481 // or for other displays we don't care about.
1482 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1483 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001484 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001485 mDisplay = display;
1486
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001487 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001488 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001489 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001490 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001491 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001492 mLandscapeRotation = Surface.ROTATION_0;
1493 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001494 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001495 mPortraitRotation = Surface.ROTATION_90;
1496 mUpsideDownRotation = Surface.ROTATION_270;
1497 } else {
1498 mPortraitRotation = Surface.ROTATION_270;
1499 mUpsideDownRotation = Surface.ROTATION_90;
1500 }
1501 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001502 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001503 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001504 mPortraitRotation = Surface.ROTATION_0;
1505 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001506 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001507 mLandscapeRotation = Surface.ROTATION_270;
1508 mSeascapeRotation = Surface.ROTATION_90;
1509 } else {
1510 mLandscapeRotation = Surface.ROTATION_90;
1511 mSeascapeRotation = Surface.ROTATION_270;
1512 }
1513 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001514
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001515 mStatusBarHeight =
1516 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001517
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001518 // Height of the navigation bar when presented horizontally at bottom
1519 mNavigationBarHeightForRotation[mPortraitRotation] =
1520 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001521 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001522 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001523 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1524 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001525
1526 // Width of the navigation bar when presented vertically along one side
1527 mNavigationBarWidthForRotation[mPortraitRotation] =
1528 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1529 mNavigationBarWidthForRotation[mLandscapeRotation] =
1530 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001531 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001532
1533 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001534 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001535 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001536
Devin Kimd7b12b42014-05-05 14:34:58 -07001537 // Allow the navigation bar to move on non-square small devices (phones).
1538 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001539
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001540 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001541 // Allow a system property to override this. Used by the emulator.
1542 // See also hasNavigationBar().
1543 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1544 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001545 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001546 } else if ("0".equals(navBarOverride)) {
1547 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001548 }
1549
Jeff Brown27f1d672012-10-17 18:32:34 -07001550 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1551 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001552 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001553 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001554 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001555 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001556 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001557 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001558
Chong Zhangae6119ff2014-11-11 18:54:39 -08001559 // For demo purposes, allow the rotation of the remote display to be controlled.
1560 // By default, remote display locks rotation to landscape.
1561 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1562 mDemoRotation = mPortraitRotation;
1563 } else {
1564 mDemoRotation = mLandscapeRotation;
1565 }
1566 mDemoRotationLock = SystemProperties.getBoolean(
1567 "persist.demo.rotationlock", false);
1568
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001569 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1570 // http://developer.android.com/guide/practices/screens_support.html#range
1571 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1572 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1573 // For debug purposes the next line turns this feature off with:
1574 // $ adb shell setprop config.override_forced_orient true
1575 // $ adb shell wm size reset
1576 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1577 }
1578
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001579 /**
1580 * @return whether the navigation bar can be hidden, e.g. the device has a
1581 * navigation bar and touch exploration is not enabled
1582 */
1583 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001584 return mHasNavigationBar
1585 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001586 }
1587
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001588 @Override
1589 public boolean isDefaultOrientationForced() {
1590 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001591 }
1592
Dianne Hackbornc652de82013-02-15 16:32:56 -08001593 @Override
1594 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1595 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1596 mOverscanLeft = left;
1597 mOverscanTop = top;
1598 mOverscanRight = right;
1599 mOverscanBottom = bottom;
1600 }
1601 }
1602
Dianne Hackbornc777e072010-02-12 13:07:59 -08001603 public void updateSettings() {
1604 ContentResolver resolver = mContext.getContentResolver();
1605 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001606 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001607 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001608 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001609 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1610 UserHandle.USER_CURRENT);
1611 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001612 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001613 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1614 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001615
Jeff Browna20dda42014-05-27 20:57:24 -07001616 // Configure wake gesture.
1617 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1618 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1619 UserHandle.USER_CURRENT) != 0;
1620 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1621 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1622 updateWakeGestureListenerLp();
1623 }
1624
Jeff Brown207673cd2012-06-05 17:47:11 -07001625 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001626 int userRotation = Settings.System.getIntForUser(resolver,
1627 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1628 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001629 if (mUserRotation != userRotation) {
1630 mUserRotation = userRotation;
1631 updateRotation = true;
1632 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001633 int userRotationMode = Settings.System.getIntForUser(resolver,
1634 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001635 WindowManagerPolicy.USER_ROTATION_FREE :
1636 WindowManagerPolicy.USER_ROTATION_LOCKED;
1637 if (mUserRotationMode != userRotationMode) {
1638 mUserRotationMode = userRotationMode;
1639 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001640 updateOrientationListenerLp();
1641 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001642
Dianne Hackbornc777e072010-02-12 13:07:59 -08001643 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001644 int pointerLocation = Settings.System.getIntForUser(resolver,
1645 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001646 if (mPointerLocationMode != pointerLocation) {
1647 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001648 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1649 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001650 }
1651 }
1652 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001653 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1654 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1655 String imId = Settings.Secure.getStringForUser(resolver,
1656 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001657 boolean hasSoftInput = imId != null && imId.length() > 0;
1658 if (mHasSoftInput != hasSoftInput) {
1659 mHasSoftInput = hasSoftInput;
1660 updateRotation = true;
1661 }
John Spurlockf1a36642013-10-12 17:50:42 -04001662 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001663 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001664 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001665 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001666 }
1667 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001668 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001669 }
Jeff Brown70825162012-03-28 17:27:48 -07001670 }
1671
Jeff Browna20dda42014-05-27 20:57:24 -07001672 private void updateWakeGestureListenerLp() {
1673 if (shouldEnableWakeGestureLp()) {
1674 mWakeGestureListener.requestWakeUpTrigger();
1675 } else {
1676 mWakeGestureListener.cancelWakeUpTrigger();
1677 }
1678 }
1679
1680 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001681 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001682 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1683 && mWakeGestureListener.isSupported();
1684 }
1685
Jeff Brown70825162012-03-28 17:27:48 -07001686 private void enablePointerLocation() {
1687 if (mPointerLocationView == null) {
1688 mPointerLocationView = new PointerLocationView(mContext);
1689 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001690 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1691 WindowManager.LayoutParams.MATCH_PARENT,
1692 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001693 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001694 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1695 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1696 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1697 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001698 if (ActivityManager.isHighEndGfx()) {
1699 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1700 lp.privateFlags |=
1701 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1702 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001703 lp.format = PixelFormat.TRANSLUCENT;
1704 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001705 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001706 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001707 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001708 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001709 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001710 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001711 }
Jeff Brown70825162012-03-28 17:27:48 -07001712
1713 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001714 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001715 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1716 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001717 wm.removeView(mPointerLocationView);
1718 mPointerLocationView = null;
1719 }
1720 }
1721
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001722 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001723 try {
1724 int rotation = mContext.getResources().getInteger(resID);
1725 switch (rotation) {
1726 case 0:
1727 return Surface.ROTATION_0;
1728 case 90:
1729 return Surface.ROTATION_90;
1730 case 180:
1731 return Surface.ROTATION_180;
1732 case 270:
1733 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001734 }
1735 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001736 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001737 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001738 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001739 }
1740
1741 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001742 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001743 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001744 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001745
1746 outAppOp[0] = AppOpsManager.OP_NONE;
1747
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001748 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1749 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1750 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1751 return WindowManagerGlobal.ADD_INVALID_TYPE;
1752 }
1753
1754 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1755 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001756 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001757 }
1758 String permission = null;
1759 switch (type) {
1760 case TYPE_TOAST:
1761 // XXX right now the app process has complete control over
1762 // this... should introduce a token to let the system
1763 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001764 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001765 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001766 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001767 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001768 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001769 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001770 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001771 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001772 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001773 break;
1774 case TYPE_PHONE:
1775 case TYPE_PRIORITY_PHONE:
1776 case TYPE_SYSTEM_ALERT:
1777 case TYPE_SYSTEM_ERROR:
1778 case TYPE_SYSTEM_OVERLAY:
1779 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001780 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001781 break;
1782 default:
1783 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1784 }
1785 if (permission != null) {
1786 if (mContext.checkCallingOrSelfPermission(permission)
1787 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001788 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001789 }
1790 }
Jeff Brown98365d72012-08-19 20:30:52 -07001791 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001792 }
Craig Mautner88400d32012-09-30 12:35:45 -07001793
1794 @Override
1795 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1796
1797 // If this switch statement is modified, modify the comment in the declarations of
1798 // the type in {@link WindowManager.LayoutParams} as well.
1799 switch (attrs.type) {
1800 default:
1801 // These are the windows that by default are shown only to the user that created
1802 // them. If this needs to be overridden, set
1803 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1804 // {@link WindowManager.LayoutParams}. Note that permission
1805 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1806 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1807 return true;
1808 }
1809 break;
1810
1811 // These are the windows that by default are shown to all users. However, to
1812 // protect against spoofing, check permissions below.
1813 case TYPE_APPLICATION_STARTING:
1814 case TYPE_BOOT_PROGRESS:
1815 case TYPE_DISPLAY_OVERLAY:
1816 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001817 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001818 case TYPE_KEYGUARD_DIALOG:
1819 case TYPE_MAGNIFICATION_OVERLAY:
1820 case TYPE_NAVIGATION_BAR:
1821 case TYPE_NAVIGATION_BAR_PANEL:
1822 case TYPE_PHONE:
1823 case TYPE_POINTER:
1824 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001825 case TYPE_SEARCH_BAR:
1826 case TYPE_STATUS_BAR:
1827 case TYPE_STATUS_BAR_PANEL:
1828 case TYPE_STATUS_BAR_SUB_PANEL:
1829 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001830 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001831 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001832 break;
1833 }
1834
1835 // Check if third party app has set window to system window type.
1836 return mContext.checkCallingOrSelfPermission(
1837 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1838 != PackageManager.PERMISSION_GRANTED;
1839 }
1840
Craig Mautner967212c2013-04-13 21:10:58 -07001841 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001842 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1843 switch (attrs.type) {
1844 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001845 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001846 // These types of windows can't receive input events.
1847 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1848 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001849 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001850 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001851 case TYPE_STATUS_BAR:
1852
1853 // If the Keyguard is in a hidden state (occluded by another window), we force to
1854 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1855 // the keyguard as occluded wouldn't set these flags again.
1856 // See {@link #processKeyguardSetHiddenResultLw}.
1857 if (mKeyguardHidden) {
1858 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1859 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1860 }
1861 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001862 }
Adrian Roos38502112014-04-09 21:04:11 +02001863
1864 if (attrs.type != TYPE_STATUS_BAR) {
1865 // The status bar is the only window allowed to exhibit keyguard behavior.
1866 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1867 }
Adrian Roosea562512014-05-05 13:33:03 +02001868
1869 if (ActivityManager.isHighEndGfx()
1870 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001871 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001872 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1873 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001874 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001875
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001876 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001877 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001878 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001879
Michael Wright3818c922014-09-02 13:59:07 -07001880 private void readCameraLensCoverState() {
1881 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1882 }
1883
Jeff Browndaa37532012-05-01 15:54:03 -07001884 private boolean isHidden(int accessibilityMode) {
1885 switch (accessibilityMode) {
1886 case 1:
1887 return mLidState == LID_CLOSED;
1888 case 2:
1889 return mLidState == LID_OPEN;
1890 default:
1891 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001892 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001893 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001894
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001895 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001896 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001897 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1898 int navigationPresence) {
1899 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1900
Jeff Brownf71343d2013-05-31 17:59:11 -07001901 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001902 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001903 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001904
Jeff Browndaa37532012-05-01 15:54:03 -07001905 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1906 || (keyboardPresence == PRESENCE_INTERNAL
1907 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001908 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001909 if (!mHasSoftInput) {
1910 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1911 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001912 }
1913
Jeff Browndaa37532012-05-01 15:54:03 -07001914 if (config.navigation == Configuration.NAVIGATION_NONAV
1915 || (navigationPresence == PRESENCE_INTERNAL
1916 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001917 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001918 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001919 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001920
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001921 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001922 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001923 public int windowTypeToLayerLw(int type) {
1924 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001925 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001926 }
1927 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001928 case TYPE_PRIVATE_PRESENTATION:
1929 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001930 case TYPE_WALLPAPER:
1931 // wallpaper is at the bottom, though the window manager may move it.
1932 return 2;
1933 case TYPE_PHONE:
1934 return 3;
1935 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07001936 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001937 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001938 case TYPE_VOICE_INTERACTION:
1939 // voice interaction layer is almost immediately above apps.
1940 return 5;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001941 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001942 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001943 case TYPE_TOAST:
1944 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001945 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001946 case TYPE_PRIORITY_PHONE:
1947 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001948 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001949 case TYPE_DREAM:
1950 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001951 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001952 case TYPE_SYSTEM_ALERT:
1953 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001954 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001955 case TYPE_INPUT_METHOD:
1956 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001957 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001958 case TYPE_INPUT_METHOD_DIALOG:
1959 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001960 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001961 case TYPE_KEYGUARD_SCRIM:
1962 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001963 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001964 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001965 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001966 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001967 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001968 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001969 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001970 case TYPE_KEYGUARD_DIALOG:
1971 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001972 case TYPE_VOLUME_OVERLAY:
1973 // the on-screen volume indicator and controller shown when the user
1974 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001975 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001976 case TYPE_SYSTEM_OVERLAY:
1977 // the on-screen volume indicator and controller shown when the user
1978 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001979 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001980 case TYPE_NAVIGATION_BAR:
1981 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001982 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001983 case TYPE_NAVIGATION_BAR_PANEL:
1984 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001985 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001986 case TYPE_SYSTEM_ERROR:
1987 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001988 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001989 case TYPE_MAGNIFICATION_OVERLAY:
1990 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001991 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001992 case TYPE_DISPLAY_OVERLAY:
1993 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001994 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001995 case TYPE_DRAG:
1996 // the drag layer: input for drag-and-drop is associated with this window,
1997 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001998 return 25;
Svetoslav3a5c7212014-10-14 09:54:26 -07001999 case TYPE_ACCESSIBILITY_OVERLAY:
2000 // overlay put by accessibility services to intercept user interaction
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002001 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002002 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002003 return 27;
Svetoslav3a5c7212014-10-14 09:54:26 -07002004 case TYPE_BOOT_PROGRESS:
2005 return 28;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002006 case TYPE_POINTER:
2007 // the (mouse) pointer layer
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002008 return 29;
Svetoslav3a5c7212014-10-14 09:54:26 -07002009 case TYPE_HIDDEN_NAV_CONSUMER:
2010 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002011 }
2012 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002013 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002014 }
2015
2016 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002017 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002018 public int subWindowTypeToLayerLw(int type) {
2019 switch (type) {
2020 case TYPE_APPLICATION_PANEL:
2021 case TYPE_APPLICATION_ATTACHED_DIALOG:
2022 return APPLICATION_PANEL_SUBLAYER;
2023 case TYPE_APPLICATION_MEDIA:
2024 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002025 case TYPE_APPLICATION_MEDIA_OVERLAY:
2026 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002027 case TYPE_APPLICATION_SUB_PANEL:
2028 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002029 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2030 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002031 }
2032 Log.e(TAG, "Unknown sub-window type: " + type);
2033 return 0;
2034 }
2035
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002036 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002037 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002038 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002039 }
2040
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002041 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002042 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002043 if (mHasNavigationBar) {
2044 // For a basic navigation bar, when we are in landscape mode we place
2045 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002046 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2047 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002048 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002049 }
2050 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002051 }
2052
Jose Lima9546b202014-07-02 17:21:51 -07002053 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002054 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002055 if (mHasNavigationBar) {
2056 // For a basic navigation bar, when we are in portrait mode we place
2057 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002058 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2059 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002060 }
2061 }
2062 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002063 }
2064
Jose Lima9546b202014-07-02 17:21:51 -07002065 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002066 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2067 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002068 }
2069
Jose Lima9546b202014-07-02 17:21:51 -07002070 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002071 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002072 // There is a separate status bar at the top of the display. We don't count that as part
2073 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002074 // we do want to exclude it since applications can't generally use that part
2075 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002076 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002077 }
2078
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002079 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002080 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2081 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002082 (isKeyguardHostWindow(attrs) &&
2083 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002084 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002085 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002086
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002087 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002088 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2089 return attrs.type == TYPE_STATUS_BAR;
2090 }
2091
2092 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002093 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002094 switch (attrs.type) {
2095 case TYPE_STATUS_BAR:
2096 case TYPE_NAVIGATION_BAR:
2097 case TYPE_WALLPAPER:
2098 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002099 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002100 return false;
2101 default:
2102 return true;
2103 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002104 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002105
Craig Mautner7d7808f2014-09-11 18:02:38 -07002106 @Override
2107 public WindowState getWinShowWhenLockedLw() {
2108 return mWinShowWhenLocked;
2109 }
2110
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002111 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002112 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002113 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2114 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002115 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002116 if (!SHOW_STARTING_ANIMATIONS) {
2117 return null;
2118 }
2119 if (packageName == null) {
2120 return null;
2121 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002122
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002123 WindowManager wm = null;
2124 View view = null;
2125
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002126 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002127 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002128 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2129 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2130 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002131 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002132 try {
2133 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002134 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002135 } catch (PackageManager.NameNotFoundException e) {
2136 // Ignore
2137 }
2138 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002139
Jorim Jaggib10e33f2015-02-04 21:57:40 +01002140 Window win = new PhoneWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002141 final TypedArray ta = win.getWindowStyle();
2142 if (ta.getBoolean(
2143 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2144 || ta.getBoolean(
2145 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002146 return null;
2147 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002148
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002149 Resources r = context.getResources();
2150 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002151
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002152 win.setType(
2153 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
2154 // Force the window flags: this is a fake window, so it is not really
2155 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2156 // flag because we do know that the next window will take input
2157 // focus, so we want to get the IME window up on top of us right away.
2158 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002159 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002160 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2161 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2162 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002163 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002164 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2165 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2166 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002167
Adam Powell04fe6eb2013-05-31 14:39:48 -07002168 win.setDefaultIcon(icon);
2169 win.setDefaultLogo(logo);
2170
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002171 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002172 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002173
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002174 final WindowManager.LayoutParams params = win.getAttributes();
2175 params.token = appToken;
2176 params.packageName = packageName;
2177 params.windowAnimations = win.getWindowStyle().getResourceId(
2178 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002179 params.privateFlags |=
2180 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002181 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002182
2183 if (!compatInfo.supportsScreen()) {
2184 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2185 }
2186
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002187 params.setTitle("Starting " + packageName);
2188
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002189 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2190 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002191
2192 if (win.isFloating()) {
2193 // Whoops, there is no way to display an animation/preview
2194 // of such a thing! After all that work... let's skip it.
2195 // (Note that we must do this here because it is in
2196 // getDecorView() where the theme is evaluated... maybe
2197 // we should peek the floating attribute from the theme
2198 // earlier.)
2199 return null;
2200 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002201
Craig Mautner6fbda632012-07-03 09:26:39 -07002202 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002203 TAG, "Adding starting window for " + packageName
2204 + " / " + appToken + ": "
2205 + (view.getParent() != null ? view : null));
2206
2207 wm.addView(view, params);
2208
2209 // Only return the view if it was successfully added to the
2210 // window manager... which we can tell by it having a parent.
2211 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002212 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002213 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002214 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2215 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002216 } catch (RuntimeException e) {
2217 // don't crash if something else bad happens, for example a
2218 // failure loading resources because we are loading from an app
2219 // on external storage that has been unmounted.
2220 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002221 } finally {
2222 if (view != null && view.getParent() == null) {
2223 Log.w(TAG, "view not successfully added to wm, removing view");
2224 wm.removeViewImmediate(view);
2225 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002226 }
2227
2228 return null;
2229 }
2230
2231 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002232 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002233 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002234 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2235 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002236
2237 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002238 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002239 wm.removeView(window);
2240 }
2241 }
2242
2243 /**
2244 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002245 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002246 * Currently enforces that three window types are singletons:
2247 * <ul>
2248 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002249 * <li>KEYGUARD_TYPE</li>
2250 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002251 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002252 * @param win The window to be added
2253 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002254 *
Jeff Brown98365d72012-08-19 20:30:52 -07002255 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2256 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002257 */
Jose Lima9546b202014-07-02 17:21:51 -07002258 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002259 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2260 switch (attrs.type) {
2261 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002262 mContext.enforceCallingOrSelfPermission(
2263 android.Manifest.permission.STATUS_BAR_SERVICE,
2264 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002265 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002266 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002267 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002268 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002269 }
2270 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002271 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002272 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002273 case TYPE_NAVIGATION_BAR:
2274 mContext.enforceCallingOrSelfPermission(
2275 android.Manifest.permission.STATUS_BAR_SERVICE,
2276 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002277 if (mNavigationBar != null) {
2278 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002279 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002280 }
2281 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002282 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002283 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002284 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002285 break;
Jim Millere898ac52012-04-06 17:10:57 -07002286 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002287 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002288 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002289 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002290 mContext.enforceCallingOrSelfPermission(
2291 android.Manifest.permission.STATUS_BAR_SERVICE,
2292 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002293 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002294 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002295 if (mKeyguardScrim != null) {
2296 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2297 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002298 mKeyguardScrim = win;
2299 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002300 }
Jeff Brown98365d72012-08-19 20:30:52 -07002301 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002302 }
2303
2304 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002305 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002306 public void removeWindowLw(WindowState win) {
2307 if (mStatusBar == win) {
2308 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002309 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002310 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002311 } else if (mKeyguardScrim == win) {
2312 Log.v(TAG, "Removing keyguard scrim");
2313 mKeyguardScrim = null;
2314 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002315 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002316 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002317 }
2318 }
2319
2320 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002321
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002322 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002323 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002324 public int selectAnimationLw(WindowState win, int transit) {
2325 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2326 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002327 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002328 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002329 if (transit == TRANSIT_EXIT
2330 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002331 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002332 } else if (transit == TRANSIT_ENTER
2333 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002334 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002335 }
2336 } else if (win == mNavigationBar) {
2337 // This can be on either the bottom or the right.
2338 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002339 if (transit == TRANSIT_EXIT
2340 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002341 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002342 } else if (transit == TRANSIT_ENTER
2343 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002344 return R.anim.dock_bottom_enter;
2345 }
2346 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002347 if (transit == TRANSIT_EXIT
2348 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002349 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002350 } else if (transit == TRANSIT_ENTER
2351 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002352 return R.anim.dock_right_enter;
2353 }
2354 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002355 }
2356
2357 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002358 if (win.hasAppShownWindows()) {
2359 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2360 return com.android.internal.R.anim.app_starting_exit;
2361 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002362 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002363 && transit == TRANSIT_ENTER) {
2364 // Special case: we are animating in a dream, while the keyguard
2365 // is shown. We don't want an animation on the dream, because
2366 // we need it shown immediately with the keyguard animating away
2367 // to reveal it.
2368 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002369 }
2370
2371 return 0;
2372 }
2373
Craig Mautner3c174372013-02-21 17:54:37 -08002374 @Override
2375 public void selectRotationAnimationLw(int anim[]) {
2376 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2377 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2378 + (mTopFullscreenOpaqueWindowState == null ?
2379 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2380 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2381 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2382 case ROTATION_ANIMATION_CROSSFADE:
2383 anim[0] = R.anim.rotation_animation_xfade_exit;
2384 anim[1] = R.anim.rotation_animation_enter;
2385 break;
2386 case ROTATION_ANIMATION_JUMPCUT:
2387 anim[0] = R.anim.rotation_animation_jump_exit;
2388 anim[1] = R.anim.rotation_animation_enter;
2389 break;
2390 case ROTATION_ANIMATION_ROTATE:
2391 default:
2392 anim[0] = anim[1] = 0;
2393 break;
2394 }
2395 } else {
2396 anim[0] = anim[1] = 0;
2397 }
2398 }
2399
2400 @Override
2401 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2402 boolean forceDefault) {
2403 switch (exitAnimId) {
2404 case R.anim.rotation_animation_xfade_exit:
2405 case R.anim.rotation_animation_jump_exit:
2406 // These are the only cases that matter.
2407 if (forceDefault) {
2408 return false;
2409 }
2410 int anim[] = new int[2];
2411 selectRotationAnimationLw(anim);
2412 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2413 default:
2414 return true;
2415 }
2416 }
2417
2418 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002419 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2420 boolean goingToNotificationShade) {
2421 if (goingToNotificationShade) {
2422 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002423 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002424
2425 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2426 R.anim.lock_screen_behind_enter_wallpaper :
2427 R.anim.lock_screen_behind_enter);
2428
2429 // TODO: Use XML interpolators when we have log interpolators available in XML.
2430 final List<Animation> animations = set.getAnimations();
2431 for (int i = animations.size() - 1; i >= 0; --i) {
2432 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2433 }
2434
2435 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002436 }
2437
2438
2439 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002440 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2441 if (goingToNotificationShade) {
2442 return null;
2443 } else {
2444 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2445 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002446 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002447
2448 private static void awakenDreams() {
2449 IDreamManager dreamManager = getDreamManager();
2450 if (dreamManager != null) {
2451 try {
2452 dreamManager.awaken();
2453 } catch (RemoteException e) {
2454 // fine, stay asleep then
2455 }
2456 }
2457 }
2458
2459 static IDreamManager getDreamManager() {
2460 return IDreamManager.Stub.asInterface(
2461 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2462 }
2463
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002464 TelecomManager getTelecommService() {
2465 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002466 }
2467
Jeff Brown4d396052010-10-29 21:50:21 -07002468 static IAudioService getAudioService() {
2469 IAudioService audioService = IAudioService.Stub.asInterface(
2470 ServiceManager.checkService(Context.AUDIO_SERVICE));
2471 if (audioService == null) {
2472 Log.w(TAG, "Unable to find IAudioService interface.");
2473 }
2474 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002475 }
2476
2477 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002478 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002479 }
2480
2481 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2482 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2483 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2484 };
2485
2486 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002487 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002488 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002489 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002490 final int keyCode = event.getKeyCode();
2491 final int repeatCount = event.getRepeatCount();
2492 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002493 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002494 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2495 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002496
Jeff Brown40013652012-05-16 21:22:36 -07002497 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002498 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002499 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2500 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002501 }
2502
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002503 // If we think we might have a volume down & power key chord on the way
2504 // but we're not sure, then tell the dispatcher to wait a little while and
2505 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002506 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002507 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002508 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002509 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2510 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002511 if (now < timeoutTime) {
2512 return timeoutTime - now;
2513 }
2514 }
2515 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002516 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002517 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002518 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002519 }
2520 return -1;
2521 }
2522 }
2523
Michael Wright6a62e552014-06-03 19:19:48 -07002524 // Cancel any pending meta actions if we see any other keys being pressed between the down
2525 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002526 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002527 mPendingMetaAction = false;
2528 }
2529
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002530 // First we always handle the home key here, so applications
2531 // can never break it, although if keyguard is on, we do let
2532 // it handle it, because that gives us the correct 5 second
2533 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002534 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002535
Jeff Brown49ed71d2010-12-06 17:13:33 -08002536 // If we have released the home key, and didn't do anything else
2537 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002538 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002539 cancelPreloadRecentApps();
2540
Jeff Brown49ed71d2010-12-06 17:13:33 -08002541 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002542 if (mHomeConsumed) {
2543 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002544 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002545 }
Jeff Browncaca8812013-05-09 13:34:33 -07002546
2547 if (canceled) {
2548 Log.i(TAG, "Ignoring HOME; event canceled.");
2549 return -1;
2550 }
2551
Yorke Lee4f803242014-12-15 23:22:06 +00002552 // If an incoming call is ringing, HOME is totally disabled.
2553 // (The user is already on the InCallUI at this point,
2554 // and his ONLY options are to answer or reject the call.)
2555 TelecomManager telecomManager = getTelecommService();
2556 if (telecomManager != null && telecomManager.isRinging()) {
2557 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2558 return -1;
2559 }
2560
Jeff Browncaca8812013-05-09 13:34:33 -07002561 // Delay handling home if a double-tap is possible.
2562 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2563 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2564 mHomeDoubleTapPending = true;
2565 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2566 ViewConfiguration.getDoubleTapTimeout());
2567 return -1;
2568 }
2569
Jeff Brown13f00f02014-10-31 14:45:50 -07002570 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002571 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002572 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002573
2574 // If a system window has focus, then it doesn't make sense
2575 // right now to interact with applications.
2576 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2577 if (attrs != null) {
2578 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002579 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2580 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2581 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002582 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002583 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002584 }
2585 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2586 for (int i=0; i<typeCount; i++) {
2587 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2588 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002589 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002590 }
2591 }
2592 }
Jeff Browncaca8812013-05-09 13:34:33 -07002593
2594 // Remember that home is pressed and handle special actions.
2595 if (repeatCount == 0) {
2596 mHomePressed = true;
2597 if (mHomeDoubleTapPending) {
2598 mHomeDoubleTapPending = false;
2599 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2600 handleDoubleTapOnHome();
2601 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2602 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2603 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002604 }
Jeff Browncaca8812013-05-09 13:34:33 -07002605 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2606 if (!keyguardOn) {
2607 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002608 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002609 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002610 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002611 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002612 // Hijack modified menu keys for debugging features
2613 final int chordBug = KeyEvent.META_SHIFT_ON;
2614
2615 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002616 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002617 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002618 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2619 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002620 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002621 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002622 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002623 Intent service = new Intent();
2624 service.setClassName(mContext, "com.android.server.LoadAverageService");
2625 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002626 boolean shown = Settings.Global.getInt(
2627 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002628 if (!shown) {
2629 mContext.startService(service);
2630 } else {
2631 mContext.stopService(service);
2632 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002633 Settings.Global.putInt(
2634 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002635 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002636 }
2637 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002638 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002639 if (down) {
2640 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002641 mSearchKeyShortcutPending = true;
2642 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002643 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002644 } else {
2645 mSearchKeyShortcutPending = false;
2646 if (mConsumeSearchKeyUp) {
2647 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002648 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002649 }
2650 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002651 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002652 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002653 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002654 if (down && repeatCount == 0) {
2655 preloadRecentApps();
2656 } else if (!down) {
2657 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002658 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002659 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002660 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002661 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2662 if (down) {
2663 if (repeatCount == 0) {
2664 mAssistKeyLongPressed = false;
2665 } else if (repeatCount == 1) {
2666 mAssistKeyLongPressed = true;
2667 if (!keyguardOn) {
2668 launchAssistLongPressAction();
2669 }
2670 }
2671 } else {
2672 if (mAssistKeyLongPressed) {
2673 mAssistKeyLongPressed = false;
2674 } else {
2675 if (!keyguardOn) {
2676 launchAssistAction();
2677 }
2678 }
2679 }
2680 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002681 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2682 if (!down) {
2683 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002684 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002685 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2686 } else {
2687 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002688 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002689 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002690 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002691 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002692 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2693 if (down && repeatCount == 0) {
2694 mHandler.post(mScreenshotRunnable);
2695 }
2696 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002697 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2698 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2699 if (down) {
2700 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2701
2702 // Disable autobrightness if it's on
2703 int auto = Settings.System.getIntForUser(
2704 mContext.getContentResolver(),
2705 Settings.System.SCREEN_BRIGHTNESS_MODE,
2706 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2707 UserHandle.USER_CURRENT_OR_SELF);
2708 if (auto != 0) {
2709 Settings.System.putIntForUser(mContext.getContentResolver(),
2710 Settings.System.SCREEN_BRIGHTNESS_MODE,
2711 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2712 UserHandle.USER_CURRENT_OR_SELF);
2713 }
2714
2715 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2716 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2717 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2718 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2719 Settings.System.SCREEN_BRIGHTNESS,
2720 mPowerManager.getDefaultScreenBrightnessSetting(),
2721 UserHandle.USER_CURRENT_OR_SELF);
2722 brightness += step;
2723 // Make sure we don't go beyond the limits.
2724 brightness = Math.min(max, brightness);
2725 brightness = Math.max(min, brightness);
2726
2727 Settings.System.putIntForUser(mContext.getContentResolver(),
2728 Settings.System.SCREEN_BRIGHTNESS, brightness,
2729 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002730 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002731 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002732 }
2733 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002734 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002735 if (down) {
2736 mPendingMetaAction = true;
2737 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002738 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002739 }
2740 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002741 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002742
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002743 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002744 // Any printing key that is chorded with Search should be consumed
2745 // even if no shortcut was invoked. This prevents text from being
2746 // inadvertently inserted when using a keyboard that has built-in macro
2747 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002748 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002749 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2750 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002751 mConsumeSearchKeyUp = true;
2752 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002753 if (down && repeatCount == 0 && !keyguardOn) {
2754 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2755 if (shortcutIntent != null) {
2756 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002757 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002758 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002759 } catch (ActivityNotFoundException ex) {
2760 Slog.w(TAG, "Dropping shortcut key combination because "
2761 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002762 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002763 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002764 } else {
2765 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002766 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002767 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002768 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002769 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002770 }
2771 }
2772
Jeff Brown68b909d2011-12-07 16:36:01 -08002773 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002774 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002775 && (metaState & KeyEvent.META_META_ON) != 0) {
2776 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002777 if (kcm.isPrintingKey(keyCode)) {
2778 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2779 metaState & ~(KeyEvent.META_META_ON
2780 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2781 if (shortcutIntent != null) {
2782 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2783 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002784 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002785 } catch (ActivityNotFoundException ex) {
2786 Slog.w(TAG, "Dropping shortcut key combination because "
2787 + "the activity to which it is registered was not found: "
2788 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2789 }
2790 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002791 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002792 }
2793 }
2794
Jeff Brown6651a632011-11-28 12:59:11 -08002795 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002796 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002797 String category = sApplicationLaunchKeyCategories.get(keyCode);
2798 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002799 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002800 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2801 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002802 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002803 } catch (ActivityNotFoundException ex) {
2804 Slog.w(TAG, "Dropping application launch key because "
2805 + "the activity to which it is registered was not found: "
2806 + "keyCode=" + keyCode + ", category=" + category, ex);
2807 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002808 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002809 }
2810 }
2811
Michael Wright61c46752014-08-21 16:57:33 -07002812 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002813 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002814 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002815 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002816 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002817 mRecentAppsHeldModifiers = shiftlessModifiers;
2818 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002819 return -1;
2820 }
2821 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002822 } else if (!down && mRecentAppsHeldModifiers != 0
2823 && (metaState & mRecentAppsHeldModifiers) == 0) {
2824 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002825 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002826 }
2827
Jeff Browncf39bdf2012-05-18 14:41:19 -07002828 // Handle keyboard language switching.
2829 if (down && repeatCount == 0
2830 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2831 || (keyCode == KeyEvent.KEYCODE_SPACE
2832 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2833 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2834 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2835 return -1;
2836 }
2837 if (mLanguageSwitchKeyPressed && !down
2838 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2839 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2840 mLanguageSwitchKeyPressed = false;
2841 return -1;
2842 }
2843
Jeff Brown13f00f02014-10-31 14:45:50 -07002844 if (isValidGlobalKey(keyCode)
2845 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002846 return -1;
2847 }
2848
Michael Wright6a62e552014-06-03 19:19:48 -07002849 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002850 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002851 return -1;
2852 }
2853
Jeff Brown68b909d2011-12-07 16:36:01 -08002854 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002855 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002856 }
2857
Jeff Brown3915bb82010-11-05 15:02:16 -07002858 /** {@inheritDoc} */
2859 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002860 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002861 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002862 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002863 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2864 + ", flags=" + event.getFlags()
2865 + ", keyCode=" + event.getKeyCode()
2866 + ", scanCode=" + event.getScanCode()
2867 + ", metaState=" + event.getMetaState()
2868 + ", repeatCount=" + event.getRepeatCount()
2869 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002870 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002871
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002872 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002873 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2874 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002875 final int keyCode = event.getKeyCode();
2876 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002877 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2878 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002879
Jeff Brown54875002011-04-06 15:33:01 -07002880 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002881 final FallbackAction fallbackAction;
2882 if (initialDown) {
2883 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2884 } else {
2885 fallbackAction = mFallbackActions.get(keyCode);
2886 }
2887
2888 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002889 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002890 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2891 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002892 }
2893
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002894 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2895 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002896 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002897 event.getAction(), fallbackAction.keyCode,
2898 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002899 event.getDeviceId(), event.getScanCode(),
2900 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002901
2902 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2903 fallbackEvent.recycle();
2904 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002905 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002906
2907 if (initialDown) {
2908 mFallbackActions.put(keyCode, fallbackAction);
2909 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2910 mFallbackActions.remove(keyCode);
2911 fallbackAction.recycle();
2912 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002913 }
2914 }
2915
Jeff Brown40013652012-05-16 21:22:36 -07002916 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002917 if (fallbackEvent == null) {
2918 Slog.d(TAG, "No fallback.");
2919 } else {
2920 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2921 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002922 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002923 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002924 }
2925
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002926 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002927 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002928 if ((actions & ACTION_PASS_TO_USER) != 0) {
2929 long delayMillis = interceptKeyBeforeDispatching(
2930 win, fallbackEvent, policyFlags);
2931 if (delayMillis == 0) {
2932 return true;
2933 }
2934 }
2935 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002936 }
2937
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002938 private void launchAssistLongPressAction() {
2939 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2940 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2941
2942 // launch the search activity
2943 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2944 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2945 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002946 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002947 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002948 SearchManager searchManager = getSearchManager();
2949 if (searchManager != null) {
2950 searchManager.stopSearch();
2951 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002952 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002953 } catch (ActivityNotFoundException e) {
2954 Slog.w(TAG, "No activity to handle assist long press action.", e);
2955 }
2956 }
2957
2958 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002959 launchAssistAction(null);
2960 }
2961
2962 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002963 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002964 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002965 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002966 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002967 if (hint != null) {
2968 intent.putExtra(hint, true);
2969 }
Jim Miller45308b12012-06-18 19:23:39 -07002970 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2971 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2972 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2973 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002974 startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002975 } catch (ActivityNotFoundException e) {
2976 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002977 }
2978 }
2979 }
2980
Bart Sears8b1c27c2015-03-18 23:51:02 +00002981 private void startActivityAsUser(Intent intent, UserHandle handle) {
2982 if (isUserSetupComplete()) {
2983 mContext.startActivityAsUser(intent, handle);
2984 } else {
2985 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
2986 }
2987 }
2988
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002989 private SearchManager getSearchManager() {
2990 if (mSearchManager == null) {
2991 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2992 }
2993 return mSearchManager;
2994 }
2995
Jeff Browncaca8812013-05-09 13:34:33 -07002996 private void preloadRecentApps() {
2997 mPreloadedRecentApps = true;
2998 try {
2999 IStatusBarService statusbar = getStatusBarService();
3000 if (statusbar != null) {
3001 statusbar.preloadRecentApps();
3002 }
3003 } catch (RemoteException e) {
3004 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3005 // re-acquire status bar service next time it is needed.
3006 mStatusBarService = null;
3007 }
3008 }
3009
3010 private void cancelPreloadRecentApps() {
3011 if (mPreloadedRecentApps) {
3012 mPreloadedRecentApps = false;
3013 try {
3014 IStatusBarService statusbar = getStatusBarService();
3015 if (statusbar != null) {
3016 statusbar.cancelPreloadRecentApps();
3017 }
3018 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003019 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003020 // re-acquire status bar service next time it is needed.
3021 mStatusBarService = null;
3022 }
3023 }
3024 }
3025
3026 private void toggleRecentApps() {
3027 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003028 try {
3029 IStatusBarService statusbar = getStatusBarService();
3030 if (statusbar != null) {
3031 statusbar.toggleRecentApps();
3032 }
3033 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003034 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3035 // re-acquire status bar service next time it is needed.
3036 mStatusBarService = null;
3037 }
3038 }
3039
Craig Mautner84984fa2014-06-19 11:19:20 -07003040 @Override
3041 public void showRecentApps() {
3042 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3043 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3044 }
3045
Winson Chung1e8d71b2014-05-16 17:05:22 -07003046 private void showRecentApps(boolean triggeredFromAltTab) {
3047 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3048 try {
3049 IStatusBarService statusbar = getStatusBarService();
3050 if (statusbar != null) {
3051 statusbar.showRecentApps(triggeredFromAltTab);
3052 }
3053 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003054 Slog.e(TAG, "RemoteException when showing recent apps", e);
3055 // re-acquire status bar service next time it is needed.
3056 mStatusBarService = null;
3057 }
3058 }
3059
Winson Chungcdcd4872014-08-05 18:00:13 -07003060 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003061 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3062 try {
3063 IStatusBarService statusbar = getStatusBarService();
3064 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003065 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003066 }
3067 } catch (RemoteException e) {
3068 Slog.e(TAG, "RemoteException when closing recent apps", e);
3069 // re-acquire status bar service next time it is needed.
3070 mStatusBarService = null;
3071 }
3072 }
3073
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003074 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003075 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003076 }
3077
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003078 /**
3079 * A home key -> launch home action was detected. Take the appropriate action
3080 * given the situation with the keyguard.
3081 */
Bryce Lee662ed802015-04-10 20:11:39 +00003082 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3083 if (respectKeyguard) {
3084 if (isKeyguardShowingAndNotOccluded()) {
3085 // don't launch home if keyguard showing
3086 return;
3087 }
3088
3089 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3090 // when in keyguard restricted mode, must first verify unlock
3091 // before launching home
3092 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3093 @Override
3094 public void onKeyguardExitResult(boolean success) {
3095 if (success) {
3096 try {
3097 ActivityManagerNative.getDefault().stopAppSwitches();
3098 } catch (RemoteException e) {
3099 }
3100 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3101 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003102 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003103 }
Bryce Lee662ed802015-04-10 20:11:39 +00003104 });
3105 return;
3106 }
3107 }
3108
3109 // no keyguard stuff to worry about, just launch home!
3110 try {
3111 ActivityManagerNative.getDefault().stopAppSwitches();
3112 } catch (RemoteException e) {
3113 }
3114 if (mRecentsVisible) {
3115 // Hide Recents and notify it to launch Home
3116 if (awakenFromDreams) {
3117 awakenDreams();
3118 }
3119 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3120 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003121 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003122 // Otherwise, just launch Home
3123 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3124 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003125 }
3126 }
3127
John Spurlock04db1762013-05-13 12:46:41 -04003128 private final Runnable mClearHideNavigationFlag = new Runnable() {
3129 @Override
3130 public void run() {
3131 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3132 // Clear flags.
3133 mForceClearedSystemUiFlags &=
3134 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3135 }
3136 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003137 }
3138 };
3139
3140 /**
3141 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3142 * to determine when the nav bar should be shown and prevent applications from
3143 * receiving those touches.
3144 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003145 final class HideNavInputEventReceiver extends InputEventReceiver {
3146 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3147 super(inputChannel, looper);
3148 }
3149
Dianne Hackborndf89e652011-10-06 22:35:11 -07003150 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003151 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003152 boolean handled = false;
3153 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003154 if (event instanceof MotionEvent
3155 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3156 final MotionEvent motionEvent = (MotionEvent)event;
3157 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003158 // When the user taps down, we re-show the nav bar.
3159 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003160 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003161 // Any user activity always causes us to show the
3162 // navigation controls, if they had been hidden.
3163 // We also clear the low profile and only content
3164 // flags so that tapping on the screen will atomically
3165 // restore all currently hidden screen decorations.
3166 int newVal = mResettingSystemUiFlags |
3167 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3168 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3169 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003170 if (mResettingSystemUiFlags != newVal) {
3171 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003172 changed = true;
3173 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003174 // We don't allow the system's nav bar to be hidden
3175 // again for 1 second, to prevent applications from
3176 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003177 newVal = mForceClearedSystemUiFlags |
3178 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003179 if (mForceClearedSystemUiFlags != newVal) {
3180 mForceClearedSystemUiFlags = newVal;
3181 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003182 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003183 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003184 }
3185 if (changed) {
3186 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3187 }
3188 }
3189 }
3190 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003191 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003192 }
3193 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003194 }
3195 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3196 new InputEventReceiver.Factory() {
3197 @Override
3198 public InputEventReceiver createInputEventReceiver(
3199 InputChannel inputChannel, Looper looper) {
3200 return new HideNavInputEventReceiver(inputChannel, looper);
3201 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003202 };
3203
3204 @Override
3205 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003206 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3207 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003208 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003209
Dianne Hackborndf89e652011-10-06 22:35:11 -07003210 // Reset any bits in mForceClearingStatusBarVisibility that
3211 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003212 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003213 // Clear any bits in the new visibility that are currently being
3214 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003215 return visibility & ~mResettingSystemUiFlags
3216 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003217 }
3218
Craig Mautner69b08182012-09-05 13:07:13 -07003219 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003220 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3221 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003222 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003223 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3224 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003225
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003226 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003227 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003228 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003229 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003230 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003231 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3232 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3233 } else {
3234 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3235 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3236 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003237 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3238 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003239 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003240 availRight - mStableFullscreenRight,
3241 availBottom - mStableFullscreenBottom);
3242 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003243 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003244 availRight - mStableRight, availBottom - mStableBottom);
3245 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003246 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003247 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003248 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003249 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003250 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003251 availRight - mCurRight, availBottom - mCurBottom);
3252 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003253 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003254 availRight - mCurRight, availBottom - mCurBottom);
3255 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003256
3257 outStableInsets.set(mStableLeft, mStableTop,
3258 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003259 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003260 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003261 outContentInsets.setEmpty();
3262 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003263 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003264
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003265 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003266 @Override
3267 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3268 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003269 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3270 if (isDefaultDisplay) {
3271 switch (displayRotation) {
3272 case Surface.ROTATION_90:
3273 overscanLeft = mOverscanTop;
3274 overscanTop = mOverscanRight;
3275 overscanRight = mOverscanBottom;
3276 overscanBottom = mOverscanLeft;
3277 break;
3278 case Surface.ROTATION_180:
3279 overscanLeft = mOverscanRight;
3280 overscanTop = mOverscanBottom;
3281 overscanRight = mOverscanLeft;
3282 overscanBottom = mOverscanTop;
3283 break;
3284 case Surface.ROTATION_270:
3285 overscanLeft = mOverscanBottom;
3286 overscanTop = mOverscanLeft;
3287 overscanRight = mOverscanTop;
3288 overscanBottom = mOverscanRight;
3289 break;
3290 default:
3291 overscanLeft = mOverscanLeft;
3292 overscanTop = mOverscanTop;
3293 overscanRight = mOverscanRight;
3294 overscanBottom = mOverscanBottom;
3295 break;
3296 }
3297 } else {
3298 overscanLeft = 0;
3299 overscanTop = 0;
3300 overscanRight = 0;
3301 overscanBottom = 0;
3302 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003303 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3304 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3305 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3306 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003307 mSystemLeft = 0;
3308 mSystemTop = 0;
3309 mSystemRight = displayWidth;
3310 mSystemBottom = displayHeight;
3311 mUnrestrictedScreenLeft = overscanLeft;
3312 mUnrestrictedScreenTop = overscanTop;
3313 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3314 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3315 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3316 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003317 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3318 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003319 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003320 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003321 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003322 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003323 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003324 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003325 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003326 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003327 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003328 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003329
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003330 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3331 final Rect pf = mTmpParentFrame;
3332 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003333 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003334 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003335 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003336 pf.left = df.left = of.left = vf.left = mDockLeft;
3337 pf.top = df.top = of.top = vf.top = mDockTop;
3338 pf.right = df.right = of.right = vf.right = mDockRight;
3339 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003340 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003341
Craig Mautner69b08182012-09-05 13:07:13 -07003342 if (isDefaultDisplay) {
3343 // For purposes of putting out fake window up to steal focus, we will
3344 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003345 final int sysui = mLastSystemUiFlags;
3346 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003347 boolean navTranslucent = (sysui
3348 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003349 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3350 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3351 boolean navAllowedHidden = immersive || immersiveSticky;
3352 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003353 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3354 if (!isKeyguardShowing) {
3355 navTranslucent &= areTranslucentBarsAllowed();
3356 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003357
Craig Mautner69b08182012-09-05 13:07:13 -07003358 // When the navigation bar isn't visible, we put up a fake
3359 // input window to catch all touch events. This way we can
3360 // detect when the user presses anywhere to bring back the nav
3361 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003362 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07003363 if (mHideNavFakeWindow != null) {
3364 mHideNavFakeWindow.dismiss();
3365 mHideNavFakeWindow = null;
3366 }
3367 } else if (mHideNavFakeWindow == null) {
3368 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
3369 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07003370 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07003371 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003372 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003373
Craig Mautner69b08182012-09-05 13:07:13 -07003374 // For purposes of positioning and showing the nav bar, if we have
3375 // decided that it can't be hidden (because of the screen aspect ratio),
3376 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003377 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003378
John Spurlockad3e6cb2013-04-30 08:47:43 -04003379 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003380 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003381 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003382 // Force the navigation bar to its appropriate place and
3383 // size. We need to do this directly, instead of relying on
3384 // it to bubble up from the nav bar, because this needs to
3385 // change atomically with screen rotations.
3386 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3387 if (mNavigationBarOnBottom) {
3388 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003389 int top = displayHeight - overscanBottom
3390 - mNavigationBarHeightForRotation[displayRotation];
3391 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003392 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003393 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003394 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003395 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003396 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003397 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003398 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3399 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003400 } else {
3401 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003402 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003403 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003404 if (navVisible && !navTranslucent && !navAllowedHidden
3405 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003406 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003407 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003408 // and not in the process of animating on or off, then
3409 // we can tell the app that it is covered by it.
3410 mSystemBottom = mTmpNavigationFrame.top;
3411 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003412 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003413 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003414 int left = displayWidth - overscanRight
3415 - mNavigationBarWidthForRotation[displayRotation];
3416 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003417 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003418 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003419 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003420 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003421 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003422 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003423 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3424 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003425 } else {
3426 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003427 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003428 }
John Spurlockbd957402013-10-03 11:38:39 -04003429 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3430 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003431 // If the nav bar is currently requested to be visible,
3432 // and not in the process of animating on or off, then
3433 // we can tell the app that it is covered by it.
3434 mSystemRight = mTmpNavigationFrame.left;
3435 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003436 }
Craig Mautner69b08182012-09-05 13:07:13 -07003437 // Make sure the content and current rectangles are updated to
3438 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003439 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3440 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3441 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3442 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003443 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3444 // And compute the final frame.
3445 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003446 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3447 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003448 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003449 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003450 updateSysUiVisibility = true;
3451 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003452 }
Craig Mautnereda67292013-04-28 13:50:14 -07003453 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003454 mDockLeft, mDockTop, mDockRight, mDockBottom));
3455
3456 // decide where the status bar goes ahead of time
3457 if (mStatusBar != null) {
3458 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003459 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3460 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3461 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3462 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3463 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003464 vf.left = mStableLeft;
3465 vf.top = mStableTop;
3466 vf.right = mStableRight;
3467 vf.bottom = mStableBottom;
3468
3469 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3470
3471 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003472 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003473
3474 // For layout, the status bar is always at the top with our fixed height.
3475 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3476
John Spurlocke1f366f2013-08-05 12:22:40 -04003477 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003478 boolean statusBarTranslucent = (sysui
3479 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003480 if (!isKeyguardShowing) {
3481 statusBarTranslucent &= areTranslucentBarsAllowed();
3482 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003483
Craig Mautner69b08182012-09-05 13:07:13 -07003484 // If the status bar is hidden, we don't want to cause
3485 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003486 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003487 // Status bar may go away, so the screen area it occupies
3488 // is available to apps but just covering them when the
3489 // status bar is visible.
3490 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3491
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003492 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3493 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3494 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3495 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003496
Craig Mautnereda67292013-04-28 13:50:14 -07003497 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003498 String.format(
3499 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3500 mDockLeft, mDockTop, mDockRight, mDockBottom,
3501 mContentLeft, mContentTop, mContentRight, mContentBottom,
3502 mCurLeft, mCurTop, mCurRight, mCurBottom));
3503 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003504 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003505 && !statusBarTransient && !statusBarTranslucent
3506 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003507 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003508 // and not in the process of animating on or off, then
3509 // we can tell the app that it is covered by it.
3510 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3511 }
John Spurlock27735a42013-08-14 17:57:38 -04003512 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003513 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003514 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003515 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003516 if (updateSysUiVisibility) {
3517 updateSystemUiVisibilityLw();
3518 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003519 }
3520 }
3521
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003522 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003523 @Override
John Spurlock46646232013-09-30 22:32:42 -04003524 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003525 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3526 return mStatusBar.getSurfaceLayer();
3527 }
3528
3529 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3530 return mNavigationBar.getSurfaceLayer();
3531 }
3532
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003533 return 0;
3534 }
3535
Craig Mautner967212c2013-04-13 21:10:58 -07003536 @Override
3537 public void getContentRectLw(Rect r) {
3538 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3539 }
3540
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003541 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3542 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003543 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3544 // Here's a special case: if this attached window is a panel that is
3545 // above the dock window, and the window it is attached to is below
3546 // the dock window, then the frames we computed for the window it is
3547 // attached to can not be used because the dock is effectively part
3548 // of the underlying window and the attached window is floating on top
3549 // of the whole thing. So, we ignore the attached window and explicitly
3550 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003551 df.left = of.left = cf.left = vf.left = mDockLeft;
3552 df.top = of.top = cf.top = vf.top = mDockTop;
3553 df.right = of.right = cf.right = vf.right = mDockRight;
3554 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003555 } else {
3556 // The effective display frame of the attached window depends on
3557 // whether it is taking care of insetting its content. If not,
3558 // we need to use the parent's content frame so that the entire
3559 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003560 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003561 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003562 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003563 // Set the content frame of the attached window to the parent's decor frame
3564 // (same as content frame when IME isn't present) if specifically requested by
3565 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3566 // Otherwise, use the overscan frame.
3567 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3568 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003569 } else {
3570 // If the window is resizing, then we want to base the content
3571 // frame on our attached content frame to resize... however,
3572 // things can be tricky if the attached window is NOT in resize
3573 // mode, in which case its content frame will be larger.
3574 // Ungh. So to deal with that, make sure the content frame
3575 // we end up using is not covering the IM dock.
3576 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003577 if (attached.isVoiceInteraction()) {
3578 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3579 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3580 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3581 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3582 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003583 if (cf.left < mContentLeft) cf.left = mContentLeft;
3584 if (cf.top < mContentTop) cf.top = mContentTop;
3585 if (cf.right > mContentRight) cf.right = mContentRight;
3586 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3587 }
3588 }
3589 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003590 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003591 vf.set(attached.getVisibleFrameLw());
3592 }
3593 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3594 // window should be positioned relative to its parent or the entire
3595 // screen.
3596 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3597 ? attached.getFrameLw() : df);
3598 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003599
3600 private void applyStableConstraints(int sysui, int fl, Rect r) {
3601 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3602 // If app is requesting a stable layout, don't let the
3603 // content insets go below the stable values.
3604 if ((fl & FLAG_FULLSCREEN) != 0) {
3605 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3606 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3607 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3608 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3609 } else {
3610 if (r.left < mStableLeft) r.left = mStableLeft;
3611 if (r.top < mStableTop) r.top = mStableTop;
3612 if (r.right > mStableRight) r.right = mStableRight;
3613 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3614 }
3615 }
3616 }
3617
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003618 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003619 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003620 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003621 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003622 final WindowManager.LayoutParams attrs = win.getAttrs();
3623 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3624 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003625 return;
3626 }
Craig Mautner69b08182012-09-05 13:07:13 -07003627 final boolean isDefaultDisplay = win.isDefaultDisplay();
3628 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003629 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3630 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003631 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003632 offsetInputMethodWindowLw(mLastInputMethodWindow);
3633 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003634
John Spurlockc6d1c602014-01-17 15:22:06 -05003635 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003636 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003637 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003638
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003639 final Rect pf = mTmpParentFrame;
3640 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003641 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003642 final Rect cf = mTmpContentFrame;
3643 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003644 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003645 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003646 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003647
3648 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003649 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003650
Craig Mautnerf683b562012-10-02 11:10:57 -07003651 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3652
Adrian Roosfa104232014-06-20 16:10:14 -07003653 if (isDefaultDisplay) {
3654 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3655 } else {
3656 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3657 }
3658
Craig Mautner69b08182012-09-05 13:07:13 -07003659 if (!isDefaultDisplay) {
3660 if (attached != null) {
3661 // If this window is attached to another, our display
3662 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003663 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003664 } else {
3665 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003666 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3667 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3668 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003669 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003670 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003671 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003672 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003673 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003674 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3675 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3676 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003677 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003678 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003679 // ...with content insets above the nav bar
3680 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003681 // IM dock windows always go to the bottom of the screen.
3682 attrs.gravity = Gravity.BOTTOM;
3683 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003684 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
3685 pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft;
3686 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3687 pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft
3688 + mUnrestrictedScreenWidth;
3689 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3690 + mUnrestrictedScreenHeight;
3691 cf.bottom = vf.bottom = mStableBottom;
3692 cf.top = vf.top = mStableTop;
Jorim Jaggie0700182014-08-21 01:12:37 +02003693 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3694 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3695 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3696 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3697 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3698 cf.left = vf.left = mStableLeft;
3699 cf.top = vf.top = mStableTop;
3700 cf.right = vf.right = mStableRight;
3701 vf.bottom = mStableBottom;
3702 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003703 } else {
John Spurlock46646232013-09-30 22:32:42 -04003704
3705 // Default policy decor for the default display
3706 dcf.left = mSystemLeft;
3707 dcf.top = mSystemTop;
3708 dcf.right = mSystemRight;
3709 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003710 final boolean inheritTranslucentDecor = (attrs.privateFlags
3711 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003712 final boolean isAppWindow =
3713 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3714 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3715 final boolean topAtRest =
3716 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3717 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003718 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3719 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003720 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3721 && (fl & WindowManager.LayoutParams.
3722 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003723 // Ensure policy decor includes status bar
3724 dcf.top = mStableTop;
3725 }
John Spurlockbd957402013-10-03 11:38:39 -04003726 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003727 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3728 && (fl & WindowManager.LayoutParams.
3729 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003730 // Ensure policy decor includes navigation bar
3731 dcf.bottom = mStableBottom;
3732 dcf.right = mStableRight;
3733 }
3734 }
3735
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003736 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3737 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003738 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003739 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003740 // This is the case for a normal activity window: we want it
3741 // to cover all of the screen space, and it can take care of
3742 // moving its contents to account for screen decorations that
3743 // intrude into that space.
3744 if (attached != null) {
3745 // If this window is attached to another, our display
3746 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003747 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003748 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003749 if (attrs.type == TYPE_STATUS_BAR_PANEL
3750 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003751 // Status bar panels are the only windows who can go on top of
3752 // the status bar. They are protected by the STATUS_BAR_SERVICE
3753 // permission, so they have the same privileges as the status
3754 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003755 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003756 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003757
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003758 pf.left = df.left = of.left = hasNavBar
3759 ? mDockLeft : mUnrestrictedScreenLeft;
3760 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3761 pf.right = df.right = of.right = hasNavBar
3762 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3763 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3764 pf.bottom = df.bottom = of.bottom = hasNavBar
3765 ? mRestrictedScreenTop+mRestrictedScreenHeight
3766 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003767
Craig Mautnereda67292013-04-28 13:50:14 -07003768 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003769 "Laying out status bar window: (%d,%d - %d,%d)",
3770 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003771 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003772 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3773 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3774 // Asking to layout into the overscan region, so give it that pure
3775 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003776 pf.left = df.left = of.left = mOverscanScreenLeft;
3777 pf.top = df.top = of.top = mOverscanScreenTop;
3778 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3779 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3780 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003781 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003782 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003783 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3784 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003785 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003786 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003787 // only do this for application windows to ensure no window that
3788 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003789 pf.left = df.left = mOverscanScreenLeft;
3790 pf.top = df.top = mOverscanScreenTop;
3791 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3792 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003793 // We need to tell the app about where the frame inside the overscan
3794 // is, so it can inset its content by that amount -- it didn't ask
3795 // to actually extend itself into the overscan region.
3796 of.left = mUnrestrictedScreenLeft;
3797 of.top = mUnrestrictedScreenTop;
3798 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3799 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003800 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003801 pf.left = df.left = mRestrictedOverscanScreenLeft;
3802 pf.top = df.top = mRestrictedOverscanScreenTop;
3803 pf.right = df.right = mRestrictedOverscanScreenLeft
3804 + mRestrictedOverscanScreenWidth;
3805 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3806 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003807 // We need to tell the app about where the frame inside the overscan
3808 // is, so it can inset its content by that amount -- it didn't ask
3809 // to actually extend itself into the overscan region.
3810 of.left = mUnrestrictedScreenLeft;
3811 of.top = mUnrestrictedScreenTop;
3812 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3813 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003814 }
Craig Mautner69b08182012-09-05 13:07:13 -07003815
John Spurlock46646232013-09-30 22:32:42 -04003816 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003817 if (win.isVoiceInteraction()) {
3818 cf.left = mVoiceContentLeft;
3819 cf.top = mVoiceContentTop;
3820 cf.right = mVoiceContentRight;
3821 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003822 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003823 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3824 cf.left = mDockLeft;
3825 cf.top = mDockTop;
3826 cf.right = mDockRight;
3827 cf.bottom = mDockBottom;
3828 } else {
3829 cf.left = mContentLeft;
3830 cf.top = mContentTop;
3831 cf.right = mContentRight;
3832 cf.bottom = mContentBottom;
3833 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003834 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003835 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003836 // Full screen windows are always given a layout that is as if the
3837 // status bar and other transient decors are gone. This is to avoid
3838 // bad states when moving from a window that is not hding the
3839 // status bar to one that is.
3840 cf.left = mRestrictedScreenLeft;
3841 cf.top = mRestrictedScreenTop;
3842 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3843 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003844 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003845 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003846 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3847 vf.left = mCurLeft;
3848 vf.top = mCurTop;
3849 vf.right = mCurRight;
3850 vf.bottom = mCurBottom;
3851 } else {
3852 vf.set(cf);
3853 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003854 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003855 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3856 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3857 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003858 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3859 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003860 // A window that has requested to fill the entire screen just
3861 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003862 if (attrs.type == TYPE_STATUS_BAR_PANEL
3863 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003864 pf.left = df.left = of.left = cf.left = hasNavBar
3865 ? mDockLeft : mUnrestrictedScreenLeft;
3866 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3867 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003868 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003869 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003870 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003871 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003872 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003873 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003874 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3875 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003876 } else if (attrs.type == TYPE_NAVIGATION_BAR
3877 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003878 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003879 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3880 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3881 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3882 + mUnrestrictedScreenWidth;
3883 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3884 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003885 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003886 "Laying out navigation bar window: (%d,%d - %d,%d)",
3887 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003888 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3889 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003890 && ((fl & FLAG_FULLSCREEN) != 0)) {
3891 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003892 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3893 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3894 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3895 + mOverscanScreenWidth;
3896 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3897 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003898 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003899 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003900 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3901 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3902 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3903 + mOverscanScreenWidth;
3904 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3905 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003906 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003907 // The wallpaper also has Real Ultimate Power, but we want to tell
3908 // it about the overscan area.
3909 pf.left = df.left = mOverscanScreenLeft;
3910 pf.top = df.top = mOverscanScreenTop;
3911 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3912 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3913 of.left = cf.left = mUnrestrictedScreenLeft;
3914 of.top = cf.top = mUnrestrictedScreenTop;
3915 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3916 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003917 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003918 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3919 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3920 // Asking to layout into the overscan region, so give it that pure
3921 // unrestricted area.
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
Dianne Hackbornc652de82013-02-15 16:32:56 -08003925 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003926 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003927 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003928 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003929 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003930 && (attrs.type == TYPE_STATUS_BAR
3931 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07003932 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04003933 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3934 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003935 // Asking for layout as if the nav bar is hidden, lets the
3936 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003937 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003938 // can be above the nav bar can do this.
3939 // XXX This assumes that an app asking for this will also
3940 // ask for layout in only content. We can't currently figure out
3941 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003942 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3943 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3944 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3945 + mUnrestrictedScreenWidth;
3946 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3947 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003948 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003949 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3950 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3951 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3952 + mRestrictedScreenWidth;
3953 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3954 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003955 }
Craig Mautner69b08182012-09-05 13:07:13 -07003956
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003957 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003958
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003959 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3960 vf.left = mCurLeft;
3961 vf.top = mCurTop;
3962 vf.right = mCurRight;
3963 vf.bottom = mCurBottom;
3964 } else {
3965 vf.set(cf);
3966 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003967 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003968 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3969 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003970 // A child window should be placed inside of the same visible
3971 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003972 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003973 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003974 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3975 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003976 // Otherwise, a normal window must be placed inside the content
3977 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003978 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3979 // Status bar panels are the only windows who can go on top of
3980 // the status bar. They are protected by the STATUS_BAR_SERVICE
3981 // permission, so they have the same privileges as the status
3982 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003983 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3984 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3985 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3986 + mRestrictedScreenWidth;
3987 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3988 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003989 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3990 || attrs.type == TYPE_VOLUME_OVERLAY) {
3991 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003992 pf.left = df.left = of.left = cf.left = mStableLeft;
3993 pf.top = df.top = of.top = cf.top = mStableTop;
3994 pf.right = df.right = of.right = cf.right = mStableRight;
3995 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003996 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003997 pf.left = mContentLeft;
3998 pf.top = mContentTop;
3999 pf.right = mContentRight;
4000 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004001 if (win.isVoiceInteraction()) {
4002 df.left = of.left = cf.left = mVoiceContentLeft;
4003 df.top = of.top = cf.top = mVoiceContentTop;
4004 df.right = of.right = cf.right = mVoiceContentRight;
4005 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4006 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004007 df.left = of.left = cf.left = mDockLeft;
4008 df.top = of.top = cf.top = mDockTop;
4009 df.right = of.right = cf.right = mDockRight;
4010 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004011 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004012 df.left = of.left = cf.left = mContentLeft;
4013 df.top = of.top = cf.top = mContentTop;
4014 df.right = of.right = cf.right = mContentRight;
4015 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004016 }
4017 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4018 vf.left = mCurLeft;
4019 vf.top = mCurTop;
4020 vf.right = mCurRight;
4021 vf.bottom = mCurBottom;
4022 } else {
4023 vf.set(cf);
4024 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004025 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004026 }
4027 }
Craig Mautner69b08182012-09-05 13:07:13 -07004028
Craig Mautnerb816bed2013-07-23 10:26:17 -07004029 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4030 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004031 df.left = df.top = -10000;
4032 df.right = df.bottom = 10000;
4033 if (attrs.type != TYPE_WALLPAPER) {
4034 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4035 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4036 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004037 }
4038
Craig Mautnereda67292013-04-28 13:50:14 -07004039 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004040 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004041 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004042 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004043 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004044 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004045 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004046 + " dcf=" + dcf.toShortString()
4047 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07004048
Adrian Roosfa104232014-06-20 16:10:14 -07004049 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07004050
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004051 // Dock windows carve out the bottom of the screen, so normal windows
4052 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004053 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4054 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004055 setLastInputMethodWindowLw(null, null);
4056 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004057 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004058 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4059 && !win.getGivenInsetsPendingLw()) {
4060 offsetVoiceInputWindowLw(win);
4061 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004062 }
4063
satok1bc0a492012-04-25 22:47:12 +09004064 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004065 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004066 top += win.getGivenContentInsetsLw().top;
4067 if (mContentBottom > top) {
4068 mContentBottom = top;
4069 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004070 if (mVoiceContentBottom > top) {
4071 mVoiceContentBottom = top;
4072 }
satok1bc0a492012-04-25 22:47:12 +09004073 top = win.getVisibleFrameLw().top;
4074 top += win.getGivenVisibleInsetsLw().top;
4075 if (mCurBottom > top) {
4076 mCurBottom = top;
4077 }
Craig Mautnereda67292013-04-28 13:50:14 -07004078 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004079 + mDockBottom + " mContentBottom="
4080 + mContentBottom + " mCurBottom=" + mCurBottom);
4081 }
4082
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004083 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004084 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004085 top += win.getGivenContentInsetsLw().top;
4086 if (mVoiceContentBottom > top) {
4087 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004088 }
4089 }
4090
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004091 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004092 @Override
4093 public void finishLayoutLw() {
4094 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004095 }
4096
4097 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004098 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004099 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004100 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004101 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004102 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004103 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004104 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004105 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004106 mForcingShowNavBar = false;
4107 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004108
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004109 mHideLockScreen = false;
4110 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004111 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004112 mShowingLockscreen = false;
4113 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004114 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004115 mKeyguardSecure = isKeyguardSecure();
4116 mKeyguardSecureIncludingHidden = mKeyguardSecure
4117 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004118 }
4119
4120 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004121 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004122 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004123 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4124 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004125 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004126 if (mTopFullscreenOpaqueWindowState == null
4127 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4128 mForcingShowNavBar = true;
4129 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004130 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004131 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004132 mForceStatusBarFromKeyguard = true;
4133 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004134 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004135 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004136 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004137 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004138 mForceStatusBarFromKeyguard = true;
4139 } else {
4140 mForceStatusBar = true;
4141 }
4142 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004143 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004144 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004145 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004146 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Craig Mautner7d7808f2014-09-11 18:02:38 -07004147 && attrs.type < FIRST_SYSTEM_WINDOW;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004148 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004149 // If the lockscreen was showing when the dream started then wait
4150 // for the dream to draw before hiding the lockscreen.
4151 if (!mDreamingLockscreen
4152 || (win.isVisibleLw() && win.hasDrawnLw())) {
4153 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004154 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004155 }
4156 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004157
Craig Mautner00156ec2014-03-06 22:29:02 -08004158 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07004159 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerab55e522014-03-03 13:26:03 -08004160 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004161 final IApplicationToken appToken = win.getAppToken();
4162 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004163 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004164 mAppsToBeHidden.remove(appToken);
4165 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004166 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004167 if (dismissKeyguard && !mKeyguardSecure) {
4168 mAppsThatDismissKeyguard.add(appToken);
4169 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004170 mWinShowWhenLocked = win;
4171 mHideLockScreen = true;
4172 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004173 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004174 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004175 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004176 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004177 mAppsToBeHidden.add(appToken);
4178 } else {
4179 mAppsToBeHidden.remove(appToken);
4180 }
4181 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004182 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004183 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004184 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004185 if (attrs.x == 0 && attrs.y == 0
4186 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4187 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4188 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4189 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004190 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4191 mTopFullscreenOpaqueOrDimmingWindowState = win;
4192 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004193 if (!mAppsThatDismissKeyguard.isEmpty() &&
4194 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4195 if (DEBUG_LAYOUT) Slog.v(TAG,
4196 "Setting mDismissKeyguard true by win " + win);
4197 mDismissKeyguard = mWinDismissingKeyguard == win ?
4198 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
4199 mWinDismissingKeyguard = win;
Jim Millerab954542014-10-10 18:21:49 -07004200 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004201 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4202 if (DEBUG_LAYOUT) Slog.v(TAG,
4203 "Setting mHideLockScreen to true by win " + win);
4204 mHideLockScreen = true;
4205 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004206 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004207 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004208 mAllowLockscreenWhenOn = true;
4209 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004210 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004211
4212 if (mWinShowWhenLocked != null &&
4213 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
4214 win.hideLw(false);
4215 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004216 }
4217 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004218 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4219 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4220 && win.isDimming()) {
4221 mTopFullscreenOpaqueOrDimmingWindowState = win;
4222 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004223 }
4224
4225 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004226 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004227 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004228 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4229 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4230 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004231 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4232 // fullscreen window.
4233 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4234 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4235 mTopFullscreenOpaqueWindowState.hideLw(false);
4236 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4237 }
4238
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004239 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004240 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004241
4242 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4243 ? mTopFullscreenOpaqueWindowState.getAttrs()
4244 : null;
4245
Jeff Brownc8018eb2012-10-29 21:33:27 -07004246 // If we are not currently showing a dream then remember the current
4247 // lockscreen state. We will use this to determine whether the dream
4248 // started while the lockscreen was showing and remember this state
4249 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004250 if (!mShowingDream) {
4251 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004252 if (mDreamingSleepTokenNeeded) {
4253 mDreamingSleepTokenNeeded = false;
4254 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4255 }
4256 } else {
4257 if (!mDreamingSleepTokenNeeded) {
4258 mDreamingSleepTokenNeeded = true;
4259 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4260 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004261 }
4262
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004263 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004264 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004265 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004266 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004267 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07004268 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004269 if (mStatusBarController.setBarShowingLw(true)) {
4270 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4271 }
Craig Mautner81defc72013-10-29 11:10:42 -07004272 // Maintain fullscreen layout until incoming animation is complete.
4273 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004274 // Transient status bar on the lockscreen is not allowed
4275 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4276 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4277 mLastSystemUiFlags, mLastSystemUiFlags);
4278 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004279 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004280 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004281 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004282 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004283 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004284 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004285 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004286 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004287 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004288 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004289 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004290 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004291 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4292 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004293 if (mStatusBarController.isTransientShowing()) {
4294 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004295 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4296 }
4297 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004298 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004299 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004300 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004301 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004302 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004303 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004304 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004305 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004306 if (mStatusBarController.setBarShowingLw(true)) {
4307 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4308 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004309 }
4310 }
4311 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004312
Craig Mautner81defc72013-10-29 11:10:42 -07004313 if (mTopIsFullscreen != topIsFullscreen) {
4314 if (!topIsFullscreen) {
4315 // Force another layout when status bar becomes fully shown.
4316 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4317 }
4318 mTopIsFullscreen = topIsFullscreen;
4319 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004320
Craig Mautner39834192012-09-02 07:47:24 -07004321 // Hide the key guard if a visible window explicitly specifies that it wants to be
4322 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004323 if (mKeyguardDelegate != null && mStatusBar != null) {
4324 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4325 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004326 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004327 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004328 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004329 changes |= FINISH_LAYOUT_REDO_LAYOUT
4330 | FINISH_LAYOUT_REDO_CONFIG
4331 | FINISH_LAYOUT_REDO_WALLPAPER;
4332 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004333 if (mKeyguardDelegate.isShowing()) {
4334 mHandler.post(new Runnable() {
4335 @Override
4336 public void run() {
4337 mKeyguardDelegate.keyguardDone(false, false);
4338 }
4339 });
4340 }
4341 } else if (mHideLockScreen) {
4342 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004343 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004344 changes |= FINISH_LAYOUT_REDO_LAYOUT
4345 | FINISH_LAYOUT_REDO_CONFIG
4346 | FINISH_LAYOUT_REDO_WALLPAPER;
4347 }
4348 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
4349 // This is the case of keyguard isSecure() and not mHideLockScreen.
4350 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4351 // Only launch the next keyguard unlock window once per window.
4352 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004353 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004354 changes |= FINISH_LAYOUT_REDO_LAYOUT
4355 | FINISH_LAYOUT_REDO_CONFIG
4356 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004357 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004358 mHandler.post(new Runnable() {
4359 @Override
4360 public void run() {
4361 mKeyguardDelegate.dismiss();
4362 }
4363 });
4364 }
4365 } else {
4366 mWinDismissingKeyguard = null;
4367 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004368 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004369 changes |= FINISH_LAYOUT_REDO_LAYOUT
4370 | FINISH_LAYOUT_REDO_CONFIG
4371 | FINISH_LAYOUT_REDO_WALLPAPER;
4372 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004373 }
4374 }
Joe Onorato664644d2011-01-23 17:53:23 -08004375
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004376 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004377 // If the navigation bar has been hidden or shown, we need to do another
4378 // layout pass to update that window.
4379 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4380 }
Joe Onorato664644d2011-01-23 17:53:23 -08004381
Mike Lockwood28569302010-01-28 11:54:40 -05004382 // update since mAllowLockscreenWhenOn might have changed
4383 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004384 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004385 }
4386
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004387 /**
Jim Millerab954542014-10-10 18:21:49 -07004388 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004389 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004390 * @return Whether the flags have changed and we have to redo the layout.
4391 */
Jim Millerab954542014-10-10 18:21:49 -07004392 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4393 boolean wasOccluded = mKeyguardOccluded;
4394 boolean showing = mKeyguardDelegate.isShowing();
4395 if (wasOccluded && !isOccluded && showing) {
4396 mKeyguardOccluded = false;
4397 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004398 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4399 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4400 return true;
Jim Millerab954542014-10-10 18:21:49 -07004401 } else if (!wasOccluded && isOccluded && showing) {
4402 mKeyguardOccluded = true;
4403 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004404 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4405 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4406 return true;
4407 } else {
4408 return false;
4409 }
4410 }
4411
4412 private boolean isStatusBarKeyguard() {
4413 return mStatusBar != null
4414 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4415 }
4416
Jose Lima9546b202014-07-02 17:21:51 -07004417 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004418 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004419 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004420 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004421 return false;
4422 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004423 return true;
4424 }
4425
Jose Lima9546b202014-07-02 17:21:51 -07004426 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004427 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004428 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004429 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004430 // If the navigation bar has been hidden or shown, we need to do another
4431 // layout pass to update that window.
4432 return FINISH_LAYOUT_REDO_LAYOUT;
4433 }
4434 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004435 }
4436
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004437 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004438 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004439 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4440 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004441 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4442 if (newLidState == mLidState) {
4443 return;
4444 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004445
Jeff Brownc458ce92012-04-30 14:58:40 -07004446 mLidState = newLidState;
4447 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004448 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004449
4450 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004451 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004452 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004453 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004454 }
4455 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004456
Michael Wright3818c922014-09-02 13:59:07 -07004457 @Override
4458 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4459 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4460 if (mCameraLensCoverState == lensCoverState) {
4461 return;
4462 }
4463 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4464 lensCoverState == CAMERA_LENS_UNCOVERED) {
4465 Intent intent;
4466 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4467 mKeyguardDelegate.isShowing();
4468 if (keyguardActive) {
4469 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4470 } else {
4471 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4472 }
Bryce Lee584a4452014-10-21 15:55:55 -07004473 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004474 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004475 }
4476 mCameraLensCoverState = lensCoverState;
4477 }
4478
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004479 void setHdmiPlugged(boolean plugged) {
4480 if (mHdmiPlugged != plugged) {
4481 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004482 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004483 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004484 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004485 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004486 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004487 }
4488 }
4489
Joe Onoratoea495d42011-04-06 11:41:11 -07004490 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004491 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004492 // watch for HDMI plug messages if the hdmi switch exists
4493 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4494 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4495
Joe Onoratoea495d42011-04-06 11:41:11 -07004496 final String filename = "/sys/class/switch/hdmi/state";
4497 FileReader reader = null;
4498 try {
4499 reader = new FileReader(filename);
4500 char[] buf = new char[15];
4501 int n = reader.read(buf);
4502 if (n > 1) {
4503 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4504 }
4505 } catch (IOException ex) {
4506 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4507 } catch (NumberFormatException ex) {
4508 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4509 } finally {
4510 if (reader != null) {
4511 try {
4512 reader.close();
4513 } catch (IOException ex) {
4514 }
Joe Onoratodc100302011-01-11 17:07:41 -08004515 }
4516 }
4517 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004518 // This dance forces the code in setHdmiPlugged to run.
4519 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4520 mHdmiPlugged = !plugged;
4521 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004522 }
4523
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004524 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004525 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004526
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004527 final Runnable mScreenshotTimeout = new Runnable() {
4528 @Override public void run() {
4529 synchronized (mScreenshotLock) {
4530 if (mScreenshotConnection != null) {
4531 mContext.unbindService(mScreenshotConnection);
4532 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004533 }
Winson Chung9112ec32011-06-27 13:15:32 -07004534 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004535 }
4536 };
4537
4538 // Assume this is called from the Handler thread.
4539 private void takeScreenshot() {
4540 synchronized (mScreenshotLock) {
4541 if (mScreenshotConnection != null) {
4542 return;
4543 }
4544 ComponentName cn = new ComponentName("com.android.systemui",
4545 "com.android.systemui.screenshot.TakeScreenshotService");
4546 Intent intent = new Intent();
4547 intent.setComponent(cn);
4548 ServiceConnection conn = new ServiceConnection() {
4549 @Override
4550 public void onServiceConnected(ComponentName name, IBinder service) {
4551 synchronized (mScreenshotLock) {
4552 if (mScreenshotConnection != this) {
4553 return;
4554 }
4555 Messenger messenger = new Messenger(service);
4556 Message msg = Message.obtain(null, 1);
4557 final ServiceConnection myConn = this;
4558 Handler h = new Handler(mHandler.getLooper()) {
4559 @Override
4560 public void handleMessage(Message msg) {
4561 synchronized (mScreenshotLock) {
4562 if (mScreenshotConnection == myConn) {
4563 mContext.unbindService(mScreenshotConnection);
4564 mScreenshotConnection = null;
4565 mHandler.removeCallbacks(mScreenshotTimeout);
4566 }
4567 }
4568 }
4569 };
4570 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004571 msg.arg1 = msg.arg2 = 0;
4572 if (mStatusBar != null && mStatusBar.isVisibleLw())
4573 msg.arg1 = 1;
4574 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4575 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004576 try {
4577 messenger.send(msg);
4578 } catch (RemoteException e) {
4579 }
4580 }
4581 }
4582 @Override
4583 public void onServiceDisconnected(ComponentName name) {}
4584 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004585 if (mContext.bindServiceAsUser(
4586 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004587 mScreenshotConnection = conn;
4588 mHandler.postDelayed(mScreenshotTimeout, 10000);
4589 }
4590 }
Winson Chung9112ec32011-06-27 13:15:32 -07004591 }
4592
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004593 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004594 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004595 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004596 if (!mSystemBooted) {
4597 // If we have not yet booted, don't let key events do anything.
4598 return 0;
4599 }
4600
Jeff Brown037c33e2014-04-09 00:31:55 -07004601 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004602 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4603 final boolean canceled = event.isCanceled();
4604 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004605
Jeff Brown3122e442010-10-11 23:32:49 -07004606 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004607
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004608 // If screen is off then we treat the case where the keyguard is open but hidden
4609 // the same as if it were open and in front.
4610 // This will prevent any keys other than the power button from waking the screen
4611 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004612 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004613 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004614 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004615 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004616
Jeff Brown40013652012-05-16 21:22:36 -07004617 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004618 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004619 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004620 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004621 }
4622
Jeff Brown037c33e2014-04-09 00:31:55 -07004623 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004624 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004625 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4626 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004627 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004628 // When the device is interactive or the key is injected pass the
4629 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004630 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004631 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004632 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4633 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4634 // to the application but preserve its wake key status to make sure we still move
4635 // from dozing to fully interactive if we would normally go from off to fully
4636 // interactive.
4637 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004638 } else {
4639 // When the screen is off and the key is not injected, determine whether
4640 // to wake the device but don't pass the key to the application.
4641 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004642 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4643 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004644 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004645 }
4646
Justin Kohd378ad72013-04-01 12:18:26 -07004647 // If the key would be handled globally, just return the result, don't worry about special
4648 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004649 if (isValidGlobalKey(keyCode)
4650 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004651 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004652 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004653 }
Justin Kohd378ad72013-04-01 12:18:26 -07004654 return result;
4655 }
4656
Jeff Brownbae8e772014-06-12 19:59:45 -07004657 boolean useHapticFeedback = down
4658 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4659 && event.getRepeatCount() == 0;
4660
Jeff Brown4d396052010-10-29 21:50:21 -07004661 // Handle special keys.
4662 switch (keyCode) {
4663 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004664 case KeyEvent.KEYCODE_VOLUME_UP:
4665 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004666 if (mUseTvRouting) {
4667 // On TVs volume keys never go to the foreground app
4668 result &= ~ACTION_PASS_TO_USER;
4669 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004670 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4671 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004672 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004673 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004674 mScreenshotChordVolumeDownKeyTriggered = true;
4675 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4676 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004677 cancelPendingPowerKeyAction();
4678 interceptScreenshotChord();
4679 }
4680 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004681 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004682 cancelPendingScreenshotChordAction();
4683 }
4684 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4685 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004686 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004687 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004688 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004689 cancelPendingPowerKeyAction();
4690 cancelPendingScreenshotChordAction();
4691 }
4692 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004693 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004694 cancelPendingScreenshotChordAction();
4695 }
4696 }
Jeff Brown4d396052010-10-29 21:50:21 -07004697 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004698 TelecomManager telecomManager = getTelecommService();
4699 if (telecomManager != null) {
4700 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004701 // If an incoming call is ringing, either VOLUME key means
4702 // "silence ringer". We handle these keys here, rather than
4703 // in the InCallScreen, to make sure we'll respond to them
4704 // even if the InCallScreen hasn't come to the foreground yet.
4705 // Look for the DOWN event here, to agree with the "fallback"
4706 // behavior in the InCallScreen.
4707 Log.i(TAG, "interceptKeyBeforeQueueing:"
4708 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004709
Santos Cordon6848f722014-05-21 15:22:12 -07004710 // Silence the ringer. (It's safe to call this
4711 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004712 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004713
Santos Cordon6848f722014-05-21 15:22:12 -07004714 // And *don't* pass this key thru to the current activity
4715 // (which is probably the InCallScreen.)
4716 result &= ~ACTION_PASS_TO_USER;
4717 break;
4718 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004719 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004720 && (result & ACTION_PASS_TO_USER) == 0) {
4721 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004722 // the application, just pass it to the session service.
4723
4724 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004725 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004726 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004727 }
4728 }
4729
RoboErik430fc482014-06-12 15:49:20 -07004730 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004731 if (mUseTvRouting) {
4732 dispatchDirectAudioEvent(event);
4733 } else {
4734 // If we aren't passing to the user and no one else
4735 // handled it send it to the session manager to
4736 // figure out.
4737 MediaSessionLegacyHelper.getHelper(mContext)
4738 .sendVolumeKeyEvent(event, true);
4739 }
Jeff Brown4d396052010-10-29 21:50:21 -07004740 break;
4741 }
4742 }
4743 break;
4744 }
4745
4746 case KeyEvent.KEYCODE_ENDCALL: {
4747 result &= ~ACTION_PASS_TO_USER;
4748 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004749 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004750 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004751 if (telecomManager != null) {
4752 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004753 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004754 if (interactive && !hungUp) {
4755 mEndCallKeyHandled = false;
4756 mHandler.postDelayed(mEndCallLongPress,
4757 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4758 } else {
4759 mEndCallKeyHandled = true;
4760 }
Jeff Brown4d396052010-10-29 21:50:21 -07004761 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004762 if (!mEndCallKeyHandled) {
4763 mHandler.removeCallbacks(mEndCallLongPress);
4764 if (!canceled) {
4765 if ((mEndcallBehavior
4766 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4767 if (goHome()) {
4768 break;
4769 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004770 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004771 if ((mEndcallBehavior
4772 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4773 mPowerManager.goToSleep(event.getEventTime(),
4774 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4775 isWakeKey = false;
4776 }
Jeff Brown4d396052010-10-29 21:50:21 -07004777 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004778 }
Jeff Brown4d396052010-10-29 21:50:21 -07004779 }
4780 break;
4781 }
4782
4783 case KeyEvent.KEYCODE_POWER: {
4784 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004785 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004786 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004787 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004788 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004789 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004790 }
4791 break;
4792 }
4793
Jeff Brown6212a492014-03-07 13:58:47 -08004794 case KeyEvent.KEYCODE_SLEEP: {
4795 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004796 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004797 if (!mPowerManager.isInteractive()) {
4798 useHapticFeedback = false; // suppress feedback if already non-interactive
4799 }
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004800 sleepPress(event);
Jeff Brown6212a492014-03-07 13:58:47 -08004801 break;
4802 }
4803
4804 case KeyEvent.KEYCODE_WAKEUP: {
4805 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004806 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004807 break;
4808 }
4809
Jeff Brown4d396052010-10-29 21:50:21 -07004810 case KeyEvent.KEYCODE_MEDIA_PLAY:
4811 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4812 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004813 case KeyEvent.KEYCODE_HEADSETHOOK:
4814 case KeyEvent.KEYCODE_MUTE:
4815 case KeyEvent.KEYCODE_MEDIA_STOP:
4816 case KeyEvent.KEYCODE_MEDIA_NEXT:
4817 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4818 case KeyEvent.KEYCODE_MEDIA_REWIND:
4819 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004820 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4821 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004822 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4823 // If the global session is active pass all media keys to it
4824 // instead of the active window.
4825 result &= ~ACTION_PASS_TO_USER;
4826 }
Jeff Brown4d396052010-10-29 21:50:21 -07004827 if ((result & ACTION_PASS_TO_USER) == 0) {
4828 // Only do this if we would otherwise not pass it to the user. In that
4829 // case, the PhoneWindow class will do the same thing, except it will
4830 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004831 // Note that we need to make a copy of the key event here because the
4832 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004833 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004834 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4835 new KeyEvent(event));
4836 msg.setAsynchronous(true);
4837 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004838 }
4839 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004840 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004841
Jeff Brown4d396052010-10-29 21:50:21 -07004842 case KeyEvent.KEYCODE_CALL: {
4843 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004844 TelecomManager telecomManager = getTelecommService();
4845 if (telecomManager != null) {
4846 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004847 Log.i(TAG, "interceptKeyBeforeQueueing:"
4848 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004849 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004850
Santos Cordon6848f722014-05-21 15:22:12 -07004851 // And *don't* pass this key thru to the current activity
4852 // (which is presumably the InCallScreen.)
4853 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004854 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004855 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004856 }
Jeff Brown4d396052010-10-29 21:50:21 -07004857 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004858 }
Michael Wright869a67c2014-08-26 19:33:06 -07004859 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4860 // Only do this if we would otherwise not pass it to the user. In that case,
4861 // interceptKeyBeforeDispatching would apply a similar but different policy in
4862 // order to invoke voice assist actions. Note that we need to make a copy of the
4863 // key event here because the original key event will be recycled when we return.
4864 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4865 mBroadcastWakeLock.acquire();
4866 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4867 keyguardActive ? 1 : 0, 0);
4868 msg.setAsynchronous(true);
4869 msg.sendToTarget();
4870 }
4871 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004872 }
Jeff Brown26875502014-01-30 21:47:47 -08004873
Jeff Brownbae8e772014-06-12 19:59:45 -07004874 if (useHapticFeedback) {
4875 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4876 }
4877
Jeff Brown26875502014-01-30 21:47:47 -08004878 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004879 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004880 }
Bryce Lee584a4452014-10-21 15:55:55 -07004881
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004882 return result;
4883 }
4884
Jeff Brown1c2e4942012-11-06 16:32:01 -08004885 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004886 * Returns true if the key can have global actions attached to it.
4887 * We reserve all power management keys for the system since they require
4888 * very careful handling.
4889 */
4890 private static boolean isValidGlobalKey(int keyCode) {
4891 switch (keyCode) {
4892 case KeyEvent.KEYCODE_POWER:
4893 case KeyEvent.KEYCODE_WAKEUP:
4894 case KeyEvent.KEYCODE_SLEEP:
4895 return false;
4896 default:
4897 return true;
4898 }
4899 }
4900
4901 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08004902 * When the screen is off we ignore some keys that might otherwise typically
4903 * be considered wake keys. We filter them out here.
4904 *
4905 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4906 * is always considered a wake key.
4907 */
4908 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4909 switch (keyCode) {
4910 // ignore volume keys unless docked
4911 case KeyEvent.KEYCODE_VOLUME_UP:
4912 case KeyEvent.KEYCODE_VOLUME_DOWN:
4913 case KeyEvent.KEYCODE_VOLUME_MUTE:
4914 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4915
4916 // ignore media and camera keys
4917 case KeyEvent.KEYCODE_MUTE:
4918 case KeyEvent.KEYCODE_HEADSETHOOK:
4919 case KeyEvent.KEYCODE_MEDIA_PLAY:
4920 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4921 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4922 case KeyEvent.KEYCODE_MEDIA_STOP:
4923 case KeyEvent.KEYCODE_MEDIA_NEXT:
4924 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4925 case KeyEvent.KEYCODE_MEDIA_REWIND:
4926 case KeyEvent.KEYCODE_MEDIA_RECORD:
4927 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004928 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004929 case KeyEvent.KEYCODE_CAMERA:
4930 return false;
4931 }
4932 return true;
4933 }
4934
4935
Jeff Brown56194eb2011-03-02 19:23:13 -08004936 /** {@inheritDoc} */
4937 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004938 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4939 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08004940 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
4941 return 0;
4942 }
Michael Wright70af00a2014-09-03 19:30:20 -07004943 }
Bryce Lee5c138322014-11-03 08:26:09 -08004944
Michael Wright70af00a2014-09-03 19:30:20 -07004945 if (shouldDispatchInputWhenNonInteractive()) {
4946 return ACTION_PASS_TO_USER;
4947 }
Bryce Lee5c138322014-11-03 08:26:09 -08004948
Bryce Lee812d7022014-11-10 13:33:28 -08004949 // If we have not passed the action up and we are in theater mode without dreaming,
4950 // there will be no dream to intercept the touch and wake into ambient. The device should
4951 // wake up in this case.
4952 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
4953 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
4954 }
4955
Jeff Brown037c33e2014-04-09 00:31:55 -07004956 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004957 }
4958
Michael Wright70af00a2014-09-03 19:30:20 -07004959 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08004960 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07004961 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
4962 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08004963 return true;
4964 }
4965
4966 // Send events to a dozing dream even if the screen is off since the dream
4967 // is in control of the state of the screen.
4968 IDreamManager dreamManager = getDreamManager();
4969
4970 try {
4971 if (dreamManager != null && dreamManager.isDreaming()) {
4972 return true;
4973 }
4974 } catch (RemoteException e) {
4975 Slog.e(TAG, "RemoteException when checking if dreaming", e);
4976 }
4977
4978 // Otherwise, consume events since the user can't see what is being
4979 // interacted with.
4980 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07004981 }
4982
RoboErik001c59c2015-01-26 15:53:51 -08004983 private void dispatchDirectAudioEvent(KeyEvent event) {
4984 if (event.getAction() != KeyEvent.ACTION_DOWN) {
4985 return;
4986 }
4987 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04004988 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
4989 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08004990 String pkgName = mContext.getOpPackageName();
4991 switch (keyCode) {
4992 case KeyEvent.KEYCODE_VOLUME_UP:
4993 try {
John Spurlockee5ad722015-03-03 16:17:21 -05004994 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04004995 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08004996 } catch (RemoteException e) {
4997 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
4998 }
4999 break;
5000 case KeyEvent.KEYCODE_VOLUME_DOWN:
5001 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005002 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005003 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005004 } catch (RemoteException e) {
5005 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5006 }
5007 break;
5008 case KeyEvent.KEYCODE_VOLUME_MUTE:
5009 try {
5010 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005011 getAudioService().adjustSuggestedStreamVolume(
5012 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005013 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005014 }
5015 } catch (RemoteException e) {
5016 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5017 }
5018 break;
5019 }
5020 }
5021
Jeff Brown40013652012-05-16 21:22:36 -07005022 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5023 if (DEBUG_INPUT) {
5024 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005025 }
5026
Jeff Brown40013652012-05-16 21:22:36 -07005027 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5028 if (DEBUG_INPUT) {
5029 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5030 }
5031
5032 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5033 mHavePendingMediaKeyRepeatWithWakeLock = false;
5034 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5035 }
5036
5037 dispatchMediaKeyWithWakeLockToAudioService(event);
5038
5039 if (event.getAction() == KeyEvent.ACTION_DOWN
5040 && event.getRepeatCount() == 0) {
5041 mHavePendingMediaKeyRepeatWithWakeLock = true;
5042
5043 Message msg = mHandler.obtainMessage(
5044 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5045 msg.setAsynchronous(true);
5046 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5047 } else {
5048 mBroadcastWakeLock.release();
5049 }
5050 }
5051
5052 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5053 mHavePendingMediaKeyRepeatWithWakeLock = false;
5054
5055 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5056 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5057 if (DEBUG_INPUT) {
5058 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5059 }
5060
5061 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5062 mBroadcastWakeLock.release();
5063 }
5064
5065 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5066 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005067 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005068 }
5069 }
5070
Michael Wright869a67c2014-08-26 19:33:06 -07005071 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
5072 Intent voiceIntent =
5073 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5074 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005075 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005076 mBroadcastWakeLock.release();
5077 }
5078
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005079 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005080 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005081 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005082 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5083 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5084 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005085 } else {
5086 try {
5087 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5088 ServiceManager.getService(Context.UI_MODE_SERVICE));
5089 mUiMode = uiModeService.getCurrentModeType();
5090 } catch (RemoteException e) {
5091 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005092 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005093 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005094 synchronized (mLock) {
5095 updateOrientationListenerLp();
5096 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005097 }
5098 };
5099
Jeff Brown6aaf2952012-10-05 16:01:08 -07005100 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5101 @Override
5102 public void onReceive(Context context, Intent intent) {
5103 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005104 if (mKeyguardDelegate != null) {
5105 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005106 }
5107 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005108 if (mKeyguardDelegate != null) {
5109 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005110 }
5111 }
5112 }
5113 };
5114
Christopher Tate5e08af02012-09-21 17:17:22 -07005115 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5116 @Override
5117 public void onReceive(Context context, Intent intent) {
5118 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5119 // tickle the settings observer: this first ensures that we're
5120 // observing the relevant settings for the newly-active user,
5121 // and then updates our own bookkeeping based on the now-
5122 // current user.
5123 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005124
5125 // force a re-application of focused window sysui visibility.
5126 // the window may never have been shown for this user
5127 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005128 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005129 mLastSystemUiFlags = 0;
5130 updateSystemUiVisibilityLw();
5131 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005132 }
5133 }
5134 };
5135
John Spurlockd9b70bd2014-02-06 17:02:44 -05005136 private final Runnable mRequestTransientNav = new Runnable() {
5137 @Override
5138 public void run() {
5139 requestTransientBars(mNavigationBar);
5140 }
5141 };
5142
John Spurlocke1f366f2013-08-05 12:22:40 -04005143 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005144 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005145 if (!isUserSetupComplete()) {
5146 // Swipe-up for navigation bar is disabled during setup
5147 return;
5148 }
John Spurlock27735a42013-08-14 17:57:38 -04005149 boolean sb = mStatusBarController.checkShowTransientBarLw();
5150 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005151 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005152 // Don't show status bar when swiping on already visible navigation bar
5153 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005154 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005155 return;
5156 }
John Spurlock27735a42013-08-14 17:57:38 -04005157 if (sb) mStatusBarController.showTransient();
5158 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005159 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005160 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005161 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005162 }
5163 }
5164
Jeff Brown3ee549c2014-09-22 20:14:39 -07005165 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005166 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07005167 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005168 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07005169 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005170
5171 // We must get this work done here because the power manager will drop
5172 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005173 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005174 mAwake = false;
5175 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005176 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005177 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005178 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005179 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005180
5181 if (mKeyguardDelegate != null) {
5182 mKeyguardDelegate.onScreenTurnedOff(why);
5183 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005184 }
5185
Jeff Brown13f00f02014-10-31 14:45:50 -07005186 private void wakeUpFromPowerKey(long eventTime) {
5187 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5188 }
5189
Bryce Lee5c138322014-11-03 08:26:09 -08005190 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Lee584a4452014-10-21 15:55:55 -07005191 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005192 return false;
Bryce Lee584a4452014-10-21 15:55:55 -07005193 }
5194
5195 mPowerManager.wakeUp(wakeTime);
Bryce Lee5c138322014-11-03 08:26:09 -08005196 return true;
Bryce Lee584a4452014-10-21 15:55:55 -07005197 }
5198
Jeff Brown3ee549c2014-09-22 20:14:39 -07005199 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005200 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07005201 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005202 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07005203 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005204
Jeff Brown3ee549c2014-09-22 20:14:39 -07005205 // Since goToSleep performs these functions synchronously, we must
5206 // do the same here. We cannot post this work to a handler because
5207 // that might cause it to become reordered with respect to what
5208 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005209 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005210 mAwake = true;
5211 mKeyguardDrawComplete = false;
5212 if (mKeyguardDelegate != null) {
5213 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5214 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5215 }
5216
Jeff Browna20dda42014-05-27 20:57:24 -07005217 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005218 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005219 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005220 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005221
Jim Miller5ecd8112013-01-09 18:50:26 -08005222 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07005223 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005224 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005225 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005226 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005227 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005228 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005229 }
5230
Jeff Brown36c4db82014-09-19 12:05:31 -07005231 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005232 synchronized (mLock) {
5233 if (!mAwake || mKeyguardDrawComplete) {
5234 return; // spurious
5235 }
5236
Jeff Brown36c4db82014-09-19 12:05:31 -07005237 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005238 if (mKeyguardDelegate != null) {
5239 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5240 }
5241 }
5242
5243 finishScreenTurningOn();
5244 }
5245
5246 // Called on the DisplayManager's DisplayPowerController thread.
5247 @Override
5248 public void screenTurnedOff() {
5249 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5250
5251 synchronized (mLock) {
5252 mScreenOnEarly = false;
5253 mScreenOnFully = false;
5254 mWindowManagerDrawComplete = false;
5255 mScreenOnListener = null;
5256 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005257 }
5258 }
5259
Jeff Brown3ee549c2014-09-22 20:14:39 -07005260 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005261 @Override
5262 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005263 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005264
Jeff Brown3ee549c2014-09-22 20:14:39 -07005265 synchronized (mLock) {
5266 mScreenOnEarly = true;
5267 mScreenOnFully = false;
5268 mWindowManagerDrawComplete = false;
5269 mScreenOnListener = screenOnListener;
5270 updateOrientationListenerLp();
5271 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005272
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005273 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5274 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005275 // ... eventually calls finishWindowsDrawn
5276 }
5277
Jeff Brown36c4db82014-09-19 12:05:31 -07005278 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005279 synchronized (mLock) {
5280 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5281 return; // spurious
5282 }
5283
Jeff Brown36c4db82014-09-19 12:05:31 -07005284 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005285 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005286
5287 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005288 }
5289
Craig Mautner8a0da012014-05-31 15:13:37 -07005290 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005291 final ScreenOnListener listener;
5292 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005293 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005294 if (DEBUG_WAKEUP) Slog.d(TAG,
5295 "finishScreenTurningOn: mAwake=" + mAwake
5296 + ", mScreenOnEarly=" + mScreenOnEarly
5297 + ", mScreenOnFully=" + mScreenOnFully
5298 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5299 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5300
5301 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5302 || (mAwake && !mKeyguardDrawComplete)) {
5303 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005304 }
5305
Jeff Brown3ee549c2014-09-22 20:14:39 -07005306 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5307 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005308 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005309 mScreenOnFully = true;
5310
5311 // Remember the first time we draw the keyguard so we know when we're done with
5312 // the main part of booting and can enable the screen and hide boot messages.
5313 if (!mKeyguardDrawnOnce && mAwake) {
5314 mKeyguardDrawnOnce = true;
5315 enableScreen = true;
5316 if (mBootMessageNeedsHiding) {
5317 mBootMessageNeedsHiding = false;
5318 hideBootMessages();
5319 }
5320 } else {
5321 enableScreen = false;
5322 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005323 }
5324
Jeff Brown3ee549c2014-09-22 20:14:39 -07005325 if (listener != null) {
5326 listener.onScreenOn();
5327 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005328
Jeff Brown3ee549c2014-09-22 20:14:39 -07005329 if (enableScreen) {
5330 try {
5331 mWindowManager.enableScreenIfNeeded();
5332 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005333 }
Craig Mautnera631d492014-08-05 15:16:01 -07005334 }
5335 }
5336
5337 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005338 synchronized (mLock) {
5339 if (!mKeyguardDrawnOnce) {
5340 mBootMessageNeedsHiding = true;
5341 return; // keyguard hasn't drawn the first time yet, not done booting
5342 }
Craig Mautnera631d492014-08-05 15:16:01 -07005343 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005344
5345 if (mBootMsgDialog != null) {
5346 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5347 mBootMsgDialog.dismiss();
5348 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005349 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005350 }
5351
5352 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005353 public boolean isScreenOn() {
5354 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005355 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005356
Dianne Hackborn08743722009-12-21 12:16:51 -08005357 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005358 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005359 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005360 if (mKeyguardDelegate != null) {
5361 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005362 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005363 }
5364
5365 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005366 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005367 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005368 if (mKeyguardDelegate != null) {
5369 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005370 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005371 }
5372
Jim Millerab954542014-10-10 18:21:49 -07005373 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005374 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005375 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005376 }
5377
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005378 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005379 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005380 public boolean isKeyguardLocked() {
5381 return keyguardOn();
5382 }
5383
5384 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005385 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005386 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005387 if (mKeyguardDelegate == null) return false;
5388 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005389 }
5390
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005391 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005392 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005393 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005394 if (mKeyguardDelegate == null) return false;
5395 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005396 }
5397
Jose Lima9546b202014-07-02 17:21:51 -07005398 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005399 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005400 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005401 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005402 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005403 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005404 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005405 // ask the keyguard to prompt the user to authenticate if necessary
5406 mKeyguardDelegate.dismiss();
5407 }
5408 });
5409 }
5410 }
5411
5412 public void notifyActivityDrawnForKeyguardLw() {
5413 if (mKeyguardDelegate != null) {
5414 mHandler.post(new Runnable() {
5415 @Override
5416 public void run() {
5417 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005418 }
5419 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005420 }
5421 }
5422
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005423 @Override
5424 public boolean isKeyguardDrawnLw() {
5425 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005426 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005427 }
5428 }
5429
Jorim Jaggi0d674622014-05-21 01:34:15 +02005430 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005431 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005432 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005433 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005434 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005435 }
5436 }
5437
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005438 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005439 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005440 }
5441
5442 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005443 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005444 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005445
Jeff Brown01a98dd2011-09-20 15:08:29 -07005446 @Override
5447 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005448 if (false) {
5449 Slog.v(TAG, "rotationForOrientationLw(orient="
5450 + orientation + ", last=" + lastRotation
5451 + "); user=" + mUserRotation + " "
5452 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5453 ? "USER_ROTATION_LOCKED" : "")
5454 );
5455 }
5456
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005457 if (mForceDefaultOrientation) {
5458 return Surface.ROTATION_0;
5459 }
5460
The Android Open Source Project0727d222009-03-11 12:11:58 -07005461 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005462 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5463 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005464 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005465 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005466
Jeff Browndec6cf42011-11-15 14:08:20 -08005467 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005468 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005469 // Ignore sensor when lid switch is open and rotation is forced.
5470 preferredRotation = mLidOpenRotation;
5471 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005472 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005473 // Ignore sensor when in car dock unless explicitly enabled.
5474 // This case can override the behavior of NOSENSOR, and can also
5475 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005476 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005477 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005478 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5479 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5480 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005481 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005482 // Ignore sensor when in desk dock unless explicitly enabled.
5483 // This case can override the behavior of NOSENSOR, and can also
5484 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005485 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005486 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005487 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5488 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005489 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005490 preferredRotation = mDemoHdmiRotation;
5491 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5492 && mUndockedHdmiRotation >= 0) {
5493 // Ignore sensor when plugged into HDMI and an undocked orientation has
5494 // been specified in the configuration (only for legacy devices without
5495 // full multi-display support).
5496 // Note that the dock orientation overrides the HDMI orientation.
5497 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005498 } else if (mDemoRotationLock) {
5499 // Ignore sensor when demo rotation lock is enabled.
5500 // Note that the dock orientation and HDMI rotation lock override this.
5501 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005502 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5503 // Application just wants to remain locked in the last rotation.
5504 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005505 } else if (!mSupportAutoRotation) {
5506 // If we don't support auto-rotation then bail out here and ignore
5507 // the sensor and any rotation lock settings.
5508 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005509 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005510 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005511 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5512 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5513 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5514 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005515 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5516 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5517 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5518 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5519 // Otherwise, use sensor only if requested by the application or enabled
5520 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005521 if (mAllowAllRotations < 0) {
5522 // Can't read this during init() because the context doesn't
5523 // have display metrics at that time so we cannot determine
5524 // tablet vs. phone then.
5525 mAllowAllRotations = mContext.getResources().getBoolean(
5526 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5527 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005528 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005529 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005530 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5531 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005532 preferredRotation = sensorRotation;
5533 } else {
5534 preferredRotation = lastRotation;
5535 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005536 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5537 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5538 // Apply rotation lock. Does not apply to NOSENSOR.
5539 // The idea is that the user rotation expresses a weak preference for the direction
5540 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5541 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005542 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005543 } else {
5544 // No overriding preference.
5545 // We will do exactly what the application asked us to do.
5546 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005547 }
5548
Dianne Hackborne5439f22010-10-02 16:53:50 -07005549 switch (orientation) {
5550 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005551 // Return portrait unless overridden.
5552 if (isAnyPortrait(preferredRotation)) {
5553 return preferredRotation;
5554 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005555 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005556
Jeff Brown01a98dd2011-09-20 15:08:29 -07005557 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005558 // Return landscape unless overridden.
5559 if (isLandscapeOrSeascape(preferredRotation)) {
5560 return preferredRotation;
5561 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005562 return mLandscapeRotation;
5563
5564 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005565 // Return reverse portrait unless overridden.
5566 if (isAnyPortrait(preferredRotation)) {
5567 return preferredRotation;
5568 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005569 return mUpsideDownRotation;
5570
5571 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005572 // Return seascape unless overridden.
5573 if (isLandscapeOrSeascape(preferredRotation)) {
5574 return preferredRotation;
5575 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005576 return mSeascapeRotation;
5577
5578 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005579 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005580 // Return either landscape rotation.
5581 if (isLandscapeOrSeascape(preferredRotation)) {
5582 return preferredRotation;
5583 }
5584 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005585 return lastRotation;
5586 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005587 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005588
Jeff Brown01a98dd2011-09-20 15:08:29 -07005589 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005590 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005591 // Return either portrait rotation.
5592 if (isAnyPortrait(preferredRotation)) {
5593 return preferredRotation;
5594 }
5595 if (isAnyPortrait(lastRotation)) {
5596 return lastRotation;
5597 }
5598 return mPortraitRotation;
5599
5600 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005601 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5602 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005603 if (preferredRotation >= 0) {
5604 return preferredRotation;
5605 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005606 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005607 }
5608 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005609 }
5610
Jeff Brown01a98dd2011-09-20 15:08:29 -07005611 @Override
5612 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5613 switch (orientation) {
5614 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5615 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5616 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5617 return isAnyPortrait(rotation);
5618
5619 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5620 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5621 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5622 return isLandscapeOrSeascape(rotation);
5623
5624 default:
5625 return true;
5626 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005627 }
5628
Jeff Brownc0347aa2011-09-23 17:26:09 -07005629 @Override
5630 public void setRotationLw(int rotation) {
5631 mOrientationListener.setCurrentRotation(rotation);
5632 }
5633
Jeff Brown01a98dd2011-09-20 15:08:29 -07005634 private boolean isLandscapeOrSeascape(int rotation) {
5635 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005636 }
5637
Jeff Brown01a98dd2011-09-20 15:08:29 -07005638 private boolean isAnyPortrait(int rotation) {
5639 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005640 }
5641
Jose Lima9546b202014-07-02 17:21:51 -07005642 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005643 public int getUserRotationMode() {
5644 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005645 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5646 WindowManagerPolicy.USER_ROTATION_FREE :
5647 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005648 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005649
5650 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005651 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005652 public void setUserRotationMode(int mode, int rot) {
5653 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005654
5655 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005656 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005657 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005658 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005659 rot,
5660 UserHandle.USER_CURRENT);
5661 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005662 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005663 0,
5664 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005665 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005666 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005667 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005668 1,
5669 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005670 }
5671 }
5672
Jose Lima9546b202014-07-02 17:21:51 -07005673 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005674 public void setSafeMode(boolean safeMode) {
5675 mSafeMode = safeMode;
5676 performHapticFeedbackLw(null, safeMode
5677 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5678 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005679 }
Craig Mautnereda67292013-04-28 13:50:14 -07005680
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005681 static long[] getLongIntArray(Resources r, int resid) {
5682 int[] ar = r.getIntArray(resid);
5683 if (ar == null) {
5684 return null;
5685 }
5686 long[] out = new long[ar.length];
5687 for (int i=0; i<ar.length; i++) {
5688 out[i] = ar[i];
5689 }
5690 return out;
5691 }
Craig Mautnereda67292013-04-28 13:50:14 -07005692
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005693 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005694 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005695 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005696 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005697 mKeyguardDelegate.onSystemReady();
5698
Michael Wright3818c922014-09-02 13:59:07 -07005699 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005700 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005701 synchronized (mLock) {
5702 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005703 mSystemReady = true;
5704 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005705 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005706 public void run() {
5707 updateSettings();
5708 }
5709 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005710 }
5711 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005712
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005713 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005714 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005715 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005716 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005717 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005718 mKeyguardDelegate.onBootCompleted();
5719 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005720 synchronized (mLock) {
5721 mSystemBooted = true;
5722 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005723 wakingUp();
5724 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005725 }
5726
Dianne Hackborn661cd522011-08-22 00:26:20 -07005727 ProgressDialog mBootMsgDialog = null;
5728
5729 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005730 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005731 public void showBootMessage(final CharSequence msg, final boolean always) {
5732 mHandler.post(new Runnable() {
5733 @Override public void run() {
5734 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005735 int theme;
5736 if (mContext.getPackageManager().hasSystemFeature(
5737 PackageManager.FEATURE_WATCH)) {
5738 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5739 } else if (mContext.getPackageManager().hasSystemFeature(
5740 PackageManager.FEATURE_TELEVISION)) {
5741 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5742 } else {
5743 theme = 0;
5744 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005745
5746 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005747 // This dialog will consume all events coming in to
5748 // it, to avoid it trying to do things too early in boot.
5749 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5750 return true;
5751 }
5752 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5753 return true;
5754 }
5755 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5756 return true;
5757 }
5758 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5759 return true;
5760 }
5761 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5762 return true;
5763 }
5764 @Override public boolean dispatchPopulateAccessibilityEvent(
5765 AccessibilityEvent event) {
5766 return true;
5767 }
5768 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005769 if (mContext.getPackageManager().isUpgrade()) {
5770 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5771 } else {
5772 mBootMsgDialog.setTitle(R.string.android_start_title);
5773 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005774 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5775 mBootMsgDialog.setIndeterminate(true);
5776 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005777 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005778 mBootMsgDialog.getWindow().addFlags(
5779 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5780 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5781 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005782 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5783 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5784 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005785 mBootMsgDialog.setCancelable(false);
5786 mBootMsgDialog.show();
5787 }
5788 mBootMsgDialog.setMessage(msg);
5789 }
5790 });
5791 }
5792
5793 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005794 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005795 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005796 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005797 }
5798
Mike Lockwood28569302010-01-28 11:54:40 -05005799 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005800 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005801 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005802 // ***************************************
5803 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5804 // ***************************************
5805 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5806 // WITH ITS LOCKS HELD.
5807 //
5808 // This code must be VERY careful about the locks
5809 // it acquires.
5810 // In fact, the current code acquires way too many,
5811 // and probably has lurking deadlocks.
5812
Mike Lockwood28569302010-01-28 11:54:40 -05005813 synchronized (mScreenLockTimeout) {
5814 if (mLockScreenTimerActive) {
5815 // reset the timer
5816 mHandler.removeCallbacks(mScreenLockTimeout);
5817 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5818 }
5819 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005820 }
5821
Adam Cohenf7522022012-10-03 20:03:18 -07005822 class ScreenLockTimeout implements Runnable {
5823 Bundle options;
5824
5825 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005826 public void run() {
5827 synchronized (this) {
5828 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005829 if (mKeyguardDelegate != null) {
5830 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005831 }
Mike Lockwood28569302010-01-28 11:54:40 -05005832 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005833 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005834 }
5835 }
Mike Lockwood28569302010-01-28 11:54:40 -05005836
Adam Cohenf7522022012-10-03 20:03:18 -07005837 public void setLockOptions(Bundle options) {
5838 this.options = options;
5839 }
5840 }
5841
5842 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5843
Jose Lima9546b202014-07-02 17:21:51 -07005844 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005845 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005846 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5847 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005848 if (options != null) {
5849 // In case multiple calls are made to lockNow, we don't wipe out the options
5850 // until the runnable actually executes.
5851 mScreenLockTimeout.setLockOptions(options);
5852 }
Jim Miller93c518e2012-01-17 15:55:31 -08005853 mHandler.post(mScreenLockTimeout);
5854 }
5855
Mike Lockwood28569302010-01-28 11:54:40 -05005856 private void updateLockScreenTimeout() {
5857 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005858 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005859 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005860 if (mLockScreenTimerActive != enable) {
5861 if (enable) {
5862 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5863 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5864 } else {
5865 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5866 mHandler.removeCallbacks(mScreenLockTimeout);
5867 }
5868 mLockScreenTimerActive = enable;
5869 }
5870 }
5871 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005872
Jeff Brown061ea992015-04-17 19:55:47 -07005873 private void updateDreamingSleepToken(boolean acquire) {
5874 if (acquire) {
5875 if (mDreamingSleepToken == null) {
5876 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
5877 }
5878 } else {
5879 if (mDreamingSleepToken != null) {
5880 mDreamingSleepToken.release();
5881 }
5882 }
5883 }
5884
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005885 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005886 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005887 public void enableScreenAfterBoot() {
5888 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005889 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005890 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005891 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005892
Jeff Brownc458ce92012-04-30 14:58:40 -07005893 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005894 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005895 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005896 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005897 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005898 }
Jeff Browna20dda42014-05-27 20:57:24 -07005899
5900 synchronized (mLock) {
5901 updateWakeGestureListenerLp();
5902 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005903 }
5904
Jeff Brown4f5fa282014-06-12 19:19:15 -07005905 void updateUiMode() {
5906 if (mUiModeManager == null) {
5907 mUiModeManager = IUiModeManager.Stub.asInterface(
5908 ServiceManager.getService(Context.UI_MODE_SERVICE));
5909 }
5910 try {
5911 mUiMode = mUiModeManager.getCurrentModeType();
5912 } catch (RemoteException e) {
5913 }
5914 }
5915
Jeff Brown01a98dd2011-09-20 15:08:29 -07005916 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005917 try {
5918 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005919 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5920 } catch (RemoteException e) {
5921 // Ignore
5922 }
5923 }
5924
5925 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5926 try {
5927 //set orientation on WindowManager
5928 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005929 } catch (RemoteException e) {
5930 // Ignore
5931 }
5932 }
5933
Daniel Sandler6396c722013-04-16 20:19:09 -04005934 /**
5935 * Return an Intent to launch the currently active dock app as home. Returns
5936 * null if the standard home should be launched, which is the case if any of the following is
5937 * true:
5938 * <ul>
5939 * <li>The device is not in either car mode or desk mode
5940 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5941 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5942 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5943 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5944 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005945 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005946 */
5947 Intent createHomeDockIntent() {
5948 Intent intent = null;
5949
5950 // What home does is based on the mode, not the dock state. That
5951 // is, when in car mode you should be taken to car home regardless
5952 // of whether we are actually in a car dock.
5953 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5954 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5955 intent = mCarDockIntent;
5956 }
5957 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5958 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5959 intent = mDeskDockIntent;
5960 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005961 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5962 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5963 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5964 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5965 // Always launch dock home from home when watch is docked, if it exists.
5966 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005967 }
5968
5969 if (intent == null) {
5970 return null;
5971 }
5972
5973 ActivityInfo ai = null;
5974 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5975 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005976 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005977 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005978 if (info != null) {
5979 ai = info.activityInfo;
5980 }
5981 if (ai != null
5982 && ai.metaData != null
5983 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5984 intent = new Intent(intent);
5985 intent.setClassName(ai.packageName, ai.name);
5986 return intent;
5987 }
5988
5989 return null;
5990 }
5991
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005992 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
5993 if (awakenFromDreams) {
5994 awakenDreams();
5995 }
Daniel Sandler6396c722013-04-16 20:19:09 -04005996
5997 Intent dock = createHomeDockIntent();
5998 if (dock != null) {
5999 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006000 if (fromHomeKey) {
6001 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6002 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006003 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006004 return;
6005 } catch (ActivityNotFoundException e) {
6006 }
6007 }
6008
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006009 Intent intent;
6010
6011 if (fromHomeKey) {
6012 intent = new Intent(mHomeIntent);
6013 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6014 } else {
6015 intent = mHomeIntent;
6016 }
6017
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006018 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006019 }
Craig Mautnereda67292013-04-28 13:50:14 -07006020
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006021 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006022 * goes to the home screen
6023 * @return whether it did anything
6024 */
6025 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006026 if (!isUserSetupComplete()) {
6027 Slog.i(TAG, "Not going home because user setup is in progress.");
6028 return false;
6029 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006030 if (false) {
6031 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006032 try {
6033 ActivityManagerNative.getDefault().stopAppSwitches();
6034 } catch (RemoteException e) {
6035 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006036 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006037 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006038 } else {
6039 // This code brings home to the front or, if it is already
6040 // at the front, puts the device to sleep.
6041 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006042 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6043 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6044 Log.d(TAG, "UTS-TEST-MODE");
6045 } else {
6046 ActivityManagerNative.getDefault().stopAppSwitches();
6047 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006048 Intent dock = createHomeDockIntent();
6049 if (dock != null) {
6050 int result = ActivityManagerNative.getDefault()
6051 .startActivityAsUser(null, null, dock,
6052 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6053 null, null, 0,
6054 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006055 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006056 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6057 return false;
6058 }
6059 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006060 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006061 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006062 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006063 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006064 null, null, 0,
6065 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006066 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006067 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006068 return false;
6069 }
6070 } catch (RemoteException ex) {
6071 // bummer, the activity manager, which is in this process, is dead
6072 }
6073 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006074 return true;
6075 }
Craig Mautnereda67292013-04-28 13:50:14 -07006076
6077 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006078 public void setCurrentOrientationLw(int newOrientation) {
6079 synchronized (mLock) {
6080 if (newOrientation != mCurrentAppOrientation) {
6081 mCurrentAppOrientation = newOrientation;
6082 updateOrientationListenerLp();
6083 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006084 }
6085 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006086
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006087 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6088 if (!isGlobalAccessibilityGestureEnabled()) {
6089 return;
6090 }
6091 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6092 Context.AUDIO_SERVICE);
6093 if (audioManager.isSilentMode()) {
6094 return;
6095 }
6096 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6097 Settings.System.DEFAULT_NOTIFICATION_URI);
6098 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6099 ringTone.play();
6100 }
Craig Mautnereda67292013-04-28 13:50:14 -07006101
Bryce Lee584a4452014-10-21 15:55:55 -07006102 private boolean isTheaterModeEnabled() {
6103 return Settings.Global.getInt(mContext.getContentResolver(),
6104 Settings.Global.THEATER_MODE_ON, 0) == 1;
6105 }
6106
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006107 private boolean isGlobalAccessibilityGestureEnabled() {
6108 return Settings.Global.getInt(mContext.getContentResolver(),
6109 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6110 }
6111
Craig Mautnereda67292013-04-28 13:50:14 -07006112 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006113 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006114 if (!mVibrator.hasVibrator()) {
6115 return false;
6116 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006117 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6118 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006119 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006120 return false;
6121 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006122 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006123 switch (effectId) {
6124 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006125 pattern = mLongPressVibePattern;
6126 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006127 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006128 pattern = mVirtualKeyVibePattern;
6129 break;
6130 case HapticFeedbackConstants.KEYBOARD_TAP:
6131 pattern = mKeyboardTapVibePattern;
6132 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006133 case HapticFeedbackConstants.CLOCK_TICK:
6134 pattern = mClockTickVibePattern;
6135 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006136 case HapticFeedbackConstants.CALENDAR_DATE:
6137 pattern = mCalendarDateVibePattern;
6138 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006139 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006140 pattern = mSafeModeDisabledVibePattern;
6141 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006142 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006143 pattern = mSafeModeEnabledVibePattern;
6144 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006145 default:
6146 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006147 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006148 int owningUid;
6149 String owningPackage;
6150 if (win != null) {
6151 owningUid = win.getOwningUid();
6152 owningPackage = win.getOwningPackage();
6153 } else {
6154 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006155 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006156 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006157 if (pattern.length == 1) {
6158 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006159 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006160 } else {
6161 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006162 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006163 }
6164 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006165 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006166
6167 @Override
6168 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006169 }
6170
Jeff Brownc38c9be2012-10-04 13:16:19 -07006171 @Override
6172 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006173 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006174 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006175 }
6176 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006177
Dianne Hackborndf89e652011-10-06 22:35:11 -07006178 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006179 // If there is no window focused, there will be nobody to handle the events
6180 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006181 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6182 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006183 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006184 return 0;
6185 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006186 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006187 // We are updating at a point where the keyguard has gotten
6188 // focus, but we were last in a state where the top window is
6189 // hiding it. This is probably because the keyguard as been
6190 // shown while the top window was displayed, so we want to ignore
6191 // it here because this is just a very transient change and it
6192 // will quickly lose focus once it correctly gets hidden.
6193 return 0;
6194 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006195
John Spurlock1db8b682014-02-18 11:18:59 -05006196 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006197 & ~mResettingSystemUiFlags
6198 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006199 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006200 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006201 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006202 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006203 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006204 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006205 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006206 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006207 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006208 return 0;
6209 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006210 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006211 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006212 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006213 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006214 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006215 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006216 try {
6217 IStatusBarService statusbar = getStatusBarService();
6218 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006219 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006220 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006221 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006222 } catch (RemoteException e) {
6223 // re-acquire status bar service next time it is needed.
6224 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006225 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006226 }
6227 });
6228 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006229 }
6230
Adrian Rooscd3884d2015-02-18 17:25:23 +01006231 private int updateLightStatusBarLw(int vis) {
6232 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6233 ? mStatusBar
6234 : mTopFullscreenOpaqueOrDimmingWindowState;
6235
6236 if (statusColorWin != null) {
6237 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6238 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6239 // its light flag.
6240 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6241 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6242 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6243 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6244 // Otherwise if it's dimming, clear the light flag.
6245 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6246 }
6247 }
6248 return vis;
6249 }
6250
John Spurlock79da8332013-09-20 12:04:47 -04006251 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006252 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006253 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6254 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006255 : mTopFullscreenOpaqueWindowState;
6256 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6257 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6258
John Spurlock27735a42013-08-14 17:57:38 -04006259 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04006260 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006261 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006262 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6263 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006264 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006265 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6266 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006267 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006268 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6269 }
John Spurlockbd957402013-10-03 11:38:39 -04006270 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006271 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006272
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006273 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006274 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6275 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006276 }
6277
John Spurlock27735a42013-08-14 17:57:38 -04006278 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006279 boolean immersiveSticky =
6280 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006281 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006282 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006283 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006284 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6285 boolean hideStatusBarSysui =
6286 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006287 boolean hideNavBarSysui =
6288 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006289
John Spurlock27735a42013-08-14 17:57:38 -04006290 boolean transientStatusBarAllowed =
6291 mStatusBar != null && (
6292 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006293 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006294 || statusBarHasFocus);
6295
John Spurlockf1a36642013-10-12 17:50:42 -04006296 boolean transientNavBarAllowed =
6297 mNavigationBar != null &&
6298 hideNavBarSysui && immersiveSticky;
6299
John Spurlockf25706f2013-11-07 18:02:43 -05006300 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006301 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006302 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006303 && !transientNavBarAllowed;
6304 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006305 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006306 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006307 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006308 }
John Spurlock27735a42013-08-14 17:57:38 -04006309
6310 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6311
6312 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006313 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6314 boolean newImmersiveMode = isImmersiveMode(vis);
6315 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006316 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006317 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6318 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006319 }
John Spurlock27735a42013-08-14 17:57:38 -04006320
John Spurlockf1a36642013-10-12 17:50:42 -04006321 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6322
John Spurlocke1f366f2013-08-05 12:22:40 -04006323 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006324 }
6325
John Spurlockf1a36642013-10-12 17:50:42 -04006326 private void clearClearableFlagsLw() {
6327 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6328 if (newVal != mResettingSystemUiFlags) {
6329 mResettingSystemUiFlags = newVal;
6330 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6331 }
6332 }
6333
6334 private boolean isImmersiveMode(int vis) {
6335 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006336 return mNavigationBar != null
6337 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006338 && (vis & flags) != 0
6339 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006340 }
6341
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006342 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006343 * @return whether the navigation or status bar can be made translucent
6344 *
6345 * This should return true unless touch exploration is not enabled or
6346 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006347 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006348 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006349 return mTranslucentDecorEnabled
6350 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006351 }
6352
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006353 // Use this instead of checking config_showNavigationBar so that it can be consistently
6354 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006355 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006356 public boolean hasNavigationBar() {
6357 return mHasNavigationBar;
6358 }
6359
satok1bc0a492012-04-25 22:47:12 +09006360 @Override
6361 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6362 mLastInputMethodWindow = ime;
6363 mLastInputMethodTargetWindow = target;
6364 }
6365
Craig Mautnerf1b67412012-09-19 13:18:29 -07006366 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006367 public int getInputMethodWindowVisibleHeightLw() {
6368 return mDockBottom - mCurBottom;
6369 }
6370
6371 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006372 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006373 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006374 if (mKeyguardDelegate != null) {
6375 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006376 }
John Spurlock13451a22012-09-28 14:40:41 -04006377 if (mStatusBarService != null) {
6378 try {
6379 mStatusBarService.setCurrentUser(newUserId);
6380 } catch (RemoteException e) {
6381 // oh well
6382 }
6383 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006384 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006385 }
6386
6387 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006388 public boolean canMagnifyWindow(int windowType) {
6389 switch (windowType) {
6390 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6391 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6392 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6393 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6394 return false;
6395 }
6396 }
6397 return true;
6398 }
6399
6400 @Override
6401 public boolean isTopLevelWindow(int windowType) {
6402 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6403 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6404 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6405 }
6406 return true;
6407 }
6408
Jim Miller4eeb4f62012-11-08 00:04:29 -08006409 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006410 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006411 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006412 pw.print(" mSystemReady="); pw.print(mSystemReady);
6413 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006414 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006415 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006416 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006417 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006418 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6419 || mForceClearedSystemUiFlags != 0) {
6420 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6421 pw.print(Integer.toHexString(mLastSystemUiFlags));
6422 pw.print(" mResettingSystemUiFlags=0x");
6423 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6424 pw.print(" mForceClearedSystemUiFlags=0x");
6425 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006426 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006427 if (mLastFocusNeedsMenu) {
6428 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6429 pw.println(mLastFocusNeedsMenu);
6430 }
Jeff Browna20dda42014-05-27 20:57:24 -07006431 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6432 pw.println(mWakeGestureEnabledSetting);
6433
Jeff Brownbcdfc622014-03-06 19:13:04 -08006434 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006435 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6436 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006437 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6438 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6439 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6440 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006441 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006442 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006443 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6444 pw.print(mCarDockEnablesAccelerometer);
6445 pw.print(" mDeskDockEnablesAccelerometer=");
6446 pw.println(mDeskDockEnablesAccelerometer);
6447 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6448 pw.print(mLidKeyboardAccessibility);
6449 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006450 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006451 pw.print(prefix);
6452 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6453 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006454 pw.print(prefix);
6455 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6456 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006457 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006458 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6459 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6460 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6461 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6462 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6463 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6464 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006465 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6466 pw.print(","); pw.print(mOverscanScreenTop);
6467 pw.print(") "); pw.print(mOverscanScreenWidth);
6468 pw.print("x"); pw.println(mOverscanScreenHeight);
6469 if (mOverscanLeft != 0 || mOverscanTop != 0
6470 || mOverscanRight != 0 || mOverscanBottom != 0) {
6471 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6472 pw.print(" top="); pw.print(mOverscanTop);
6473 pw.print(" right="); pw.print(mOverscanRight);
6474 pw.print(" bottom="); pw.println(mOverscanBottom);
6475 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006476 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6477 pw.print(mRestrictedOverscanScreenLeft);
6478 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6479 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6480 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006481 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6482 pw.print(","); pw.print(mUnrestrictedScreenTop);
6483 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6484 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6485 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6486 pw.print(","); pw.print(mRestrictedScreenTop);
6487 pw.print(") "); pw.print(mRestrictedScreenWidth);
6488 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006489 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6490 pw.print(","); pw.print(mStableFullscreenTop);
6491 pw.print(")-("); pw.print(mStableFullscreenRight);
6492 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006493 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6494 pw.print(","); pw.print(mStableTop);
6495 pw.print(")-("); pw.print(mStableRight);
6496 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006497 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6498 pw.print(","); pw.print(mSystemTop);
6499 pw.print(")-("); pw.print(mSystemRight);
6500 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006501 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6502 pw.print(","); pw.print(mCurTop);
6503 pw.print(")-("); pw.print(mCurRight);
6504 pw.print(","); pw.print(mCurBottom); pw.println(")");
6505 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6506 pw.print(","); pw.print(mContentTop);
6507 pw.print(")-("); pw.print(mContentRight);
6508 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006509 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6510 pw.print(","); pw.print(mVoiceContentTop);
6511 pw.print(")-("); pw.print(mVoiceContentRight);
6512 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006513 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6514 pw.print(","); pw.print(mDockTop);
6515 pw.print(")-("); pw.print(mDockRight);
6516 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006517 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6518 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006519 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6520 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006521 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6522 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006523 if (mLastInputMethodWindow != null) {
6524 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6525 pw.println(mLastInputMethodWindow);
6526 }
6527 if (mLastInputMethodTargetWindow != null) {
6528 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6529 pw.println(mLastInputMethodTargetWindow);
6530 }
6531 if (mStatusBar != null) {
6532 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006533 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6534 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006535 }
6536 if (mNavigationBar != null) {
6537 pw.print(prefix); pw.print("mNavigationBar=");
6538 pw.println(mNavigationBar);
6539 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006540 if (mFocusedWindow != null) {
6541 pw.print(prefix); pw.print("mFocusedWindow=");
6542 pw.println(mFocusedWindow);
6543 }
6544 if (mFocusedApp != null) {
6545 pw.print(prefix); pw.print("mFocusedApp=");
6546 pw.println(mFocusedApp);
6547 }
6548 if (mWinDismissingKeyguard != null) {
6549 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6550 pw.println(mWinDismissingKeyguard);
6551 }
6552 if (mTopFullscreenOpaqueWindowState != null) {
6553 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6554 pw.println(mTopFullscreenOpaqueWindowState);
6555 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006556 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6557 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6558 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6559 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006560 if (mForcingShowNavBar) {
6561 pw.print(prefix); pw.print("mForcingShowNavBar=");
6562 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6563 pw.println(mForcingShowNavBarLayer);
6564 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006565 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006566 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006567 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6568 pw.print(" mForceStatusBarFromKeyguard=");
6569 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006570 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006571 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006572 pw.print(" mHomePressed="); pw.println(mHomePressed);
6573 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6574 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6575 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6576 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6577 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6578 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6579 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6580 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6581 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6582 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006583 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6584 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6585 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006586
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006587 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006588 mStatusBarController.dump(pw, prefix);
6589 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006590 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006591
Jeff Browna20dda42014-05-27 20:57:24 -07006592 if (mWakeGestureListener != null) {
6593 mWakeGestureListener.dump(pw, prefix);
6594 }
Jeff Brown600f0032014-05-22 17:06:00 -07006595 if (mOrientationListener != null) {
6596 mOrientationListener.dump(pw, prefix);
6597 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006598 if (mBurnInProtectionHelper != null) {
6599 mBurnInProtectionHelper.dump(prefix, pw);
6600 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006601 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006602}