blob: fbacd751527b862463014f66eb1ce465fda7c0a8 [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;
Craig Mautner88400d32012-09-30 12:35:45 -0700188
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800189 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
190 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
191 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500192 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700193 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800194
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700195 /**
196 * These are the system UI flags that, when changing, can cause the layout
197 * of the screen to change.
198 */
199 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400200 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400201 | View.SYSTEM_UI_FLAG_FULLSCREEN
202 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200203 | View.NAVIGATION_BAR_TRANSLUCENT
204 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700205
John Spurlock7b414672014-07-18 13:02:39 -0400206 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
207 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
208 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
209 .build();
210
Jim Miller5ecd8112013-01-09 18:50:26 -0800211 /**
212 * Keyguard stuff
213 */
214 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100215 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700216 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800217
Jeff Brown6651a632011-11-28 12:59:11 -0800218 /* Table of Application Launch keys. Maps from key codes to intent categories.
219 *
220 * These are special keys that are used to launch particular kinds of applications,
221 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
222 * usage page. We don't support quite that many yet...
223 */
224 static SparseArray<String> sApplicationLaunchKeyCategories;
225 static {
226 sApplicationLaunchKeyCategories = new SparseArray<String>();
227 sApplicationLaunchKeyCategories.append(
228 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
229 sApplicationLaunchKeyCategories.append(
230 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
231 sApplicationLaunchKeyCategories.append(
232 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
233 sApplicationLaunchKeyCategories.append(
234 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
235 sApplicationLaunchKeyCategories.append(
236 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
237 sApplicationLaunchKeyCategories.append(
238 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
239 }
240
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700241 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
242 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
243
Dianne Hackborndf89e652011-10-06 22:35:11 -0700244 /**
245 * Lock protecting internal state. Must not call out into window
246 * manager with lock held. (This lock will be acquired in places
247 * where the window manager is calling in with its own lock held.)
248 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800249 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700250
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800251 Context mContext;
252 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700253 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700254 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700255 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700256 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700257 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400258 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700259 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700260 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800261 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700262 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800263 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000264 BurnInProtectionHelper mBurnInProtectionHelper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800265
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700266 // Vibrator pattern for haptic feedback of a long press.
267 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700268
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700269 // Vibrator pattern for haptic feedback of virtual key press.
270 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700271
Amith Yamasanic33cb712010-02-10 15:21:49 -0800272 // Vibrator pattern for a short vibration.
273 long[] mKeyboardTapVibePattern;
274
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700275 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
276 long[] mClockTickVibePattern;
277
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700278 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
279 long[] mCalendarDateVibePattern;
280
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700281 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
282 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700283
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700284 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
285 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700286
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800287 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
288 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400289
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800290 boolean mSafeMode;
291 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700292 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400293 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400294 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700295 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400296 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
297 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
298 int[] mNavigationBarHeightForRotation = new int[4];
299 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400300
Craig Mautnera631d492014-08-05 15:16:01 -0700301 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800302 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700303 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700304 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700305 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700306 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
307 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
308 }
309 };
310 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
311 @Override
312 public void onShown(IBinder windowToken) {
313 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
314 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
315 }
316 };
317
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800318 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800319 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900320 WindowState mLastInputMethodWindow = null;
321 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800322
Jeff Brown13f00f02014-10-31 14:45:50 -0700323 // FIXME This state is shared between the input reader and handler thread.
324 // Technically it's broken and buggy but it has been like this for many years
325 // and we have not yet seen any problems. Someday we'll rewrite this logic
326 // so that only one thread is involved in handling input policy. Unfortunately
327 // it's on a critical path for power management so we can't just post the work to the
328 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
329 // to hold wakelocks during dispatch and eliminating the critical path.
330 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800331 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700332 volatile int mPowerKeyPressCounter;
333 volatile boolean mEndCallKeyHandled;
334
Winson Chungd42a6cf2014-06-03 16:24:04 -0700335 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700336 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700337 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800338
Jeff Brown2e7760e2012-04-11 15:14:55 -0700339 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700340 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700341 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800342
Dianne Hackbornc777e072010-02-12 13:07:59 -0800343 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700344 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800345 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700346 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400347 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700348 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700349 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400350 int mCarDockRotation;
351 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700352 int mUndockedHdmiRotation;
353 int mDemoHdmiRotation;
354 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800355 int mDemoRotation;
356 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400357
Jeff Browna20dda42014-05-27 20:57:24 -0700358 boolean mWakeGestureEnabledSetting;
359 MyWakeGestureListener mWakeGestureListener;
360
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700361 // Default display does not rotate, apps that require non-default orientation will have to
362 // have the orientation emulated.
363 private boolean mForceDefaultOrientation = false;
364
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400365 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
366 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700367 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400368
Jeff Brownbcdfc622014-03-06 19:13:04 -0800369 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700370 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400371 boolean mCarDockEnablesAccelerometer;
372 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700373 int mLidKeyboardAccessibility;
374 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700375 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700376 int mShortPressOnPowerBehavior;
377 int mLongPressOnPowerBehavior;
378 int mDoublePressOnPowerBehavior;
379 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000380 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700381 boolean mAwake;
382 boolean mScreenOnEarly;
383 boolean mScreenOnFully;
384 ScreenOnListener mScreenOnListener;
385 boolean mKeyguardDrawComplete;
386 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800387 boolean mOrientationSensorEnabled = false;
388 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800389 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400390 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800391 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700392
Jeff Brown70825162012-03-28 17:27:48 -0700393 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800394
395 // The last window we were told about in focusChanged.
396 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800397 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800398
Jeff Brown70825162012-03-28 17:27:48 -0700399 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800400
Dianne Hackbornc652de82013-02-15 16:32:56 -0800401 // The current size of the screen; really; extends into the overscan area of
402 // the screen and doesn't account for any system elements like the status bar.
403 int mOverscanScreenLeft, mOverscanScreenTop;
404 int mOverscanScreenWidth, mOverscanScreenHeight;
405 // The current visible size of the screen; really; (ir)regardless of whether the status
406 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800407 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
408 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800409 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
410 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
411 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700412 // The current size of the screen; these may be different than (0,0)-(dw,dh)
413 // if the status bar can't be hidden; in that case it effectively carves out
414 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800415 int mRestrictedScreenLeft, mRestrictedScreenTop;
416 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700417 // During layout, the current screen borders accounting for any currently
418 // visible system UI elements.
419 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700420 // For applications requesting stable content insets, these are them.
421 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700422 // For applications requesting stable content insets but have also set the
423 // fullscreen window flag, these are the stable dimensions without the status bar.
424 int mStableFullscreenLeft, mStableFullscreenTop;
425 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800426 // During layout, the current screen borders with all outer decoration
427 // (status bar, input method dock) accounted for.
428 int mCurLeft, mCurTop, mCurRight, mCurBottom;
429 // During layout, the frame in which content should be displayed
430 // to the user, accounting for all screen decoration except for any
431 // space they deem as available for other content. This is usually
432 // the same as mCur*, but may be larger if the screen decor has supplied
433 // content insets.
434 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700435 // During layout, the frame in which voice content should be displayed
436 // to the user, accounting for all screen decoration except for any
437 // space they deem as available for other content.
438 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800439 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800440 // windows are placed.
441 int mDockLeft, mDockTop, mDockRight, mDockBottom;
442 // During layout, the layer at which the doc window is placed.
443 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700444 // During layout, this is the layer of the status bar.
445 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700446 int mLastSystemUiFlags;
447 // Bits that we are in the process of clearing, so we want to prevent
448 // them from being set by applications until everything has been updated
449 // to have them clear.
450 int mResettingSystemUiFlags = 0;
451 // Bits that we are currently always keeping cleared.
452 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800453 // What we last reported to system UI about whether the compatibility
454 // menu needs to be displayed.
455 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700456
457 FakeWindow mHideNavFakeWindow = null;
458
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800459 static final Rect mTmpParentFrame = new Rect();
460 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800461 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800462 static final Rect mTmpContentFrame = new Rect();
463 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400464 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700465 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700466 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700467
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800468 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100469 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700470 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200471 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400472 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800473 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700474 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700475 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800476 boolean mForcingShowNavBar;
477 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700478
479 // States of keyguard dismiss.
480 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
481 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
482 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
483 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
484
485 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
486 * be done once per window. */
487 private WindowState mWinDismissingKeyguard;
488
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700489 /** The window that is currently showing "over" the keyguard. If there is an app window
490 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
491 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
492 * the wallpaper. */
493 private WindowState mWinShowWhenLocked;
494
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700495 boolean mShowingLockscreen;
496 boolean mShowingDream;
497 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700498 boolean mDreamingSleepTokenNeeded;
499 SleepToken mDreamingSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700500 boolean mKeyguardSecure;
501 boolean mKeyguardSecureIncludingHidden;
502 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800503 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700504 boolean mHomeConsumed;
505 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800506 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700507 Intent mCarDockIntent;
508 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700509 boolean mSearchKeyShortcutPending;
510 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700511 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700512 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800513
Mike Lockwood28569302010-01-28 11:54:40 -0500514 // support for activating the lock screen while the screen is on
515 boolean mAllowLockscreenWhenOn;
516 int mLockScreenTimeout;
517 boolean mLockScreenTimerActive;
518
David Brownbaf8d092010-03-08 21:52:59 -0800519 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800520 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800521
522 // Behavior of POWER button while in-call and screen on.
523 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
524 int mIncallPowerBehavior;
525
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700526 Display mDisplay;
527
Dianne Hackborn9d132642011-04-21 17:26:39 -0700528 int mLandscapeRotation = 0; // default landscape rotation
529 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
530 int mPortraitRotation = 0; // default portrait rotation
531 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700532
Dianne Hackbornc652de82013-02-15 16:32:56 -0800533 int mOverscanLeft = 0;
534 int mOverscanTop = 0;
535 int mOverscanRight = 0;
536 int mOverscanBottom = 0;
537
Joe Onorato46b0d682010-11-22 17:37:27 -0800538 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700539 private int mLongPressOnHomeBehavior;
540
541 // What we do when the user double-taps on home
542 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800543
Bryce Lee584a4452014-10-21 15:55:55 -0700544 // Allowed theater mode wake actions
545 private boolean mAllowTheaterModeWakeFromKey;
546 private boolean mAllowTheaterModeWakeFromPowerKey;
547 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800548 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700549 private boolean mAllowTheaterModeWakeFromCameraLens;
550 private boolean mAllowTheaterModeWakeFromLidSwitch;
551 private boolean mAllowTheaterModeWakeFromWakeGesture;
552
Bryce Leed3b28402015-03-09 15:49:13 +0000553 // Whether to support long press from power button in non-interactive mode
554 private boolean mSupportLongPressPowerWhenNonInteractive;
555
Bryce Lee55e846d2014-11-04 12:43:44 -0800556 // Whether to go to sleep entering theater mode from power button
557 private boolean mGoToSleepOnButtonPressTheaterMode;
558
Winson Chung9112ec32011-06-27 13:15:32 -0700559 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700560 // Time to volume and power must be pressed within this interval of each other.
561 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700562 // Increase the chord delay when taking a screenshot from the keyguard
563 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800564 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700565 private boolean mScreenshotChordVolumeDownKeyTriggered;
566 private long mScreenshotChordVolumeDownKeyTime;
567 private boolean mScreenshotChordVolumeDownKeyConsumed;
568 private boolean mScreenshotChordVolumeUpKeyTriggered;
569 private boolean mScreenshotChordPowerKeyTriggered;
570 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700571
Michael Wrightb854e242013-02-05 17:54:02 -0800572 /* The number of steps between min and max brightness */
573 private static final int BRIGHTNESS_STEPS = 10;
574
Christopher Tate5e08af02012-09-21 17:17:22 -0700575 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800576 ShortcutManager mShortcutManager;
577 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700578 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700579 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800580
Craig Mautnerd625ab22013-09-06 13:40:31 -0700581 private int mCurrentUserId;
582
Justin Kohd378ad72013-04-01 12:18:26 -0700583 // Maps global key codes to the components that will handle them.
584 private GlobalKeyManager mGlobalKeyManager;
585
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700586 // Fallback actions by key code.
587 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
588 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800589
Jorim Jaggi76a16232014-08-08 17:00:47 +0200590 private final LogDecelerateInterpolator mLogDecelerateInterpolator
591 = new LogDecelerateInterpolator(100, 0);
592
Jeff Brown70825162012-03-28 17:27:48 -0700593 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
594 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700595 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
596 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700597 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
598 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
599 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700600 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700601 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700602 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700603 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700604 private static final int MSG_POWER_DELAYED_PRESS = 13;
605 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700606 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jeff Brown70825162012-03-28 17:27:48 -0700607
608 private class PolicyHandler extends Handler {
609 @Override
610 public void handleMessage(Message msg) {
611 switch (msg.what) {
612 case MSG_ENABLE_POINTER_LOCATION:
613 enablePointerLocation();
614 break;
615 case MSG_DISABLE_POINTER_LOCATION:
616 disablePointerLocation();
617 break;
Jeff Brown40013652012-05-16 21:22:36 -0700618 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
619 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
620 break;
621 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
622 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
623 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700624 case MSG_DISPATCH_SHOW_RECENTS:
625 showRecentApps(false);
626 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700627 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
628 showGlobalActionsInternal();
629 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700630 case MSG_KEYGUARD_DRAWN_COMPLETE:
631 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700632 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700633 break;
634 case MSG_KEYGUARD_DRAWN_TIMEOUT:
635 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700636 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700637 break;
638 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
639 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700640 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700641 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700642 case MSG_HIDE_BOOT_MESSAGE:
643 handleHideBootMessage();
644 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700645 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
646 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
647 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700648 case MSG_POWER_DELAYED_PRESS:
649 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
650 finishPowerKeyPress();
651 break;
652 case MSG_POWER_LONG_PRESS:
653 powerLongPress();
654 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700655 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
656 updateDreamingSleepToken(msg.arg1 != 0);
657 break;
Jeff Brown70825162012-03-28 17:27:48 -0700658 }
659 }
660 }
661
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800662 private UEventObserver mHDMIObserver = new UEventObserver() {
663 @Override
664 public void onUEvent(UEventObserver.UEvent event) {
665 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
666 }
667 };
668
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800669 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800670 SettingsObserver(Handler handler) {
671 super(handler);
672 }
David Brownbaf8d092010-03-08 21:52:59 -0800673
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800674 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700675 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800676 ContentResolver resolver = mContext.getContentResolver();
677 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700678 Settings.System.END_BUTTON_BEHAVIOR), false, this,
679 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800680 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700681 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
682 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700683 resolver.registerContentObserver(Settings.Secure.getUriFor(
684 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
685 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800686 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700687 Settings.System.ACCELEROMETER_ROTATION), false, this,
688 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500689 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700690 Settings.System.USER_ROTATION), false, this,
691 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400692 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700693 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
694 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800695 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700696 Settings.System.POINTER_LOCATION), false, this,
697 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800698 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700699 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
700 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500701 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400702 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700703 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500704 resolver.registerContentObserver(Settings.Global.getUriFor(
705 Settings.Global.POLICY_CONTROL), false, this,
706 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800707 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800708 }
709
710 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800711 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700712 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800713 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800714 }
Craig Mautner967212c2013-04-13 21:10:58 -0700715
Jeff Browna20dda42014-05-27 20:57:24 -0700716 class MyWakeGestureListener extends WakeGestureListener {
717 MyWakeGestureListener(Context context, Handler handler) {
718 super(context, handler);
719 }
720
721 @Override
722 public void onWakeUp() {
723 synchronized (mLock) {
724 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700725 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700726 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700727 }
728 }
729 }
730 }
731
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800732 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800733 MyOrientationListener(Context context, Handler handler) {
734 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800735 }
Craig Mautner967212c2013-04-13 21:10:58 -0700736
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800737 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700738 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700739 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700740 updateRotation(false);
741 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800742 }
743 MyOrientationListener mOrientationListener;
744
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100745 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400746
John Spurlock27735a42013-08-14 17:57:38 -0400747 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400748 View.NAVIGATION_BAR_TRANSIENT,
749 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400750 View.NAVIGATION_BAR_TRANSLUCENT,
751 StatusBarManager.WINDOW_NAVIGATION_BAR,
752 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400753
John Spurlockf1a36642013-10-12 17:50:42 -0400754 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400755
Craig Mautner037aa8d2013-06-07 10:35:44 -0700756 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400757
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700758 IStatusBarService getStatusBarService() {
759 synchronized (mServiceAquireLock) {
760 if (mStatusBarService == null) {
761 mStatusBarService = IStatusBarService.Stub.asInterface(
762 ServiceManager.getService("statusbar"));
763 }
764 return mStatusBarService;
765 }
766 }
767
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700768 /*
769 * We always let the sensor be switched on by default except when
770 * the user has explicitly disabled sensor based rotation or when the
771 * screen is switched off.
772 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700773 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800774 if (mSupportAutoRotation) {
775 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
776 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
777 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
778 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
779 // If the application has explicitly requested to follow the
780 // orientation, then we need to turn the sensor on.
781 return true;
782 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800783 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700784 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800785 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
786 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
787 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400788 // enable accelerometer if we are docked in a dock that enables accelerometer
789 // orientation management,
790 return true;
791 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700792 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800793 // If the setting for using the sensor by default is enabled, then
794 // we will always leave it on. Note that the user could go to
795 // a window that forces an orientation that does not use the
796 // sensor and in theory we could turn it off... however, when next
797 // turning it on we won't have a good value for the current
798 // orientation for a little bit, which can cause orientation
799 // changes to lag, so we'd like to keep it always on. (It will
800 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700801 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800802 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800803 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800804 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700805
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800806 /*
807 * Various use cases for invoking this function
808 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700809 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800810 * if not already enabled
811 * screen turned on and current app does not have sensor orientation, disable listeners if
812 * already enabled
813 * screen turning on and current app has sensor based orientation, enable listeners if needed
814 * screen turning on and current app has nosensor based orientation, do nothing
815 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700816 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800817 if (!mOrientationListener.canDetectOrientation()) {
818 // If sensor is turned off or nonexistent for some reason
819 return;
820 }
821 //Could have been invoked due to screen turning on or off or
822 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700823 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
824 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
825 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800826 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700827 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700828 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800829 disable = false;
830 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700831 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800832 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700833 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800834 mOrientationSensorEnabled = true;
835 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700836 }
837 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800838 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700839 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800840 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700841 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800842 mOrientationSensorEnabled = false;
843 }
844 }
845
Jeff Brown13f00f02014-10-31 14:45:50 -0700846 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
847 // Hold a wake lock until the power key is released.
848 if (!mPowerKeyWakeLock.isHeld()) {
849 mPowerKeyWakeLock.acquire();
850 }
851
852 // Cancel multi-press detection timeout.
853 if (mPowerKeyPressCounter != 0) {
854 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
855 }
856
857 // Detect user pressing the power button in panic when an application has
858 // taken over the whole screen.
859 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800860 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700861 if (panic) {
862 mHandler.post(mRequestTransientNav);
863 }
864
865 // Latch power key state to detect screenshot chord.
866 if (interactive && !mScreenshotChordPowerKeyTriggered
867 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
868 mScreenshotChordPowerKeyTriggered = true;
869 mScreenshotChordPowerKeyTime = event.getDownTime();
870 interceptScreenshotChord();
871 }
872
873 // Stop ringing or end call if configured to do so when power is pressed.
874 TelecomManager telecomManager = getTelecommService();
875 boolean hungUp = false;
876 if (telecomManager != null) {
877 if (telecomManager.isRinging()) {
878 // Pressing Power while there's a ringing incoming
879 // call should silence the ringer.
880 telecomManager.silenceRinger();
881 } else if ((mIncallPowerBehavior
882 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
883 && telecomManager.isInCall() && interactive) {
884 // Otherwise, if "Power button ends call" is enabled,
885 // the Power button will hang up any current active call.
886 hungUp = telecomManager.endCall();
887 }
888 }
889
890 // If the power key has still not yet been handled, then detect short
891 // press, long press, or multi press and decide what to do.
892 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
893 || mScreenshotChordVolumeUpKeyTriggered;
894 if (!mPowerKeyHandled) {
895 if (interactive) {
896 // When interactive, we're already awake.
897 // Wait for a long press or for the button to be released to decide what to do.
898 if (hasLongPressOnPowerBehavior()) {
899 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
900 msg.setAsynchronous(true);
901 mHandler.sendMessageDelayed(msg,
902 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
903 }
904 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800905 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800906
Bryce Leed3b28402015-03-09 15:49:13 +0000907 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
908 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
909 msg.setAsynchronous(true);
910 mHandler.sendMessageDelayed(msg,
911 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800912 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000913 } else {
914 final int maxCount = getMaxMultiPressPowerCount();
915
916 if (maxCount <= 1) {
917 mPowerKeyHandled = true;
918 } else {
919 mBeganFromNonInteractive = true;
920 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700921 }
922 }
Jeff Brown4d396052010-10-29 21:50:21 -0700923 }
924 }
925
Jeff Brown13f00f02014-10-31 14:45:50 -0700926 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
927 final boolean handled = canceled || mPowerKeyHandled;
928 mScreenshotChordPowerKeyTriggered = false;
929 cancelPendingScreenshotChordAction();
930 cancelPendingPowerKeyAction();
931
932 if (!handled) {
933 // Figure out how to handle the key now that it has been released.
934 mPowerKeyPressCounter += 1;
935
936 final int maxCount = getMaxMultiPressPowerCount();
937 final long eventTime = event.getDownTime();
938 if (mPowerKeyPressCounter < maxCount) {
939 // This could be a multi-press. Wait a little bit longer to confirm.
940 // Continue holding the wake lock.
941 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
942 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
943 msg.setAsynchronous(true);
944 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
945 return;
946 }
947
948 // No other actions. Handle it immediately.
949 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700950 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700951
952 // Done. Reset our state.
953 finishPowerKeyPress();
954 }
955
956 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800957 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700958 mPowerKeyPressCounter = 0;
959 if (mPowerKeyWakeLock.isHeld()) {
960 mPowerKeyWakeLock.release();
961 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700962 }
963
964 private void cancelPendingPowerKeyAction() {
965 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700966 mPowerKeyHandled = true;
967 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700968 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700969 }
970
971 private void powerPress(long eventTime, boolean interactive, int count) {
972 if (mScreenOnEarly && !mScreenOnFully) {
973 Slog.i(TAG, "Suppressed redundant power key press while "
974 + "already in the process of turning the screen on.");
975 return;
Jeff Brownff204712011-10-25 21:27:54 -0700976 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700977
978 if (count == 2) {
979 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
980 } else if (count == 3) {
981 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -0800982 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700983 switch (mShortPressOnPowerBehavior) {
984 case SHORT_PRESS_POWER_NOTHING:
985 break;
986 case SHORT_PRESS_POWER_GO_TO_SLEEP:
987 mPowerManager.goToSleep(eventTime,
988 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
989 break;
990 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
991 mPowerManager.goToSleep(eventTime,
992 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
993 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
994 break;
995 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
996 mPowerManager.goToSleep(eventTime,
997 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
998 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
999 launchHomeFromHotKey();
1000 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001001 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001002 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001003 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001004 }
1005 }
1006 }
1007
1008 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1009 switch (behavior) {
1010 case MULTI_PRESS_POWER_NOTHING:
1011 break;
1012 case MULTI_PRESS_POWER_THEATER_MODE:
1013 if (isTheaterModeEnabled()) {
1014 Slog.i(TAG, "Toggling theater mode off.");
1015 Settings.Global.putInt(mContext.getContentResolver(),
1016 Settings.Global.THEATER_MODE_ON, 0);
1017 if (!interactive) {
1018 wakeUpFromPowerKey(eventTime);
1019 }
1020 } else {
1021 Slog.i(TAG, "Toggling theater mode on.");
1022 Settings.Global.putInt(mContext.getContentResolver(),
1023 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001024
1025 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001026 mPowerManager.goToSleep(eventTime,
1027 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1028 }
1029 }
1030 break;
1031 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001032 Slog.i(TAG, "Starting brightness boost.");
1033 if (!interactive) {
1034 wakeUpFromPowerKey(eventTime);
1035 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001036 mPowerManager.boostScreenBrightness(eventTime);
1037 break;
1038 }
1039 }
1040
1041 private int getMaxMultiPressPowerCount() {
1042 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1043 return 3;
1044 }
1045 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1046 return 2;
1047 }
1048 return 1;
1049 }
1050
1051 private void powerLongPress() {
1052 final int behavior = getResolvedLongPressOnPowerBehavior();
1053 switch (behavior) {
1054 case LONG_PRESS_POWER_NOTHING:
1055 break;
1056 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1057 mPowerKeyHandled = true;
1058 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1059 performAuditoryFeedbackForAccessibilityIfNeed();
1060 }
1061 showGlobalActionsInternal();
1062 break;
1063 case LONG_PRESS_POWER_SHUT_OFF:
1064 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1065 mPowerKeyHandled = true;
1066 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1067 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1068 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1069 break;
1070 }
1071 }
1072
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001073 private void sleepPress(KeyEvent event) {
1074 switch (mShortPressOnSleepBehavior) {
1075 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
1076 mPowerManager.goToSleep(event.getEventTime(),
1077 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1078 break;
1079 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001080 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001081 mPowerManager.goToSleep(event.getEventTime(),
1082 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1083 break;
1084 }
1085 }
1086
Jeff Brown13f00f02014-10-31 14:45:50 -07001087 private int getResolvedLongPressOnPowerBehavior() {
1088 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1089 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1090 }
1091 return mLongPressOnPowerBehavior;
1092 }
1093
1094 private boolean hasLongPressOnPowerBehavior() {
1095 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001096 }
1097
1098 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001099 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001100 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1101 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001102 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001103 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1104 && now <= mScreenshotChordPowerKeyTime
1105 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1106 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001107 cancelPendingPowerKeyAction();
1108
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001109 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001110 }
1111 }
1112 }
1113
Winson Chung1cea2f32012-10-08 20:42:01 -07001114 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001115 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001116 // Double the time it takes to take a screenshot from the keyguard
1117 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001118 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001119 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001120 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001121 }
1122
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001123 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001124 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001125 }
1126
Jeff Brown13f00f02014-10-31 14:45:50 -07001127 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001128 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001129 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001130 mEndCallKeyHandled = true;
1131 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1132 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001133 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001134 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001135 }
1136 };
1137
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001138 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001139 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001140 public void run() {
1141 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001142 }
1143 };
1144
Alan Viverettee34560b22014-07-10 14:50:06 -07001145 @Override
1146 public void showGlobalActions() {
1147 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1148 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1149 }
1150
1151 void showGlobalActionsInternal() {
1152 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001153 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001154 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001155 }
Jim Millerab954542014-10-10 18:21:49 -07001156 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001157 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1158 if (keyguardShowing) {
1159 // since it took two seconds of long press to bring this up,
1160 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001161 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001162 }
1163 }
1164
1165 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001166 return Settings.Global.getInt(
1167 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001168 }
1169
Maurice Lam99c6e072014-04-28 18:24:28 -07001170 boolean isUserSetupComplete() {
1171 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1172 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1173 }
1174
Jeff Brown13f00f02014-10-31 14:45:50 -07001175 private void handleShortPressOnHome() {
1176 // If there's a dream running then use home to escape the dream
1177 // but don't actually go home.
1178 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1179 mDreamManagerInternal.stopDream(false /*immediate*/);
1180 return;
1181 }
1182
1183 // Go home!
1184 launchHomeFromHotKey();
1185 }
1186
Patrick Dubroyece94522011-02-23 18:35:01 -08001187 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -08001188 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001189 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001190 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001191
Jeff Browncaca8812013-05-09 13:34:33 -07001192 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1193 toggleRecentApps();
1194 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1195 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -07001196 }
1197 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001198 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001199
Jeff Browncaca8812013-05-09 13:34:33 -07001200 private void handleDoubleTapOnHome() {
1201 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1202 mHomeConsumed = true;
1203 toggleRecentApps();
1204 }
1205 }
1206
1207 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1208 @Override
1209 public void run() {
1210 if (mHomeDoubleTapPending) {
1211 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001212 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001213 }
1214 }
1215 };
1216
Mark Renoufc1256912015-03-11 14:38:23 -04001217 private boolean isRoundWindow() {
1218 return mContext.getResources().getBoolean(com.android.internal.R.bool.config_windowIsRound)
1219 || (Build.HARDWARE.contains("goldfish")
1220 && SystemProperties.getBoolean(ViewRootImpl.PROPERTY_EMULATOR_CIRCULAR, false));
1221 }
1222
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001223 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001224 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001225 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001226 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001227 mContext = context;
1228 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001229 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001230 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001231 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001232 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Mark Renoufc1256912015-03-11 14:38:23 -04001233
1234 // Init display burn-in protection
1235 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1236 com.android.internal.R.bool.config_enableBurnInProtection);
1237 // Allow a system property to override this. Used by developer settings.
1238 boolean burnInProtectionDevMode =
1239 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1240 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1241 final int minHorizontal;
1242 final int maxHorizontal;
1243 final int minVertical;
1244 final int maxVertical;
1245 final int maxRadius;
1246 if (burnInProtectionDevMode) {
1247 minHorizontal = -8;
1248 maxHorizontal = 8;
1249 minVertical = -8;
1250 maxVertical = -4;
1251 maxRadius = (isRoundWindow()) ? 6 : -1;
1252 } else {
1253 Resources resources = context.getResources();
1254 minHorizontal = resources.getInteger(
1255 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1256 maxHorizontal = resources.getInteger(
1257 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1258 minVertical = resources.getInteger(
1259 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1260 maxVertical = resources.getInteger(
1261 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1262 maxRadius = resources.getInteger(
1263 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1264 }
1265 mBurnInProtectionHelper = new BurnInProtectionHelper(
1266 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001267 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001268
Jeff Brown70825162012-03-28 17:27:48 -07001269 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001270 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001271 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001272 try {
1273 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1274 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001275 mSettingsObserver = new SettingsObserver(mHandler);
1276 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001277 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001278 mUiMode = context.getResources().getInteger(
1279 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001280 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1281 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1282 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1283 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001284 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1285 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1286 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1287 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1288 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1289 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1290 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1291 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001292
Jeff Brown96307042012-07-27 15:51:34 -07001293 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1294 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001295 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001296 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1297 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001298 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001299 mSupportAutoRotation = mContext.getResources().getBoolean(
1300 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001301 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001302 com.android.internal.R.integer.config_lidOpenRotation);
1303 mCarDockRotation = readRotation(
1304 com.android.internal.R.integer.config_carDockRotation);
1305 mDeskDockRotation = readRotation(
1306 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001307 mUndockedHdmiRotation = readRotation(
1308 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001309 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1310 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1311 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1312 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001313 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1314 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1315 mLidNavigationAccessibility = mContext.getResources().getInteger(
1316 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001317 mLidControlsSleep = mContext.getResources().getBoolean(
1318 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001319 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1320 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001321
1322 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1323 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1324 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1325 || mContext.getResources().getBoolean(
1326 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1327 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1328 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001329 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1330 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001331 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1332 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1333 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1334 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1335 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1336 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1337
Bryce Lee55e846d2014-11-04 12:43:44 -08001338 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1339 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1340
Bryce Leed3b28402015-03-09 15:49:13 +00001341 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1342 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1343
Jeff Brown13f00f02014-10-31 14:45:50 -07001344 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1345 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1346 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1347 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1348 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1349 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1350 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1351 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001352 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1353 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001354
John Spurlock61560172015-02-06 19:46:04 -05001355 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001356
Jeff Brownf71343d2013-05-31 17:59:11 -07001357 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001358
Svetoslav8e3feb12014-02-24 13:46:47 -08001359 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1360 Context.ACCESSIBILITY_SERVICE);
1361
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001362 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001363 IntentFilter filter = new IntentFilter();
1364 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1365 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1366 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1367 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001368 filter.addAction(Intent.ACTION_DOCK_EVENT);
1369 Intent intent = context.registerReceiver(mDockReceiver, filter);
1370 if (intent != null) {
1371 // Retrieve current sticky dock event broadcast.
1372 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1373 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1374 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001375
Jeff Brown6aaf2952012-10-05 16:01:08 -07001376 // register for dream-related broadcasts
1377 filter = new IntentFilter();
1378 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1379 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1380 context.registerReceiver(mDreamReceiver, filter);
1381
Christopher Tate5e08af02012-09-21 17:17:22 -07001382 // register for multiuser-relevant broadcasts
1383 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1384 context.registerReceiver(mMultiuserReceiver, filter);
1385
John Spurlock57306e62013-04-22 09:48:49 -04001386 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001387 mSystemGestures = new SystemGesturesPointerEventListener(context,
1388 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001389 @Override
1390 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001391 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001392 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001393 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001394 }
1395 @Override
1396 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001397 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001398 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001399 }
1400 }
1401 @Override
1402 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001403 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001404 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001405 }
1406 }
1407 @Override
1408 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001409 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001410 }
Adrian Roos3595be42015-03-05 16:31:15 +01001411 @Override
1412 public void onDown() {
1413 mOrientationListener.onTouchStart();
1414 }
1415 @Override
1416 public void onUpOrCancel() {
1417 mOrientationListener.onTouchEnd();
1418 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001419 });
John Spurlockf1a36642013-10-12 17:50:42 -04001420 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001421 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001422
Jeff Brownc2346132012-04-13 01:55:38 -07001423 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001424 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1425 com.android.internal.R.array.config_longPressVibePattern);
1426 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1427 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001428 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1429 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001430 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1431 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001432 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1433 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001434 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1435 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1436 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1437 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001438
Christopher Tatee90585f2012-03-05 18:56:25 -08001439 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1440 com.android.internal.R.bool.config_enableScreenshotChord);
1441
Justin Kohd378ad72013-04-01 12:18:26 -07001442 mGlobalKeyManager = new GlobalKeyManager(mContext);
1443
Joe Onoratoea495d42011-04-06 11:41:11 -07001444 // Controls rotation and the like.
1445 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001446
1447 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001448 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001449 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001450 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001451
1452 mWindowManagerInternal.registerAppTransitionListener(
1453 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001454 }
1455
Jeff Brownf71343d2013-05-31 17:59:11 -07001456 /**
1457 * Read values from config.xml that may be overridden depending on
1458 * the configuration of the device.
1459 * eg. Disable long press on home goes to recents on sw600dp.
1460 */
1461 private void readConfigurationDependentBehaviors() {
1462 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1463 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1464 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1465 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1466 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1467 }
1468
1469 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1470 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1471 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1472 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1473 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1474 }
1475 }
1476
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001477 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001478 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001479 // This method might be called before the policy has been fully initialized
1480 // or for other displays we don't care about.
1481 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1482 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001483 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001484 mDisplay = display;
1485
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001486 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001487 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001488 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001489 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001490 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001491 mLandscapeRotation = Surface.ROTATION_0;
1492 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001493 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001494 mPortraitRotation = Surface.ROTATION_90;
1495 mUpsideDownRotation = Surface.ROTATION_270;
1496 } else {
1497 mPortraitRotation = Surface.ROTATION_270;
1498 mUpsideDownRotation = Surface.ROTATION_90;
1499 }
1500 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001501 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001502 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001503 mPortraitRotation = Surface.ROTATION_0;
1504 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001505 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001506 mLandscapeRotation = Surface.ROTATION_270;
1507 mSeascapeRotation = Surface.ROTATION_90;
1508 } else {
1509 mLandscapeRotation = Surface.ROTATION_90;
1510 mSeascapeRotation = Surface.ROTATION_270;
1511 }
1512 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001513
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001514 mStatusBarHeight =
1515 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001516
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001517 // Height of the navigation bar when presented horizontally at bottom
1518 mNavigationBarHeightForRotation[mPortraitRotation] =
1519 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001520 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001521 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001522 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1523 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001524
1525 // Width of the navigation bar when presented vertically along one side
1526 mNavigationBarWidthForRotation[mPortraitRotation] =
1527 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1528 mNavigationBarWidthForRotation[mLandscapeRotation] =
1529 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001530 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001531
1532 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001533 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001534 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001535
Devin Kimd7b12b42014-05-05 14:34:58 -07001536 // Allow the navigation bar to move on non-square small devices (phones).
1537 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001538
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001539 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001540 // Allow a system property to override this. Used by the emulator.
1541 // See also hasNavigationBar().
1542 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1543 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001544 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001545 } else if ("0".equals(navBarOverride)) {
1546 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001547 }
1548
Jeff Brown27f1d672012-10-17 18:32:34 -07001549 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1550 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001551 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001552 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001553 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001554 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001555 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001556 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001557
Chong Zhangae6119ff2014-11-11 18:54:39 -08001558 // For demo purposes, allow the rotation of the remote display to be controlled.
1559 // By default, remote display locks rotation to landscape.
1560 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1561 mDemoRotation = mPortraitRotation;
1562 } else {
1563 mDemoRotation = mLandscapeRotation;
1564 }
1565 mDemoRotationLock = SystemProperties.getBoolean(
1566 "persist.demo.rotationlock", false);
1567
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001568 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1569 // http://developer.android.com/guide/practices/screens_support.html#range
1570 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1571 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1572 // For debug purposes the next line turns this feature off with:
1573 // $ adb shell setprop config.override_forced_orient true
1574 // $ adb shell wm size reset
1575 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1576 }
1577
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001578 /**
1579 * @return whether the navigation bar can be hidden, e.g. the device has a
1580 * navigation bar and touch exploration is not enabled
1581 */
1582 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001583 return mHasNavigationBar
1584 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001585 }
1586
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001587 @Override
1588 public boolean isDefaultOrientationForced() {
1589 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001590 }
1591
Dianne Hackbornc652de82013-02-15 16:32:56 -08001592 @Override
1593 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1594 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1595 mOverscanLeft = left;
1596 mOverscanTop = top;
1597 mOverscanRight = right;
1598 mOverscanBottom = bottom;
1599 }
1600 }
1601
Dianne Hackbornc777e072010-02-12 13:07:59 -08001602 public void updateSettings() {
1603 ContentResolver resolver = mContext.getContentResolver();
1604 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001605 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001606 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001607 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001608 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1609 UserHandle.USER_CURRENT);
1610 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001611 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001612 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1613 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001614
Jeff Browna20dda42014-05-27 20:57:24 -07001615 // Configure wake gesture.
1616 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1617 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1618 UserHandle.USER_CURRENT) != 0;
1619 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1620 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1621 updateWakeGestureListenerLp();
1622 }
1623
Jeff Brown207673cd2012-06-05 17:47:11 -07001624 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001625 int userRotation = Settings.System.getIntForUser(resolver,
1626 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1627 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001628 if (mUserRotation != userRotation) {
1629 mUserRotation = userRotation;
1630 updateRotation = true;
1631 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001632 int userRotationMode = Settings.System.getIntForUser(resolver,
1633 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001634 WindowManagerPolicy.USER_ROTATION_FREE :
1635 WindowManagerPolicy.USER_ROTATION_LOCKED;
1636 if (mUserRotationMode != userRotationMode) {
1637 mUserRotationMode = userRotationMode;
1638 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001639 updateOrientationListenerLp();
1640 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001641
Dianne Hackbornc777e072010-02-12 13:07:59 -08001642 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001643 int pointerLocation = Settings.System.getIntForUser(resolver,
1644 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001645 if (mPointerLocationMode != pointerLocation) {
1646 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001647 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1648 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001649 }
1650 }
1651 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001652 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1653 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1654 String imId = Settings.Secure.getStringForUser(resolver,
1655 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001656 boolean hasSoftInput = imId != null && imId.length() > 0;
1657 if (mHasSoftInput != hasSoftInput) {
1658 mHasSoftInput = hasSoftInput;
1659 updateRotation = true;
1660 }
John Spurlockf1a36642013-10-12 17:50:42 -04001661 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001662 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001663 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001664 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001665 }
1666 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001667 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001668 }
Jeff Brown70825162012-03-28 17:27:48 -07001669 }
1670
Jeff Browna20dda42014-05-27 20:57:24 -07001671 private void updateWakeGestureListenerLp() {
1672 if (shouldEnableWakeGestureLp()) {
1673 mWakeGestureListener.requestWakeUpTrigger();
1674 } else {
1675 mWakeGestureListener.cancelWakeUpTrigger();
1676 }
1677 }
1678
1679 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001680 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001681 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1682 && mWakeGestureListener.isSupported();
1683 }
1684
Jeff Brown70825162012-03-28 17:27:48 -07001685 private void enablePointerLocation() {
1686 if (mPointerLocationView == null) {
1687 mPointerLocationView = new PointerLocationView(mContext);
1688 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001689 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1690 WindowManager.LayoutParams.MATCH_PARENT,
1691 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001692 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001693 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1694 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1695 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1696 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001697 if (ActivityManager.isHighEndGfx()) {
1698 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1699 lp.privateFlags |=
1700 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1701 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001702 lp.format = PixelFormat.TRANSLUCENT;
1703 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001704 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001705 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001706 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001707 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001708 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001709 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001710 }
Jeff Brown70825162012-03-28 17:27:48 -07001711
1712 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001713 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001714 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1715 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001716 wm.removeView(mPointerLocationView);
1717 mPointerLocationView = null;
1718 }
1719 }
1720
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001721 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001722 try {
1723 int rotation = mContext.getResources().getInteger(resID);
1724 switch (rotation) {
1725 case 0:
1726 return Surface.ROTATION_0;
1727 case 90:
1728 return Surface.ROTATION_90;
1729 case 180:
1730 return Surface.ROTATION_180;
1731 case 270:
1732 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001733 }
1734 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001735 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001736 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001737 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001738 }
1739
1740 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001741 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001742 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001743 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001744
1745 outAppOp[0] = AppOpsManager.OP_NONE;
1746
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001747 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1748 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1749 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1750 return WindowManagerGlobal.ADD_INVALID_TYPE;
1751 }
1752
1753 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1754 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001755 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001756 }
1757 String permission = null;
1758 switch (type) {
1759 case TYPE_TOAST:
1760 // XXX right now the app process has complete control over
1761 // this... should introduce a token to let the system
1762 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001763 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001764 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001765 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001766 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001767 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001768 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001769 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001770 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001771 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001772 break;
1773 case TYPE_PHONE:
1774 case TYPE_PRIORITY_PHONE:
1775 case TYPE_SYSTEM_ALERT:
1776 case TYPE_SYSTEM_ERROR:
1777 case TYPE_SYSTEM_OVERLAY:
1778 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001779 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001780 break;
1781 default:
1782 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1783 }
1784 if (permission != null) {
1785 if (mContext.checkCallingOrSelfPermission(permission)
1786 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001787 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001788 }
1789 }
Jeff Brown98365d72012-08-19 20:30:52 -07001790 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001791 }
Craig Mautner88400d32012-09-30 12:35:45 -07001792
1793 @Override
1794 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1795
1796 // If this switch statement is modified, modify the comment in the declarations of
1797 // the type in {@link WindowManager.LayoutParams} as well.
1798 switch (attrs.type) {
1799 default:
1800 // These are the windows that by default are shown only to the user that created
1801 // them. If this needs to be overridden, set
1802 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1803 // {@link WindowManager.LayoutParams}. Note that permission
1804 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1805 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1806 return true;
1807 }
1808 break;
1809
1810 // These are the windows that by default are shown to all users. However, to
1811 // protect against spoofing, check permissions below.
1812 case TYPE_APPLICATION_STARTING:
1813 case TYPE_BOOT_PROGRESS:
1814 case TYPE_DISPLAY_OVERLAY:
1815 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001816 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001817 case TYPE_KEYGUARD_DIALOG:
1818 case TYPE_MAGNIFICATION_OVERLAY:
1819 case TYPE_NAVIGATION_BAR:
1820 case TYPE_NAVIGATION_BAR_PANEL:
1821 case TYPE_PHONE:
1822 case TYPE_POINTER:
1823 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001824 case TYPE_SEARCH_BAR:
1825 case TYPE_STATUS_BAR:
1826 case TYPE_STATUS_BAR_PANEL:
1827 case TYPE_STATUS_BAR_SUB_PANEL:
1828 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001829 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001830 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001831 break;
1832 }
1833
1834 // Check if third party app has set window to system window type.
1835 return mContext.checkCallingOrSelfPermission(
1836 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1837 != PackageManager.PERMISSION_GRANTED;
1838 }
1839
Craig Mautner967212c2013-04-13 21:10:58 -07001840 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001841 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1842 switch (attrs.type) {
1843 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001844 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001845 // These types of windows can't receive input events.
1846 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1847 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001848 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001849 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001850 case TYPE_STATUS_BAR:
1851
1852 // If the Keyguard is in a hidden state (occluded by another window), we force to
1853 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1854 // the keyguard as occluded wouldn't set these flags again.
1855 // See {@link #processKeyguardSetHiddenResultLw}.
1856 if (mKeyguardHidden) {
1857 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1858 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1859 }
1860 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001861 }
Adrian Roos38502112014-04-09 21:04:11 +02001862
1863 if (attrs.type != TYPE_STATUS_BAR) {
1864 // The status bar is the only window allowed to exhibit keyguard behavior.
1865 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1866 }
Adrian Roosea562512014-05-05 13:33:03 +02001867
1868 if (ActivityManager.isHighEndGfx()
1869 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001870 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001871 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1872 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001873 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001874
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001875 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001876 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001877 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001878
Michael Wright3818c922014-09-02 13:59:07 -07001879 private void readCameraLensCoverState() {
1880 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1881 }
1882
Jeff Browndaa37532012-05-01 15:54:03 -07001883 private boolean isHidden(int accessibilityMode) {
1884 switch (accessibilityMode) {
1885 case 1:
1886 return mLidState == LID_CLOSED;
1887 case 2:
1888 return mLidState == LID_OPEN;
1889 default:
1890 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001891 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001892 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001893
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001894 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001895 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001896 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1897 int navigationPresence) {
1898 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1899
Jeff Brownf71343d2013-05-31 17:59:11 -07001900 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001901 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001902 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001903
Jeff Browndaa37532012-05-01 15:54:03 -07001904 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1905 || (keyboardPresence == PRESENCE_INTERNAL
1906 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001907 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001908 if (!mHasSoftInput) {
1909 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1910 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001911 }
1912
Jeff Browndaa37532012-05-01 15:54:03 -07001913 if (config.navigation == Configuration.NAVIGATION_NONAV
1914 || (navigationPresence == PRESENCE_INTERNAL
1915 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001916 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001917 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001918 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001919
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001920 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001921 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001922 public int windowTypeToLayerLw(int type) {
1923 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001924 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001925 }
1926 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001927 case TYPE_PRIVATE_PRESENTATION:
1928 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001929 case TYPE_WALLPAPER:
1930 // wallpaper is at the bottom, though the window manager may move it.
1931 return 2;
1932 case TYPE_PHONE:
1933 return 3;
1934 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07001935 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001936 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001937 case TYPE_VOICE_INTERACTION:
1938 // voice interaction layer is almost immediately above apps.
1939 return 5;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001940 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001941 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001942 case TYPE_TOAST:
1943 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001944 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001945 case TYPE_PRIORITY_PHONE:
1946 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001947 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001948 case TYPE_DREAM:
1949 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001950 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001951 case TYPE_SYSTEM_ALERT:
1952 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001953 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001954 case TYPE_INPUT_METHOD:
1955 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001956 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001957 case TYPE_INPUT_METHOD_DIALOG:
1958 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001959 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001960 case TYPE_KEYGUARD_SCRIM:
1961 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001962 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001963 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001964 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001965 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001966 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001967 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001968 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001969 case TYPE_KEYGUARD_DIALOG:
1970 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001971 case TYPE_VOLUME_OVERLAY:
1972 // the on-screen volume indicator and controller shown when the user
1973 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001974 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001975 case TYPE_SYSTEM_OVERLAY:
1976 // the on-screen volume indicator and controller shown when the user
1977 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001978 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001979 case TYPE_NAVIGATION_BAR:
1980 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001981 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001982 case TYPE_NAVIGATION_BAR_PANEL:
1983 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001984 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001985 case TYPE_SYSTEM_ERROR:
1986 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001987 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001988 case TYPE_MAGNIFICATION_OVERLAY:
1989 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001990 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001991 case TYPE_DISPLAY_OVERLAY:
1992 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001993 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001994 case TYPE_DRAG:
1995 // the drag layer: input for drag-and-drop is associated with this window,
1996 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001997 return 25;
Svetoslav3a5c7212014-10-14 09:54:26 -07001998 case TYPE_ACCESSIBILITY_OVERLAY:
1999 // overlay put by accessibility services to intercept user interaction
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002000 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002001 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002002 return 27;
Svetoslav3a5c7212014-10-14 09:54:26 -07002003 case TYPE_BOOT_PROGRESS:
2004 return 28;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002005 case TYPE_POINTER:
2006 // the (mouse) pointer layer
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002007 return 29;
Svetoslav3a5c7212014-10-14 09:54:26 -07002008 case TYPE_HIDDEN_NAV_CONSUMER:
2009 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002010 }
2011 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002012 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002013 }
2014
2015 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002016 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002017 public int subWindowTypeToLayerLw(int type) {
2018 switch (type) {
2019 case TYPE_APPLICATION_PANEL:
2020 case TYPE_APPLICATION_ATTACHED_DIALOG:
2021 return APPLICATION_PANEL_SUBLAYER;
2022 case TYPE_APPLICATION_MEDIA:
2023 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002024 case TYPE_APPLICATION_MEDIA_OVERLAY:
2025 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002026 case TYPE_APPLICATION_SUB_PANEL:
2027 return APPLICATION_SUB_PANEL_SUBLAYER;
2028 }
2029 Log.e(TAG, "Unknown sub-window type: " + type);
2030 return 0;
2031 }
2032
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002033 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002034 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002035 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002036 }
2037
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002038 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002039 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002040 if (mHasNavigationBar) {
2041 // For a basic navigation bar, when we are in landscape mode we place
2042 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002043 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2044 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002045 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002046 }
2047 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002048 }
2049
Jose Lima9546b202014-07-02 17:21:51 -07002050 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002051 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002052 if (mHasNavigationBar) {
2053 // For a basic navigation bar, when we are in portrait mode we place
2054 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002055 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2056 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002057 }
2058 }
2059 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002060 }
2061
Jose Lima9546b202014-07-02 17:21:51 -07002062 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002063 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2064 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002065 }
2066
Jose Lima9546b202014-07-02 17:21:51 -07002067 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002068 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002069 // There is a separate status bar at the top of the display. We don't count that as part
2070 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002071 // we do want to exclude it since applications can't generally use that part
2072 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002073 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002074 }
2075
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002076 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002077 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2078 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002079 (isKeyguardHostWindow(attrs) &&
2080 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002081 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002082 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002083
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002084 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002085 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2086 return attrs.type == TYPE_STATUS_BAR;
2087 }
2088
2089 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002090 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002091 switch (attrs.type) {
2092 case TYPE_STATUS_BAR:
2093 case TYPE_NAVIGATION_BAR:
2094 case TYPE_WALLPAPER:
2095 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002096 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002097 return false;
2098 default:
2099 return true;
2100 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002101 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002102
Craig Mautner7d7808f2014-09-11 18:02:38 -07002103 @Override
2104 public WindowState getWinShowWhenLockedLw() {
2105 return mWinShowWhenLocked;
2106 }
2107
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002108 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002109 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002110 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2111 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002112 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002113 if (!SHOW_STARTING_ANIMATIONS) {
2114 return null;
2115 }
2116 if (packageName == null) {
2117 return null;
2118 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002119
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002120 WindowManager wm = null;
2121 View view = null;
2122
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002123 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002124 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002125 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2126 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2127 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002128 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002129 try {
2130 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002131 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002132 } catch (PackageManager.NameNotFoundException e) {
2133 // Ignore
2134 }
2135 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002136
Jorim Jaggib10e33f2015-02-04 21:57:40 +01002137 Window win = new PhoneWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002138 final TypedArray ta = win.getWindowStyle();
2139 if (ta.getBoolean(
2140 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2141 || ta.getBoolean(
2142 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002143 return null;
2144 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002145
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002146 Resources r = context.getResources();
2147 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002148
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002149 win.setType(
2150 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
2151 // Force the window flags: this is a fake window, so it is not really
2152 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2153 // flag because we do know that the next window will take input
2154 // focus, so we want to get the IME window up on top of us right away.
2155 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002156 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002157 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2158 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2159 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002160 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002161 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2162 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2163 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002164
Adam Powell04fe6eb2013-05-31 14:39:48 -07002165 win.setDefaultIcon(icon);
2166 win.setDefaultLogo(logo);
2167
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002168 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002169 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002170
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002171 final WindowManager.LayoutParams params = win.getAttributes();
2172 params.token = appToken;
2173 params.packageName = packageName;
2174 params.windowAnimations = win.getWindowStyle().getResourceId(
2175 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002176 params.privateFlags |=
2177 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002178 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002179
2180 if (!compatInfo.supportsScreen()) {
2181 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2182 }
2183
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002184 params.setTitle("Starting " + packageName);
2185
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002186 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2187 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002188
2189 if (win.isFloating()) {
2190 // Whoops, there is no way to display an animation/preview
2191 // of such a thing! After all that work... let's skip it.
2192 // (Note that we must do this here because it is in
2193 // getDecorView() where the theme is evaluated... maybe
2194 // we should peek the floating attribute from the theme
2195 // earlier.)
2196 return null;
2197 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002198
Craig Mautner6fbda632012-07-03 09:26:39 -07002199 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002200 TAG, "Adding starting window for " + packageName
2201 + " / " + appToken + ": "
2202 + (view.getParent() != null ? view : null));
2203
2204 wm.addView(view, params);
2205
2206 // Only return the view if it was successfully added to the
2207 // window manager... which we can tell by it having a parent.
2208 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002209 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002210 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002211 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2212 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002213 } catch (RuntimeException e) {
2214 // don't crash if something else bad happens, for example a
2215 // failure loading resources because we are loading from an app
2216 // on external storage that has been unmounted.
2217 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002218 } finally {
2219 if (view != null && view.getParent() == null) {
2220 Log.w(TAG, "view not successfully added to wm, removing view");
2221 wm.removeViewImmediate(view);
2222 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002223 }
2224
2225 return null;
2226 }
2227
2228 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002229 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002230 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002231 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2232 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002233
2234 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002235 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002236 wm.removeView(window);
2237 }
2238 }
2239
2240 /**
2241 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002242 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002243 * Currently enforces that three window types are singletons:
2244 * <ul>
2245 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002246 * <li>KEYGUARD_TYPE</li>
2247 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002248 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002249 * @param win The window to be added
2250 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002251 *
Jeff Brown98365d72012-08-19 20:30:52 -07002252 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2253 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002254 */
Jose Lima9546b202014-07-02 17:21:51 -07002255 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002256 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2257 switch (attrs.type) {
2258 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002259 mContext.enforceCallingOrSelfPermission(
2260 android.Manifest.permission.STATUS_BAR_SERVICE,
2261 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002262 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002263 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002264 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002265 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002266 }
2267 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002268 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002269 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002270 case TYPE_NAVIGATION_BAR:
2271 mContext.enforceCallingOrSelfPermission(
2272 android.Manifest.permission.STATUS_BAR_SERVICE,
2273 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002274 if (mNavigationBar != null) {
2275 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002276 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002277 }
2278 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002279 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002280 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002281 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002282 break;
Jim Millere898ac52012-04-06 17:10:57 -07002283 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002284 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002285 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002286 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002287 mContext.enforceCallingOrSelfPermission(
2288 android.Manifest.permission.STATUS_BAR_SERVICE,
2289 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002290 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002291 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002292 if (mKeyguardScrim != null) {
2293 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2294 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002295 mKeyguardScrim = win;
2296 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002297 }
Jeff Brown98365d72012-08-19 20:30:52 -07002298 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002299 }
2300
2301 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002302 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002303 public void removeWindowLw(WindowState win) {
2304 if (mStatusBar == win) {
2305 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002306 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002307 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002308 } else if (mKeyguardScrim == win) {
2309 Log.v(TAG, "Removing keyguard scrim");
2310 mKeyguardScrim = null;
2311 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002312 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002313 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002314 }
2315 }
2316
2317 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002318
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002319 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002320 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002321 public int selectAnimationLw(WindowState win, int transit) {
2322 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2323 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002324 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002325 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002326 if (transit == TRANSIT_EXIT
2327 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002328 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002329 } else if (transit == TRANSIT_ENTER
2330 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002331 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002332 }
2333 } else if (win == mNavigationBar) {
2334 // This can be on either the bottom or the right.
2335 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002336 if (transit == TRANSIT_EXIT
2337 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002338 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002339 } else if (transit == TRANSIT_ENTER
2340 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002341 return R.anim.dock_bottom_enter;
2342 }
2343 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002344 if (transit == TRANSIT_EXIT
2345 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002346 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002347 } else if (transit == TRANSIT_ENTER
2348 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002349 return R.anim.dock_right_enter;
2350 }
2351 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002352 }
2353
2354 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002355 if (win.hasAppShownWindows()) {
2356 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2357 return com.android.internal.R.anim.app_starting_exit;
2358 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002359 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002360 && transit == TRANSIT_ENTER) {
2361 // Special case: we are animating in a dream, while the keyguard
2362 // is shown. We don't want an animation on the dream, because
2363 // we need it shown immediately with the keyguard animating away
2364 // to reveal it.
2365 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002366 }
2367
2368 return 0;
2369 }
2370
Craig Mautner3c174372013-02-21 17:54:37 -08002371 @Override
2372 public void selectRotationAnimationLw(int anim[]) {
2373 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2374 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2375 + (mTopFullscreenOpaqueWindowState == null ?
2376 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2377 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2378 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2379 case ROTATION_ANIMATION_CROSSFADE:
2380 anim[0] = R.anim.rotation_animation_xfade_exit;
2381 anim[1] = R.anim.rotation_animation_enter;
2382 break;
2383 case ROTATION_ANIMATION_JUMPCUT:
2384 anim[0] = R.anim.rotation_animation_jump_exit;
2385 anim[1] = R.anim.rotation_animation_enter;
2386 break;
2387 case ROTATION_ANIMATION_ROTATE:
2388 default:
2389 anim[0] = anim[1] = 0;
2390 break;
2391 }
2392 } else {
2393 anim[0] = anim[1] = 0;
2394 }
2395 }
2396
2397 @Override
2398 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2399 boolean forceDefault) {
2400 switch (exitAnimId) {
2401 case R.anim.rotation_animation_xfade_exit:
2402 case R.anim.rotation_animation_jump_exit:
2403 // These are the only cases that matter.
2404 if (forceDefault) {
2405 return false;
2406 }
2407 int anim[] = new int[2];
2408 selectRotationAnimationLw(anim);
2409 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2410 default:
2411 return true;
2412 }
2413 }
2414
2415 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002416 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2417 boolean goingToNotificationShade) {
2418 if (goingToNotificationShade) {
2419 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002420 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002421
2422 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2423 R.anim.lock_screen_behind_enter_wallpaper :
2424 R.anim.lock_screen_behind_enter);
2425
2426 // TODO: Use XML interpolators when we have log interpolators available in XML.
2427 final List<Animation> animations = set.getAnimations();
2428 for (int i = animations.size() - 1; i >= 0; --i) {
2429 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2430 }
2431
2432 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002433 }
2434
2435
2436 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002437 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2438 if (goingToNotificationShade) {
2439 return null;
2440 } else {
2441 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2442 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002443 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002444
2445 private static void awakenDreams() {
2446 IDreamManager dreamManager = getDreamManager();
2447 if (dreamManager != null) {
2448 try {
2449 dreamManager.awaken();
2450 } catch (RemoteException e) {
2451 // fine, stay asleep then
2452 }
2453 }
2454 }
2455
2456 static IDreamManager getDreamManager() {
2457 return IDreamManager.Stub.asInterface(
2458 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2459 }
2460
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002461 TelecomManager getTelecommService() {
2462 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002463 }
2464
Jeff Brown4d396052010-10-29 21:50:21 -07002465 static IAudioService getAudioService() {
2466 IAudioService audioService = IAudioService.Stub.asInterface(
2467 ServiceManager.checkService(Context.AUDIO_SERVICE));
2468 if (audioService == null) {
2469 Log.w(TAG, "Unable to find IAudioService interface.");
2470 }
2471 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002472 }
2473
2474 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002475 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002476 }
2477
2478 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2479 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2480 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2481 };
2482
2483 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002484 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002485 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002486 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002487 final int keyCode = event.getKeyCode();
2488 final int repeatCount = event.getRepeatCount();
2489 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002490 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002491 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2492 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002493
Jeff Brown40013652012-05-16 21:22:36 -07002494 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002495 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002496 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2497 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002498 }
2499
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002500 // If we think we might have a volume down & power key chord on the way
2501 // but we're not sure, then tell the dispatcher to wait a little while and
2502 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002503 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002504 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002505 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002506 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2507 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002508 if (now < timeoutTime) {
2509 return timeoutTime - now;
2510 }
2511 }
2512 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002513 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002514 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002515 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002516 }
2517 return -1;
2518 }
2519 }
2520
Michael Wright6a62e552014-06-03 19:19:48 -07002521 // Cancel any pending meta actions if we see any other keys being pressed between the down
2522 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002523 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002524 mPendingMetaAction = false;
2525 }
2526
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002527 // First we always handle the home key here, so applications
2528 // can never break it, although if keyguard is on, we do let
2529 // it handle it, because that gives us the correct 5 second
2530 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002531 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002532
Jeff Brown49ed71d2010-12-06 17:13:33 -08002533 // If we have released the home key, and didn't do anything else
2534 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002535 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002536 cancelPreloadRecentApps();
2537
Jeff Brown49ed71d2010-12-06 17:13:33 -08002538 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002539 if (mHomeConsumed) {
2540 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002541 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002542 }
Jeff Browncaca8812013-05-09 13:34:33 -07002543
2544 if (canceled) {
2545 Log.i(TAG, "Ignoring HOME; event canceled.");
2546 return -1;
2547 }
2548
Yorke Lee4f803242014-12-15 23:22:06 +00002549 // If an incoming call is ringing, HOME is totally disabled.
2550 // (The user is already on the InCallUI at this point,
2551 // and his ONLY options are to answer or reject the call.)
2552 TelecomManager telecomManager = getTelecommService();
2553 if (telecomManager != null && telecomManager.isRinging()) {
2554 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2555 return -1;
2556 }
2557
Jeff Browncaca8812013-05-09 13:34:33 -07002558 // Delay handling home if a double-tap is possible.
2559 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2560 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2561 mHomeDoubleTapPending = true;
2562 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2563 ViewConfiguration.getDoubleTapTimeout());
2564 return -1;
2565 }
2566
Jeff Brown13f00f02014-10-31 14:45:50 -07002567 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002568 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002569 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002570
2571 // If a system window has focus, then it doesn't make sense
2572 // right now to interact with applications.
2573 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2574 if (attrs != null) {
2575 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002576 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2577 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2578 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002579 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002580 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002581 }
2582 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2583 for (int i=0; i<typeCount; i++) {
2584 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2585 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002586 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002587 }
2588 }
2589 }
Jeff Browncaca8812013-05-09 13:34:33 -07002590
2591 // Remember that home is pressed and handle special actions.
2592 if (repeatCount == 0) {
2593 mHomePressed = true;
2594 if (mHomeDoubleTapPending) {
2595 mHomeDoubleTapPending = false;
2596 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2597 handleDoubleTapOnHome();
2598 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2599 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2600 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002601 }
Jeff Browncaca8812013-05-09 13:34:33 -07002602 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2603 if (!keyguardOn) {
2604 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002605 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002606 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002607 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002608 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002609 // Hijack modified menu keys for debugging features
2610 final int chordBug = KeyEvent.META_SHIFT_ON;
2611
2612 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002613 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002614 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002615 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2616 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002617 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002618 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002619 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002620 Intent service = new Intent();
2621 service.setClassName(mContext, "com.android.server.LoadAverageService");
2622 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002623 boolean shown = Settings.Global.getInt(
2624 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002625 if (!shown) {
2626 mContext.startService(service);
2627 } else {
2628 mContext.stopService(service);
2629 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002630 Settings.Global.putInt(
2631 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002632 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002633 }
2634 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002635 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002636 if (down) {
2637 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002638 mSearchKeyShortcutPending = true;
2639 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002640 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002641 } else {
2642 mSearchKeyShortcutPending = false;
2643 if (mConsumeSearchKeyUp) {
2644 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002645 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002646 }
2647 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002648 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002649 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002650 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002651 if (down && repeatCount == 0) {
2652 preloadRecentApps();
2653 } else if (!down) {
2654 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002655 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002656 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002657 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002658 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2659 if (down) {
2660 if (repeatCount == 0) {
2661 mAssistKeyLongPressed = false;
2662 } else if (repeatCount == 1) {
2663 mAssistKeyLongPressed = true;
2664 if (!keyguardOn) {
2665 launchAssistLongPressAction();
2666 }
2667 }
2668 } else {
2669 if (mAssistKeyLongPressed) {
2670 mAssistKeyLongPressed = false;
2671 } else {
2672 if (!keyguardOn) {
2673 launchAssistAction();
2674 }
2675 }
2676 }
2677 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002678 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2679 if (!down) {
2680 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002681 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002682 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2683 } else {
2684 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002685 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002686 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002687 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002688 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002689 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2690 if (down && repeatCount == 0) {
2691 mHandler.post(mScreenshotRunnable);
2692 }
2693 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002694 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2695 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2696 if (down) {
2697 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2698
2699 // Disable autobrightness if it's on
2700 int auto = Settings.System.getIntForUser(
2701 mContext.getContentResolver(),
2702 Settings.System.SCREEN_BRIGHTNESS_MODE,
2703 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2704 UserHandle.USER_CURRENT_OR_SELF);
2705 if (auto != 0) {
2706 Settings.System.putIntForUser(mContext.getContentResolver(),
2707 Settings.System.SCREEN_BRIGHTNESS_MODE,
2708 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2709 UserHandle.USER_CURRENT_OR_SELF);
2710 }
2711
2712 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2713 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2714 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2715 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2716 Settings.System.SCREEN_BRIGHTNESS,
2717 mPowerManager.getDefaultScreenBrightnessSetting(),
2718 UserHandle.USER_CURRENT_OR_SELF);
2719 brightness += step;
2720 // Make sure we don't go beyond the limits.
2721 brightness = Math.min(max, brightness);
2722 brightness = Math.max(min, brightness);
2723
2724 Settings.System.putIntForUser(mContext.getContentResolver(),
2725 Settings.System.SCREEN_BRIGHTNESS, brightness,
2726 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002727 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002728 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002729 }
2730 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002731 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002732 if (down) {
2733 mPendingMetaAction = true;
2734 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002735 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002736 }
2737 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002738 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002739
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002740 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002741 // Any printing key that is chorded with Search should be consumed
2742 // even if no shortcut was invoked. This prevents text from being
2743 // inadvertently inserted when using a keyboard that has built-in macro
2744 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002745 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002746 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2747 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002748 mConsumeSearchKeyUp = true;
2749 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002750 if (down && repeatCount == 0 && !keyguardOn) {
2751 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2752 if (shortcutIntent != null) {
2753 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002754 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002755 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002756 } catch (ActivityNotFoundException ex) {
2757 Slog.w(TAG, "Dropping shortcut key combination because "
2758 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002759 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002760 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002761 } else {
2762 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002763 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002764 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002765 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002766 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002767 }
2768 }
2769
Jeff Brown68b909d2011-12-07 16:36:01 -08002770 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002771 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002772 && (metaState & KeyEvent.META_META_ON) != 0) {
2773 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002774 if (kcm.isPrintingKey(keyCode)) {
2775 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2776 metaState & ~(KeyEvent.META_META_ON
2777 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2778 if (shortcutIntent != null) {
2779 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2780 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002781 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002782 } catch (ActivityNotFoundException ex) {
2783 Slog.w(TAG, "Dropping shortcut key combination because "
2784 + "the activity to which it is registered was not found: "
2785 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2786 }
2787 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002788 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002789 }
2790 }
2791
Jeff Brown6651a632011-11-28 12:59:11 -08002792 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002793 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002794 String category = sApplicationLaunchKeyCategories.get(keyCode);
2795 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002796 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002797 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2798 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002799 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002800 } catch (ActivityNotFoundException ex) {
2801 Slog.w(TAG, "Dropping application launch key because "
2802 + "the activity to which it is registered was not found: "
2803 + "keyCode=" + keyCode + ", category=" + category, ex);
2804 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002805 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002806 }
2807 }
2808
Michael Wright61c46752014-08-21 16:57:33 -07002809 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002810 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002811 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002812 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002813 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002814 mRecentAppsHeldModifiers = shiftlessModifiers;
2815 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002816 return -1;
2817 }
2818 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002819 } else if (!down && mRecentAppsHeldModifiers != 0
2820 && (metaState & mRecentAppsHeldModifiers) == 0) {
2821 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002822 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002823 }
2824
Jeff Browncf39bdf2012-05-18 14:41:19 -07002825 // Handle keyboard language switching.
2826 if (down && repeatCount == 0
2827 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2828 || (keyCode == KeyEvent.KEYCODE_SPACE
2829 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2830 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2831 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2832 return -1;
2833 }
2834 if (mLanguageSwitchKeyPressed && !down
2835 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2836 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2837 mLanguageSwitchKeyPressed = false;
2838 return -1;
2839 }
2840
Jeff Brown13f00f02014-10-31 14:45:50 -07002841 if (isValidGlobalKey(keyCode)
2842 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002843 return -1;
2844 }
2845
Michael Wright6a62e552014-06-03 19:19:48 -07002846 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002847 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002848 return -1;
2849 }
2850
Jeff Brown68b909d2011-12-07 16:36:01 -08002851 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002852 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002853 }
2854
Jeff Brown3915bb82010-11-05 15:02:16 -07002855 /** {@inheritDoc} */
2856 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002857 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002858 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002859 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002860 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2861 + ", flags=" + event.getFlags()
2862 + ", keyCode=" + event.getKeyCode()
2863 + ", scanCode=" + event.getScanCode()
2864 + ", metaState=" + event.getMetaState()
2865 + ", repeatCount=" + event.getRepeatCount()
2866 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002867 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002868
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002869 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002870 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2871 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002872 final int keyCode = event.getKeyCode();
2873 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002874 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2875 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002876
Jeff Brown54875002011-04-06 15:33:01 -07002877 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002878 final FallbackAction fallbackAction;
2879 if (initialDown) {
2880 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2881 } else {
2882 fallbackAction = mFallbackActions.get(keyCode);
2883 }
2884
2885 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002886 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002887 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2888 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002889 }
2890
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002891 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2892 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002893 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002894 event.getAction(), fallbackAction.keyCode,
2895 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002896 event.getDeviceId(), event.getScanCode(),
2897 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002898
2899 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2900 fallbackEvent.recycle();
2901 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002902 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002903
2904 if (initialDown) {
2905 mFallbackActions.put(keyCode, fallbackAction);
2906 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2907 mFallbackActions.remove(keyCode);
2908 fallbackAction.recycle();
2909 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002910 }
2911 }
2912
Jeff Brown40013652012-05-16 21:22:36 -07002913 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002914 if (fallbackEvent == null) {
2915 Slog.d(TAG, "No fallback.");
2916 } else {
2917 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2918 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002919 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002920 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002921 }
2922
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002923 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002924 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002925 if ((actions & ACTION_PASS_TO_USER) != 0) {
2926 long delayMillis = interceptKeyBeforeDispatching(
2927 win, fallbackEvent, policyFlags);
2928 if (delayMillis == 0) {
2929 return true;
2930 }
2931 }
2932 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002933 }
2934
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002935 private void launchAssistLongPressAction() {
2936 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2937 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2938
2939 // launch the search activity
2940 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2941 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2942 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002943 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002944 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002945 SearchManager searchManager = getSearchManager();
2946 if (searchManager != null) {
2947 searchManager.stopSearch();
2948 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002949 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002950 } catch (ActivityNotFoundException e) {
2951 Slog.w(TAG, "No activity to handle assist long press action.", e);
2952 }
2953 }
2954
2955 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002956 launchAssistAction(null);
2957 }
2958
2959 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002960 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002961 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002962 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002963 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002964 if (hint != null) {
2965 intent.putExtra(hint, true);
2966 }
Jim Miller45308b12012-06-18 19:23:39 -07002967 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2968 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2969 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2970 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002971 startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002972 } catch (ActivityNotFoundException e) {
2973 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002974 }
2975 }
2976 }
2977
Bart Sears8b1c27c2015-03-18 23:51:02 +00002978 private void startActivityAsUser(Intent intent, UserHandle handle) {
2979 if (isUserSetupComplete()) {
2980 mContext.startActivityAsUser(intent, handle);
2981 } else {
2982 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
2983 }
2984 }
2985
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002986 private SearchManager getSearchManager() {
2987 if (mSearchManager == null) {
2988 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2989 }
2990 return mSearchManager;
2991 }
2992
Jeff Browncaca8812013-05-09 13:34:33 -07002993 private void preloadRecentApps() {
2994 mPreloadedRecentApps = true;
2995 try {
2996 IStatusBarService statusbar = getStatusBarService();
2997 if (statusbar != null) {
2998 statusbar.preloadRecentApps();
2999 }
3000 } catch (RemoteException e) {
3001 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3002 // re-acquire status bar service next time it is needed.
3003 mStatusBarService = null;
3004 }
3005 }
3006
3007 private void cancelPreloadRecentApps() {
3008 if (mPreloadedRecentApps) {
3009 mPreloadedRecentApps = false;
3010 try {
3011 IStatusBarService statusbar = getStatusBarService();
3012 if (statusbar != null) {
3013 statusbar.cancelPreloadRecentApps();
3014 }
3015 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003016 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003017 // re-acquire status bar service next time it is needed.
3018 mStatusBarService = null;
3019 }
3020 }
3021 }
3022
3023 private void toggleRecentApps() {
3024 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003025 try {
3026 IStatusBarService statusbar = getStatusBarService();
3027 if (statusbar != null) {
3028 statusbar.toggleRecentApps();
3029 }
3030 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003031 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3032 // re-acquire status bar service next time it is needed.
3033 mStatusBarService = null;
3034 }
3035 }
3036
Craig Mautner84984fa2014-06-19 11:19:20 -07003037 @Override
3038 public void showRecentApps() {
3039 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3040 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3041 }
3042
Winson Chung1e8d71b2014-05-16 17:05:22 -07003043 private void showRecentApps(boolean triggeredFromAltTab) {
3044 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3045 try {
3046 IStatusBarService statusbar = getStatusBarService();
3047 if (statusbar != null) {
3048 statusbar.showRecentApps(triggeredFromAltTab);
3049 }
3050 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003051 Slog.e(TAG, "RemoteException when showing recent apps", e);
3052 // re-acquire status bar service next time it is needed.
3053 mStatusBarService = null;
3054 }
3055 }
3056
Winson Chungcdcd4872014-08-05 18:00:13 -07003057 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003058 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3059 try {
3060 IStatusBarService statusbar = getStatusBarService();
3061 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003062 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003063 }
3064 } catch (RemoteException e) {
3065 Slog.e(TAG, "RemoteException when closing recent apps", e);
3066 // re-acquire status bar service next time it is needed.
3067 mStatusBarService = null;
3068 }
3069 }
3070
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003071 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003072 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003073 }
3074
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003075 /**
3076 * A home key -> launch home action was detected. Take the appropriate action
3077 * given the situation with the keyguard.
3078 */
Bryce Lee662ed802015-04-10 20:11:39 +00003079 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3080 if (respectKeyguard) {
3081 if (isKeyguardShowingAndNotOccluded()) {
3082 // don't launch home if keyguard showing
3083 return;
3084 }
3085
3086 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3087 // when in keyguard restricted mode, must first verify unlock
3088 // before launching home
3089 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3090 @Override
3091 public void onKeyguardExitResult(boolean success) {
3092 if (success) {
3093 try {
3094 ActivityManagerNative.getDefault().stopAppSwitches();
3095 } catch (RemoteException e) {
3096 }
3097 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3098 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003099 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003100 }
Bryce Lee662ed802015-04-10 20:11:39 +00003101 });
3102 return;
3103 }
3104 }
3105
3106 // no keyguard stuff to worry about, just launch home!
3107 try {
3108 ActivityManagerNative.getDefault().stopAppSwitches();
3109 } catch (RemoteException e) {
3110 }
3111 if (mRecentsVisible) {
3112 // Hide Recents and notify it to launch Home
3113 if (awakenFromDreams) {
3114 awakenDreams();
3115 }
3116 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3117 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003118 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003119 // Otherwise, just launch Home
3120 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3121 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003122 }
3123 }
3124
John Spurlock04db1762013-05-13 12:46:41 -04003125 private final Runnable mClearHideNavigationFlag = new Runnable() {
3126 @Override
3127 public void run() {
3128 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3129 // Clear flags.
3130 mForceClearedSystemUiFlags &=
3131 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3132 }
3133 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003134 }
3135 };
3136
3137 /**
3138 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3139 * to determine when the nav bar should be shown and prevent applications from
3140 * receiving those touches.
3141 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003142 final class HideNavInputEventReceiver extends InputEventReceiver {
3143 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3144 super(inputChannel, looper);
3145 }
3146
Dianne Hackborndf89e652011-10-06 22:35:11 -07003147 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003148 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003149 boolean handled = false;
3150 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003151 if (event instanceof MotionEvent
3152 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3153 final MotionEvent motionEvent = (MotionEvent)event;
3154 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003155 // When the user taps down, we re-show the nav bar.
3156 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003157 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003158 // Any user activity always causes us to show the
3159 // navigation controls, if they had been hidden.
3160 // We also clear the low profile and only content
3161 // flags so that tapping on the screen will atomically
3162 // restore all currently hidden screen decorations.
3163 int newVal = mResettingSystemUiFlags |
3164 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3165 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3166 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003167 if (mResettingSystemUiFlags != newVal) {
3168 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003169 changed = true;
3170 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003171 // We don't allow the system's nav bar to be hidden
3172 // again for 1 second, to prevent applications from
3173 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003174 newVal = mForceClearedSystemUiFlags |
3175 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003176 if (mForceClearedSystemUiFlags != newVal) {
3177 mForceClearedSystemUiFlags = newVal;
3178 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003179 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003180 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003181 }
3182 if (changed) {
3183 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3184 }
3185 }
3186 }
3187 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003188 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003189 }
3190 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003191 }
3192 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3193 new InputEventReceiver.Factory() {
3194 @Override
3195 public InputEventReceiver createInputEventReceiver(
3196 InputChannel inputChannel, Looper looper) {
3197 return new HideNavInputEventReceiver(inputChannel, looper);
3198 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003199 };
3200
3201 @Override
3202 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003203 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3204 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003205 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003206
Dianne Hackborndf89e652011-10-06 22:35:11 -07003207 // Reset any bits in mForceClearingStatusBarVisibility that
3208 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003209 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003210 // Clear any bits in the new visibility that are currently being
3211 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003212 return visibility & ~mResettingSystemUiFlags
3213 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003214 }
3215
Craig Mautner69b08182012-09-05 13:07:13 -07003216 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003217 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3218 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003219 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003220 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3221 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003222
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003223 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003224 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003225 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003226 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003227 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003228 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3229 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3230 } else {
3231 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3232 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3233 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003234 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3235 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003236 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003237 availRight - mStableFullscreenRight,
3238 availBottom - mStableFullscreenBottom);
3239 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003240 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003241 availRight - mStableRight, availBottom - mStableBottom);
3242 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003243 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003244 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003245 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003246 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003247 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003248 availRight - mCurRight, availBottom - mCurBottom);
3249 } else {
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 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003253
3254 outStableInsets.set(mStableLeft, mStableTop,
3255 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003256 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003257 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003258 outContentInsets.setEmpty();
3259 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003260 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003261
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003262 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003263 @Override
3264 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3265 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003266 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3267 if (isDefaultDisplay) {
3268 switch (displayRotation) {
3269 case Surface.ROTATION_90:
3270 overscanLeft = mOverscanTop;
3271 overscanTop = mOverscanRight;
3272 overscanRight = mOverscanBottom;
3273 overscanBottom = mOverscanLeft;
3274 break;
3275 case Surface.ROTATION_180:
3276 overscanLeft = mOverscanRight;
3277 overscanTop = mOverscanBottom;
3278 overscanRight = mOverscanLeft;
3279 overscanBottom = mOverscanTop;
3280 break;
3281 case Surface.ROTATION_270:
3282 overscanLeft = mOverscanBottom;
3283 overscanTop = mOverscanLeft;
3284 overscanRight = mOverscanTop;
3285 overscanBottom = mOverscanRight;
3286 break;
3287 default:
3288 overscanLeft = mOverscanLeft;
3289 overscanTop = mOverscanTop;
3290 overscanRight = mOverscanRight;
3291 overscanBottom = mOverscanBottom;
3292 break;
3293 }
3294 } else {
3295 overscanLeft = 0;
3296 overscanTop = 0;
3297 overscanRight = 0;
3298 overscanBottom = 0;
3299 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003300 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3301 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3302 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3303 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003304 mSystemLeft = 0;
3305 mSystemTop = 0;
3306 mSystemRight = displayWidth;
3307 mSystemBottom = displayHeight;
3308 mUnrestrictedScreenLeft = overscanLeft;
3309 mUnrestrictedScreenTop = overscanTop;
3310 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3311 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3312 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3313 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003314 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3315 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003316 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003317 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003318 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003319 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003320 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003321 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003322 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003323 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003324 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003325 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003326
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003327 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3328 final Rect pf = mTmpParentFrame;
3329 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003330 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003331 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003332 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003333 pf.left = df.left = of.left = vf.left = mDockLeft;
3334 pf.top = df.top = of.top = vf.top = mDockTop;
3335 pf.right = df.right = of.right = vf.right = mDockRight;
3336 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003337 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003338
Craig Mautner69b08182012-09-05 13:07:13 -07003339 if (isDefaultDisplay) {
3340 // For purposes of putting out fake window up to steal focus, we will
3341 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003342 final int sysui = mLastSystemUiFlags;
3343 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003344 boolean navTranslucent = (sysui
3345 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003346 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3347 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3348 boolean navAllowedHidden = immersive || immersiveSticky;
3349 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003350 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3351 if (!isKeyguardShowing) {
3352 navTranslucent &= areTranslucentBarsAllowed();
3353 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003354
Craig Mautner69b08182012-09-05 13:07:13 -07003355 // When the navigation bar isn't visible, we put up a fake
3356 // input window to catch all touch events. This way we can
3357 // detect when the user presses anywhere to bring back the nav
3358 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003359 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07003360 if (mHideNavFakeWindow != null) {
3361 mHideNavFakeWindow.dismiss();
3362 mHideNavFakeWindow = null;
3363 }
3364 } else if (mHideNavFakeWindow == null) {
3365 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
3366 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07003367 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07003368 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003369 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003370
Craig Mautner69b08182012-09-05 13:07:13 -07003371 // For purposes of positioning and showing the nav bar, if we have
3372 // decided that it can't be hidden (because of the screen aspect ratio),
3373 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003374 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003375
John Spurlockad3e6cb2013-04-30 08:47:43 -04003376 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003377 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003378 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003379 // Force the navigation bar to its appropriate place and
3380 // size. We need to do this directly, instead of relying on
3381 // it to bubble up from the nav bar, because this needs to
3382 // change atomically with screen rotations.
3383 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3384 if (mNavigationBarOnBottom) {
3385 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003386 int top = displayHeight - overscanBottom
3387 - mNavigationBarHeightForRotation[displayRotation];
3388 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003389 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003390 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003391 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003392 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003393 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003394 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003395 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3396 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003397 } else {
3398 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003399 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003400 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003401 if (navVisible && !navTranslucent && !navAllowedHidden
3402 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003403 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003404 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003405 // and not in the process of animating on or off, then
3406 // we can tell the app that it is covered by it.
3407 mSystemBottom = mTmpNavigationFrame.top;
3408 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003409 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003410 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003411 int left = displayWidth - overscanRight
3412 - mNavigationBarWidthForRotation[displayRotation];
3413 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003414 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003415 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003416 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003417 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003418 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003419 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003420 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3421 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003422 } else {
3423 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003424 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003425 }
John Spurlockbd957402013-10-03 11:38:39 -04003426 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3427 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003428 // If the nav bar is currently requested to be visible,
3429 // and not in the process of animating on or off, then
3430 // we can tell the app that it is covered by it.
3431 mSystemRight = mTmpNavigationFrame.left;
3432 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003433 }
Craig Mautner69b08182012-09-05 13:07:13 -07003434 // Make sure the content and current rectangles are updated to
3435 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003436 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3437 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3438 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3439 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003440 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3441 // And compute the final frame.
3442 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003443 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3444 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003445 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003446 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003447 updateSysUiVisibility = true;
3448 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003449 }
Craig Mautnereda67292013-04-28 13:50:14 -07003450 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003451 mDockLeft, mDockTop, mDockRight, mDockBottom));
3452
3453 // decide where the status bar goes ahead of time
3454 if (mStatusBar != null) {
3455 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003456 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3457 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3458 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3459 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3460 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003461 vf.left = mStableLeft;
3462 vf.top = mStableTop;
3463 vf.right = mStableRight;
3464 vf.bottom = mStableBottom;
3465
3466 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3467
3468 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003469 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003470
3471 // For layout, the status bar is always at the top with our fixed height.
3472 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3473
John Spurlocke1f366f2013-08-05 12:22:40 -04003474 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003475 boolean statusBarTranslucent = (sysui
3476 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003477 if (!isKeyguardShowing) {
3478 statusBarTranslucent &= areTranslucentBarsAllowed();
3479 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003480
Craig Mautner69b08182012-09-05 13:07:13 -07003481 // If the status bar is hidden, we don't want to cause
3482 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003483 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003484 // Status bar may go away, so the screen area it occupies
3485 // is available to apps but just covering them when the
3486 // status bar is visible.
3487 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3488
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003489 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3490 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3491 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3492 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003493
Craig Mautnereda67292013-04-28 13:50:14 -07003494 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003495 String.format(
3496 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3497 mDockLeft, mDockTop, mDockRight, mDockBottom,
3498 mContentLeft, mContentTop, mContentRight, mContentBottom,
3499 mCurLeft, mCurTop, mCurRight, mCurBottom));
3500 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003501 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003502 && !statusBarTransient && !statusBarTranslucent
3503 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003504 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003505 // and not in the process of animating on or off, then
3506 // we can tell the app that it is covered by it.
3507 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3508 }
John Spurlock27735a42013-08-14 17:57:38 -04003509 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003510 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003511 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003512 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003513 if (updateSysUiVisibility) {
3514 updateSystemUiVisibilityLw();
3515 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003516 }
3517 }
3518
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003519 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003520 @Override
John Spurlock46646232013-09-30 22:32:42 -04003521 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003522 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3523 return mStatusBar.getSurfaceLayer();
3524 }
3525
3526 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3527 return mNavigationBar.getSurfaceLayer();
3528 }
3529
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003530 return 0;
3531 }
3532
Craig Mautner967212c2013-04-13 21:10:58 -07003533 @Override
3534 public void getContentRectLw(Rect r) {
3535 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3536 }
3537
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003538 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3539 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003540 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3541 // Here's a special case: if this attached window is a panel that is
3542 // above the dock window, and the window it is attached to is below
3543 // the dock window, then the frames we computed for the window it is
3544 // attached to can not be used because the dock is effectively part
3545 // of the underlying window and the attached window is floating on top
3546 // of the whole thing. So, we ignore the attached window and explicitly
3547 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003548 df.left = of.left = cf.left = vf.left = mDockLeft;
3549 df.top = of.top = cf.top = vf.top = mDockTop;
3550 df.right = of.right = cf.right = vf.right = mDockRight;
3551 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003552 } else {
3553 // The effective display frame of the attached window depends on
3554 // whether it is taking care of insetting its content. If not,
3555 // we need to use the parent's content frame so that the entire
3556 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003557 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003558 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003559 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003560 // Set the content frame of the attached window to the parent's decor frame
3561 // (same as content frame when IME isn't present) if specifically requested by
3562 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3563 // Otherwise, use the overscan frame.
3564 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3565 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003566 } else {
3567 // If the window is resizing, then we want to base the content
3568 // frame on our attached content frame to resize... however,
3569 // things can be tricky if the attached window is NOT in resize
3570 // mode, in which case its content frame will be larger.
3571 // Ungh. So to deal with that, make sure the content frame
3572 // we end up using is not covering the IM dock.
3573 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003574 if (attached.isVoiceInteraction()) {
3575 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3576 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3577 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3578 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3579 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003580 if (cf.left < mContentLeft) cf.left = mContentLeft;
3581 if (cf.top < mContentTop) cf.top = mContentTop;
3582 if (cf.right > mContentRight) cf.right = mContentRight;
3583 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3584 }
3585 }
3586 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003587 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003588 vf.set(attached.getVisibleFrameLw());
3589 }
3590 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3591 // window should be positioned relative to its parent or the entire
3592 // screen.
3593 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3594 ? attached.getFrameLw() : df);
3595 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003596
3597 private void applyStableConstraints(int sysui, int fl, Rect r) {
3598 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3599 // If app is requesting a stable layout, don't let the
3600 // content insets go below the stable values.
3601 if ((fl & FLAG_FULLSCREEN) != 0) {
3602 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3603 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3604 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3605 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3606 } else {
3607 if (r.left < mStableLeft) r.left = mStableLeft;
3608 if (r.top < mStableTop) r.top = mStableTop;
3609 if (r.right > mStableRight) r.right = mStableRight;
3610 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3611 }
3612 }
3613 }
3614
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003615 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003616 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003617 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003618 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003619 final WindowManager.LayoutParams attrs = win.getAttrs();
3620 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3621 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003622 return;
3623 }
Craig Mautner69b08182012-09-05 13:07:13 -07003624 final boolean isDefaultDisplay = win.isDefaultDisplay();
3625 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003626 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3627 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003628 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003629 offsetInputMethodWindowLw(mLastInputMethodWindow);
3630 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003631
John Spurlockc6d1c602014-01-17 15:22:06 -05003632 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003633 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003634 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003635
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003636 final Rect pf = mTmpParentFrame;
3637 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003638 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003639 final Rect cf = mTmpContentFrame;
3640 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003641 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003642 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003643 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003644
3645 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003646 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003647
Craig Mautnerf683b562012-10-02 11:10:57 -07003648 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3649
Adrian Roosfa104232014-06-20 16:10:14 -07003650 if (isDefaultDisplay) {
3651 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3652 } else {
3653 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3654 }
3655
Craig Mautner69b08182012-09-05 13:07:13 -07003656 if (!isDefaultDisplay) {
3657 if (attached != null) {
3658 // If this window is attached to another, our display
3659 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003660 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003661 } else {
3662 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003663 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3664 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3665 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003666 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003667 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003668 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003669 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003670 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003671 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3672 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3673 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003674 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003675 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003676 // ...with content insets above the nav bar
3677 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003678 // IM dock windows always go to the bottom of the screen.
3679 attrs.gravity = Gravity.BOTTOM;
3680 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003681 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
3682 pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft;
3683 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3684 pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft
3685 + mUnrestrictedScreenWidth;
3686 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3687 + mUnrestrictedScreenHeight;
3688 cf.bottom = vf.bottom = mStableBottom;
3689 cf.top = vf.top = mStableTop;
Jorim Jaggie0700182014-08-21 01:12:37 +02003690 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3691 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3692 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3693 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3694 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3695 cf.left = vf.left = mStableLeft;
3696 cf.top = vf.top = mStableTop;
3697 cf.right = vf.right = mStableRight;
3698 vf.bottom = mStableBottom;
3699 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003700 } else {
John Spurlock46646232013-09-30 22:32:42 -04003701
3702 // Default policy decor for the default display
3703 dcf.left = mSystemLeft;
3704 dcf.top = mSystemTop;
3705 dcf.right = mSystemRight;
3706 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003707 final boolean inheritTranslucentDecor = (attrs.privateFlags
3708 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003709 final boolean isAppWindow =
3710 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3711 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3712 final boolean topAtRest =
3713 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3714 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003715 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3716 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003717 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3718 && (fl & WindowManager.LayoutParams.
3719 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003720 // Ensure policy decor includes status bar
3721 dcf.top = mStableTop;
3722 }
John Spurlockbd957402013-10-03 11:38:39 -04003723 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003724 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3725 && (fl & WindowManager.LayoutParams.
3726 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003727 // Ensure policy decor includes navigation bar
3728 dcf.bottom = mStableBottom;
3729 dcf.right = mStableRight;
3730 }
3731 }
3732
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003733 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3734 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003735 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003736 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003737 // This is the case for a normal activity window: we want it
3738 // to cover all of the screen space, and it can take care of
3739 // moving its contents to account for screen decorations that
3740 // intrude into that space.
3741 if (attached != null) {
3742 // If this window is attached to another, our display
3743 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003744 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003745 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003746 if (attrs.type == TYPE_STATUS_BAR_PANEL
3747 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003748 // Status bar panels are the only windows who can go on top of
3749 // the status bar. They are protected by the STATUS_BAR_SERVICE
3750 // permission, so they have the same privileges as the status
3751 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003752 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003753 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003754
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003755 pf.left = df.left = of.left = hasNavBar
3756 ? mDockLeft : mUnrestrictedScreenLeft;
3757 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3758 pf.right = df.right = of.right = hasNavBar
3759 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3760 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3761 pf.bottom = df.bottom = of.bottom = hasNavBar
3762 ? mRestrictedScreenTop+mRestrictedScreenHeight
3763 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003764
Craig Mautnereda67292013-04-28 13:50:14 -07003765 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003766 "Laying out status bar window: (%d,%d - %d,%d)",
3767 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003768 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003769 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3770 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3771 // Asking to layout into the overscan region, so give it that pure
3772 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003773 pf.left = df.left = of.left = mOverscanScreenLeft;
3774 pf.top = df.top = of.top = mOverscanScreenTop;
3775 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3776 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3777 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003778 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003779 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003780 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3781 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003782 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003783 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003784 // only do this for application windows to ensure no window that
3785 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003786 pf.left = df.left = mOverscanScreenLeft;
3787 pf.top = df.top = mOverscanScreenTop;
3788 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3789 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003790 // We need to tell the app about where the frame inside the overscan
3791 // is, so it can inset its content by that amount -- it didn't ask
3792 // to actually extend itself into the overscan region.
3793 of.left = mUnrestrictedScreenLeft;
3794 of.top = mUnrestrictedScreenTop;
3795 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3796 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003797 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003798 pf.left = df.left = mRestrictedOverscanScreenLeft;
3799 pf.top = df.top = mRestrictedOverscanScreenTop;
3800 pf.right = df.right = mRestrictedOverscanScreenLeft
3801 + mRestrictedOverscanScreenWidth;
3802 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3803 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003804 // We need to tell the app about where the frame inside the overscan
3805 // is, so it can inset its content by that amount -- it didn't ask
3806 // to actually extend itself into the overscan region.
3807 of.left = mUnrestrictedScreenLeft;
3808 of.top = mUnrestrictedScreenTop;
3809 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3810 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003811 }
Craig Mautner69b08182012-09-05 13:07:13 -07003812
John Spurlock46646232013-09-30 22:32:42 -04003813 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003814 if (win.isVoiceInteraction()) {
3815 cf.left = mVoiceContentLeft;
3816 cf.top = mVoiceContentTop;
3817 cf.right = mVoiceContentRight;
3818 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003819 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003820 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3821 cf.left = mDockLeft;
3822 cf.top = mDockTop;
3823 cf.right = mDockRight;
3824 cf.bottom = mDockBottom;
3825 } else {
3826 cf.left = mContentLeft;
3827 cf.top = mContentTop;
3828 cf.right = mContentRight;
3829 cf.bottom = mContentBottom;
3830 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003831 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003832 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003833 // Full screen windows are always given a layout that is as if the
3834 // status bar and other transient decors are gone. This is to avoid
3835 // bad states when moving from a window that is not hding the
3836 // status bar to one that is.
3837 cf.left = mRestrictedScreenLeft;
3838 cf.top = mRestrictedScreenTop;
3839 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3840 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003841 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003842 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003843 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3844 vf.left = mCurLeft;
3845 vf.top = mCurTop;
3846 vf.right = mCurRight;
3847 vf.bottom = mCurBottom;
3848 } else {
3849 vf.set(cf);
3850 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003851 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003852 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3853 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3854 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003855 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3856 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003857 // A window that has requested to fill the entire screen just
3858 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003859 if (attrs.type == TYPE_STATUS_BAR_PANEL
3860 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003861 pf.left = df.left = of.left = cf.left = hasNavBar
3862 ? mDockLeft : mUnrestrictedScreenLeft;
3863 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3864 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003865 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003866 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003867 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003868 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003869 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003870 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003871 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3872 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003873 } else if (attrs.type == TYPE_NAVIGATION_BAR
3874 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003875 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003876 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3877 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3878 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3879 + mUnrestrictedScreenWidth;
3880 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3881 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003882 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003883 "Laying out navigation bar window: (%d,%d - %d,%d)",
3884 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003885 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3886 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003887 && ((fl & FLAG_FULLSCREEN) != 0)) {
3888 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003889 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3890 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3891 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3892 + mOverscanScreenWidth;
3893 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3894 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003895 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003896 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003897 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3898 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3899 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3900 + mOverscanScreenWidth;
3901 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3902 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003903 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003904 // The wallpaper also has Real Ultimate Power, but we want to tell
3905 // it about the overscan area.
3906 pf.left = df.left = mOverscanScreenLeft;
3907 pf.top = df.top = mOverscanScreenTop;
3908 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3909 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3910 of.left = cf.left = mUnrestrictedScreenLeft;
3911 of.top = cf.top = mUnrestrictedScreenTop;
3912 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3913 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003914 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003915 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3916 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3917 // Asking to layout into the overscan region, so give it that pure
3918 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003919 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3920 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3921 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003922 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003923 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003924 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003925 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003926 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003927 && (attrs.type == TYPE_STATUS_BAR
3928 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07003929 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04003930 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3931 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003932 // Asking for layout as if the nav bar is hidden, lets the
3933 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003934 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003935 // can be above the nav bar can do this.
3936 // XXX This assumes that an app asking for this will also
3937 // ask for layout in only content. We can't currently figure out
3938 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003939 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3940 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3941 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3942 + mUnrestrictedScreenWidth;
3943 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3944 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003945 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003946 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3947 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3948 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3949 + mRestrictedScreenWidth;
3950 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3951 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003952 }
Craig Mautner69b08182012-09-05 13:07:13 -07003953
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003954 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003955
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003956 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3957 vf.left = mCurLeft;
3958 vf.top = mCurTop;
3959 vf.right = mCurRight;
3960 vf.bottom = mCurBottom;
3961 } else {
3962 vf.set(cf);
3963 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003964 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003965 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3966 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003967 // A child window should be placed inside of the same visible
3968 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003969 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003970 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003971 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3972 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003973 // Otherwise, a normal window must be placed inside the content
3974 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003975 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3976 // Status bar panels are the only windows who can go on top of
3977 // the status bar. They are protected by the STATUS_BAR_SERVICE
3978 // permission, so they have the same privileges as the status
3979 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003980 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3981 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3982 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3983 + mRestrictedScreenWidth;
3984 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3985 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003986 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3987 || attrs.type == TYPE_VOLUME_OVERLAY) {
3988 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003989 pf.left = df.left = of.left = cf.left = mStableLeft;
3990 pf.top = df.top = of.top = cf.top = mStableTop;
3991 pf.right = df.right = of.right = cf.right = mStableRight;
3992 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003993 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003994 pf.left = mContentLeft;
3995 pf.top = mContentTop;
3996 pf.right = mContentRight;
3997 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003998 if (win.isVoiceInteraction()) {
3999 df.left = of.left = cf.left = mVoiceContentLeft;
4000 df.top = of.top = cf.top = mVoiceContentTop;
4001 df.right = of.right = cf.right = mVoiceContentRight;
4002 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4003 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004004 df.left = of.left = cf.left = mDockLeft;
4005 df.top = of.top = cf.top = mDockTop;
4006 df.right = of.right = cf.right = mDockRight;
4007 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004008 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004009 df.left = of.left = cf.left = mContentLeft;
4010 df.top = of.top = cf.top = mContentTop;
4011 df.right = of.right = cf.right = mContentRight;
4012 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004013 }
4014 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4015 vf.left = mCurLeft;
4016 vf.top = mCurTop;
4017 vf.right = mCurRight;
4018 vf.bottom = mCurBottom;
4019 } else {
4020 vf.set(cf);
4021 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004022 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004023 }
4024 }
Craig Mautner69b08182012-09-05 13:07:13 -07004025
Craig Mautnerb816bed2013-07-23 10:26:17 -07004026 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4027 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004028 df.left = df.top = -10000;
4029 df.right = df.bottom = 10000;
4030 if (attrs.type != TYPE_WALLPAPER) {
4031 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4032 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4033 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004034 }
4035
Craig Mautnereda67292013-04-28 13:50:14 -07004036 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004037 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004038 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004039 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004040 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004041 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004042 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004043 + " dcf=" + dcf.toShortString()
4044 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07004045
Adrian Roosfa104232014-06-20 16:10:14 -07004046 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07004047
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004048 // Dock windows carve out the bottom of the screen, so normal windows
4049 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004050 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4051 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004052 setLastInputMethodWindowLw(null, null);
4053 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004054 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004055 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4056 && !win.getGivenInsetsPendingLw()) {
4057 offsetVoiceInputWindowLw(win);
4058 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004059 }
4060
satok1bc0a492012-04-25 22:47:12 +09004061 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004062 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004063 top += win.getGivenContentInsetsLw().top;
4064 if (mContentBottom > top) {
4065 mContentBottom = top;
4066 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004067 if (mVoiceContentBottom > top) {
4068 mVoiceContentBottom = top;
4069 }
satok1bc0a492012-04-25 22:47:12 +09004070 top = win.getVisibleFrameLw().top;
4071 top += win.getGivenVisibleInsetsLw().top;
4072 if (mCurBottom > top) {
4073 mCurBottom = top;
4074 }
Craig Mautnereda67292013-04-28 13:50:14 -07004075 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004076 + mDockBottom + " mContentBottom="
4077 + mContentBottom + " mCurBottom=" + mCurBottom);
4078 }
4079
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004080 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004081 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004082 top += win.getGivenContentInsetsLw().top;
4083 if (mVoiceContentBottom > top) {
4084 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004085 }
4086 }
4087
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004088 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004089 @Override
4090 public void finishLayoutLw() {
4091 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004092 }
4093
4094 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004095 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004096 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004097 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004098 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004099 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004100 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004101 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004102 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004103 mForcingShowNavBar = false;
4104 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004105
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004106 mHideLockScreen = false;
4107 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004108 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004109 mShowingLockscreen = false;
4110 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004111 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004112 mKeyguardSecure = isKeyguardSecure();
4113 mKeyguardSecureIncludingHidden = mKeyguardSecure
4114 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004115 }
4116
4117 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004118 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004119 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004120 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4121 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004122 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004123 if (mTopFullscreenOpaqueWindowState == null
4124 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4125 mForcingShowNavBar = true;
4126 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004127 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004128 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004129 mForceStatusBarFromKeyguard = true;
4130 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004131 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004132 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004133 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004134 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004135 mForceStatusBarFromKeyguard = true;
4136 } else {
4137 mForceStatusBar = true;
4138 }
4139 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004140 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004141 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004142 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004143 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Craig Mautner7d7808f2014-09-11 18:02:38 -07004144 && attrs.type < FIRST_SYSTEM_WINDOW;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004145 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004146 // If the lockscreen was showing when the dream started then wait
4147 // for the dream to draw before hiding the lockscreen.
4148 if (!mDreamingLockscreen
4149 || (win.isVisibleLw() && win.hasDrawnLw())) {
4150 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004151 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004152 }
4153 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004154
Craig Mautner00156ec2014-03-06 22:29:02 -08004155 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07004156 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerab55e522014-03-03 13:26:03 -08004157 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004158 final IApplicationToken appToken = win.getAppToken();
4159 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004160 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004161 mAppsToBeHidden.remove(appToken);
4162 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004163 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004164 if (dismissKeyguard && !mKeyguardSecure) {
4165 mAppsThatDismissKeyguard.add(appToken);
4166 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004167 mWinShowWhenLocked = win;
4168 mHideLockScreen = true;
4169 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004170 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004171 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004172 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004173 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004174 mAppsToBeHidden.add(appToken);
4175 } else {
4176 mAppsToBeHidden.remove(appToken);
4177 }
4178 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004179 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004180 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004181 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004182 if (attrs.x == 0 && attrs.y == 0
4183 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4184 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4185 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4186 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004187 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4188 mTopFullscreenOpaqueOrDimmingWindowState = win;
4189 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004190 if (!mAppsThatDismissKeyguard.isEmpty() &&
4191 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4192 if (DEBUG_LAYOUT) Slog.v(TAG,
4193 "Setting mDismissKeyguard true by win " + win);
4194 mDismissKeyguard = mWinDismissingKeyguard == win ?
4195 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
4196 mWinDismissingKeyguard = win;
Jim Millerab954542014-10-10 18:21:49 -07004197 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004198 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4199 if (DEBUG_LAYOUT) Slog.v(TAG,
4200 "Setting mHideLockScreen to true by win " + win);
4201 mHideLockScreen = true;
4202 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004203 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004204 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004205 mAllowLockscreenWhenOn = true;
4206 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004207 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004208
4209 if (mWinShowWhenLocked != null &&
4210 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
4211 win.hideLw(false);
4212 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004213 }
4214 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004215 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4216 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4217 && win.isDimming()) {
4218 mTopFullscreenOpaqueOrDimmingWindowState = win;
4219 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004220 }
4221
4222 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004223 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004224 public int finishPostLayoutPolicyLw() {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004225 if (mWinShowWhenLocked != null &&
4226 mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) {
4227 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4228 // fullscreen window.
4229 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4230 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4231 mTopFullscreenOpaqueWindowState.hideLw(false);
4232 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4233 }
4234
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004235 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004236 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004237
4238 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4239 ? mTopFullscreenOpaqueWindowState.getAttrs()
4240 : null;
4241
Jeff Brownc8018eb2012-10-29 21:33:27 -07004242 // If we are not currently showing a dream then remember the current
4243 // lockscreen state. We will use this to determine whether the dream
4244 // started while the lockscreen was showing and remember this state
4245 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004246 if (!mShowingDream) {
4247 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004248 if (mDreamingSleepTokenNeeded) {
4249 mDreamingSleepTokenNeeded = false;
4250 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4251 }
4252 } else {
4253 if (!mDreamingSleepTokenNeeded) {
4254 mDreamingSleepTokenNeeded = true;
4255 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4256 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004257 }
4258
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004259 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004260 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004261 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004262 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004263 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07004264 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004265 if (mStatusBarController.setBarShowingLw(true)) {
4266 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4267 }
Craig Mautner81defc72013-10-29 11:10:42 -07004268 // Maintain fullscreen layout until incoming animation is complete.
4269 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004270 // Transient status bar on the lockscreen is not allowed
4271 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4272 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4273 mLastSystemUiFlags, mLastSystemUiFlags);
4274 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004275 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004276 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004277 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004278 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004279 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004280 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004281 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004282 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004283 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004284 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004285 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004286 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004287 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4288 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004289 if (mStatusBarController.isTransientShowing()) {
4290 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004291 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4292 }
4293 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004294 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004295 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004296 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004297 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004298 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004299 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004300 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004301 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004302 if (mStatusBarController.setBarShowingLw(true)) {
4303 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4304 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004305 }
4306 }
4307 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004308
Craig Mautner81defc72013-10-29 11:10:42 -07004309 if (mTopIsFullscreen != topIsFullscreen) {
4310 if (!topIsFullscreen) {
4311 // Force another layout when status bar becomes fully shown.
4312 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4313 }
4314 mTopIsFullscreen = topIsFullscreen;
4315 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004316
Craig Mautner39834192012-09-02 07:47:24 -07004317 // Hide the key guard if a visible window explicitly specifies that it wants to be
4318 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004319 if (mKeyguardDelegate != null && mStatusBar != null) {
4320 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4321 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004322 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004323 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004324 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004325 changes |= FINISH_LAYOUT_REDO_LAYOUT
4326 | FINISH_LAYOUT_REDO_CONFIG
4327 | FINISH_LAYOUT_REDO_WALLPAPER;
4328 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004329 if (mKeyguardDelegate.isShowing()) {
4330 mHandler.post(new Runnable() {
4331 @Override
4332 public void run() {
4333 mKeyguardDelegate.keyguardDone(false, false);
4334 }
4335 });
4336 }
4337 } else if (mHideLockScreen) {
4338 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004339 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004340 changes |= FINISH_LAYOUT_REDO_LAYOUT
4341 | FINISH_LAYOUT_REDO_CONFIG
4342 | FINISH_LAYOUT_REDO_WALLPAPER;
4343 }
4344 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
4345 // This is the case of keyguard isSecure() and not mHideLockScreen.
4346 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4347 // Only launch the next keyguard unlock window once per window.
4348 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004349 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004350 changes |= FINISH_LAYOUT_REDO_LAYOUT
4351 | FINISH_LAYOUT_REDO_CONFIG
4352 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004353 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004354 mHandler.post(new Runnable() {
4355 @Override
4356 public void run() {
4357 mKeyguardDelegate.dismiss();
4358 }
4359 });
4360 }
4361 } else {
4362 mWinDismissingKeyguard = null;
4363 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004364 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004365 changes |= FINISH_LAYOUT_REDO_LAYOUT
4366 | FINISH_LAYOUT_REDO_CONFIG
4367 | FINISH_LAYOUT_REDO_WALLPAPER;
4368 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004369 }
4370 }
Joe Onorato664644d2011-01-23 17:53:23 -08004371
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004372 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004373 // If the navigation bar has been hidden or shown, we need to do another
4374 // layout pass to update that window.
4375 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4376 }
Joe Onorato664644d2011-01-23 17:53:23 -08004377
Mike Lockwood28569302010-01-28 11:54:40 -05004378 // update since mAllowLockscreenWhenOn might have changed
4379 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004380 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004381 }
4382
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004383 /**
Jim Millerab954542014-10-10 18:21:49 -07004384 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004385 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004386 * @return Whether the flags have changed and we have to redo the layout.
4387 */
Jim Millerab954542014-10-10 18:21:49 -07004388 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4389 boolean wasOccluded = mKeyguardOccluded;
4390 boolean showing = mKeyguardDelegate.isShowing();
4391 if (wasOccluded && !isOccluded && showing) {
4392 mKeyguardOccluded = false;
4393 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004394 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4395 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4396 return true;
Jim Millerab954542014-10-10 18:21:49 -07004397 } else if (!wasOccluded && isOccluded && showing) {
4398 mKeyguardOccluded = true;
4399 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004400 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4401 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4402 return true;
4403 } else {
4404 return false;
4405 }
4406 }
4407
4408 private boolean isStatusBarKeyguard() {
4409 return mStatusBar != null
4410 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4411 }
4412
Jose Lima9546b202014-07-02 17:21:51 -07004413 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004414 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004415 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004416 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004417 return false;
4418 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004419 return true;
4420 }
4421
Jose Lima9546b202014-07-02 17:21:51 -07004422 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004423 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004424 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004425 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004426 // If the navigation bar has been hidden or shown, we need to do another
4427 // layout pass to update that window.
4428 return FINISH_LAYOUT_REDO_LAYOUT;
4429 }
4430 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004431 }
4432
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004433 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004434 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004435 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4436 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004437 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4438 if (newLidState == mLidState) {
4439 return;
4440 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004441
Jeff Brownc458ce92012-04-30 14:58:40 -07004442 mLidState = newLidState;
4443 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004444 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004445
4446 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004447 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004448 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004449 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004450 }
4451 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004452
Michael Wright3818c922014-09-02 13:59:07 -07004453 @Override
4454 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4455 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4456 if (mCameraLensCoverState == lensCoverState) {
4457 return;
4458 }
4459 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4460 lensCoverState == CAMERA_LENS_UNCOVERED) {
4461 Intent intent;
4462 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4463 mKeyguardDelegate.isShowing();
4464 if (keyguardActive) {
4465 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4466 } else {
4467 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4468 }
Bryce Lee584a4452014-10-21 15:55:55 -07004469 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004470 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004471 }
4472 mCameraLensCoverState = lensCoverState;
4473 }
4474
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004475 void setHdmiPlugged(boolean plugged) {
4476 if (mHdmiPlugged != plugged) {
4477 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004478 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004479 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004480 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004481 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004482 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004483 }
4484 }
4485
Joe Onoratoea495d42011-04-06 11:41:11 -07004486 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004487 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004488 // watch for HDMI plug messages if the hdmi switch exists
4489 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4490 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4491
Joe Onoratoea495d42011-04-06 11:41:11 -07004492 final String filename = "/sys/class/switch/hdmi/state";
4493 FileReader reader = null;
4494 try {
4495 reader = new FileReader(filename);
4496 char[] buf = new char[15];
4497 int n = reader.read(buf);
4498 if (n > 1) {
4499 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4500 }
4501 } catch (IOException ex) {
4502 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4503 } catch (NumberFormatException ex) {
4504 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4505 } finally {
4506 if (reader != null) {
4507 try {
4508 reader.close();
4509 } catch (IOException ex) {
4510 }
Joe Onoratodc100302011-01-11 17:07:41 -08004511 }
4512 }
4513 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004514 // This dance forces the code in setHdmiPlugged to run.
4515 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4516 mHdmiPlugged = !plugged;
4517 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004518 }
4519
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004520 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004521 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004522
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004523 final Runnable mScreenshotTimeout = new Runnable() {
4524 @Override public void run() {
4525 synchronized (mScreenshotLock) {
4526 if (mScreenshotConnection != null) {
4527 mContext.unbindService(mScreenshotConnection);
4528 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004529 }
Winson Chung9112ec32011-06-27 13:15:32 -07004530 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004531 }
4532 };
4533
4534 // Assume this is called from the Handler thread.
4535 private void takeScreenshot() {
4536 synchronized (mScreenshotLock) {
4537 if (mScreenshotConnection != null) {
4538 return;
4539 }
4540 ComponentName cn = new ComponentName("com.android.systemui",
4541 "com.android.systemui.screenshot.TakeScreenshotService");
4542 Intent intent = new Intent();
4543 intent.setComponent(cn);
4544 ServiceConnection conn = new ServiceConnection() {
4545 @Override
4546 public void onServiceConnected(ComponentName name, IBinder service) {
4547 synchronized (mScreenshotLock) {
4548 if (mScreenshotConnection != this) {
4549 return;
4550 }
4551 Messenger messenger = new Messenger(service);
4552 Message msg = Message.obtain(null, 1);
4553 final ServiceConnection myConn = this;
4554 Handler h = new Handler(mHandler.getLooper()) {
4555 @Override
4556 public void handleMessage(Message msg) {
4557 synchronized (mScreenshotLock) {
4558 if (mScreenshotConnection == myConn) {
4559 mContext.unbindService(mScreenshotConnection);
4560 mScreenshotConnection = null;
4561 mHandler.removeCallbacks(mScreenshotTimeout);
4562 }
4563 }
4564 }
4565 };
4566 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004567 msg.arg1 = msg.arg2 = 0;
4568 if (mStatusBar != null && mStatusBar.isVisibleLw())
4569 msg.arg1 = 1;
4570 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4571 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004572 try {
4573 messenger.send(msg);
4574 } catch (RemoteException e) {
4575 }
4576 }
4577 }
4578 @Override
4579 public void onServiceDisconnected(ComponentName name) {}
4580 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004581 if (mContext.bindServiceAsUser(
4582 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004583 mScreenshotConnection = conn;
4584 mHandler.postDelayed(mScreenshotTimeout, 10000);
4585 }
4586 }
Winson Chung9112ec32011-06-27 13:15:32 -07004587 }
4588
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004589 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004590 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004591 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004592 if (!mSystemBooted) {
4593 // If we have not yet booted, don't let key events do anything.
4594 return 0;
4595 }
4596
Jeff Brown037c33e2014-04-09 00:31:55 -07004597 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004598 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4599 final boolean canceled = event.isCanceled();
4600 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004601
Jeff Brown3122e442010-10-11 23:32:49 -07004602 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004603
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004604 // If screen is off then we treat the case where the keyguard is open but hidden
4605 // the same as if it were open and in front.
4606 // This will prevent any keys other than the power button from waking the screen
4607 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004608 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004609 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004610 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004611 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004612
Jeff Brown40013652012-05-16 21:22:36 -07004613 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004614 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004615 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004616 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004617 }
4618
Jeff Brown037c33e2014-04-09 00:31:55 -07004619 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004620 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004621 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4622 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004623 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004624 // When the device is interactive or the key is injected pass the
4625 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004626 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004627 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004628 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4629 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4630 // to the application but preserve its wake key status to make sure we still move
4631 // from dozing to fully interactive if we would normally go from off to fully
4632 // interactive.
4633 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004634 } else {
4635 // When the screen is off and the key is not injected, determine whether
4636 // to wake the device but don't pass the key to the application.
4637 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004638 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4639 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004640 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004641 }
4642
Justin Kohd378ad72013-04-01 12:18:26 -07004643 // If the key would be handled globally, just return the result, don't worry about special
4644 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004645 if (isValidGlobalKey(keyCode)
4646 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004647 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004648 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004649 }
Justin Kohd378ad72013-04-01 12:18:26 -07004650 return result;
4651 }
4652
Jeff Brownbae8e772014-06-12 19:59:45 -07004653 boolean useHapticFeedback = down
4654 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4655 && event.getRepeatCount() == 0;
4656
Jeff Brown4d396052010-10-29 21:50:21 -07004657 // Handle special keys.
4658 switch (keyCode) {
4659 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004660 case KeyEvent.KEYCODE_VOLUME_UP:
4661 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004662 if (mUseTvRouting) {
4663 // On TVs volume keys never go to the foreground app
4664 result &= ~ACTION_PASS_TO_USER;
4665 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004666 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4667 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004668 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004669 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004670 mScreenshotChordVolumeDownKeyTriggered = true;
4671 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4672 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004673 cancelPendingPowerKeyAction();
4674 interceptScreenshotChord();
4675 }
4676 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004677 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004678 cancelPendingScreenshotChordAction();
4679 }
4680 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4681 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004682 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004683 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004684 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004685 cancelPendingPowerKeyAction();
4686 cancelPendingScreenshotChordAction();
4687 }
4688 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004689 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004690 cancelPendingScreenshotChordAction();
4691 }
4692 }
Jeff Brown4d396052010-10-29 21:50:21 -07004693 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004694 TelecomManager telecomManager = getTelecommService();
4695 if (telecomManager != null) {
4696 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004697 // If an incoming call is ringing, either VOLUME key means
4698 // "silence ringer". We handle these keys here, rather than
4699 // in the InCallScreen, to make sure we'll respond to them
4700 // even if the InCallScreen hasn't come to the foreground yet.
4701 // Look for the DOWN event here, to agree with the "fallback"
4702 // behavior in the InCallScreen.
4703 Log.i(TAG, "interceptKeyBeforeQueueing:"
4704 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004705
Santos Cordon6848f722014-05-21 15:22:12 -07004706 // Silence the ringer. (It's safe to call this
4707 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004708 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004709
Santos Cordon6848f722014-05-21 15:22:12 -07004710 // And *don't* pass this key thru to the current activity
4711 // (which is probably the InCallScreen.)
4712 result &= ~ACTION_PASS_TO_USER;
4713 break;
4714 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004715 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004716 && (result & ACTION_PASS_TO_USER) == 0) {
4717 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004718 // the application, just pass it to the session service.
4719
4720 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004721 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004722 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004723 }
4724 }
4725
RoboErik430fc482014-06-12 15:49:20 -07004726 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004727 if (mUseTvRouting) {
4728 dispatchDirectAudioEvent(event);
4729 } else {
4730 // If we aren't passing to the user and no one else
4731 // handled it send it to the session manager to
4732 // figure out.
4733 MediaSessionLegacyHelper.getHelper(mContext)
4734 .sendVolumeKeyEvent(event, true);
4735 }
Jeff Brown4d396052010-10-29 21:50:21 -07004736 break;
4737 }
4738 }
4739 break;
4740 }
4741
4742 case KeyEvent.KEYCODE_ENDCALL: {
4743 result &= ~ACTION_PASS_TO_USER;
4744 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004745 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004746 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004747 if (telecomManager != null) {
4748 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004749 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004750 if (interactive && !hungUp) {
4751 mEndCallKeyHandled = false;
4752 mHandler.postDelayed(mEndCallLongPress,
4753 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4754 } else {
4755 mEndCallKeyHandled = true;
4756 }
Jeff Brown4d396052010-10-29 21:50:21 -07004757 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004758 if (!mEndCallKeyHandled) {
4759 mHandler.removeCallbacks(mEndCallLongPress);
4760 if (!canceled) {
4761 if ((mEndcallBehavior
4762 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4763 if (goHome()) {
4764 break;
4765 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004766 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004767 if ((mEndcallBehavior
4768 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4769 mPowerManager.goToSleep(event.getEventTime(),
4770 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4771 isWakeKey = false;
4772 }
Jeff Brown4d396052010-10-29 21:50:21 -07004773 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004774 }
Jeff Brown4d396052010-10-29 21:50:21 -07004775 }
4776 break;
4777 }
4778
4779 case KeyEvent.KEYCODE_POWER: {
4780 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004781 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004782 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004783 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004784 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004785 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004786 }
4787 break;
4788 }
4789
Jeff Brown6212a492014-03-07 13:58:47 -08004790 case KeyEvent.KEYCODE_SLEEP: {
4791 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004792 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004793 if (!mPowerManager.isInteractive()) {
4794 useHapticFeedback = false; // suppress feedback if already non-interactive
4795 }
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004796 sleepPress(event);
Jeff Brown6212a492014-03-07 13:58:47 -08004797 break;
4798 }
4799
4800 case KeyEvent.KEYCODE_WAKEUP: {
4801 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004802 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004803 break;
4804 }
4805
Jeff Brown4d396052010-10-29 21:50:21 -07004806 case KeyEvent.KEYCODE_MEDIA_PLAY:
4807 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4808 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004809 case KeyEvent.KEYCODE_HEADSETHOOK:
4810 case KeyEvent.KEYCODE_MUTE:
4811 case KeyEvent.KEYCODE_MEDIA_STOP:
4812 case KeyEvent.KEYCODE_MEDIA_NEXT:
4813 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4814 case KeyEvent.KEYCODE_MEDIA_REWIND:
4815 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004816 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4817 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004818 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4819 // If the global session is active pass all media keys to it
4820 // instead of the active window.
4821 result &= ~ACTION_PASS_TO_USER;
4822 }
Jeff Brown4d396052010-10-29 21:50:21 -07004823 if ((result & ACTION_PASS_TO_USER) == 0) {
4824 // Only do this if we would otherwise not pass it to the user. In that
4825 // case, the PhoneWindow class will do the same thing, except it will
4826 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004827 // Note that we need to make a copy of the key event here because the
4828 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004829 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004830 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4831 new KeyEvent(event));
4832 msg.setAsynchronous(true);
4833 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004834 }
4835 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004836 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004837
Jeff Brown4d396052010-10-29 21:50:21 -07004838 case KeyEvent.KEYCODE_CALL: {
4839 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004840 TelecomManager telecomManager = getTelecommService();
4841 if (telecomManager != null) {
4842 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004843 Log.i(TAG, "interceptKeyBeforeQueueing:"
4844 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004845 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004846
Santos Cordon6848f722014-05-21 15:22:12 -07004847 // And *don't* pass this key thru to the current activity
4848 // (which is presumably the InCallScreen.)
4849 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004850 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004851 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004852 }
Jeff Brown4d396052010-10-29 21:50:21 -07004853 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004854 }
Michael Wright869a67c2014-08-26 19:33:06 -07004855 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4856 // Only do this if we would otherwise not pass it to the user. In that case,
4857 // interceptKeyBeforeDispatching would apply a similar but different policy in
4858 // order to invoke voice assist actions. Note that we need to make a copy of the
4859 // key event here because the original key event will be recycled when we return.
4860 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4861 mBroadcastWakeLock.acquire();
4862 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4863 keyguardActive ? 1 : 0, 0);
4864 msg.setAsynchronous(true);
4865 msg.sendToTarget();
4866 }
4867 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004868 }
Jeff Brown26875502014-01-30 21:47:47 -08004869
Jeff Brownbae8e772014-06-12 19:59:45 -07004870 if (useHapticFeedback) {
4871 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4872 }
4873
Jeff Brown26875502014-01-30 21:47:47 -08004874 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004875 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004876 }
Bryce Lee584a4452014-10-21 15:55:55 -07004877
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004878 return result;
4879 }
4880
Jeff Brown1c2e4942012-11-06 16:32:01 -08004881 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004882 * Returns true if the key can have global actions attached to it.
4883 * We reserve all power management keys for the system since they require
4884 * very careful handling.
4885 */
4886 private static boolean isValidGlobalKey(int keyCode) {
4887 switch (keyCode) {
4888 case KeyEvent.KEYCODE_POWER:
4889 case KeyEvent.KEYCODE_WAKEUP:
4890 case KeyEvent.KEYCODE_SLEEP:
4891 return false;
4892 default:
4893 return true;
4894 }
4895 }
4896
4897 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08004898 * When the screen is off we ignore some keys that might otherwise typically
4899 * be considered wake keys. We filter them out here.
4900 *
4901 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4902 * is always considered a wake key.
4903 */
4904 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4905 switch (keyCode) {
4906 // ignore volume keys unless docked
4907 case KeyEvent.KEYCODE_VOLUME_UP:
4908 case KeyEvent.KEYCODE_VOLUME_DOWN:
4909 case KeyEvent.KEYCODE_VOLUME_MUTE:
4910 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4911
4912 // ignore media and camera keys
4913 case KeyEvent.KEYCODE_MUTE:
4914 case KeyEvent.KEYCODE_HEADSETHOOK:
4915 case KeyEvent.KEYCODE_MEDIA_PLAY:
4916 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4917 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4918 case KeyEvent.KEYCODE_MEDIA_STOP:
4919 case KeyEvent.KEYCODE_MEDIA_NEXT:
4920 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4921 case KeyEvent.KEYCODE_MEDIA_REWIND:
4922 case KeyEvent.KEYCODE_MEDIA_RECORD:
4923 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004924 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004925 case KeyEvent.KEYCODE_CAMERA:
4926 return false;
4927 }
4928 return true;
4929 }
4930
4931
Jeff Brown56194eb2011-03-02 19:23:13 -08004932 /** {@inheritDoc} */
4933 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004934 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4935 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08004936 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
4937 return 0;
4938 }
Michael Wright70af00a2014-09-03 19:30:20 -07004939 }
Bryce Lee5c138322014-11-03 08:26:09 -08004940
Michael Wright70af00a2014-09-03 19:30:20 -07004941 if (shouldDispatchInputWhenNonInteractive()) {
4942 return ACTION_PASS_TO_USER;
4943 }
Bryce Lee5c138322014-11-03 08:26:09 -08004944
Bryce Lee812d7022014-11-10 13:33:28 -08004945 // If we have not passed the action up and we are in theater mode without dreaming,
4946 // there will be no dream to intercept the touch and wake into ambient. The device should
4947 // wake up in this case.
4948 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
4949 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
4950 }
4951
Jeff Brown037c33e2014-04-09 00:31:55 -07004952 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004953 }
4954
Michael Wright70af00a2014-09-03 19:30:20 -07004955 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08004956 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07004957 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
4958 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08004959 return true;
4960 }
4961
4962 // Send events to a dozing dream even if the screen is off since the dream
4963 // is in control of the state of the screen.
4964 IDreamManager dreamManager = getDreamManager();
4965
4966 try {
4967 if (dreamManager != null && dreamManager.isDreaming()) {
4968 return true;
4969 }
4970 } catch (RemoteException e) {
4971 Slog.e(TAG, "RemoteException when checking if dreaming", e);
4972 }
4973
4974 // Otherwise, consume events since the user can't see what is being
4975 // interacted with.
4976 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07004977 }
4978
RoboErik001c59c2015-01-26 15:53:51 -08004979 private void dispatchDirectAudioEvent(KeyEvent event) {
4980 if (event.getAction() != KeyEvent.ACTION_DOWN) {
4981 return;
4982 }
4983 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04004984 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
4985 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08004986 String pkgName = mContext.getOpPackageName();
4987 switch (keyCode) {
4988 case KeyEvent.KEYCODE_VOLUME_UP:
4989 try {
John Spurlockee5ad722015-03-03 16:17:21 -05004990 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04004991 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08004992 } catch (RemoteException e) {
4993 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
4994 }
4995 break;
4996 case KeyEvent.KEYCODE_VOLUME_DOWN:
4997 try {
John Spurlockee5ad722015-03-03 16:17:21 -05004998 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04004999 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005000 } catch (RemoteException e) {
5001 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5002 }
5003 break;
5004 case KeyEvent.KEYCODE_VOLUME_MUTE:
5005 try {
5006 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005007 getAudioService().adjustSuggestedStreamVolume(
5008 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005009 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005010 }
5011 } catch (RemoteException e) {
5012 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5013 }
5014 break;
5015 }
5016 }
5017
Jeff Brown40013652012-05-16 21:22:36 -07005018 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5019 if (DEBUG_INPUT) {
5020 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005021 }
5022
Jeff Brown40013652012-05-16 21:22:36 -07005023 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5024 if (DEBUG_INPUT) {
5025 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5026 }
5027
5028 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5029 mHavePendingMediaKeyRepeatWithWakeLock = false;
5030 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5031 }
5032
5033 dispatchMediaKeyWithWakeLockToAudioService(event);
5034
5035 if (event.getAction() == KeyEvent.ACTION_DOWN
5036 && event.getRepeatCount() == 0) {
5037 mHavePendingMediaKeyRepeatWithWakeLock = true;
5038
5039 Message msg = mHandler.obtainMessage(
5040 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5041 msg.setAsynchronous(true);
5042 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5043 } else {
5044 mBroadcastWakeLock.release();
5045 }
5046 }
5047
5048 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5049 mHavePendingMediaKeyRepeatWithWakeLock = false;
5050
5051 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5052 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5053 if (DEBUG_INPUT) {
5054 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5055 }
5056
5057 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5058 mBroadcastWakeLock.release();
5059 }
5060
5061 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5062 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005063 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005064 }
5065 }
5066
Michael Wright869a67c2014-08-26 19:33:06 -07005067 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
5068 Intent voiceIntent =
5069 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5070 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005071 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005072 mBroadcastWakeLock.release();
5073 }
5074
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005075 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005076 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005077 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005078 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5079 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5080 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005081 } else {
5082 try {
5083 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5084 ServiceManager.getService(Context.UI_MODE_SERVICE));
5085 mUiMode = uiModeService.getCurrentModeType();
5086 } catch (RemoteException e) {
5087 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005088 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005089 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005090 synchronized (mLock) {
5091 updateOrientationListenerLp();
5092 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005093 }
5094 };
5095
Jeff Brown6aaf2952012-10-05 16:01:08 -07005096 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5097 @Override
5098 public void onReceive(Context context, Intent intent) {
5099 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005100 if (mKeyguardDelegate != null) {
5101 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005102 }
5103 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005104 if (mKeyguardDelegate != null) {
5105 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005106 }
5107 }
5108 }
5109 };
5110
Christopher Tate5e08af02012-09-21 17:17:22 -07005111 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5112 @Override
5113 public void onReceive(Context context, Intent intent) {
5114 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5115 // tickle the settings observer: this first ensures that we're
5116 // observing the relevant settings for the newly-active user,
5117 // and then updates our own bookkeeping based on the now-
5118 // current user.
5119 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005120
5121 // force a re-application of focused window sysui visibility.
5122 // the window may never have been shown for this user
5123 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005124 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005125 mLastSystemUiFlags = 0;
5126 updateSystemUiVisibilityLw();
5127 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005128 }
5129 }
5130 };
5131
John Spurlockd9b70bd2014-02-06 17:02:44 -05005132 private final Runnable mRequestTransientNav = new Runnable() {
5133 @Override
5134 public void run() {
5135 requestTransientBars(mNavigationBar);
5136 }
5137 };
5138
John Spurlocke1f366f2013-08-05 12:22:40 -04005139 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005140 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005141 if (!isUserSetupComplete()) {
5142 // Swipe-up for navigation bar is disabled during setup
5143 return;
5144 }
John Spurlock27735a42013-08-14 17:57:38 -04005145 boolean sb = mStatusBarController.checkShowTransientBarLw();
5146 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005147 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005148 // Don't show status bar when swiping on already visible navigation bar
5149 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005150 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005151 return;
5152 }
John Spurlock27735a42013-08-14 17:57:38 -04005153 if (sb) mStatusBarController.showTransient();
5154 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005155 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005156 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005157 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005158 }
5159 }
5160
Jeff Brown3ee549c2014-09-22 20:14:39 -07005161 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005162 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07005163 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005164 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07005165 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005166
5167 // We must get this work done here because the power manager will drop
5168 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005169 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005170 mAwake = false;
5171 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005172 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005173 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005174 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005175 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005176
5177 if (mKeyguardDelegate != null) {
5178 mKeyguardDelegate.onScreenTurnedOff(why);
5179 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005180 }
5181
Jeff Brown13f00f02014-10-31 14:45:50 -07005182 private void wakeUpFromPowerKey(long eventTime) {
5183 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5184 }
5185
Bryce Lee5c138322014-11-03 08:26:09 -08005186 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Lee584a4452014-10-21 15:55:55 -07005187 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005188 return false;
Bryce Lee584a4452014-10-21 15:55:55 -07005189 }
5190
5191 mPowerManager.wakeUp(wakeTime);
Bryce Lee5c138322014-11-03 08:26:09 -08005192 return true;
Bryce Lee584a4452014-10-21 15:55:55 -07005193 }
5194
Jeff Brown3ee549c2014-09-22 20:14:39 -07005195 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005196 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07005197 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005198 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07005199 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005200
Jeff Brown3ee549c2014-09-22 20:14:39 -07005201 // Since goToSleep performs these functions synchronously, we must
5202 // do the same here. We cannot post this work to a handler because
5203 // that might cause it to become reordered with respect to what
5204 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005205 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005206 mAwake = true;
5207 mKeyguardDrawComplete = false;
5208 if (mKeyguardDelegate != null) {
5209 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5210 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5211 }
5212
Jeff Browna20dda42014-05-27 20:57:24 -07005213 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005214 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005215 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005216 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005217
Jim Miller5ecd8112013-01-09 18:50:26 -08005218 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07005219 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005220 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005221 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005222 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005223 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005224 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005225 }
5226
Jeff Brown36c4db82014-09-19 12:05:31 -07005227 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005228 synchronized (mLock) {
5229 if (!mAwake || mKeyguardDrawComplete) {
5230 return; // spurious
5231 }
5232
Jeff Brown36c4db82014-09-19 12:05:31 -07005233 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005234 if (mKeyguardDelegate != null) {
5235 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5236 }
5237 }
5238
5239 finishScreenTurningOn();
5240 }
5241
5242 // Called on the DisplayManager's DisplayPowerController thread.
5243 @Override
5244 public void screenTurnedOff() {
5245 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5246
5247 synchronized (mLock) {
5248 mScreenOnEarly = false;
5249 mScreenOnFully = false;
5250 mWindowManagerDrawComplete = false;
5251 mScreenOnListener = null;
5252 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005253 }
5254 }
5255
Jeff Brown3ee549c2014-09-22 20:14:39 -07005256 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005257 @Override
5258 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005259 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005260
Jeff Brown3ee549c2014-09-22 20:14:39 -07005261 synchronized (mLock) {
5262 mScreenOnEarly = true;
5263 mScreenOnFully = false;
5264 mWindowManagerDrawComplete = false;
5265 mScreenOnListener = screenOnListener;
5266 updateOrientationListenerLp();
5267 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005268
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005269 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5270 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005271 // ... eventually calls finishWindowsDrawn
5272 }
5273
Jeff Brown36c4db82014-09-19 12:05:31 -07005274 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005275 synchronized (mLock) {
5276 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5277 return; // spurious
5278 }
5279
Jeff Brown36c4db82014-09-19 12:05:31 -07005280 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005281 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005282
5283 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005284 }
5285
Craig Mautner8a0da012014-05-31 15:13:37 -07005286 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005287 final ScreenOnListener listener;
5288 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005289 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005290 if (DEBUG_WAKEUP) Slog.d(TAG,
5291 "finishScreenTurningOn: mAwake=" + mAwake
5292 + ", mScreenOnEarly=" + mScreenOnEarly
5293 + ", mScreenOnFully=" + mScreenOnFully
5294 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5295 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5296
5297 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5298 || (mAwake && !mKeyguardDrawComplete)) {
5299 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005300 }
5301
Jeff Brown3ee549c2014-09-22 20:14:39 -07005302 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5303 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005304 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005305 mScreenOnFully = true;
5306
5307 // Remember the first time we draw the keyguard so we know when we're done with
5308 // the main part of booting and can enable the screen and hide boot messages.
5309 if (!mKeyguardDrawnOnce && mAwake) {
5310 mKeyguardDrawnOnce = true;
5311 enableScreen = true;
5312 if (mBootMessageNeedsHiding) {
5313 mBootMessageNeedsHiding = false;
5314 hideBootMessages();
5315 }
5316 } else {
5317 enableScreen = false;
5318 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005319 }
5320
Jeff Brown3ee549c2014-09-22 20:14:39 -07005321 if (listener != null) {
5322 listener.onScreenOn();
5323 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005324
Jeff Brown3ee549c2014-09-22 20:14:39 -07005325 if (enableScreen) {
5326 try {
5327 mWindowManager.enableScreenIfNeeded();
5328 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005329 }
Craig Mautnera631d492014-08-05 15:16:01 -07005330 }
5331 }
5332
5333 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005334 synchronized (mLock) {
5335 if (!mKeyguardDrawnOnce) {
5336 mBootMessageNeedsHiding = true;
5337 return; // keyguard hasn't drawn the first time yet, not done booting
5338 }
Craig Mautnera631d492014-08-05 15:16:01 -07005339 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005340
5341 if (mBootMsgDialog != null) {
5342 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5343 mBootMsgDialog.dismiss();
5344 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005345 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005346 }
5347
5348 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005349 public boolean isScreenOn() {
5350 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005351 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005352
Dianne Hackborn08743722009-12-21 12:16:51 -08005353 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005354 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005355 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005356 if (mKeyguardDelegate != null) {
5357 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005358 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005359 }
5360
5361 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005362 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005363 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005364 if (mKeyguardDelegate != null) {
5365 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005366 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005367 }
5368
Jim Millerab954542014-10-10 18:21:49 -07005369 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005370 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005371 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005372 }
5373
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005374 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005375 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005376 public boolean isKeyguardLocked() {
5377 return keyguardOn();
5378 }
5379
5380 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005381 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005382 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005383 if (mKeyguardDelegate == null) return false;
5384 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005385 }
5386
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005387 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005388 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005389 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005390 if (mKeyguardDelegate == null) return false;
5391 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005392 }
5393
Jose Lima9546b202014-07-02 17:21:51 -07005394 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005395 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005396 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005397 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005398 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005399 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005400 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005401 // ask the keyguard to prompt the user to authenticate if necessary
5402 mKeyguardDelegate.dismiss();
5403 }
5404 });
5405 }
5406 }
5407
5408 public void notifyActivityDrawnForKeyguardLw() {
5409 if (mKeyguardDelegate != null) {
5410 mHandler.post(new Runnable() {
5411 @Override
5412 public void run() {
5413 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005414 }
5415 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005416 }
5417 }
5418
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005419 @Override
5420 public boolean isKeyguardDrawnLw() {
5421 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005422 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005423 }
5424 }
5425
Jorim Jaggi0d674622014-05-21 01:34:15 +02005426 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005427 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005428 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005429 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005430 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005431 }
5432 }
5433
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005434 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005435 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005436 }
5437
5438 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005439 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005440 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005441
Jeff Brown01a98dd2011-09-20 15:08:29 -07005442 @Override
5443 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005444 if (false) {
5445 Slog.v(TAG, "rotationForOrientationLw(orient="
5446 + orientation + ", last=" + lastRotation
5447 + "); user=" + mUserRotation + " "
5448 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5449 ? "USER_ROTATION_LOCKED" : "")
5450 );
5451 }
5452
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005453 if (mForceDefaultOrientation) {
5454 return Surface.ROTATION_0;
5455 }
5456
The Android Open Source Project0727d222009-03-11 12:11:58 -07005457 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005458 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5459 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005460 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005461 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005462
Jeff Browndec6cf42011-11-15 14:08:20 -08005463 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005464 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005465 // Ignore sensor when lid switch is open and rotation is forced.
5466 preferredRotation = mLidOpenRotation;
5467 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005468 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005469 // Ignore sensor when in car dock unless explicitly enabled.
5470 // This case can override the behavior of NOSENSOR, and can also
5471 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005472 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005473 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005474 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5475 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5476 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005477 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005478 // Ignore sensor when in desk dock unless explicitly enabled.
5479 // This case can override the behavior of NOSENSOR, and can also
5480 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005481 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005482 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005483 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5484 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005485 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005486 preferredRotation = mDemoHdmiRotation;
5487 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5488 && mUndockedHdmiRotation >= 0) {
5489 // Ignore sensor when plugged into HDMI and an undocked orientation has
5490 // been specified in the configuration (only for legacy devices without
5491 // full multi-display support).
5492 // Note that the dock orientation overrides the HDMI orientation.
5493 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005494 } else if (mDemoRotationLock) {
5495 // Ignore sensor when demo rotation lock is enabled.
5496 // Note that the dock orientation and HDMI rotation lock override this.
5497 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005498 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5499 // Application just wants to remain locked in the last rotation.
5500 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005501 } else if (!mSupportAutoRotation) {
5502 // If we don't support auto-rotation then bail out here and ignore
5503 // the sensor and any rotation lock settings.
5504 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005505 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005506 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005507 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5508 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5509 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5510 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005511 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5512 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5513 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5514 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5515 // Otherwise, use sensor only if requested by the application or enabled
5516 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005517 if (mAllowAllRotations < 0) {
5518 // Can't read this during init() because the context doesn't
5519 // have display metrics at that time so we cannot determine
5520 // tablet vs. phone then.
5521 mAllowAllRotations = mContext.getResources().getBoolean(
5522 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5523 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005524 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005525 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005526 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5527 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005528 preferredRotation = sensorRotation;
5529 } else {
5530 preferredRotation = lastRotation;
5531 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005532 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5533 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5534 // Apply rotation lock. Does not apply to NOSENSOR.
5535 // The idea is that the user rotation expresses a weak preference for the direction
5536 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5537 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005538 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005539 } else {
5540 // No overriding preference.
5541 // We will do exactly what the application asked us to do.
5542 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005543 }
5544
Dianne Hackborne5439f22010-10-02 16:53:50 -07005545 switch (orientation) {
5546 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005547 // Return portrait unless overridden.
5548 if (isAnyPortrait(preferredRotation)) {
5549 return preferredRotation;
5550 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005551 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005552
Jeff Brown01a98dd2011-09-20 15:08:29 -07005553 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005554 // Return landscape unless overridden.
5555 if (isLandscapeOrSeascape(preferredRotation)) {
5556 return preferredRotation;
5557 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005558 return mLandscapeRotation;
5559
5560 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005561 // Return reverse portrait unless overridden.
5562 if (isAnyPortrait(preferredRotation)) {
5563 return preferredRotation;
5564 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005565 return mUpsideDownRotation;
5566
5567 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005568 // Return seascape unless overridden.
5569 if (isLandscapeOrSeascape(preferredRotation)) {
5570 return preferredRotation;
5571 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005572 return mSeascapeRotation;
5573
5574 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005575 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005576 // Return either landscape rotation.
5577 if (isLandscapeOrSeascape(preferredRotation)) {
5578 return preferredRotation;
5579 }
5580 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005581 return lastRotation;
5582 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005583 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005584
Jeff Brown01a98dd2011-09-20 15:08:29 -07005585 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005586 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005587 // Return either portrait rotation.
5588 if (isAnyPortrait(preferredRotation)) {
5589 return preferredRotation;
5590 }
5591 if (isAnyPortrait(lastRotation)) {
5592 return lastRotation;
5593 }
5594 return mPortraitRotation;
5595
5596 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005597 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5598 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005599 if (preferredRotation >= 0) {
5600 return preferredRotation;
5601 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005602 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005603 }
5604 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005605 }
5606
Jeff Brown01a98dd2011-09-20 15:08:29 -07005607 @Override
5608 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5609 switch (orientation) {
5610 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5611 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5612 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5613 return isAnyPortrait(rotation);
5614
5615 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5616 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5617 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5618 return isLandscapeOrSeascape(rotation);
5619
5620 default:
5621 return true;
5622 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005623 }
5624
Jeff Brownc0347aa2011-09-23 17:26:09 -07005625 @Override
5626 public void setRotationLw(int rotation) {
5627 mOrientationListener.setCurrentRotation(rotation);
5628 }
5629
Jeff Brown01a98dd2011-09-20 15:08:29 -07005630 private boolean isLandscapeOrSeascape(int rotation) {
5631 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005632 }
5633
Jeff Brown01a98dd2011-09-20 15:08:29 -07005634 private boolean isAnyPortrait(int rotation) {
5635 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005636 }
5637
Jose Lima9546b202014-07-02 17:21:51 -07005638 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005639 public int getUserRotationMode() {
5640 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005641 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5642 WindowManagerPolicy.USER_ROTATION_FREE :
5643 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005644 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005645
5646 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005647 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005648 public void setUserRotationMode(int mode, int rot) {
5649 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005650
5651 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005652 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005653 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005654 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005655 rot,
5656 UserHandle.USER_CURRENT);
5657 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005658 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005659 0,
5660 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005661 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005662 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005663 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005664 1,
5665 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005666 }
5667 }
5668
Jose Lima9546b202014-07-02 17:21:51 -07005669 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005670 public void setSafeMode(boolean safeMode) {
5671 mSafeMode = safeMode;
5672 performHapticFeedbackLw(null, safeMode
5673 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5674 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005675 }
Craig Mautnereda67292013-04-28 13:50:14 -07005676
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005677 static long[] getLongIntArray(Resources r, int resid) {
5678 int[] ar = r.getIntArray(resid);
5679 if (ar == null) {
5680 return null;
5681 }
5682 long[] out = new long[ar.length];
5683 for (int i=0; i<ar.length; i++) {
5684 out[i] = ar[i];
5685 }
5686 return out;
5687 }
Craig Mautnereda67292013-04-28 13:50:14 -07005688
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005689 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005690 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005691 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005692 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005693 mKeyguardDelegate.onSystemReady();
5694
Michael Wright3818c922014-09-02 13:59:07 -07005695 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005696 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005697 synchronized (mLock) {
5698 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005699 mSystemReady = true;
5700 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005701 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005702 public void run() {
5703 updateSettings();
5704 }
5705 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005706 }
5707 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005708
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005709 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005710 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005711 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005712 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005713 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005714 mKeyguardDelegate.onBootCompleted();
5715 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005716 synchronized (mLock) {
5717 mSystemBooted = true;
5718 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005719 wakingUp();
5720 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005721 }
5722
Dianne Hackborn661cd522011-08-22 00:26:20 -07005723 ProgressDialog mBootMsgDialog = null;
5724
5725 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005726 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005727 public void showBootMessage(final CharSequence msg, final boolean always) {
5728 mHandler.post(new Runnable() {
5729 @Override public void run() {
5730 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005731 int theme;
5732 if (mContext.getPackageManager().hasSystemFeature(
5733 PackageManager.FEATURE_WATCH)) {
5734 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5735 } else if (mContext.getPackageManager().hasSystemFeature(
5736 PackageManager.FEATURE_TELEVISION)) {
5737 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5738 } else {
5739 theme = 0;
5740 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005741
5742 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005743 // This dialog will consume all events coming in to
5744 // it, to avoid it trying to do things too early in boot.
5745 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5746 return true;
5747 }
5748 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5749 return true;
5750 }
5751 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5752 return true;
5753 }
5754 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5755 return true;
5756 }
5757 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5758 return true;
5759 }
5760 @Override public boolean dispatchPopulateAccessibilityEvent(
5761 AccessibilityEvent event) {
5762 return true;
5763 }
5764 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005765 if (mContext.getPackageManager().isUpgrade()) {
5766 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5767 } else {
5768 mBootMsgDialog.setTitle(R.string.android_start_title);
5769 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005770 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5771 mBootMsgDialog.setIndeterminate(true);
5772 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005773 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005774 mBootMsgDialog.getWindow().addFlags(
5775 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5776 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5777 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005778 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5779 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5780 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005781 mBootMsgDialog.setCancelable(false);
5782 mBootMsgDialog.show();
5783 }
5784 mBootMsgDialog.setMessage(msg);
5785 }
5786 });
5787 }
5788
5789 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005790 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005791 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005792 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005793 }
5794
Mike Lockwood28569302010-01-28 11:54:40 -05005795 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005796 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005797 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005798 // ***************************************
5799 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5800 // ***************************************
5801 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5802 // WITH ITS LOCKS HELD.
5803 //
5804 // This code must be VERY careful about the locks
5805 // it acquires.
5806 // In fact, the current code acquires way too many,
5807 // and probably has lurking deadlocks.
5808
Mike Lockwood28569302010-01-28 11:54:40 -05005809 synchronized (mScreenLockTimeout) {
5810 if (mLockScreenTimerActive) {
5811 // reset the timer
5812 mHandler.removeCallbacks(mScreenLockTimeout);
5813 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5814 }
5815 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005816 }
5817
Adam Cohenf7522022012-10-03 20:03:18 -07005818 class ScreenLockTimeout implements Runnable {
5819 Bundle options;
5820
5821 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005822 public void run() {
5823 synchronized (this) {
5824 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005825 if (mKeyguardDelegate != null) {
5826 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005827 }
Mike Lockwood28569302010-01-28 11:54:40 -05005828 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005829 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005830 }
5831 }
Mike Lockwood28569302010-01-28 11:54:40 -05005832
Adam Cohenf7522022012-10-03 20:03:18 -07005833 public void setLockOptions(Bundle options) {
5834 this.options = options;
5835 }
5836 }
5837
5838 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5839
Jose Lima9546b202014-07-02 17:21:51 -07005840 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005841 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005842 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5843 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005844 if (options != null) {
5845 // In case multiple calls are made to lockNow, we don't wipe out the options
5846 // until the runnable actually executes.
5847 mScreenLockTimeout.setLockOptions(options);
5848 }
Jim Miller93c518e2012-01-17 15:55:31 -08005849 mHandler.post(mScreenLockTimeout);
5850 }
5851
Mike Lockwood28569302010-01-28 11:54:40 -05005852 private void updateLockScreenTimeout() {
5853 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005854 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005855 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005856 if (mLockScreenTimerActive != enable) {
5857 if (enable) {
5858 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5859 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5860 } else {
5861 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5862 mHandler.removeCallbacks(mScreenLockTimeout);
5863 }
5864 mLockScreenTimerActive = enable;
5865 }
5866 }
5867 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005868
Jeff Brown061ea992015-04-17 19:55:47 -07005869 private void updateDreamingSleepToken(boolean acquire) {
5870 if (acquire) {
5871 if (mDreamingSleepToken == null) {
5872 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
5873 }
5874 } else {
5875 if (mDreamingSleepToken != null) {
5876 mDreamingSleepToken.release();
5877 }
5878 }
5879 }
5880
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005881 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005882 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005883 public void enableScreenAfterBoot() {
5884 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005885 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005886 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005887 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005888
Jeff Brownc458ce92012-04-30 14:58:40 -07005889 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005890 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005891 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005892 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005893 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005894 }
Jeff Browna20dda42014-05-27 20:57:24 -07005895
5896 synchronized (mLock) {
5897 updateWakeGestureListenerLp();
5898 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005899 }
5900
Jeff Brown4f5fa282014-06-12 19:19:15 -07005901 void updateUiMode() {
5902 if (mUiModeManager == null) {
5903 mUiModeManager = IUiModeManager.Stub.asInterface(
5904 ServiceManager.getService(Context.UI_MODE_SERVICE));
5905 }
5906 try {
5907 mUiMode = mUiModeManager.getCurrentModeType();
5908 } catch (RemoteException e) {
5909 }
5910 }
5911
Jeff Brown01a98dd2011-09-20 15:08:29 -07005912 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005913 try {
5914 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005915 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5916 } catch (RemoteException e) {
5917 // Ignore
5918 }
5919 }
5920
5921 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5922 try {
5923 //set orientation on WindowManager
5924 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005925 } catch (RemoteException e) {
5926 // Ignore
5927 }
5928 }
5929
Daniel Sandler6396c722013-04-16 20:19:09 -04005930 /**
5931 * Return an Intent to launch the currently active dock app as home. Returns
5932 * null if the standard home should be launched, which is the case if any of the following is
5933 * true:
5934 * <ul>
5935 * <li>The device is not in either car mode or desk mode
5936 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5937 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5938 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5939 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5940 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005941 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005942 */
5943 Intent createHomeDockIntent() {
5944 Intent intent = null;
5945
5946 // What home does is based on the mode, not the dock state. That
5947 // is, when in car mode you should be taken to car home regardless
5948 // of whether we are actually in a car dock.
5949 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5950 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5951 intent = mCarDockIntent;
5952 }
5953 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5954 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5955 intent = mDeskDockIntent;
5956 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005957 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5958 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5959 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5960 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5961 // Always launch dock home from home when watch is docked, if it exists.
5962 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005963 }
5964
5965 if (intent == null) {
5966 return null;
5967 }
5968
5969 ActivityInfo ai = null;
5970 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5971 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005972 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005973 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005974 if (info != null) {
5975 ai = info.activityInfo;
5976 }
5977 if (ai != null
5978 && ai.metaData != null
5979 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5980 intent = new Intent(intent);
5981 intent.setClassName(ai.packageName, ai.name);
5982 return intent;
5983 }
5984
5985 return null;
5986 }
5987
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005988 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
5989 if (awakenFromDreams) {
5990 awakenDreams();
5991 }
Daniel Sandler6396c722013-04-16 20:19:09 -04005992
5993 Intent dock = createHomeDockIntent();
5994 if (dock != null) {
5995 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005996 if (fromHomeKey) {
5997 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5998 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00005999 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006000 return;
6001 } catch (ActivityNotFoundException e) {
6002 }
6003 }
6004
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006005 Intent intent;
6006
6007 if (fromHomeKey) {
6008 intent = new Intent(mHomeIntent);
6009 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6010 } else {
6011 intent = mHomeIntent;
6012 }
6013
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006014 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006015 }
Craig Mautnereda67292013-04-28 13:50:14 -07006016
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006017 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006018 * goes to the home screen
6019 * @return whether it did anything
6020 */
6021 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006022 if (!isUserSetupComplete()) {
6023 Slog.i(TAG, "Not going home because user setup is in progress.");
6024 return false;
6025 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006026 if (false) {
6027 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006028 try {
6029 ActivityManagerNative.getDefault().stopAppSwitches();
6030 } catch (RemoteException e) {
6031 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006032 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006033 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006034 } else {
6035 // This code brings home to the front or, if it is already
6036 // at the front, puts the device to sleep.
6037 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006038 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6039 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6040 Log.d(TAG, "UTS-TEST-MODE");
6041 } else {
6042 ActivityManagerNative.getDefault().stopAppSwitches();
6043 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006044 Intent dock = createHomeDockIntent();
6045 if (dock != null) {
6046 int result = ActivityManagerNative.getDefault()
6047 .startActivityAsUser(null, null, dock,
6048 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6049 null, null, 0,
6050 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006051 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006052 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6053 return false;
6054 }
6055 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006056 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006057 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006058 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006059 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006060 null, null, 0,
6061 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006062 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006063 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006064 return false;
6065 }
6066 } catch (RemoteException ex) {
6067 // bummer, the activity manager, which is in this process, is dead
6068 }
6069 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006070 return true;
6071 }
Craig Mautnereda67292013-04-28 13:50:14 -07006072
6073 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006074 public void setCurrentOrientationLw(int newOrientation) {
6075 synchronized (mLock) {
6076 if (newOrientation != mCurrentAppOrientation) {
6077 mCurrentAppOrientation = newOrientation;
6078 updateOrientationListenerLp();
6079 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006080 }
6081 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006082
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006083 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6084 if (!isGlobalAccessibilityGestureEnabled()) {
6085 return;
6086 }
6087 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6088 Context.AUDIO_SERVICE);
6089 if (audioManager.isSilentMode()) {
6090 return;
6091 }
6092 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6093 Settings.System.DEFAULT_NOTIFICATION_URI);
6094 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6095 ringTone.play();
6096 }
Craig Mautnereda67292013-04-28 13:50:14 -07006097
Bryce Lee584a4452014-10-21 15:55:55 -07006098 private boolean isTheaterModeEnabled() {
6099 return Settings.Global.getInt(mContext.getContentResolver(),
6100 Settings.Global.THEATER_MODE_ON, 0) == 1;
6101 }
6102
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006103 private boolean isGlobalAccessibilityGestureEnabled() {
6104 return Settings.Global.getInt(mContext.getContentResolver(),
6105 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6106 }
6107
Craig Mautnereda67292013-04-28 13:50:14 -07006108 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006109 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006110 if (!mVibrator.hasVibrator()) {
6111 return false;
6112 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006113 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6114 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006115 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006116 return false;
6117 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006118 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006119 switch (effectId) {
6120 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006121 pattern = mLongPressVibePattern;
6122 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006123 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006124 pattern = mVirtualKeyVibePattern;
6125 break;
6126 case HapticFeedbackConstants.KEYBOARD_TAP:
6127 pattern = mKeyboardTapVibePattern;
6128 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006129 case HapticFeedbackConstants.CLOCK_TICK:
6130 pattern = mClockTickVibePattern;
6131 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006132 case HapticFeedbackConstants.CALENDAR_DATE:
6133 pattern = mCalendarDateVibePattern;
6134 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006135 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006136 pattern = mSafeModeDisabledVibePattern;
6137 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006138 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006139 pattern = mSafeModeEnabledVibePattern;
6140 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006141 default:
6142 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006143 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006144 int owningUid;
6145 String owningPackage;
6146 if (win != null) {
6147 owningUid = win.getOwningUid();
6148 owningPackage = win.getOwningPackage();
6149 } else {
6150 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006151 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006152 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006153 if (pattern.length == 1) {
6154 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006155 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006156 } else {
6157 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006158 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006159 }
6160 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006161 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006162
6163 @Override
6164 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006165 }
6166
Jeff Brownc38c9be2012-10-04 13:16:19 -07006167 @Override
6168 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006169 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006170 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006171 }
6172 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006173
Dianne Hackborndf89e652011-10-06 22:35:11 -07006174 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006175 // If there is no window focused, there will be nobody to handle the events
6176 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006177 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6178 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006179 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006180 return 0;
6181 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006182 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006183 // We are updating at a point where the keyguard has gotten
6184 // focus, but we were last in a state where the top window is
6185 // hiding it. This is probably because the keyguard as been
6186 // shown while the top window was displayed, so we want to ignore
6187 // it here because this is just a very transient change and it
6188 // will quickly lose focus once it correctly gets hidden.
6189 return 0;
6190 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006191
John Spurlock1db8b682014-02-18 11:18:59 -05006192 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006193 & ~mResettingSystemUiFlags
6194 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006195 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006196 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006197 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006198 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006199 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006200 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006201 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006202 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006203 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006204 return 0;
6205 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006206 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006207 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006208 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006209 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006210 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006211 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006212 try {
6213 IStatusBarService statusbar = getStatusBarService();
6214 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006215 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006216 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006217 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006218 } catch (RemoteException e) {
6219 // re-acquire status bar service next time it is needed.
6220 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006221 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006222 }
6223 });
6224 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006225 }
6226
Adrian Rooscd3884d2015-02-18 17:25:23 +01006227 private int updateLightStatusBarLw(int vis) {
6228 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6229 ? mStatusBar
6230 : mTopFullscreenOpaqueOrDimmingWindowState;
6231
6232 if (statusColorWin != null) {
6233 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6234 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6235 // its light flag.
6236 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6237 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6238 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6239 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6240 // Otherwise if it's dimming, clear the light flag.
6241 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6242 }
6243 }
6244 return vis;
6245 }
6246
John Spurlock79da8332013-09-20 12:04:47 -04006247 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006248 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006249 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6250 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006251 : mTopFullscreenOpaqueWindowState;
6252 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6253 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6254
John Spurlock27735a42013-08-14 17:57:38 -04006255 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04006256 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006257 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006258 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6259 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006260 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006261 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6262 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006263 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006264 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6265 }
John Spurlockbd957402013-10-03 11:38:39 -04006266 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006267 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006268
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006269 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006270 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6271 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006272 }
6273
John Spurlock27735a42013-08-14 17:57:38 -04006274 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006275 boolean immersiveSticky =
6276 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006277 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006278 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006279 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006280 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6281 boolean hideStatusBarSysui =
6282 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006283 boolean hideNavBarSysui =
6284 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006285
John Spurlock27735a42013-08-14 17:57:38 -04006286 boolean transientStatusBarAllowed =
6287 mStatusBar != null && (
6288 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006289 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006290 || statusBarHasFocus);
6291
John Spurlockf1a36642013-10-12 17:50:42 -04006292 boolean transientNavBarAllowed =
6293 mNavigationBar != null &&
6294 hideNavBarSysui && immersiveSticky;
6295
John Spurlockf25706f2013-11-07 18:02:43 -05006296 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006297 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006298 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006299 && !transientNavBarAllowed;
6300 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006301 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006302 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006303 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006304 }
John Spurlock27735a42013-08-14 17:57:38 -04006305
6306 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6307
6308 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006309 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6310 boolean newImmersiveMode = isImmersiveMode(vis);
6311 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006312 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006313 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6314 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006315 }
John Spurlock27735a42013-08-14 17:57:38 -04006316
John Spurlockf1a36642013-10-12 17:50:42 -04006317 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6318
John Spurlocke1f366f2013-08-05 12:22:40 -04006319 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006320 }
6321
John Spurlockf1a36642013-10-12 17:50:42 -04006322 private void clearClearableFlagsLw() {
6323 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6324 if (newVal != mResettingSystemUiFlags) {
6325 mResettingSystemUiFlags = newVal;
6326 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6327 }
6328 }
6329
6330 private boolean isImmersiveMode(int vis) {
6331 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006332 return mNavigationBar != null
6333 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006334 && (vis & flags) != 0
6335 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006336 }
6337
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006338 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006339 * @return whether the navigation or status bar can be made translucent
6340 *
6341 * This should return true unless touch exploration is not enabled or
6342 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006343 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006344 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006345 return mTranslucentDecorEnabled
6346 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006347 }
6348
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006349 // Use this instead of checking config_showNavigationBar so that it can be consistently
6350 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006351 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006352 public boolean hasNavigationBar() {
6353 return mHasNavigationBar;
6354 }
6355
satok1bc0a492012-04-25 22:47:12 +09006356 @Override
6357 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6358 mLastInputMethodWindow = ime;
6359 mLastInputMethodTargetWindow = target;
6360 }
6361
Craig Mautnerf1b67412012-09-19 13:18:29 -07006362 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006363 public int getInputMethodWindowVisibleHeightLw() {
6364 return mDockBottom - mCurBottom;
6365 }
6366
6367 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006368 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006369 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006370 if (mKeyguardDelegate != null) {
6371 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006372 }
John Spurlock13451a22012-09-28 14:40:41 -04006373 if (mStatusBarService != null) {
6374 try {
6375 mStatusBarService.setCurrentUser(newUserId);
6376 } catch (RemoteException e) {
6377 // oh well
6378 }
6379 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006380 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006381 }
6382
6383 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006384 public boolean canMagnifyWindow(int windowType) {
6385 switch (windowType) {
6386 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6387 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6388 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6389 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6390 return false;
6391 }
6392 }
6393 return true;
6394 }
6395
6396 @Override
6397 public boolean isTopLevelWindow(int windowType) {
6398 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6399 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6400 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6401 }
6402 return true;
6403 }
6404
Jim Miller4eeb4f62012-11-08 00:04:29 -08006405 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006406 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006407 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006408 pw.print(" mSystemReady="); pw.print(mSystemReady);
6409 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006410 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006411 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006412 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006413 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006414 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6415 || mForceClearedSystemUiFlags != 0) {
6416 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6417 pw.print(Integer.toHexString(mLastSystemUiFlags));
6418 pw.print(" mResettingSystemUiFlags=0x");
6419 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6420 pw.print(" mForceClearedSystemUiFlags=0x");
6421 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006422 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006423 if (mLastFocusNeedsMenu) {
6424 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6425 pw.println(mLastFocusNeedsMenu);
6426 }
Jeff Browna20dda42014-05-27 20:57:24 -07006427 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6428 pw.println(mWakeGestureEnabledSetting);
6429
Jeff Brownbcdfc622014-03-06 19:13:04 -08006430 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006431 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6432 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006433 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6434 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6435 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6436 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006437 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006438 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006439 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6440 pw.print(mCarDockEnablesAccelerometer);
6441 pw.print(" mDeskDockEnablesAccelerometer=");
6442 pw.println(mDeskDockEnablesAccelerometer);
6443 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6444 pw.print(mLidKeyboardAccessibility);
6445 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006446 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006447 pw.print(prefix);
6448 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6449 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006450 pw.print(prefix);
6451 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6452 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006453 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006454 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6455 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6456 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6457 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6458 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6459 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6460 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006461 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6462 pw.print(","); pw.print(mOverscanScreenTop);
6463 pw.print(") "); pw.print(mOverscanScreenWidth);
6464 pw.print("x"); pw.println(mOverscanScreenHeight);
6465 if (mOverscanLeft != 0 || mOverscanTop != 0
6466 || mOverscanRight != 0 || mOverscanBottom != 0) {
6467 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6468 pw.print(" top="); pw.print(mOverscanTop);
6469 pw.print(" right="); pw.print(mOverscanRight);
6470 pw.print(" bottom="); pw.println(mOverscanBottom);
6471 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006472 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6473 pw.print(mRestrictedOverscanScreenLeft);
6474 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6475 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6476 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006477 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6478 pw.print(","); pw.print(mUnrestrictedScreenTop);
6479 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6480 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6481 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6482 pw.print(","); pw.print(mRestrictedScreenTop);
6483 pw.print(") "); pw.print(mRestrictedScreenWidth);
6484 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006485 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6486 pw.print(","); pw.print(mStableFullscreenTop);
6487 pw.print(")-("); pw.print(mStableFullscreenRight);
6488 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006489 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6490 pw.print(","); pw.print(mStableTop);
6491 pw.print(")-("); pw.print(mStableRight);
6492 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006493 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6494 pw.print(","); pw.print(mSystemTop);
6495 pw.print(")-("); pw.print(mSystemRight);
6496 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006497 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6498 pw.print(","); pw.print(mCurTop);
6499 pw.print(")-("); pw.print(mCurRight);
6500 pw.print(","); pw.print(mCurBottom); pw.println(")");
6501 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6502 pw.print(","); pw.print(mContentTop);
6503 pw.print(")-("); pw.print(mContentRight);
6504 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006505 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6506 pw.print(","); pw.print(mVoiceContentTop);
6507 pw.print(")-("); pw.print(mVoiceContentRight);
6508 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006509 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6510 pw.print(","); pw.print(mDockTop);
6511 pw.print(")-("); pw.print(mDockRight);
6512 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006513 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6514 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006515 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6516 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006517 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6518 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006519 if (mLastInputMethodWindow != null) {
6520 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6521 pw.println(mLastInputMethodWindow);
6522 }
6523 if (mLastInputMethodTargetWindow != null) {
6524 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6525 pw.println(mLastInputMethodTargetWindow);
6526 }
6527 if (mStatusBar != null) {
6528 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006529 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6530 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006531 }
6532 if (mNavigationBar != null) {
6533 pw.print(prefix); pw.print("mNavigationBar=");
6534 pw.println(mNavigationBar);
6535 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006536 if (mFocusedWindow != null) {
6537 pw.print(prefix); pw.print("mFocusedWindow=");
6538 pw.println(mFocusedWindow);
6539 }
6540 if (mFocusedApp != null) {
6541 pw.print(prefix); pw.print("mFocusedApp=");
6542 pw.println(mFocusedApp);
6543 }
6544 if (mWinDismissingKeyguard != null) {
6545 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6546 pw.println(mWinDismissingKeyguard);
6547 }
6548 if (mTopFullscreenOpaqueWindowState != null) {
6549 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6550 pw.println(mTopFullscreenOpaqueWindowState);
6551 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006552 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6553 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6554 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6555 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006556 if (mForcingShowNavBar) {
6557 pw.print(prefix); pw.print("mForcingShowNavBar=");
6558 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6559 pw.println(mForcingShowNavBarLayer);
6560 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006561 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006562 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006563 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6564 pw.print(" mForceStatusBarFromKeyguard=");
6565 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006566 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006567 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006568 pw.print(" mHomePressed="); pw.println(mHomePressed);
6569 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6570 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6571 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6572 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6573 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6574 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6575 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6576 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6577 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6578 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006579 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6580 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6581 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006582
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006583 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006584 mStatusBarController.dump(pw, prefix);
6585 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006586 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006587
Jeff Browna20dda42014-05-27 20:57:24 -07006588 if (mWakeGestureListener != null) {
6589 mWakeGestureListener.dump(pw, prefix);
6590 }
Jeff Brown600f0032014-05-22 17:06:00 -07006591 if (mOrientationListener != null) {
6592 mOrientationListener.dump(pw, prefix);
6593 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006594 if (mBurnInProtectionHelper != null) {
6595 mBurnInProtectionHelper.dump(prefix, pw);
6596 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006597 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006598}