blob: 62e7af4f51be541cdb6348e8eec461d80ae9f3ec [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;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080020import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080021import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040022import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070023import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070024import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040025import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080026import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070027import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080028import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040029import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080030import android.content.ContentResolver;
31import android.content.Context;
32import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070033import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070034import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080035import android.content.pm.ActivityInfo;
36import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040037import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070038import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080039import android.content.res.Configuration;
40import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070041import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080042import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080043import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080044import android.graphics.Rect;
John Spurlock7b414672014-07-18 13:02:39 -040045import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080046import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050047import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080048import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070049import android.media.Ringtone;
50import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070051import android.media.session.MediaSessionLegacyHelper;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070052import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080053import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070054import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080055import android.os.Handler;
56import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080057import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070058import android.os.Message;
59import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080060import android.os.PowerManager;
61import android.os.RemoteException;
62import android.os.ServiceManager;
63import android.os.SystemClock;
64import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080065import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070066import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080067import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070068import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080069import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070070import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040071import android.service.dreams.DreamService;
72import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070073import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070074import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070075import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080076import android.util.EventLog;
77import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070078import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080079import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070080import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080081import android.view.Gravity;
82import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080083import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080084import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070085import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070086import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080087import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080088import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080089import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080090import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080091import android.view.KeyEvent;
92import android.view.MotionEvent;
Jorim Jaggib10e33f2015-02-04 21:57:40 +010093import android.view.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080094import android.view.Surface;
95import android.view.View;
96import android.view.ViewConfiguration;
97import android.view.Window;
98import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -080099import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700100import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800101import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800102import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800103import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800104import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200105import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800106import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800107import com.android.internal.R;
Craig Mautnerae446592012-12-06 19:05:05 -0800108import com.android.internal.statusbar.IStatusBarService;
Craig Mautnerae446592012-12-06 19:05:05 -0800109import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700110import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100111import com.android.server.policy.keyguard.KeyguardServiceDelegate;
112import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800113
114import java.io.File;
115import java.io.FileReader;
116import java.io.IOException;
117import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700118import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800119import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800120
Dianne Hackbornc652de82013-02-15 16:32:56 -0800121import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700122import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
123import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
124import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700125import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
126import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
127import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800128
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800129/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700130 * WindowManagerPolicy implementation for the Android phone UI. This
131 * introduces a new method suffix, Lp, for an internal lock of the
132 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400133 * 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 -0700134 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800135 */
136public class PhoneWindowManager implements WindowManagerPolicy {
137 static final String TAG = "WindowManager";
138 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700139 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700140 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700141 static final boolean DEBUG_KEYGUARD = false;
142 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700143 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700144 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800145 static final boolean SHOW_STARTING_ANIMATIONS = true;
146 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400147
Daniel Sandler6396c722013-04-16 20:19:09 -0400148 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
149 // No longer recommended for desk docks; still useful in car docks.
150 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
151 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
152
Jeff Brown6d8fd272014-05-20 21:24:38 -0700153 static final int SHORT_PRESS_POWER_NOTHING = 0;
154 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
155 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
156 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800157 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700158
Joe Onoratod208e702010-10-08 16:22:43 -0400159 static final int LONG_PRESS_POWER_NOTHING = 0;
160 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
161 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700162 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700163
Jeff Brown13f00f02014-10-31 14:45:50 -0700164 static final int MULTI_PRESS_POWER_NOTHING = 0;
165 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
166 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
167
Michael Jurka3b1fc472011-06-13 10:54:40 -0700168 // These need to match the documentation/constant in
169 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800170 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800171 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700172 static final int LONG_PRESS_HOME_ASSIST = 2;
173
174 static final int DOUBLE_TAP_HOME_NOTHING = 0;
175 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800176
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700177 static final int APPLICATION_MEDIA_SUBLAYER = -2;
178 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800179 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800180 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700181
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800182 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
183 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
184 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500185 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700186 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800187
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700188 /**
189 * These are the system UI flags that, when changing, can cause the layout
190 * of the screen to change.
191 */
192 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400193 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400194 | View.SYSTEM_UI_FLAG_FULLSCREEN
195 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200196 | View.NAVIGATION_BAR_TRANSLUCENT
197 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700198
John Spurlock7b414672014-07-18 13:02:39 -0400199 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
200 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
201 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
202 .build();
203
Jim Miller5ecd8112013-01-09 18:50:26 -0800204 /**
205 * Keyguard stuff
206 */
207 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100208 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700209 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800210
Jeff Brown6651a632011-11-28 12:59:11 -0800211 /* Table of Application Launch keys. Maps from key codes to intent categories.
212 *
213 * These are special keys that are used to launch particular kinds of applications,
214 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
215 * usage page. We don't support quite that many yet...
216 */
217 static SparseArray<String> sApplicationLaunchKeyCategories;
218 static {
219 sApplicationLaunchKeyCategories = new SparseArray<String>();
220 sApplicationLaunchKeyCategories.append(
221 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
222 sApplicationLaunchKeyCategories.append(
223 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
224 sApplicationLaunchKeyCategories.append(
225 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
226 sApplicationLaunchKeyCategories.append(
227 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
228 sApplicationLaunchKeyCategories.append(
229 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
230 sApplicationLaunchKeyCategories.append(
231 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
232 }
233
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700234 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
235 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
236
Dianne Hackborndf89e652011-10-06 22:35:11 -0700237 /**
238 * Lock protecting internal state. Must not call out into window
239 * manager with lock held. (This lock will be acquired in places
240 * where the window manager is calling in with its own lock held.)
241 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800242 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700243
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800244 Context mContext;
245 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700246 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700247 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700248 PowerManager mPowerManager;
Jose Lima9546b202014-07-02 17:21:51 -0700249 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400250 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700251 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700252 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800253 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700254 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800255 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000256 BurnInProtectionHelper mBurnInProtectionHelper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800257
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700258 // Vibrator pattern for haptic feedback of a long press.
259 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700260
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700261 // Vibrator pattern for haptic feedback of virtual key press.
262 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700263
Amith Yamasanic33cb712010-02-10 15:21:49 -0800264 // Vibrator pattern for a short vibration.
265 long[] mKeyboardTapVibePattern;
266
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700267 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
268 long[] mClockTickVibePattern;
269
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700270 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
271 long[] mCalendarDateVibePattern;
272
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700273 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
274 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700275
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700276 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
277 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700278
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800279 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
280 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400281
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800282 boolean mSafeMode;
283 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700284 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400285 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400286 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700287 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400288 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
289 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
290 int[] mNavigationBarHeightForRotation = new int[4];
291 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400292
Craig Mautnera631d492014-08-05 15:16:01 -0700293 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800294 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700295 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700296 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700297 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700298 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
299 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
300 }
301 };
302 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
303 @Override
304 public void onShown(IBinder windowToken) {
305 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
306 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
307 }
308 };
309
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800310 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800311 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900312 WindowState mLastInputMethodWindow = null;
313 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800314
Jeff Brown13f00f02014-10-31 14:45:50 -0700315 // FIXME This state is shared between the input reader and handler thread.
316 // Technically it's broken and buggy but it has been like this for many years
317 // and we have not yet seen any problems. Someday we'll rewrite this logic
318 // so that only one thread is involved in handling input policy. Unfortunately
319 // it's on a critical path for power management so we can't just post the work to the
320 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
321 // to hold wakelocks during dispatch and eliminating the critical path.
322 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800323 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700324 volatile int mPowerKeyPressCounter;
325 volatile boolean mEndCallKeyHandled;
326
Winson Chungd42a6cf2014-06-03 16:24:04 -0700327 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700328 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700329 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800330
Jeff Brown2e7760e2012-04-11 15:14:55 -0700331 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700332 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700333 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800334
Dianne Hackbornc777e072010-02-12 13:07:59 -0800335 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700336 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800337 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700338 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400339 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700340 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700341 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400342 int mCarDockRotation;
343 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700344 int mUndockedHdmiRotation;
345 int mDemoHdmiRotation;
346 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800347 int mDemoRotation;
348 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400349
Jeff Browna20dda42014-05-27 20:57:24 -0700350 boolean mWakeGestureEnabledSetting;
351 MyWakeGestureListener mWakeGestureListener;
352
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700353 // Default display does not rotate, apps that require non-default orientation will have to
354 // have the orientation emulated.
355 private boolean mForceDefaultOrientation = false;
356
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400357 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
358 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700359 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400360
Jeff Brownbcdfc622014-03-06 19:13:04 -0800361 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700362 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400363 boolean mCarDockEnablesAccelerometer;
364 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700365 int mLidKeyboardAccessibility;
366 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700367 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700368 int mShortPressOnPowerBehavior;
369 int mLongPressOnPowerBehavior;
370 int mDoublePressOnPowerBehavior;
371 int mTriplePressOnPowerBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700372 boolean mAwake;
373 boolean mScreenOnEarly;
374 boolean mScreenOnFully;
375 ScreenOnListener mScreenOnListener;
376 boolean mKeyguardDrawComplete;
377 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800378 boolean mOrientationSensorEnabled = false;
379 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800380 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400381 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800382 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700383
Jeff Brown70825162012-03-28 17:27:48 -0700384 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800385
386 // The last window we were told about in focusChanged.
387 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800388 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800389
Jeff Brown70825162012-03-28 17:27:48 -0700390 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800391
Dianne Hackbornc652de82013-02-15 16:32:56 -0800392 // The current size of the screen; really; extends into the overscan area of
393 // the screen and doesn't account for any system elements like the status bar.
394 int mOverscanScreenLeft, mOverscanScreenTop;
395 int mOverscanScreenWidth, mOverscanScreenHeight;
396 // The current visible size of the screen; really; (ir)regardless of whether the status
397 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800398 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
399 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800400 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
401 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
402 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700403 // The current size of the screen; these may be different than (0,0)-(dw,dh)
404 // if the status bar can't be hidden; in that case it effectively carves out
405 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800406 int mRestrictedScreenLeft, mRestrictedScreenTop;
407 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700408 // During layout, the current screen borders accounting for any currently
409 // visible system UI elements.
410 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700411 // For applications requesting stable content insets, these are them.
412 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700413 // For applications requesting stable content insets but have also set the
414 // fullscreen window flag, these are the stable dimensions without the status bar.
415 int mStableFullscreenLeft, mStableFullscreenTop;
416 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800417 // During layout, the current screen borders with all outer decoration
418 // (status bar, input method dock) accounted for.
419 int mCurLeft, mCurTop, mCurRight, mCurBottom;
420 // During layout, the frame in which content should be displayed
421 // to the user, accounting for all screen decoration except for any
422 // space they deem as available for other content. This is usually
423 // the same as mCur*, but may be larger if the screen decor has supplied
424 // content insets.
425 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700426 // During layout, the frame in which voice content should be displayed
427 // to the user, accounting for all screen decoration except for any
428 // space they deem as available for other content.
429 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800430 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800431 // windows are placed.
432 int mDockLeft, mDockTop, mDockRight, mDockBottom;
433 // During layout, the layer at which the doc window is placed.
434 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700435 // During layout, this is the layer of the status bar.
436 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700437 int mLastSystemUiFlags;
438 // Bits that we are in the process of clearing, so we want to prevent
439 // them from being set by applications until everything has been updated
440 // to have them clear.
441 int mResettingSystemUiFlags = 0;
442 // Bits that we are currently always keeping cleared.
443 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800444 // What we last reported to system UI about whether the compatibility
445 // menu needs to be displayed.
446 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700447
448 FakeWindow mHideNavFakeWindow = null;
449
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800450 static final Rect mTmpParentFrame = new Rect();
451 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800452 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800453 static final Rect mTmpContentFrame = new Rect();
454 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400455 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700456 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700457 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700458
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800459 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100460 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700461 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200462 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400463 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800464 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700465 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700466 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800467 boolean mForcingShowNavBar;
468 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700469
470 // States of keyguard dismiss.
471 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
472 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
473 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
474 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
475
476 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
477 * be done once per window. */
478 private WindowState mWinDismissingKeyguard;
479
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700480 /** The window that is currently showing "over" the keyguard. If there is an app window
481 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
482 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
483 * the wallpaper. */
484 private WindowState mWinShowWhenLocked;
485
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700486 boolean mShowingLockscreen;
487 boolean mShowingDream;
488 boolean mDreamingLockscreen;
Jim Millerab954542014-10-10 18:21:49 -0700489 boolean mKeyguardSecure;
490 boolean mKeyguardSecureIncludingHidden;
491 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800492 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700493 boolean mHomeConsumed;
494 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800495 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700496 Intent mCarDockIntent;
497 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700498 boolean mSearchKeyShortcutPending;
499 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700500 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700501 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800502
Mike Lockwood28569302010-01-28 11:54:40 -0500503 // support for activating the lock screen while the screen is on
504 boolean mAllowLockscreenWhenOn;
505 int mLockScreenTimeout;
506 boolean mLockScreenTimerActive;
507
David Brownbaf8d092010-03-08 21:52:59 -0800508 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800509 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800510
511 // Behavior of POWER button while in-call and screen on.
512 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
513 int mIncallPowerBehavior;
514
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700515 Display mDisplay;
516
Dianne Hackborn9d132642011-04-21 17:26:39 -0700517 int mLandscapeRotation = 0; // default landscape rotation
518 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
519 int mPortraitRotation = 0; // default portrait rotation
520 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700521
Dianne Hackbornc652de82013-02-15 16:32:56 -0800522 int mOverscanLeft = 0;
523 int mOverscanTop = 0;
524 int mOverscanRight = 0;
525 int mOverscanBottom = 0;
526
Joe Onorato46b0d682010-11-22 17:37:27 -0800527 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700528 private int mLongPressOnHomeBehavior;
529
530 // What we do when the user double-taps on home
531 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800532
Bryce Lee584a4452014-10-21 15:55:55 -0700533 // Allowed theater mode wake actions
534 private boolean mAllowTheaterModeWakeFromKey;
535 private boolean mAllowTheaterModeWakeFromPowerKey;
536 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800537 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700538 private boolean mAllowTheaterModeWakeFromCameraLens;
539 private boolean mAllowTheaterModeWakeFromLidSwitch;
540 private boolean mAllowTheaterModeWakeFromWakeGesture;
541
Bryce Leed3b28402015-03-09 15:49:13 +0000542 // Whether to support long press from power button in non-interactive mode
543 private boolean mSupportLongPressPowerWhenNonInteractive;
544
Bryce Lee55e846d2014-11-04 12:43:44 -0800545 // Whether to go to sleep entering theater mode from power button
546 private boolean mGoToSleepOnButtonPressTheaterMode;
547
Winson Chung9112ec32011-06-27 13:15:32 -0700548 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700549 // Time to volume and power must be pressed within this interval of each other.
550 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700551 // Increase the chord delay when taking a screenshot from the keyguard
552 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800553 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700554 private boolean mScreenshotChordVolumeDownKeyTriggered;
555 private long mScreenshotChordVolumeDownKeyTime;
556 private boolean mScreenshotChordVolumeDownKeyConsumed;
557 private boolean mScreenshotChordVolumeUpKeyTriggered;
558 private boolean mScreenshotChordPowerKeyTriggered;
559 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700560
Michael Wrightb854e242013-02-05 17:54:02 -0800561 /* The number of steps between min and max brightness */
562 private static final int BRIGHTNESS_STEPS = 10;
563
Christopher Tate5e08af02012-09-21 17:17:22 -0700564 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800565 ShortcutManager mShortcutManager;
566 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700567 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700568 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800569
Craig Mautnerd625ab22013-09-06 13:40:31 -0700570 private int mCurrentUserId;
571
Justin Kohd378ad72013-04-01 12:18:26 -0700572 // Maps global key codes to the components that will handle them.
573 private GlobalKeyManager mGlobalKeyManager;
574
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700575 // Fallback actions by key code.
576 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
577 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800578
Jorim Jaggi76a16232014-08-08 17:00:47 +0200579 private final LogDecelerateInterpolator mLogDecelerateInterpolator
580 = new LogDecelerateInterpolator(100, 0);
581
Jeff Brown70825162012-03-28 17:27:48 -0700582 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
583 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700584 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
585 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700586 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
587 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
588 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700589 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700590 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700591 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700592 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700593 private static final int MSG_POWER_DELAYED_PRESS = 13;
594 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown70825162012-03-28 17:27:48 -0700595
596 private class PolicyHandler extends Handler {
597 @Override
598 public void handleMessage(Message msg) {
599 switch (msg.what) {
600 case MSG_ENABLE_POINTER_LOCATION:
601 enablePointerLocation();
602 break;
603 case MSG_DISABLE_POINTER_LOCATION:
604 disablePointerLocation();
605 break;
Jeff Brown40013652012-05-16 21:22:36 -0700606 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
607 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
608 break;
609 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
610 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
611 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700612 case MSG_DISPATCH_SHOW_RECENTS:
613 showRecentApps(false);
614 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700615 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
616 showGlobalActionsInternal();
617 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700618 case MSG_KEYGUARD_DRAWN_COMPLETE:
619 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700620 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700621 break;
622 case MSG_KEYGUARD_DRAWN_TIMEOUT:
623 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700624 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700625 break;
626 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
627 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700628 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700629 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700630 case MSG_HIDE_BOOT_MESSAGE:
631 handleHideBootMessage();
632 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700633 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
634 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
635 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700636 case MSG_POWER_DELAYED_PRESS:
637 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
638 finishPowerKeyPress();
639 break;
640 case MSG_POWER_LONG_PRESS:
641 powerLongPress();
642 break;
Jeff Brown70825162012-03-28 17:27:48 -0700643 }
644 }
645 }
646
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800647 private UEventObserver mHDMIObserver = new UEventObserver() {
648 @Override
649 public void onUEvent(UEventObserver.UEvent event) {
650 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
651 }
652 };
653
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800654 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800655 SettingsObserver(Handler handler) {
656 super(handler);
657 }
David Brownbaf8d092010-03-08 21:52:59 -0800658
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800659 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700660 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800661 ContentResolver resolver = mContext.getContentResolver();
662 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700663 Settings.System.END_BUTTON_BEHAVIOR), false, this,
664 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800665 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700666 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
667 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700668 resolver.registerContentObserver(Settings.Secure.getUriFor(
669 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
670 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800671 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700672 Settings.System.ACCELEROMETER_ROTATION), false, this,
673 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500674 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700675 Settings.System.USER_ROTATION), false, this,
676 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400677 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700678 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
679 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800680 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700681 Settings.System.POINTER_LOCATION), false, this,
682 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800683 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700684 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
685 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500686 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400687 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700688 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500689 resolver.registerContentObserver(Settings.Global.getUriFor(
690 Settings.Global.POLICY_CONTROL), false, this,
691 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800692 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800693 }
694
695 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800696 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700697 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800698 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800699 }
Craig Mautner967212c2013-04-13 21:10:58 -0700700
Jeff Browna20dda42014-05-27 20:57:24 -0700701 class MyWakeGestureListener extends WakeGestureListener {
702 MyWakeGestureListener(Context context, Handler handler) {
703 super(context, handler);
704 }
705
706 @Override
707 public void onWakeUp() {
708 synchronized (mLock) {
709 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700710 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700711 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700712 }
713 }
714 }
715 }
716
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800717 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800718 MyOrientationListener(Context context, Handler handler) {
719 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800720 }
Craig Mautner967212c2013-04-13 21:10:58 -0700721
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800722 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700723 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700724 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700725 updateRotation(false);
726 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800727 }
728 MyOrientationListener mOrientationListener;
729
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100730 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400731
John Spurlock27735a42013-08-14 17:57:38 -0400732 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400733 View.NAVIGATION_BAR_TRANSIENT,
734 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400735 View.NAVIGATION_BAR_TRANSLUCENT,
736 StatusBarManager.WINDOW_NAVIGATION_BAR,
737 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400738
John Spurlockf1a36642013-10-12 17:50:42 -0400739 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400740
Craig Mautner037aa8d2013-06-07 10:35:44 -0700741 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400742
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700743 IStatusBarService getStatusBarService() {
744 synchronized (mServiceAquireLock) {
745 if (mStatusBarService == null) {
746 mStatusBarService = IStatusBarService.Stub.asInterface(
747 ServiceManager.getService("statusbar"));
748 }
749 return mStatusBarService;
750 }
751 }
752
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700753 /*
754 * We always let the sensor be switched on by default except when
755 * the user has explicitly disabled sensor based rotation or when the
756 * screen is switched off.
757 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700758 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800759 if (mSupportAutoRotation) {
760 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
761 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
762 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
763 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
764 // If the application has explicitly requested to follow the
765 // orientation, then we need to turn the sensor on.
766 return true;
767 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800768 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700769 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800770 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
771 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
772 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400773 // enable accelerometer if we are docked in a dock that enables accelerometer
774 // orientation management,
775 return true;
776 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700777 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800778 // If the setting for using the sensor by default is enabled, then
779 // we will always leave it on. Note that the user could go to
780 // a window that forces an orientation that does not use the
781 // sensor and in theory we could turn it off... however, when next
782 // turning it on we won't have a good value for the current
783 // orientation for a little bit, which can cause orientation
784 // changes to lag, so we'd like to keep it always on. (It will
785 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700786 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800787 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800788 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800789 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700790
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800791 /*
792 * Various use cases for invoking this function
793 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700794 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800795 * if not already enabled
796 * screen turned on and current app does not have sensor orientation, disable listeners if
797 * already enabled
798 * screen turning on and current app has sensor based orientation, enable listeners if needed
799 * screen turning on and current app has nosensor based orientation, do nothing
800 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700801 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800802 if (!mOrientationListener.canDetectOrientation()) {
803 // If sensor is turned off or nonexistent for some reason
804 return;
805 }
806 //Could have been invoked due to screen turning on or off or
807 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700808 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
809 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
810 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800811 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700812 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700813 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800814 disable = false;
815 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700816 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800817 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700818 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800819 mOrientationSensorEnabled = true;
820 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700821 }
822 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800823 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700824 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800825 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700826 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800827 mOrientationSensorEnabled = false;
828 }
829 }
830
Jeff Brown13f00f02014-10-31 14:45:50 -0700831 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
832 // Hold a wake lock until the power key is released.
833 if (!mPowerKeyWakeLock.isHeld()) {
834 mPowerKeyWakeLock.acquire();
835 }
836
837 // Cancel multi-press detection timeout.
838 if (mPowerKeyPressCounter != 0) {
839 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
840 }
841
842 // Detect user pressing the power button in panic when an application has
843 // taken over the whole screen.
844 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800845 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700846 if (panic) {
847 mHandler.post(mRequestTransientNav);
848 }
849
850 // Latch power key state to detect screenshot chord.
851 if (interactive && !mScreenshotChordPowerKeyTriggered
852 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
853 mScreenshotChordPowerKeyTriggered = true;
854 mScreenshotChordPowerKeyTime = event.getDownTime();
855 interceptScreenshotChord();
856 }
857
858 // Stop ringing or end call if configured to do so when power is pressed.
859 TelecomManager telecomManager = getTelecommService();
860 boolean hungUp = false;
861 if (telecomManager != null) {
862 if (telecomManager.isRinging()) {
863 // Pressing Power while there's a ringing incoming
864 // call should silence the ringer.
865 telecomManager.silenceRinger();
866 } else if ((mIncallPowerBehavior
867 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
868 && telecomManager.isInCall() && interactive) {
869 // Otherwise, if "Power button ends call" is enabled,
870 // the Power button will hang up any current active call.
871 hungUp = telecomManager.endCall();
872 }
873 }
874
875 // If the power key has still not yet been handled, then detect short
876 // press, long press, or multi press and decide what to do.
877 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
878 || mScreenshotChordVolumeUpKeyTriggered;
879 if (!mPowerKeyHandled) {
880 if (interactive) {
881 // When interactive, we're already awake.
882 // Wait for a long press or for the button to be released to decide what to do.
883 if (hasLongPressOnPowerBehavior()) {
884 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
885 msg.setAsynchronous(true);
886 mHandler.sendMessageDelayed(msg,
887 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
888 }
889 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800890 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800891
Bryce Leed3b28402015-03-09 15:49:13 +0000892 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
893 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
894 msg.setAsynchronous(true);
895 mHandler.sendMessageDelayed(msg,
896 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800897 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000898 } else {
899 final int maxCount = getMaxMultiPressPowerCount();
900
901 if (maxCount <= 1) {
902 mPowerKeyHandled = true;
903 } else {
904 mBeganFromNonInteractive = true;
905 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700906 }
907 }
Jeff Brown4d396052010-10-29 21:50:21 -0700908 }
909 }
910
Jeff Brown13f00f02014-10-31 14:45:50 -0700911 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
912 final boolean handled = canceled || mPowerKeyHandled;
913 mScreenshotChordPowerKeyTriggered = false;
914 cancelPendingScreenshotChordAction();
915 cancelPendingPowerKeyAction();
916
917 if (!handled) {
918 // Figure out how to handle the key now that it has been released.
919 mPowerKeyPressCounter += 1;
920
921 final int maxCount = getMaxMultiPressPowerCount();
922 final long eventTime = event.getDownTime();
923 if (mPowerKeyPressCounter < maxCount) {
924 // This could be a multi-press. Wait a little bit longer to confirm.
925 // Continue holding the wake lock.
926 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
927 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
928 msg.setAsynchronous(true);
929 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
930 return;
931 }
932
933 // No other actions. Handle it immediately.
934 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700935 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700936
937 // Done. Reset our state.
938 finishPowerKeyPress();
939 }
940
941 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800942 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700943 mPowerKeyPressCounter = 0;
944 if (mPowerKeyWakeLock.isHeld()) {
945 mPowerKeyWakeLock.release();
946 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700947 }
948
949 private void cancelPendingPowerKeyAction() {
950 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700951 mPowerKeyHandled = true;
952 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700953 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700954 }
955
956 private void powerPress(long eventTime, boolean interactive, int count) {
957 if (mScreenOnEarly && !mScreenOnFully) {
958 Slog.i(TAG, "Suppressed redundant power key press while "
959 + "already in the process of turning the screen on.");
960 return;
Jeff Brownff204712011-10-25 21:27:54 -0700961 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700962
963 if (count == 2) {
964 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
965 } else if (count == 3) {
966 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -0800967 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700968 switch (mShortPressOnPowerBehavior) {
969 case SHORT_PRESS_POWER_NOTHING:
970 break;
971 case SHORT_PRESS_POWER_GO_TO_SLEEP:
972 mPowerManager.goToSleep(eventTime,
973 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
974 break;
975 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
976 mPowerManager.goToSleep(eventTime,
977 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
978 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
979 break;
980 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
981 mPowerManager.goToSleep(eventTime,
982 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
983 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
984 launchHomeFromHotKey();
985 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800986 case SHORT_PRESS_POWER_GO_HOME:
987 launchHomeFromHotKey();
988 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700989 }
990 }
991 }
992
993 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
994 switch (behavior) {
995 case MULTI_PRESS_POWER_NOTHING:
996 break;
997 case MULTI_PRESS_POWER_THEATER_MODE:
998 if (isTheaterModeEnabled()) {
999 Slog.i(TAG, "Toggling theater mode off.");
1000 Settings.Global.putInt(mContext.getContentResolver(),
1001 Settings.Global.THEATER_MODE_ON, 0);
1002 if (!interactive) {
1003 wakeUpFromPowerKey(eventTime);
1004 }
1005 } else {
1006 Slog.i(TAG, "Toggling theater mode on.");
1007 Settings.Global.putInt(mContext.getContentResolver(),
1008 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001009
1010 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001011 mPowerManager.goToSleep(eventTime,
1012 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1013 }
1014 }
1015 break;
1016 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001017 Slog.i(TAG, "Starting brightness boost.");
1018 if (!interactive) {
1019 wakeUpFromPowerKey(eventTime);
1020 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001021 mPowerManager.boostScreenBrightness(eventTime);
1022 break;
1023 }
1024 }
1025
1026 private int getMaxMultiPressPowerCount() {
1027 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1028 return 3;
1029 }
1030 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1031 return 2;
1032 }
1033 return 1;
1034 }
1035
1036 private void powerLongPress() {
1037 final int behavior = getResolvedLongPressOnPowerBehavior();
1038 switch (behavior) {
1039 case LONG_PRESS_POWER_NOTHING:
1040 break;
1041 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1042 mPowerKeyHandled = true;
1043 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1044 performAuditoryFeedbackForAccessibilityIfNeed();
1045 }
1046 showGlobalActionsInternal();
1047 break;
1048 case LONG_PRESS_POWER_SHUT_OFF:
1049 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1050 mPowerKeyHandled = true;
1051 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1052 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1053 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1054 break;
1055 }
1056 }
1057
1058 private int getResolvedLongPressOnPowerBehavior() {
1059 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1060 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1061 }
1062 return mLongPressOnPowerBehavior;
1063 }
1064
1065 private boolean hasLongPressOnPowerBehavior() {
1066 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001067 }
1068
1069 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001070 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001071 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1072 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001073 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001074 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1075 && now <= mScreenshotChordPowerKeyTime
1076 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1077 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001078 cancelPendingPowerKeyAction();
1079
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001080 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001081 }
1082 }
1083 }
1084
Winson Chung1cea2f32012-10-08 20:42:01 -07001085 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001086 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001087 // Double the time it takes to take a screenshot from the keyguard
1088 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001089 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001090 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001091 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001092 }
1093
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001094 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001095 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001096 }
1097
Jeff Brown13f00f02014-10-31 14:45:50 -07001098 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001099 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001100 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001101 mEndCallKeyHandled = true;
1102 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1103 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001104 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001105 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001106 }
1107 };
1108
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001109 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001110 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001111 public void run() {
1112 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001113 }
1114 };
1115
Alan Viverettee34560b22014-07-10 14:50:06 -07001116 @Override
1117 public void showGlobalActions() {
1118 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1119 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1120 }
1121
1122 void showGlobalActionsInternal() {
1123 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001124 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001125 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001126 }
Jim Millerab954542014-10-10 18:21:49 -07001127 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001128 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1129 if (keyguardShowing) {
1130 // since it took two seconds of long press to bring this up,
1131 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001132 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001133 }
1134 }
1135
1136 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001137 return Settings.Global.getInt(
1138 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001139 }
1140
Maurice Lam99c6e072014-04-28 18:24:28 -07001141 boolean isUserSetupComplete() {
1142 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1143 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1144 }
1145
Jeff Brown13f00f02014-10-31 14:45:50 -07001146 private void handleShortPressOnHome() {
1147 // If there's a dream running then use home to escape the dream
1148 // but don't actually go home.
1149 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1150 mDreamManagerInternal.stopDream(false /*immediate*/);
1151 return;
1152 }
1153
1154 // Go home!
1155 launchHomeFromHotKey();
1156 }
1157
Patrick Dubroyece94522011-02-23 18:35:01 -08001158 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -08001159 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001160 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001161 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001162
Jeff Browncaca8812013-05-09 13:34:33 -07001163 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1164 toggleRecentApps();
1165 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1166 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -07001167 }
1168 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001169 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001170
Jeff Browncaca8812013-05-09 13:34:33 -07001171 private void handleDoubleTapOnHome() {
1172 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1173 mHomeConsumed = true;
1174 toggleRecentApps();
1175 }
1176 }
1177
1178 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1179 @Override
1180 public void run() {
1181 if (mHomeDoubleTapPending) {
1182 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001183 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001184 }
1185 }
1186 };
1187
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001188 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001189 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001190 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001191 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001192 mContext = context;
1193 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001194 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001195 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001196 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001197 if (context.getResources().getBoolean(
1198 com.android.internal.R.bool.config_enableBurnInProtection)){
1199 mBurnInProtectionHelper = new BurnInProtectionHelper(context);
1200 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001201
Jeff Brown70825162012-03-28 17:27:48 -07001202 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001203 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001204 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001205 try {
1206 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1207 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001208 mSettingsObserver = new SettingsObserver(mHandler);
1209 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001210 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001211 mUiMode = context.getResources().getInteger(
1212 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001213 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1214 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1215 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1216 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001217 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1218 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1219 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1220 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1221 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1222 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1223 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1224 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001225
Jeff Brown96307042012-07-27 15:51:34 -07001226 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1227 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001228 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001229 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1230 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001231 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001232 mSupportAutoRotation = mContext.getResources().getBoolean(
1233 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001234 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001235 com.android.internal.R.integer.config_lidOpenRotation);
1236 mCarDockRotation = readRotation(
1237 com.android.internal.R.integer.config_carDockRotation);
1238 mDeskDockRotation = readRotation(
1239 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001240 mUndockedHdmiRotation = readRotation(
1241 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001242 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1243 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1244 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1245 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001246 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1247 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1248 mLidNavigationAccessibility = mContext.getResources().getInteger(
1249 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001250 mLidControlsSleep = mContext.getResources().getBoolean(
1251 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001252 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1253 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001254
1255 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1256 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1257 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1258 || mContext.getResources().getBoolean(
1259 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1260 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1261 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001262 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1263 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001264 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1265 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1266 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1267 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1268 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1269 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1270
Bryce Lee55e846d2014-11-04 12:43:44 -08001271 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1272 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1273
Bryce Leed3b28402015-03-09 15:49:13 +00001274 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1275 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1276
Jeff Brown13f00f02014-10-31 14:45:50 -07001277 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1278 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1279 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1280 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1281 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1282 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1283 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1284 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
1285
John Spurlock61560172015-02-06 19:46:04 -05001286 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001287
Jeff Brownf71343d2013-05-31 17:59:11 -07001288 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001289
Svetoslav8e3feb12014-02-24 13:46:47 -08001290 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1291 Context.ACCESSIBILITY_SERVICE);
1292
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001293 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001294 IntentFilter filter = new IntentFilter();
1295 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1296 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1297 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1298 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001299 filter.addAction(Intent.ACTION_DOCK_EVENT);
1300 Intent intent = context.registerReceiver(mDockReceiver, filter);
1301 if (intent != null) {
1302 // Retrieve current sticky dock event broadcast.
1303 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1304 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1305 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001306
Jeff Brown6aaf2952012-10-05 16:01:08 -07001307 // register for dream-related broadcasts
1308 filter = new IntentFilter();
1309 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1310 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1311 context.registerReceiver(mDreamReceiver, filter);
1312
Christopher Tate5e08af02012-09-21 17:17:22 -07001313 // register for multiuser-relevant broadcasts
1314 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1315 context.registerReceiver(mMultiuserReceiver, filter);
1316
John Spurlock57306e62013-04-22 09:48:49 -04001317 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001318 mSystemGestures = new SystemGesturesPointerEventListener(context,
1319 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001320 @Override
1321 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001322 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001323 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001324 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001325 }
1326 @Override
1327 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001328 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001329 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001330 }
1331 }
1332 @Override
1333 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001334 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001335 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001336 }
1337 }
1338 @Override
1339 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001340 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001341 }
1342 });
John Spurlockf1a36642013-10-12 17:50:42 -04001343 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001344 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001345
Jeff Brownc2346132012-04-13 01:55:38 -07001346 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001347 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1348 com.android.internal.R.array.config_longPressVibePattern);
1349 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1350 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001351 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1352 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001353 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1354 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001355 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1356 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001357 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1358 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1359 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1360 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001361
Christopher Tatee90585f2012-03-05 18:56:25 -08001362 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1363 com.android.internal.R.bool.config_enableScreenshotChord);
1364
Justin Kohd378ad72013-04-01 12:18:26 -07001365 mGlobalKeyManager = new GlobalKeyManager(mContext);
1366
Joe Onoratoea495d42011-04-06 11:41:11 -07001367 // Controls rotation and the like.
1368 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001369
1370 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001371 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001372 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001373 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001374
1375 mWindowManagerInternal.registerAppTransitionListener(
1376 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001377 }
1378
Jeff Brownf71343d2013-05-31 17:59:11 -07001379 /**
1380 * Read values from config.xml that may be overridden depending on
1381 * the configuration of the device.
1382 * eg. Disable long press on home goes to recents on sw600dp.
1383 */
1384 private void readConfigurationDependentBehaviors() {
1385 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1386 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1387 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1388 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1389 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1390 }
1391
1392 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1393 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1394 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1395 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1396 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1397 }
1398 }
1399
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001400 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001401 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001402 // This method might be called before the policy has been fully initialized
1403 // or for other displays we don't care about.
1404 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1405 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001406 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001407 mDisplay = display;
1408
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001409 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001410 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001411 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001412 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001413 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001414 mLandscapeRotation = Surface.ROTATION_0;
1415 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001416 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001417 mPortraitRotation = Surface.ROTATION_90;
1418 mUpsideDownRotation = Surface.ROTATION_270;
1419 } else {
1420 mPortraitRotation = Surface.ROTATION_270;
1421 mUpsideDownRotation = Surface.ROTATION_90;
1422 }
1423 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001424 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001425 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001426 mPortraitRotation = Surface.ROTATION_0;
1427 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001428 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001429 mLandscapeRotation = Surface.ROTATION_270;
1430 mSeascapeRotation = Surface.ROTATION_90;
1431 } else {
1432 mLandscapeRotation = Surface.ROTATION_90;
1433 mSeascapeRotation = Surface.ROTATION_270;
1434 }
1435 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001436
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001437 mStatusBarHeight =
1438 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001439
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001440 // Height of the navigation bar when presented horizontally at bottom
1441 mNavigationBarHeightForRotation[mPortraitRotation] =
1442 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001443 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001444 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001445 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1446 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001447
1448 // Width of the navigation bar when presented vertically along one side
1449 mNavigationBarWidthForRotation[mPortraitRotation] =
1450 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1451 mNavigationBarWidthForRotation[mLandscapeRotation] =
1452 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001453 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001454
1455 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001456 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001457 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001458
Devin Kimd7b12b42014-05-05 14:34:58 -07001459 // Allow the navigation bar to move on non-square small devices (phones).
1460 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001461
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001462 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001463 // Allow a system property to override this. Used by the emulator.
1464 // See also hasNavigationBar().
1465 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1466 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001467 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001468 } else if ("0".equals(navBarOverride)) {
1469 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001470 }
1471
Jeff Brown27f1d672012-10-17 18:32:34 -07001472 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1473 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001474 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001475 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001476 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001477 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001478 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001479 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001480
Chong Zhangae6119ff2014-11-11 18:54:39 -08001481 // For demo purposes, allow the rotation of the remote display to be controlled.
1482 // By default, remote display locks rotation to landscape.
1483 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1484 mDemoRotation = mPortraitRotation;
1485 } else {
1486 mDemoRotation = mLandscapeRotation;
1487 }
1488 mDemoRotationLock = SystemProperties.getBoolean(
1489 "persist.demo.rotationlock", false);
1490
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001491 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1492 // http://developer.android.com/guide/practices/screens_support.html#range
1493 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1494 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1495 // For debug purposes the next line turns this feature off with:
1496 // $ adb shell setprop config.override_forced_orient true
1497 // $ adb shell wm size reset
1498 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1499 }
1500
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001501 /**
1502 * @return whether the navigation bar can be hidden, e.g. the device has a
1503 * navigation bar and touch exploration is not enabled
1504 */
1505 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001506 return mHasNavigationBar
1507 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001508 }
1509
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001510 @Override
1511 public boolean isDefaultOrientationForced() {
1512 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001513 }
1514
Dianne Hackbornc652de82013-02-15 16:32:56 -08001515 @Override
1516 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1517 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1518 mOverscanLeft = left;
1519 mOverscanTop = top;
1520 mOverscanRight = right;
1521 mOverscanBottom = bottom;
1522 }
1523 }
1524
Dianne Hackbornc777e072010-02-12 13:07:59 -08001525 public void updateSettings() {
1526 ContentResolver resolver = mContext.getContentResolver();
1527 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001528 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001529 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001530 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001531 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1532 UserHandle.USER_CURRENT);
1533 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001534 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001535 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1536 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001537
Jeff Browna20dda42014-05-27 20:57:24 -07001538 // Configure wake gesture.
1539 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1540 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1541 UserHandle.USER_CURRENT) != 0;
1542 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1543 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1544 updateWakeGestureListenerLp();
1545 }
1546
Jeff Brown207673cd2012-06-05 17:47:11 -07001547 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001548 int userRotation = Settings.System.getIntForUser(resolver,
1549 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1550 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001551 if (mUserRotation != userRotation) {
1552 mUserRotation = userRotation;
1553 updateRotation = true;
1554 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001555 int userRotationMode = Settings.System.getIntForUser(resolver,
1556 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001557 WindowManagerPolicy.USER_ROTATION_FREE :
1558 WindowManagerPolicy.USER_ROTATION_LOCKED;
1559 if (mUserRotationMode != userRotationMode) {
1560 mUserRotationMode = userRotationMode;
1561 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001562 updateOrientationListenerLp();
1563 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001564
Dianne Hackbornc777e072010-02-12 13:07:59 -08001565 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001566 int pointerLocation = Settings.System.getIntForUser(resolver,
1567 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001568 if (mPointerLocationMode != pointerLocation) {
1569 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001570 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1571 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001572 }
1573 }
1574 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001575 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1576 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1577 String imId = Settings.Secure.getStringForUser(resolver,
1578 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001579 boolean hasSoftInput = imId != null && imId.length() > 0;
1580 if (mHasSoftInput != hasSoftInput) {
1581 mHasSoftInput = hasSoftInput;
1582 updateRotation = true;
1583 }
John Spurlockf1a36642013-10-12 17:50:42 -04001584 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001585 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001586 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001587 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001588 }
1589 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001590 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001591 }
Jeff Brown70825162012-03-28 17:27:48 -07001592 }
1593
Jeff Browna20dda42014-05-27 20:57:24 -07001594 private void updateWakeGestureListenerLp() {
1595 if (shouldEnableWakeGestureLp()) {
1596 mWakeGestureListener.requestWakeUpTrigger();
1597 } else {
1598 mWakeGestureListener.cancelWakeUpTrigger();
1599 }
1600 }
1601
1602 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001603 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001604 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1605 && mWakeGestureListener.isSupported();
1606 }
1607
Jeff Brown70825162012-03-28 17:27:48 -07001608 private void enablePointerLocation() {
1609 if (mPointerLocationView == null) {
1610 mPointerLocationView = new PointerLocationView(mContext);
1611 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001612 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1613 WindowManager.LayoutParams.MATCH_PARENT,
1614 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001615 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001616 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1617 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1618 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1619 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001620 if (ActivityManager.isHighEndGfx()) {
1621 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1622 lp.privateFlags |=
1623 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1624 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001625 lp.format = PixelFormat.TRANSLUCENT;
1626 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001627 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001628 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001629 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001630 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001631 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001632 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001633 }
Jeff Brown70825162012-03-28 17:27:48 -07001634
1635 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001636 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001637 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1638 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001639 wm.removeView(mPointerLocationView);
1640 mPointerLocationView = null;
1641 }
1642 }
1643
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001644 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001645 try {
1646 int rotation = mContext.getResources().getInteger(resID);
1647 switch (rotation) {
1648 case 0:
1649 return Surface.ROTATION_0;
1650 case 90:
1651 return Surface.ROTATION_90;
1652 case 180:
1653 return Surface.ROTATION_180;
1654 case 270:
1655 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001656 }
1657 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001658 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001659 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001660 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001661 }
1662
1663 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001664 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001665 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001666 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001667
1668 outAppOp[0] = AppOpsManager.OP_NONE;
1669
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001670 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1671 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1672 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1673 return WindowManagerGlobal.ADD_INVALID_TYPE;
1674 }
1675
1676 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1677 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001678 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001679 }
1680 String permission = null;
1681 switch (type) {
1682 case TYPE_TOAST:
1683 // XXX right now the app process has complete control over
1684 // this... should introduce a token to let the system
1685 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001686 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001687 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001688 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001689 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001690 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001691 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001692 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001693 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001694 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001695 break;
1696 case TYPE_PHONE:
1697 case TYPE_PRIORITY_PHONE:
1698 case TYPE_SYSTEM_ALERT:
1699 case TYPE_SYSTEM_ERROR:
1700 case TYPE_SYSTEM_OVERLAY:
1701 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001702 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001703 break;
1704 default:
1705 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1706 }
1707 if (permission != null) {
1708 if (mContext.checkCallingOrSelfPermission(permission)
1709 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001710 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001711 }
1712 }
Jeff Brown98365d72012-08-19 20:30:52 -07001713 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001714 }
Craig Mautner88400d32012-09-30 12:35:45 -07001715
1716 @Override
1717 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1718
1719 // If this switch statement is modified, modify the comment in the declarations of
1720 // the type in {@link WindowManager.LayoutParams} as well.
1721 switch (attrs.type) {
1722 default:
1723 // These are the windows that by default are shown only to the user that created
1724 // them. If this needs to be overridden, set
1725 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1726 // {@link WindowManager.LayoutParams}. Note that permission
1727 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1728 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1729 return true;
1730 }
1731 break;
1732
1733 // These are the windows that by default are shown to all users. However, to
1734 // protect against spoofing, check permissions below.
1735 case TYPE_APPLICATION_STARTING:
1736 case TYPE_BOOT_PROGRESS:
1737 case TYPE_DISPLAY_OVERLAY:
1738 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001739 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001740 case TYPE_KEYGUARD_DIALOG:
1741 case TYPE_MAGNIFICATION_OVERLAY:
1742 case TYPE_NAVIGATION_BAR:
1743 case TYPE_NAVIGATION_BAR_PANEL:
1744 case TYPE_PHONE:
1745 case TYPE_POINTER:
1746 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001747 case TYPE_SEARCH_BAR:
1748 case TYPE_STATUS_BAR:
1749 case TYPE_STATUS_BAR_PANEL:
1750 case TYPE_STATUS_BAR_SUB_PANEL:
1751 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001752 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001753 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001754 break;
1755 }
1756
1757 // Check if third party app has set window to system window type.
1758 return mContext.checkCallingOrSelfPermission(
1759 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1760 != PackageManager.PERMISSION_GRANTED;
1761 }
1762
Craig Mautner967212c2013-04-13 21:10:58 -07001763 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001764 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1765 switch (attrs.type) {
1766 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001767 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001768 // These types of windows can't receive input events.
1769 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1770 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001771 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001772 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001773 case TYPE_STATUS_BAR:
1774
1775 // If the Keyguard is in a hidden state (occluded by another window), we force to
1776 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1777 // the keyguard as occluded wouldn't set these flags again.
1778 // See {@link #processKeyguardSetHiddenResultLw}.
1779 if (mKeyguardHidden) {
1780 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1781 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1782 }
1783 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001784 }
Adrian Roos38502112014-04-09 21:04:11 +02001785
1786 if (attrs.type != TYPE_STATUS_BAR) {
1787 // The status bar is the only window allowed to exhibit keyguard behavior.
1788 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1789 }
Adrian Roosea562512014-05-05 13:33:03 +02001790
1791 if (ActivityManager.isHighEndGfx()
1792 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001793 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001794 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1795 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001796 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001797
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001798 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001799 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001800 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001801
Michael Wright3818c922014-09-02 13:59:07 -07001802 private void readCameraLensCoverState() {
1803 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1804 }
1805
Jeff Browndaa37532012-05-01 15:54:03 -07001806 private boolean isHidden(int accessibilityMode) {
1807 switch (accessibilityMode) {
1808 case 1:
1809 return mLidState == LID_CLOSED;
1810 case 2:
1811 return mLidState == LID_OPEN;
1812 default:
1813 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001814 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001815 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001816
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001817 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001818 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001819 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1820 int navigationPresence) {
1821 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1822
Jeff Brownf71343d2013-05-31 17:59:11 -07001823 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001824 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001825 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001826
Jeff Browndaa37532012-05-01 15:54:03 -07001827 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1828 || (keyboardPresence == PRESENCE_INTERNAL
1829 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001830 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001831 if (!mHasSoftInput) {
1832 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1833 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001834 }
1835
Jeff Browndaa37532012-05-01 15:54:03 -07001836 if (config.navigation == Configuration.NAVIGATION_NONAV
1837 || (navigationPresence == PRESENCE_INTERNAL
1838 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001839 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001840 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001841 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001842
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001843 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001844 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001845 public int windowTypeToLayerLw(int type) {
1846 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001847 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001848 }
1849 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001850 case TYPE_PRIVATE_PRESENTATION:
1851 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001852 case TYPE_WALLPAPER:
1853 // wallpaper is at the bottom, though the window manager may move it.
1854 return 2;
1855 case TYPE_PHONE:
1856 return 3;
1857 case TYPE_SEARCH_BAR:
1858 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001859 case TYPE_VOICE_INTERACTION:
1860 // voice interaction layer is almost immediately above apps.
1861 return 5;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001862 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001863 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001864 case TYPE_TOAST:
1865 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001866 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001867 case TYPE_PRIORITY_PHONE:
1868 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001869 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001870 case TYPE_DREAM:
1871 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001872 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001873 case TYPE_SYSTEM_ALERT:
1874 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001875 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001876 case TYPE_INPUT_METHOD:
1877 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001878 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001879 case TYPE_INPUT_METHOD_DIALOG:
1880 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001881 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001882 case TYPE_KEYGUARD_SCRIM:
1883 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001884 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001885 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001886 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001887 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001888 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001889 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001890 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001891 case TYPE_KEYGUARD_DIALOG:
1892 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001893 case TYPE_VOLUME_OVERLAY:
1894 // the on-screen volume indicator and controller shown when the user
1895 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001896 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001897 case TYPE_SYSTEM_OVERLAY:
1898 // the on-screen volume indicator and controller shown when the user
1899 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001900 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001901 case TYPE_NAVIGATION_BAR:
1902 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001903 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001904 case TYPE_NAVIGATION_BAR_PANEL:
1905 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001906 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001907 case TYPE_SYSTEM_ERROR:
1908 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001909 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001910 case TYPE_MAGNIFICATION_OVERLAY:
1911 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001912 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001913 case TYPE_DISPLAY_OVERLAY:
1914 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001915 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001916 case TYPE_DRAG:
1917 // the drag layer: input for drag-and-drop is associated with this window,
1918 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001919 return 25;
Svetoslav3a5c7212014-10-14 09:54:26 -07001920 case TYPE_ACCESSIBILITY_OVERLAY:
1921 // overlay put by accessibility services to intercept user interaction
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001922 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07001923 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001924 return 27;
Svetoslav3a5c7212014-10-14 09:54:26 -07001925 case TYPE_BOOT_PROGRESS:
1926 return 28;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001927 case TYPE_POINTER:
1928 // the (mouse) pointer layer
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001929 return 29;
Svetoslav3a5c7212014-10-14 09:54:26 -07001930 case TYPE_HIDDEN_NAV_CONSUMER:
1931 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001932 }
1933 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001934 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001935 }
1936
1937 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001938 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001939 public int subWindowTypeToLayerLw(int type) {
1940 switch (type) {
1941 case TYPE_APPLICATION_PANEL:
1942 case TYPE_APPLICATION_ATTACHED_DIALOG:
1943 return APPLICATION_PANEL_SUBLAYER;
1944 case TYPE_APPLICATION_MEDIA:
1945 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001946 case TYPE_APPLICATION_MEDIA_OVERLAY:
1947 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001948 case TYPE_APPLICATION_SUB_PANEL:
1949 return APPLICATION_SUB_PANEL_SUBLAYER;
1950 }
1951 Log.e(TAG, "Unknown sub-window type: " + type);
1952 return 0;
1953 }
1954
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001955 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001956 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001957 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001958 }
1959
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001960 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001961 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001962 if (mHasNavigationBar) {
1963 // For a basic navigation bar, when we are in landscape mode we place
1964 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001965 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1966 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001967 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001968 }
1969 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001970 }
1971
Jose Lima9546b202014-07-02 17:21:51 -07001972 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001973 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001974 if (mHasNavigationBar) {
1975 // For a basic navigation bar, when we are in portrait mode we place
1976 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001977 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1978 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001979 }
1980 }
1981 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001982 }
1983
Jose Lima9546b202014-07-02 17:21:51 -07001984 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001985 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1986 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001987 }
1988
Jose Lima9546b202014-07-02 17:21:51 -07001989 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001990 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001991 // There is a separate status bar at the top of the display. We don't count that as part
1992 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001993 // we do want to exclude it since applications can't generally use that part
1994 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001995 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001996 }
1997
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001998 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07001999 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2000 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002001 (isKeyguardHostWindow(attrs) &&
2002 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002003 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002004 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002005
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002006 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002007 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2008 return attrs.type == TYPE_STATUS_BAR;
2009 }
2010
2011 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002012 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002013 switch (attrs.type) {
2014 case TYPE_STATUS_BAR:
2015 case TYPE_NAVIGATION_BAR:
2016 case TYPE_WALLPAPER:
2017 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002018 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002019 return false;
2020 default:
2021 return true;
2022 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002023 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002024
Craig Mautner7d7808f2014-09-11 18:02:38 -07002025 @Override
2026 public WindowState getWinShowWhenLockedLw() {
2027 return mWinShowWhenLocked;
2028 }
2029
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002030 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002031 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002032 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2033 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002034 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002035 if (!SHOW_STARTING_ANIMATIONS) {
2036 return null;
2037 }
2038 if (packageName == null) {
2039 return null;
2040 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002041
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002042 WindowManager wm = null;
2043 View view = null;
2044
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002045 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002046 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002047 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2048 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2049 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002050 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002051 try {
2052 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002053 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002054 } catch (PackageManager.NameNotFoundException e) {
2055 // Ignore
2056 }
2057 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002058
Jorim Jaggib10e33f2015-02-04 21:57:40 +01002059 Window win = new PhoneWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002060 final TypedArray ta = win.getWindowStyle();
2061 if (ta.getBoolean(
2062 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2063 || ta.getBoolean(
2064 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002065 return null;
2066 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002067
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002068 Resources r = context.getResources();
2069 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002070
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002071 win.setType(
2072 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
2073 // Force the window flags: this is a fake window, so it is not really
2074 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2075 // flag because we do know that the next window will take input
2076 // focus, so we want to get the IME window up on top of us right away.
2077 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002078 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002079 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2080 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2081 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002082 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002083 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2084 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2085 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002086
Adam Powell04fe6eb2013-05-31 14:39:48 -07002087 win.setDefaultIcon(icon);
2088 win.setDefaultLogo(logo);
2089
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002090 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002091 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002092
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002093 final WindowManager.LayoutParams params = win.getAttributes();
2094 params.token = appToken;
2095 params.packageName = packageName;
2096 params.windowAnimations = win.getWindowStyle().getResourceId(
2097 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002098 params.privateFlags |=
2099 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002100 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002101
2102 if (!compatInfo.supportsScreen()) {
2103 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2104 }
2105
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002106 params.setTitle("Starting " + packageName);
2107
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002108 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2109 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002110
2111 if (win.isFloating()) {
2112 // Whoops, there is no way to display an animation/preview
2113 // of such a thing! After all that work... let's skip it.
2114 // (Note that we must do this here because it is in
2115 // getDecorView() where the theme is evaluated... maybe
2116 // we should peek the floating attribute from the theme
2117 // earlier.)
2118 return null;
2119 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002120
Craig Mautner6fbda632012-07-03 09:26:39 -07002121 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002122 TAG, "Adding starting window for " + packageName
2123 + " / " + appToken + ": "
2124 + (view.getParent() != null ? view : null));
2125
2126 wm.addView(view, params);
2127
2128 // Only return the view if it was successfully added to the
2129 // window manager... which we can tell by it having a parent.
2130 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002131 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002132 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002133 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2134 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002135 } catch (RuntimeException e) {
2136 // don't crash if something else bad happens, for example a
2137 // failure loading resources because we are loading from an app
2138 // on external storage that has been unmounted.
2139 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002140 } finally {
2141 if (view != null && view.getParent() == null) {
2142 Log.w(TAG, "view not successfully added to wm, removing view");
2143 wm.removeViewImmediate(view);
2144 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002145 }
2146
2147 return null;
2148 }
2149
2150 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002151 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002152 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002153 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2154 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002155
2156 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002157 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002158 wm.removeView(window);
2159 }
2160 }
2161
2162 /**
2163 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002164 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002165 * Currently enforces that three window types are singletons:
2166 * <ul>
2167 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002168 * <li>KEYGUARD_TYPE</li>
2169 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002170 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002171 * @param win The window to be added
2172 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002173 *
Jeff Brown98365d72012-08-19 20:30:52 -07002174 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2175 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002176 */
Jose Lima9546b202014-07-02 17:21:51 -07002177 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002178 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2179 switch (attrs.type) {
2180 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002181 mContext.enforceCallingOrSelfPermission(
2182 android.Manifest.permission.STATUS_BAR_SERVICE,
2183 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002184 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002185 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002186 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002187 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002188 }
2189 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002190 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002191 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002192 case TYPE_NAVIGATION_BAR:
2193 mContext.enforceCallingOrSelfPermission(
2194 android.Manifest.permission.STATUS_BAR_SERVICE,
2195 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002196 if (mNavigationBar != null) {
2197 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002198 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002199 }
2200 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002201 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002202 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002203 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002204 break;
Jim Millere898ac52012-04-06 17:10:57 -07002205 case TYPE_NAVIGATION_BAR_PANEL:
2206 mContext.enforceCallingOrSelfPermission(
2207 android.Manifest.permission.STATUS_BAR_SERVICE,
2208 "PhoneWindowManager");
2209 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08002210 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002211 mContext.enforceCallingOrSelfPermission(
2212 android.Manifest.permission.STATUS_BAR_SERVICE,
2213 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08002214 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002215 case TYPE_STATUS_BAR_SUB_PANEL:
2216 mContext.enforceCallingOrSelfPermission(
2217 android.Manifest.permission.STATUS_BAR_SERVICE,
2218 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002219 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002220 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002221 if (mKeyguardScrim != null) {
2222 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2223 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002224 mKeyguardScrim = win;
2225 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002226 }
Jeff Brown98365d72012-08-19 20:30:52 -07002227 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002228 }
2229
2230 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002231 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002232 public void removeWindowLw(WindowState win) {
2233 if (mStatusBar == win) {
2234 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002235 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002236 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002237 } else if (mKeyguardScrim == win) {
2238 Log.v(TAG, "Removing keyguard scrim");
2239 mKeyguardScrim = null;
2240 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002241 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002242 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002243 }
2244 }
2245
2246 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002247
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002248 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002249 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002250 public int selectAnimationLw(WindowState win, int transit) {
2251 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2252 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002253 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002254 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002255 if (transit == TRANSIT_EXIT
2256 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002257 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002258 } else if (transit == TRANSIT_ENTER
2259 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002260 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002261 }
2262 } else if (win == mNavigationBar) {
2263 // This can be on either the bottom or the right.
2264 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002265 if (transit == TRANSIT_EXIT
2266 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002267 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002268 } else if (transit == TRANSIT_ENTER
2269 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002270 return R.anim.dock_bottom_enter;
2271 }
2272 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002273 if (transit == TRANSIT_EXIT
2274 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002275 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002276 } else if (transit == TRANSIT_ENTER
2277 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002278 return R.anim.dock_right_enter;
2279 }
2280 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002281 }
2282
2283 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002284 if (win.hasAppShownWindows()) {
2285 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2286 return com.android.internal.R.anim.app_starting_exit;
2287 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002288 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002289 && transit == TRANSIT_ENTER) {
2290 // Special case: we are animating in a dream, while the keyguard
2291 // is shown. We don't want an animation on the dream, because
2292 // we need it shown immediately with the keyguard animating away
2293 // to reveal it.
2294 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002295 }
2296
2297 return 0;
2298 }
2299
Craig Mautner3c174372013-02-21 17:54:37 -08002300 @Override
2301 public void selectRotationAnimationLw(int anim[]) {
2302 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2303 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2304 + (mTopFullscreenOpaqueWindowState == null ?
2305 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2306 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2307 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2308 case ROTATION_ANIMATION_CROSSFADE:
2309 anim[0] = R.anim.rotation_animation_xfade_exit;
2310 anim[1] = R.anim.rotation_animation_enter;
2311 break;
2312 case ROTATION_ANIMATION_JUMPCUT:
2313 anim[0] = R.anim.rotation_animation_jump_exit;
2314 anim[1] = R.anim.rotation_animation_enter;
2315 break;
2316 case ROTATION_ANIMATION_ROTATE:
2317 default:
2318 anim[0] = anim[1] = 0;
2319 break;
2320 }
2321 } else {
2322 anim[0] = anim[1] = 0;
2323 }
2324 }
2325
2326 @Override
2327 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2328 boolean forceDefault) {
2329 switch (exitAnimId) {
2330 case R.anim.rotation_animation_xfade_exit:
2331 case R.anim.rotation_animation_jump_exit:
2332 // These are the only cases that matter.
2333 if (forceDefault) {
2334 return false;
2335 }
2336 int anim[] = new int[2];
2337 selectRotationAnimationLw(anim);
2338 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2339 default:
2340 return true;
2341 }
2342 }
2343
2344 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002345 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2346 boolean goingToNotificationShade) {
2347 if (goingToNotificationShade) {
2348 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002349 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002350
2351 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2352 R.anim.lock_screen_behind_enter_wallpaper :
2353 R.anim.lock_screen_behind_enter);
2354
2355 // TODO: Use XML interpolators when we have log interpolators available in XML.
2356 final List<Animation> animations = set.getAnimations();
2357 for (int i = animations.size() - 1; i >= 0; --i) {
2358 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2359 }
2360
2361 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002362 }
2363
2364
2365 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002366 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2367 if (goingToNotificationShade) {
2368 return null;
2369 } else {
2370 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2371 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002372 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002373
2374 private static void awakenDreams() {
2375 IDreamManager dreamManager = getDreamManager();
2376 if (dreamManager != null) {
2377 try {
2378 dreamManager.awaken();
2379 } catch (RemoteException e) {
2380 // fine, stay asleep then
2381 }
2382 }
2383 }
2384
2385 static IDreamManager getDreamManager() {
2386 return IDreamManager.Stub.asInterface(
2387 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2388 }
2389
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002390 TelecomManager getTelecommService() {
2391 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002392 }
2393
Jeff Brown4d396052010-10-29 21:50:21 -07002394 static IAudioService getAudioService() {
2395 IAudioService audioService = IAudioService.Stub.asInterface(
2396 ServiceManager.checkService(Context.AUDIO_SERVICE));
2397 if (audioService == null) {
2398 Log.w(TAG, "Unable to find IAudioService interface.");
2399 }
2400 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002401 }
2402
2403 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002404 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002405 }
2406
2407 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2408 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2409 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2410 };
2411
2412 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002413 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002414 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002415 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002416 final int keyCode = event.getKeyCode();
2417 final int repeatCount = event.getRepeatCount();
2418 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002419 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002420 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2421 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002422
Jeff Brown40013652012-05-16 21:22:36 -07002423 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002424 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002425 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2426 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002427 }
2428
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002429 // If we think we might have a volume down & power key chord on the way
2430 // but we're not sure, then tell the dispatcher to wait a little while and
2431 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002432 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002433 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002434 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002435 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2436 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002437 if (now < timeoutTime) {
2438 return timeoutTime - now;
2439 }
2440 }
2441 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002442 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002443 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002444 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002445 }
2446 return -1;
2447 }
2448 }
2449
Michael Wright6a62e552014-06-03 19:19:48 -07002450 // Cancel any pending meta actions if we see any other keys being pressed between the down
2451 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002452 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002453 mPendingMetaAction = false;
2454 }
2455
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002456 // First we always handle the home key here, so applications
2457 // can never break it, although if keyguard is on, we do let
2458 // it handle it, because that gives us the correct 5 second
2459 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002460 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002461
Jeff Brown49ed71d2010-12-06 17:13:33 -08002462 // If we have released the home key, and didn't do anything else
2463 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002464 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002465 cancelPreloadRecentApps();
2466
Jeff Brown49ed71d2010-12-06 17:13:33 -08002467 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002468 if (mHomeConsumed) {
2469 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002470 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002471 }
Jeff Browncaca8812013-05-09 13:34:33 -07002472
2473 if (canceled) {
2474 Log.i(TAG, "Ignoring HOME; event canceled.");
2475 return -1;
2476 }
2477
Yorke Lee4f803242014-12-15 23:22:06 +00002478 // If an incoming call is ringing, HOME is totally disabled.
2479 // (The user is already on the InCallUI at this point,
2480 // and his ONLY options are to answer or reject the call.)
2481 TelecomManager telecomManager = getTelecommService();
2482 if (telecomManager != null && telecomManager.isRinging()) {
2483 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2484 return -1;
2485 }
2486
Jeff Browncaca8812013-05-09 13:34:33 -07002487 // Delay handling home if a double-tap is possible.
2488 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2489 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2490 mHomeDoubleTapPending = true;
2491 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2492 ViewConfiguration.getDoubleTapTimeout());
2493 return -1;
2494 }
2495
Jeff Brown13f00f02014-10-31 14:45:50 -07002496 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002497 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002498 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002499
2500 // If a system window has focus, then it doesn't make sense
2501 // right now to interact with applications.
2502 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2503 if (attrs != null) {
2504 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002505 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2506 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2507 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002508 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002509 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002510 }
2511 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2512 for (int i=0; i<typeCount; i++) {
2513 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2514 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002515 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002516 }
2517 }
2518 }
Jeff Browncaca8812013-05-09 13:34:33 -07002519
2520 // Remember that home is pressed and handle special actions.
2521 if (repeatCount == 0) {
2522 mHomePressed = true;
2523 if (mHomeDoubleTapPending) {
2524 mHomeDoubleTapPending = false;
2525 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2526 handleDoubleTapOnHome();
2527 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2528 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2529 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002530 }
Jeff Browncaca8812013-05-09 13:34:33 -07002531 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2532 if (!keyguardOn) {
2533 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002534 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002535 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002536 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002537 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002538 // Hijack modified menu keys for debugging features
2539 final int chordBug = KeyEvent.META_SHIFT_ON;
2540
2541 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002542 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002543 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002544 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2545 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002546 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002547 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002548 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002549 Intent service = new Intent();
2550 service.setClassName(mContext, "com.android.server.LoadAverageService");
2551 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002552 boolean shown = Settings.Global.getInt(
2553 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002554 if (!shown) {
2555 mContext.startService(service);
2556 } else {
2557 mContext.stopService(service);
2558 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002559 Settings.Global.putInt(
2560 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002561 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002562 }
2563 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002564 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002565 if (down) {
2566 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002567 mSearchKeyShortcutPending = true;
2568 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002569 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002570 } else {
2571 mSearchKeyShortcutPending = false;
2572 if (mConsumeSearchKeyUp) {
2573 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002574 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002575 }
2576 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002577 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002578 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002579 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002580 if (down && repeatCount == 0) {
2581 preloadRecentApps();
2582 } else if (!down) {
2583 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002584 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002585 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002586 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002587 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2588 if (down) {
2589 if (repeatCount == 0) {
2590 mAssistKeyLongPressed = false;
2591 } else if (repeatCount == 1) {
2592 mAssistKeyLongPressed = true;
2593 if (!keyguardOn) {
2594 launchAssistLongPressAction();
2595 }
2596 }
2597 } else {
2598 if (mAssistKeyLongPressed) {
2599 mAssistKeyLongPressed = false;
2600 } else {
2601 if (!keyguardOn) {
2602 launchAssistAction();
2603 }
2604 }
2605 }
2606 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002607 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2608 if (!down) {
2609 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002610 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002611 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2612 } else {
2613 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002614 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002615 }
2616 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
2617 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002618 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2619 if (down && repeatCount == 0) {
2620 mHandler.post(mScreenshotRunnable);
2621 }
2622 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002623 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2624 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2625 if (down) {
2626 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2627
2628 // Disable autobrightness if it's on
2629 int auto = Settings.System.getIntForUser(
2630 mContext.getContentResolver(),
2631 Settings.System.SCREEN_BRIGHTNESS_MODE,
2632 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2633 UserHandle.USER_CURRENT_OR_SELF);
2634 if (auto != 0) {
2635 Settings.System.putIntForUser(mContext.getContentResolver(),
2636 Settings.System.SCREEN_BRIGHTNESS_MODE,
2637 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2638 UserHandle.USER_CURRENT_OR_SELF);
2639 }
2640
2641 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2642 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2643 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2644 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2645 Settings.System.SCREEN_BRIGHTNESS,
2646 mPowerManager.getDefaultScreenBrightnessSetting(),
2647 UserHandle.USER_CURRENT_OR_SELF);
2648 brightness += step;
2649 // Make sure we don't go beyond the limits.
2650 brightness = Math.min(max, brightness);
2651 brightness = Math.max(min, brightness);
2652
2653 Settings.System.putIntForUser(mContext.getContentResolver(),
2654 Settings.System.SCREEN_BRIGHTNESS, brightness,
2655 UserHandle.USER_CURRENT_OR_SELF);
Alan Viverette5a399492014-07-14 16:19:38 -07002656 mContext.startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
2657 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002658 }
2659 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002660 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002661 if (down) {
2662 mPendingMetaAction = true;
2663 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002664 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002665 }
2666 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002667 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002668
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002669 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002670 // Any printing key that is chorded with Search should be consumed
2671 // even if no shortcut was invoked. This prevents text from being
2672 // inadvertently inserted when using a keyboard that has built-in macro
2673 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002674 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002675 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2676 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002677 mConsumeSearchKeyUp = true;
2678 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002679 if (down && repeatCount == 0 && !keyguardOn) {
2680 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2681 if (shortcutIntent != null) {
2682 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002683 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002684 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002685 } catch (ActivityNotFoundException ex) {
2686 Slog.w(TAG, "Dropping shortcut key combination because "
2687 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002688 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002689 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002690 } else {
2691 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002692 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002693 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002694 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002695 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002696 }
2697 }
2698
Jeff Brown68b909d2011-12-07 16:36:01 -08002699 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002700 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002701 && (metaState & KeyEvent.META_META_ON) != 0) {
2702 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002703 if (kcm.isPrintingKey(keyCode)) {
2704 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2705 metaState & ~(KeyEvent.META_META_ON
2706 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2707 if (shortcutIntent != null) {
2708 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2709 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002710 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002711 } catch (ActivityNotFoundException ex) {
2712 Slog.w(TAG, "Dropping shortcut key combination because "
2713 + "the activity to which it is registered was not found: "
2714 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2715 }
2716 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002717 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002718 }
2719 }
2720
Jeff Brown6651a632011-11-28 12:59:11 -08002721 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002722 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002723 String category = sApplicationLaunchKeyCategories.get(keyCode);
2724 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002725 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002726 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2727 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002728 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002729 } catch (ActivityNotFoundException ex) {
2730 Slog.w(TAG, "Dropping application launch key because "
2731 + "the activity to which it is registered was not found: "
2732 + "keyCode=" + keyCode + ", category=" + category, ex);
2733 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002734 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002735 }
2736 }
2737
Michael Wright61c46752014-08-21 16:57:33 -07002738 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002739 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002740 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002741 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002742 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002743 mRecentAppsHeldModifiers = shiftlessModifiers;
2744 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002745 return -1;
2746 }
2747 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002748 } else if (!down && mRecentAppsHeldModifiers != 0
2749 && (metaState & mRecentAppsHeldModifiers) == 0) {
2750 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002751 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002752 }
2753
Jeff Browncf39bdf2012-05-18 14:41:19 -07002754 // Handle keyboard language switching.
2755 if (down && repeatCount == 0
2756 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2757 || (keyCode == KeyEvent.KEYCODE_SPACE
2758 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2759 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2760 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2761 return -1;
2762 }
2763 if (mLanguageSwitchKeyPressed && !down
2764 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2765 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2766 mLanguageSwitchKeyPressed = false;
2767 return -1;
2768 }
2769
Jeff Brown13f00f02014-10-31 14:45:50 -07002770 if (isValidGlobalKey(keyCode)
2771 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002772 return -1;
2773 }
2774
Michael Wright6a62e552014-06-03 19:19:48 -07002775 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002776 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002777 return -1;
2778 }
2779
Jeff Brown68b909d2011-12-07 16:36:01 -08002780 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002781 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002782 }
2783
Jeff Brown3915bb82010-11-05 15:02:16 -07002784 /** {@inheritDoc} */
2785 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002786 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002787 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002788 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002789 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2790 + ", flags=" + event.getFlags()
2791 + ", keyCode=" + event.getKeyCode()
2792 + ", scanCode=" + event.getScanCode()
2793 + ", metaState=" + event.getMetaState()
2794 + ", repeatCount=" + event.getRepeatCount()
2795 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002796 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002797
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002798 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002799 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2800 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002801 final int keyCode = event.getKeyCode();
2802 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002803 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2804 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002805
Jeff Brown54875002011-04-06 15:33:01 -07002806 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002807 final FallbackAction fallbackAction;
2808 if (initialDown) {
2809 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2810 } else {
2811 fallbackAction = mFallbackActions.get(keyCode);
2812 }
2813
2814 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002815 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002816 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2817 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002818 }
2819
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002820 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2821 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002822 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002823 event.getAction(), fallbackAction.keyCode,
2824 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002825 event.getDeviceId(), event.getScanCode(),
2826 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002827
2828 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2829 fallbackEvent.recycle();
2830 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002831 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002832
2833 if (initialDown) {
2834 mFallbackActions.put(keyCode, fallbackAction);
2835 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2836 mFallbackActions.remove(keyCode);
2837 fallbackAction.recycle();
2838 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002839 }
2840 }
2841
Jeff Brown40013652012-05-16 21:22:36 -07002842 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002843 if (fallbackEvent == null) {
2844 Slog.d(TAG, "No fallback.");
2845 } else {
2846 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2847 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002848 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002849 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002850 }
2851
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002852 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002853 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002854 if ((actions & ACTION_PASS_TO_USER) != 0) {
2855 long delayMillis = interceptKeyBeforeDispatching(
2856 win, fallbackEvent, policyFlags);
2857 if (delayMillis == 0) {
2858 return true;
2859 }
2860 }
2861 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002862 }
2863
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002864 private void launchAssistLongPressAction() {
2865 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2866 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2867
2868 // launch the search activity
2869 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2870 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2871 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002872 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002873 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002874 SearchManager searchManager = getSearchManager();
2875 if (searchManager != null) {
2876 searchManager.stopSearch();
2877 }
Michael Wright43e27f72013-04-10 14:06:48 -07002878 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002879 } catch (ActivityNotFoundException e) {
2880 Slog.w(TAG, "No activity to handle assist long press action.", e);
2881 }
2882 }
2883
2884 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002885 launchAssistAction(null);
2886 }
2887
2888 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002889 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002890 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002891 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002892 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002893 if (hint != null) {
2894 intent.putExtra(hint, true);
2895 }
Jim Miller45308b12012-06-18 19:23:39 -07002896 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2897 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2898 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2899 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002900 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002901 } catch (ActivityNotFoundException e) {
2902 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002903 }
2904 }
2905 }
2906
2907 private SearchManager getSearchManager() {
2908 if (mSearchManager == null) {
2909 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2910 }
2911 return mSearchManager;
2912 }
2913
Jeff Browncaca8812013-05-09 13:34:33 -07002914 private void preloadRecentApps() {
2915 mPreloadedRecentApps = true;
2916 try {
2917 IStatusBarService statusbar = getStatusBarService();
2918 if (statusbar != null) {
2919 statusbar.preloadRecentApps();
2920 }
2921 } catch (RemoteException e) {
2922 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2923 // re-acquire status bar service next time it is needed.
2924 mStatusBarService = null;
2925 }
2926 }
2927
2928 private void cancelPreloadRecentApps() {
2929 if (mPreloadedRecentApps) {
2930 mPreloadedRecentApps = false;
2931 try {
2932 IStatusBarService statusbar = getStatusBarService();
2933 if (statusbar != null) {
2934 statusbar.cancelPreloadRecentApps();
2935 }
2936 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002937 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07002938 // re-acquire status bar service next time it is needed.
2939 mStatusBarService = null;
2940 }
2941 }
2942 }
2943
2944 private void toggleRecentApps() {
2945 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07002946 try {
2947 IStatusBarService statusbar = getStatusBarService();
2948 if (statusbar != null) {
2949 statusbar.toggleRecentApps();
2950 }
2951 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002952 Slog.e(TAG, "RemoteException when toggling recent apps", e);
2953 // re-acquire status bar service next time it is needed.
2954 mStatusBarService = null;
2955 }
2956 }
2957
Craig Mautner84984fa2014-06-19 11:19:20 -07002958 @Override
2959 public void showRecentApps() {
2960 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
2961 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
2962 }
2963
Winson Chung1e8d71b2014-05-16 17:05:22 -07002964 private void showRecentApps(boolean triggeredFromAltTab) {
2965 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2966 try {
2967 IStatusBarService statusbar = getStatusBarService();
2968 if (statusbar != null) {
2969 statusbar.showRecentApps(triggeredFromAltTab);
2970 }
2971 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07002972 Slog.e(TAG, "RemoteException when showing recent apps", e);
2973 // re-acquire status bar service next time it is needed.
2974 mStatusBarService = null;
2975 }
2976 }
2977
Winson Chungcdcd4872014-08-05 18:00:13 -07002978 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002979 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2980 try {
2981 IStatusBarService statusbar = getStatusBarService();
2982 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07002983 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07002984 }
2985 } catch (RemoteException e) {
2986 Slog.e(TAG, "RemoteException when closing recent apps", e);
2987 // re-acquire status bar service next time it is needed.
2988 mStatusBarService = null;
2989 }
2990 }
2991
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002992 /**
2993 * A home key -> launch home action was detected. Take the appropriate action
2994 * given the situation with the keyguard.
2995 */
2996 void launchHomeFromHotKey() {
Jim Millerab954542014-10-10 18:21:49 -07002997 if (isKeyguardShowingAndNotOccluded()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002998 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002999 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003000 // when in keyguard restricted mode, must first verify unlock
3001 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08003002 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
Jose Lima9546b202014-07-02 17:21:51 -07003003 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003004 public void onKeyguardExitResult(boolean success) {
3005 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003006 try {
3007 ActivityManagerNative.getDefault().stopAppSwitches();
3008 } catch (RemoteException e) {
3009 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05003010 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08003011 startDockOrHome(true /*fromHomeKey*/);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003012 }
3013 }
3014 });
3015 } else {
3016 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003017 try {
3018 ActivityManagerNative.getDefault().stopAppSwitches();
3019 } catch (RemoteException e) {
3020 }
Winson Chungd543c1b2014-06-23 15:06:45 -07003021 if (mRecentsVisible) {
3022 // Hide Recents and notify it to launch Home
3023 awakenDreams();
3024 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Winson Chungcdcd4872014-08-05 18:00:13 -07003025 hideRecentApps(false, true);
Winson Chungd543c1b2014-06-23 15:06:45 -07003026 } else {
3027 // Otherwise, just launch Home
3028 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08003029 startDockOrHome(true /*fromHomeKey*/);
Winson Chungd543c1b2014-06-23 15:06:45 -07003030 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003031 }
3032 }
3033
John Spurlock04db1762013-05-13 12:46:41 -04003034 private final Runnable mClearHideNavigationFlag = new Runnable() {
3035 @Override
3036 public void run() {
3037 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3038 // Clear flags.
3039 mForceClearedSystemUiFlags &=
3040 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3041 }
3042 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003043 }
3044 };
3045
3046 /**
3047 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3048 * to determine when the nav bar should be shown and prevent applications from
3049 * receiving those touches.
3050 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003051 final class HideNavInputEventReceiver extends InputEventReceiver {
3052 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3053 super(inputChannel, looper);
3054 }
3055
Dianne Hackborndf89e652011-10-06 22:35:11 -07003056 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003057 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003058 boolean handled = false;
3059 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003060 if (event instanceof MotionEvent
3061 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3062 final MotionEvent motionEvent = (MotionEvent)event;
3063 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003064 // When the user taps down, we re-show the nav bar.
3065 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003066 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003067 // Any user activity always causes us to show the
3068 // navigation controls, if they had been hidden.
3069 // We also clear the low profile and only content
3070 // flags so that tapping on the screen will atomically
3071 // restore all currently hidden screen decorations.
3072 int newVal = mResettingSystemUiFlags |
3073 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3074 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3075 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003076 if (mResettingSystemUiFlags != newVal) {
3077 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003078 changed = true;
3079 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003080 // We don't allow the system's nav bar to be hidden
3081 // again for 1 second, to prevent applications from
3082 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003083 newVal = mForceClearedSystemUiFlags |
3084 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003085 if (mForceClearedSystemUiFlags != newVal) {
3086 mForceClearedSystemUiFlags = newVal;
3087 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003088 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003089 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003090 }
3091 if (changed) {
3092 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3093 }
3094 }
3095 }
3096 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003097 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003098 }
3099 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003100 }
3101 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3102 new InputEventReceiver.Factory() {
3103 @Override
3104 public InputEventReceiver createInputEventReceiver(
3105 InputChannel inputChannel, Looper looper) {
3106 return new HideNavInputEventReceiver(inputChannel, looper);
3107 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003108 };
3109
3110 @Override
3111 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003112 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3113 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003114 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003115
Dianne Hackborndf89e652011-10-06 22:35:11 -07003116 // Reset any bits in mForceClearingStatusBarVisibility that
3117 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003118 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003119 // Clear any bits in the new visibility that are currently being
3120 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003121 return visibility & ~mResettingSystemUiFlags
3122 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003123 }
3124
Craig Mautner69b08182012-09-05 13:07:13 -07003125 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003126 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3127 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003128 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003129 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3130 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003131
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003132 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003133 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003134 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003135 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003136 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003137 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3138 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3139 } else {
3140 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3141 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3142 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003143 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3144 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003145 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003146 availRight - mStableFullscreenRight,
3147 availBottom - mStableFullscreenBottom);
3148 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003149 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003150 availRight - mStableRight, availBottom - mStableBottom);
3151 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003152 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003153 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003154 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003155 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003156 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003157 availRight - mCurRight, availBottom - mCurBottom);
3158 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003159 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003160 availRight - mCurRight, availBottom - mCurBottom);
3161 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003162
3163 outStableInsets.set(mStableLeft, mStableTop,
3164 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003165 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003166 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003167 outContentInsets.setEmpty();
3168 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003169 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003170
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003171 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003172 @Override
3173 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3174 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003175 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3176 if (isDefaultDisplay) {
3177 switch (displayRotation) {
3178 case Surface.ROTATION_90:
3179 overscanLeft = mOverscanTop;
3180 overscanTop = mOverscanRight;
3181 overscanRight = mOverscanBottom;
3182 overscanBottom = mOverscanLeft;
3183 break;
3184 case Surface.ROTATION_180:
3185 overscanLeft = mOverscanRight;
3186 overscanTop = mOverscanBottom;
3187 overscanRight = mOverscanLeft;
3188 overscanBottom = mOverscanTop;
3189 break;
3190 case Surface.ROTATION_270:
3191 overscanLeft = mOverscanBottom;
3192 overscanTop = mOverscanLeft;
3193 overscanRight = mOverscanTop;
3194 overscanBottom = mOverscanRight;
3195 break;
3196 default:
3197 overscanLeft = mOverscanLeft;
3198 overscanTop = mOverscanTop;
3199 overscanRight = mOverscanRight;
3200 overscanBottom = mOverscanBottom;
3201 break;
3202 }
3203 } else {
3204 overscanLeft = 0;
3205 overscanTop = 0;
3206 overscanRight = 0;
3207 overscanBottom = 0;
3208 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003209 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3210 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3211 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3212 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003213 mSystemLeft = 0;
3214 mSystemTop = 0;
3215 mSystemRight = displayWidth;
3216 mSystemBottom = displayHeight;
3217 mUnrestrictedScreenLeft = overscanLeft;
3218 mUnrestrictedScreenTop = overscanTop;
3219 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3220 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3221 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3222 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003223 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3224 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003225 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003226 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003227 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003228 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003229 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003230 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003231 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003232 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003233 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003234 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003235
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003236 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3237 final Rect pf = mTmpParentFrame;
3238 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003239 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003240 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003241 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003242 pf.left = df.left = of.left = vf.left = mDockLeft;
3243 pf.top = df.top = of.top = vf.top = mDockTop;
3244 pf.right = df.right = of.right = vf.right = mDockRight;
3245 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003246 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003247
Craig Mautner69b08182012-09-05 13:07:13 -07003248 if (isDefaultDisplay) {
3249 // For purposes of putting out fake window up to steal focus, we will
3250 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003251 final int sysui = mLastSystemUiFlags;
3252 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003253 boolean navTranslucent = (sysui
3254 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003255 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3256 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3257 boolean navAllowedHidden = immersive || immersiveSticky;
3258 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003259 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3260 if (!isKeyguardShowing) {
3261 navTranslucent &= areTranslucentBarsAllowed();
3262 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003263
Craig Mautner69b08182012-09-05 13:07:13 -07003264 // When the navigation bar isn't visible, we put up a fake
3265 // input window to catch all touch events. This way we can
3266 // detect when the user presses anywhere to bring back the nav
3267 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003268 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07003269 if (mHideNavFakeWindow != null) {
3270 mHideNavFakeWindow.dismiss();
3271 mHideNavFakeWindow = null;
3272 }
3273 } else if (mHideNavFakeWindow == null) {
3274 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
3275 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07003276 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07003277 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003278 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003279
Craig Mautner69b08182012-09-05 13:07:13 -07003280 // For purposes of positioning and showing the nav bar, if we have
3281 // decided that it can't be hidden (because of the screen aspect ratio),
3282 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003283 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003284
John Spurlockad3e6cb2013-04-30 08:47:43 -04003285 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003286 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003287 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003288 // Force the navigation bar to its appropriate place and
3289 // size. We need to do this directly, instead of relying on
3290 // it to bubble up from the nav bar, because this needs to
3291 // change atomically with screen rotations.
3292 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3293 if (mNavigationBarOnBottom) {
3294 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003295 int top = displayHeight - overscanBottom
3296 - mNavigationBarHeightForRotation[displayRotation];
3297 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003298 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003299 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003300 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003301 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003302 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003303 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003304 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3305 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003306 } else {
3307 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003308 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003309 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003310 if (navVisible && !navTranslucent && !navAllowedHidden
3311 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003312 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003313 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003314 // and not in the process of animating on or off, then
3315 // we can tell the app that it is covered by it.
3316 mSystemBottom = mTmpNavigationFrame.top;
3317 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003318 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003319 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003320 int left = displayWidth - overscanRight
3321 - mNavigationBarWidthForRotation[displayRotation];
3322 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003323 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003324 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003325 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003326 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003327 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003328 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003329 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3330 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003331 } else {
3332 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003333 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003334 }
John Spurlockbd957402013-10-03 11:38:39 -04003335 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3336 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003337 // If the nav bar is currently requested to be visible,
3338 // and not in the process of animating on or off, then
3339 // we can tell the app that it is covered by it.
3340 mSystemRight = mTmpNavigationFrame.left;
3341 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003342 }
Craig Mautner69b08182012-09-05 13:07:13 -07003343 // Make sure the content and current rectangles are updated to
3344 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003345 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3346 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3347 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3348 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003349 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3350 // And compute the final frame.
3351 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003352 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3353 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003354 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003355 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003356 updateSysUiVisibility = true;
3357 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003358 }
Craig Mautnereda67292013-04-28 13:50:14 -07003359 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003360 mDockLeft, mDockTop, mDockRight, mDockBottom));
3361
3362 // decide where the status bar goes ahead of time
3363 if (mStatusBar != null) {
3364 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003365 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3366 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3367 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3368 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3369 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003370 vf.left = mStableLeft;
3371 vf.top = mStableTop;
3372 vf.right = mStableRight;
3373 vf.bottom = mStableBottom;
3374
3375 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3376
3377 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003378 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003379
3380 // For layout, the status bar is always at the top with our fixed height.
3381 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3382
John Spurlocke1f366f2013-08-05 12:22:40 -04003383 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003384 boolean statusBarTranslucent = (sysui
3385 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003386 if (!isKeyguardShowing) {
3387 statusBarTranslucent &= areTranslucentBarsAllowed();
3388 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003389
Craig Mautner69b08182012-09-05 13:07:13 -07003390 // If the status bar is hidden, we don't want to cause
3391 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003392 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003393 // Status bar may go away, so the screen area it occupies
3394 // is available to apps but just covering them when the
3395 // status bar is visible.
3396 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3397
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003398 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3399 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3400 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3401 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003402
Craig Mautnereda67292013-04-28 13:50:14 -07003403 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003404 String.format(
3405 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3406 mDockLeft, mDockTop, mDockRight, mDockBottom,
3407 mContentLeft, mContentTop, mContentRight, mContentBottom,
3408 mCurLeft, mCurTop, mCurRight, mCurBottom));
3409 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003410 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003411 && !statusBarTransient && !statusBarTranslucent
3412 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003413 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003414 // and not in the process of animating on or off, then
3415 // we can tell the app that it is covered by it.
3416 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3417 }
John Spurlock27735a42013-08-14 17:57:38 -04003418 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003419 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003420 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003421 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003422 if (updateSysUiVisibility) {
3423 updateSystemUiVisibilityLw();
3424 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003425 }
3426 }
3427
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003428 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003429 @Override
John Spurlock46646232013-09-30 22:32:42 -04003430 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003431 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
3432 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
3433 return 0;
3434 }
3435
Craig Mautner967212c2013-04-13 21:10:58 -07003436 @Override
3437 public void getContentRectLw(Rect r) {
3438 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3439 }
3440
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003441 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3442 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003443 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3444 // Here's a special case: if this attached window is a panel that is
3445 // above the dock window, and the window it is attached to is below
3446 // the dock window, then the frames we computed for the window it is
3447 // attached to can not be used because the dock is effectively part
3448 // of the underlying window and the attached window is floating on top
3449 // of the whole thing. So, we ignore the attached window and explicitly
3450 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003451 df.left = of.left = cf.left = vf.left = mDockLeft;
3452 df.top = of.top = cf.top = vf.top = mDockTop;
3453 df.right = of.right = cf.right = vf.right = mDockRight;
3454 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003455 } else {
3456 // The effective display frame of the attached window depends on
3457 // whether it is taking care of insetting its content. If not,
3458 // we need to use the parent's content frame so that the entire
3459 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003460 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003461 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003462 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003463 // Set the content frame of the attached window to the parent's decor frame
3464 // (same as content frame when IME isn't present) if specifically requested by
3465 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3466 // Otherwise, use the overscan frame.
3467 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3468 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003469 } else {
3470 // If the window is resizing, then we want to base the content
3471 // frame on our attached content frame to resize... however,
3472 // things can be tricky if the attached window is NOT in resize
3473 // mode, in which case its content frame will be larger.
3474 // Ungh. So to deal with that, make sure the content frame
3475 // we end up using is not covering the IM dock.
3476 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003477 if (attached.isVoiceInteraction()) {
3478 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3479 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3480 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3481 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3482 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003483 if (cf.left < mContentLeft) cf.left = mContentLeft;
3484 if (cf.top < mContentTop) cf.top = mContentTop;
3485 if (cf.right > mContentRight) cf.right = mContentRight;
3486 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3487 }
3488 }
3489 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003490 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003491 vf.set(attached.getVisibleFrameLw());
3492 }
3493 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3494 // window should be positioned relative to its parent or the entire
3495 // screen.
3496 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3497 ? attached.getFrameLw() : df);
3498 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003499
3500 private void applyStableConstraints(int sysui, int fl, Rect r) {
3501 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3502 // If app is requesting a stable layout, don't let the
3503 // content insets go below the stable values.
3504 if ((fl & FLAG_FULLSCREEN) != 0) {
3505 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3506 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3507 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3508 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3509 } else {
3510 if (r.left < mStableLeft) r.left = mStableLeft;
3511 if (r.top < mStableTop) r.top = mStableTop;
3512 if (r.right > mStableRight) r.right = mStableRight;
3513 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3514 }
3515 }
3516 }
3517
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003518 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003519 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003520 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003521 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003522 final WindowManager.LayoutParams attrs = win.getAttrs();
3523 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3524 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003525 return;
3526 }
Craig Mautner69b08182012-09-05 13:07:13 -07003527 final boolean isDefaultDisplay = win.isDefaultDisplay();
3528 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003529 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3530 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003531 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003532 offsetInputMethodWindowLw(mLastInputMethodWindow);
3533 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003534
John Spurlockc6d1c602014-01-17 15:22:06 -05003535 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003536 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003537 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003538
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003539 final Rect pf = mTmpParentFrame;
3540 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003541 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003542 final Rect cf = mTmpContentFrame;
3543 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003544 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003545 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003546 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003547
3548 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003549 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003550
Craig Mautnerf683b562012-10-02 11:10:57 -07003551 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3552
Adrian Roosfa104232014-06-20 16:10:14 -07003553 if (isDefaultDisplay) {
3554 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3555 } else {
3556 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3557 }
3558
Craig Mautner69b08182012-09-05 13:07:13 -07003559 if (!isDefaultDisplay) {
3560 if (attached != null) {
3561 // If this window is attached to another, our display
3562 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003563 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003564 } else {
3565 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003566 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3567 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3568 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003569 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003570 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003571 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003572 }
Dianne Hackbornae6688b2015-02-11 17:02:41 -08003573 } else if (attrs.type == TYPE_INPUT_METHOD || attrs.type == TYPE_VOICE_INTERACTION) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003574 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3575 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3576 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003577 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003578 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003579 // ...with content insets above the nav bar
3580 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003581 // IM dock windows always go to the bottom of the screen.
3582 attrs.gravity = Gravity.BOTTOM;
3583 mDockLayer = win.getSurfaceLayer();
Jorim Jaggie0700182014-08-21 01:12:37 +02003584 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3585 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3586 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3587 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3588 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3589 cf.left = vf.left = mStableLeft;
3590 cf.top = vf.top = mStableTop;
3591 cf.right = vf.right = mStableRight;
3592 vf.bottom = mStableBottom;
3593 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003594 } else {
John Spurlock46646232013-09-30 22:32:42 -04003595
3596 // Default policy decor for the default display
3597 dcf.left = mSystemLeft;
3598 dcf.top = mSystemTop;
3599 dcf.right = mSystemRight;
3600 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003601 final boolean inheritTranslucentDecor = (attrs.privateFlags
3602 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003603 final boolean isAppWindow =
3604 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3605 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3606 final boolean topAtRest =
3607 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3608 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003609 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3610 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003611 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3612 && (fl & WindowManager.LayoutParams.
3613 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003614 // Ensure policy decor includes status bar
3615 dcf.top = mStableTop;
3616 }
John Spurlockbd957402013-10-03 11:38:39 -04003617 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003618 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3619 && (fl & WindowManager.LayoutParams.
3620 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003621 // Ensure policy decor includes navigation bar
3622 dcf.bottom = mStableBottom;
3623 dcf.right = mStableRight;
3624 }
3625 }
3626
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003627 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3628 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003629 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003630 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003631 // This is the case for a normal activity window: we want it
3632 // to cover all of the screen space, and it can take care of
3633 // moving its contents to account for screen decorations that
3634 // intrude into that space.
3635 if (attached != null) {
3636 // If this window is attached to another, our display
3637 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003638 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003639 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003640 if (attrs.type == TYPE_STATUS_BAR_PANEL
3641 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003642 // Status bar panels are the only windows who can go on top of
3643 // the status bar. They are protected by the STATUS_BAR_SERVICE
3644 // permission, so they have the same privileges as the status
3645 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003646 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003647 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003648
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003649 pf.left = df.left = of.left = hasNavBar
3650 ? mDockLeft : mUnrestrictedScreenLeft;
3651 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3652 pf.right = df.right = of.right = hasNavBar
3653 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3654 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3655 pf.bottom = df.bottom = of.bottom = hasNavBar
3656 ? mRestrictedScreenTop+mRestrictedScreenHeight
3657 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003658
Craig Mautnereda67292013-04-28 13:50:14 -07003659 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003660 "Laying out status bar window: (%d,%d - %d,%d)",
3661 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003662 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003663 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3664 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3665 // Asking to layout into the overscan region, so give it that pure
3666 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003667 pf.left = df.left = of.left = mOverscanScreenLeft;
3668 pf.top = df.top = of.top = mOverscanScreenTop;
3669 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3670 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3671 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003672 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003673 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003674 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3675 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003676 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003677 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003678 // only do this for application windows to ensure no window that
3679 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003680 pf.left = df.left = mOverscanScreenLeft;
3681 pf.top = df.top = mOverscanScreenTop;
3682 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3683 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003684 // We need to tell the app about where the frame inside the overscan
3685 // is, so it can inset its content by that amount -- it didn't ask
3686 // to actually extend itself into the overscan region.
3687 of.left = mUnrestrictedScreenLeft;
3688 of.top = mUnrestrictedScreenTop;
3689 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3690 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003691 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003692 pf.left = df.left = mRestrictedOverscanScreenLeft;
3693 pf.top = df.top = mRestrictedOverscanScreenTop;
3694 pf.right = df.right = mRestrictedOverscanScreenLeft
3695 + mRestrictedOverscanScreenWidth;
3696 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3697 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003698 // We need to tell the app about where the frame inside the overscan
3699 // is, so it can inset its content by that amount -- it didn't ask
3700 // to actually extend itself into the overscan region.
3701 of.left = mUnrestrictedScreenLeft;
3702 of.top = mUnrestrictedScreenTop;
3703 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3704 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003705 }
Craig Mautner69b08182012-09-05 13:07:13 -07003706
John Spurlock46646232013-09-30 22:32:42 -04003707 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003708 if (win.isVoiceInteraction()) {
3709 cf.left = mVoiceContentLeft;
3710 cf.top = mVoiceContentTop;
3711 cf.right = mVoiceContentRight;
3712 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003713 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003714 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3715 cf.left = mDockLeft;
3716 cf.top = mDockTop;
3717 cf.right = mDockRight;
3718 cf.bottom = mDockBottom;
3719 } else {
3720 cf.left = mContentLeft;
3721 cf.top = mContentTop;
3722 cf.right = mContentRight;
3723 cf.bottom = mContentBottom;
3724 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003725 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003726 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003727 // Full screen windows are always given a layout that is as if the
3728 // status bar and other transient decors are gone. This is to avoid
3729 // bad states when moving from a window that is not hding the
3730 // status bar to one that is.
3731 cf.left = mRestrictedScreenLeft;
3732 cf.top = mRestrictedScreenTop;
3733 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3734 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003735 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003736 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003737 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3738 vf.left = mCurLeft;
3739 vf.top = mCurTop;
3740 vf.right = mCurRight;
3741 vf.bottom = mCurBottom;
3742 } else {
3743 vf.set(cf);
3744 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003745 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003746 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3747 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3748 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003749 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3750 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003751 // A window that has requested to fill the entire screen just
3752 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003753 if (attrs.type == TYPE_STATUS_BAR_PANEL
3754 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003755 pf.left = df.left = of.left = cf.left = hasNavBar
3756 ? mDockLeft : mUnrestrictedScreenLeft;
3757 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3758 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003759 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003760 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003761 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003762 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003763 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003764 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003765 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3766 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003767 } else if (attrs.type == TYPE_NAVIGATION_BAR
3768 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003769 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003770 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3771 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3772 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3773 + mUnrestrictedScreenWidth;
3774 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3775 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003776 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003777 "Laying out navigation bar window: (%d,%d - %d,%d)",
3778 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003779 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3780 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003781 && ((fl & FLAG_FULLSCREEN) != 0)) {
3782 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003783 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3784 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3785 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3786 + mOverscanScreenWidth;
3787 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3788 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003789 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003790 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003791 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3792 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3793 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3794 + mOverscanScreenWidth;
3795 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3796 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003797 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003798 // The wallpaper also has Real Ultimate Power, but we want to tell
3799 // it about the overscan area.
3800 pf.left = df.left = mOverscanScreenLeft;
3801 pf.top = df.top = mOverscanScreenTop;
3802 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3803 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3804 of.left = cf.left = mUnrestrictedScreenLeft;
3805 of.top = cf.top = mUnrestrictedScreenTop;
3806 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3807 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003808 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003809 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3810 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3811 // Asking to layout into the overscan region, so give it that pure
3812 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003813 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3814 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3815 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003816 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003817 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003818 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003819 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003820 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003821 && (attrs.type == TYPE_STATUS_BAR
3822 || attrs.type == TYPE_TOAST
John Spurlock34e13d92013-08-10 06:52:28 -04003823 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3824 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003825 // Asking for layout as if the nav bar is hidden, lets the
3826 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003827 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003828 // can be above the nav bar can do this.
3829 // XXX This assumes that an app asking for this will also
3830 // ask for layout in only content. We can't currently figure out
3831 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003832 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3833 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3834 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3835 + mUnrestrictedScreenWidth;
3836 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3837 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003838 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003839 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3840 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3841 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3842 + mRestrictedScreenWidth;
3843 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3844 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003845 }
Craig Mautner69b08182012-09-05 13:07:13 -07003846
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003847 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003848
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003849 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3850 vf.left = mCurLeft;
3851 vf.top = mCurTop;
3852 vf.right = mCurRight;
3853 vf.bottom = mCurBottom;
3854 } else {
3855 vf.set(cf);
3856 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003857 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003858 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3859 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003860 // A child window should be placed inside of the same visible
3861 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003862 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003863 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003864 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3865 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003866 // Otherwise, a normal window must be placed inside the content
3867 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003868 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3869 // Status bar panels are the only windows who can go on top of
3870 // the status bar. They are protected by the STATUS_BAR_SERVICE
3871 // permission, so they have the same privileges as the status
3872 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003873 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3874 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3875 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3876 + mRestrictedScreenWidth;
3877 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3878 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003879 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3880 || attrs.type == TYPE_VOLUME_OVERLAY) {
3881 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003882 pf.left = df.left = of.left = cf.left = mStableLeft;
3883 pf.top = df.top = of.top = cf.top = mStableTop;
3884 pf.right = df.right = of.right = cf.right = mStableRight;
3885 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003886 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003887 pf.left = mContentLeft;
3888 pf.top = mContentTop;
3889 pf.right = mContentRight;
3890 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003891 if (win.isVoiceInteraction()) {
3892 df.left = of.left = cf.left = mVoiceContentLeft;
3893 df.top = of.top = cf.top = mVoiceContentTop;
3894 df.right = of.right = cf.right = mVoiceContentRight;
3895 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3896 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003897 df.left = of.left = cf.left = mDockLeft;
3898 df.top = of.top = cf.top = mDockTop;
3899 df.right = of.right = cf.right = mDockRight;
3900 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003901 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003902 df.left = of.left = cf.left = mContentLeft;
3903 df.top = of.top = cf.top = mContentTop;
3904 df.right = of.right = cf.right = mContentRight;
3905 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003906 }
3907 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3908 vf.left = mCurLeft;
3909 vf.top = mCurTop;
3910 vf.right = mCurRight;
3911 vf.bottom = mCurBottom;
3912 } else {
3913 vf.set(cf);
3914 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003915 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003916 }
3917 }
Craig Mautner69b08182012-09-05 13:07:13 -07003918
Craig Mautnerb816bed2013-07-23 10:26:17 -07003919 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3920 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003921 df.left = df.top = -10000;
3922 df.right = df.bottom = 10000;
3923 if (attrs.type != TYPE_WALLPAPER) {
3924 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3925 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
3926 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003927 }
3928
Craig Mautnereda67292013-04-28 13:50:14 -07003929 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003930 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07003931 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003932 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003933 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003934 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003935 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07003936 + " dcf=" + dcf.toShortString()
3937 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003938
Adrian Roosfa104232014-06-20 16:10:14 -07003939 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07003940
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003941 // Dock windows carve out the bottom of the screen, so normal windows
3942 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003943 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3944 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003945 setLastInputMethodWindowLw(null, null);
3946 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003947 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003948 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
3949 && !win.getGivenInsetsPendingLw()) {
3950 offsetVoiceInputWindowLw(win);
3951 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003952 }
3953
satok1bc0a492012-04-25 22:47:12 +09003954 private void offsetInputMethodWindowLw(WindowState win) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08003955 int top = win.getDisplayFrameLw().top;
satok1bc0a492012-04-25 22:47:12 +09003956 top += win.getGivenContentInsetsLw().top;
3957 if (mContentBottom > top) {
3958 mContentBottom = top;
3959 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003960 if (mVoiceContentBottom > top) {
3961 mVoiceContentBottom = top;
3962 }
satok1bc0a492012-04-25 22:47:12 +09003963 top = win.getVisibleFrameLw().top;
3964 top += win.getGivenVisibleInsetsLw().top;
3965 if (mCurBottom > top) {
3966 mCurBottom = top;
3967 }
Craig Mautnereda67292013-04-28 13:50:14 -07003968 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003969 + mDockBottom + " mContentBottom="
3970 + mContentBottom + " mCurBottom=" + mCurBottom);
3971 }
3972
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003973 private void offsetVoiceInputWindowLw(WindowState win) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08003974 int top = win.getDisplayFrameLw().top;
3975 top += win.getGivenContentInsetsLw().top;
3976 if (mVoiceContentBottom > top) {
3977 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003978 }
3979 }
3980
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003981 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003982 @Override
3983 public void finishLayoutLw() {
3984 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003985 }
3986
3987 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003988 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003989 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003990 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01003991 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003992 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02003993 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003994 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003995 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003996 mForcingShowNavBar = false;
3997 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07003998
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003999 mHideLockScreen = false;
4000 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004001 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004002 mShowingLockscreen = false;
4003 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004004 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004005 mKeyguardSecure = isKeyguardSecure();
4006 mKeyguardSecureIncludingHidden = mKeyguardSecure
4007 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004008 }
4009
4010 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004011 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004012 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004013 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4014 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004015 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004016 if (mTopFullscreenOpaqueWindowState == null
4017 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4018 mForcingShowNavBar = true;
4019 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004020 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004021 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004022 mForceStatusBarFromKeyguard = true;
4023 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004024 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004025 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004026 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004027 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004028 mForceStatusBarFromKeyguard = true;
4029 } else {
4030 mForceStatusBar = true;
4031 }
4032 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004033 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004034 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004035 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004036 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Craig Mautner7d7808f2014-09-11 18:02:38 -07004037 && attrs.type < FIRST_SYSTEM_WINDOW;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004038 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004039 // If the lockscreen was showing when the dream started then wait
4040 // for the dream to draw before hiding the lockscreen.
4041 if (!mDreamingLockscreen
4042 || (win.isVisibleLw() && win.hasDrawnLw())) {
4043 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004044 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004045 }
4046 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004047
Craig Mautner00156ec2014-03-06 22:29:02 -08004048 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07004049 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerab55e522014-03-03 13:26:03 -08004050 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004051 final IApplicationToken appToken = win.getAppToken();
4052 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004053 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004054 mAppsToBeHidden.remove(appToken);
4055 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004056 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004057 if (dismissKeyguard && !mKeyguardSecure) {
4058 mAppsThatDismissKeyguard.add(appToken);
4059 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004060 mWinShowWhenLocked = win;
4061 mHideLockScreen = true;
4062 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004063 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004064 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004065 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004066 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004067 mAppsToBeHidden.add(appToken);
4068 } else {
4069 mAppsToBeHidden.remove(appToken);
4070 }
4071 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004072 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004073 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004074 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004075 if (attrs.x == 0 && attrs.y == 0
4076 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4077 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4078 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4079 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004080 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4081 mTopFullscreenOpaqueOrDimmingWindowState = win;
4082 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004083 if (!mAppsThatDismissKeyguard.isEmpty() &&
4084 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4085 if (DEBUG_LAYOUT) Slog.v(TAG,
4086 "Setting mDismissKeyguard true by win " + win);
4087 mDismissKeyguard = mWinDismissingKeyguard == win ?
4088 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
4089 mWinDismissingKeyguard = win;
Jim Millerab954542014-10-10 18:21:49 -07004090 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004091 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4092 if (DEBUG_LAYOUT) Slog.v(TAG,
4093 "Setting mHideLockScreen to true by win " + win);
4094 mHideLockScreen = true;
4095 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004096 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004097 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004098 mAllowLockscreenWhenOn = true;
4099 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004100 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004101
4102 if (mWinShowWhenLocked != null &&
4103 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
4104 win.hideLw(false);
4105 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004106 }
4107 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004108 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4109 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4110 && win.isDimming()) {
4111 mTopFullscreenOpaqueOrDimmingWindowState = win;
4112 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004113 }
4114
4115 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004116 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004117 public int finishPostLayoutPolicyLw() {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004118 if (mWinShowWhenLocked != null &&
4119 mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) {
4120 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4121 // fullscreen window.
4122 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4123 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4124 mTopFullscreenOpaqueWindowState.hideLw(false);
4125 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4126 }
4127
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004128 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004129 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004130
4131 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4132 ? mTopFullscreenOpaqueWindowState.getAttrs()
4133 : null;
4134
Jeff Brownc8018eb2012-10-29 21:33:27 -07004135 // If we are not currently showing a dream then remember the current
4136 // lockscreen state. We will use this to determine whether the dream
4137 // started while the lockscreen was showing and remember this state
4138 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004139 if (!mShowingDream) {
4140 mDreamingLockscreen = mShowingLockscreen;
4141 }
4142
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004143 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004144 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004145 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004146 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004147 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07004148 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004149 if (mStatusBarController.setBarShowingLw(true)) {
4150 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4151 }
Craig Mautner81defc72013-10-29 11:10:42 -07004152 // Maintain fullscreen layout until incoming animation is complete.
4153 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004154 // Transient status bar on the lockscreen is not allowed
4155 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4156 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4157 mLastSystemUiFlags, mLastSystemUiFlags);
4158 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004159 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004160 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004161 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004162 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004163 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004164 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004165 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004166 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004167 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004168 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004169 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004170 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004171 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4172 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004173 if (mStatusBarController.isTransientShowing()) {
4174 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004175 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4176 }
4177 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004178 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004179 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004180 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004181 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004182 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004183 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004184 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004185 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004186 if (mStatusBarController.setBarShowingLw(true)) {
4187 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4188 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004189 }
4190 }
4191 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004192
Craig Mautner81defc72013-10-29 11:10:42 -07004193 if (mTopIsFullscreen != topIsFullscreen) {
4194 if (!topIsFullscreen) {
4195 // Force another layout when status bar becomes fully shown.
4196 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4197 }
4198 mTopIsFullscreen = topIsFullscreen;
4199 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004200
Craig Mautner39834192012-09-02 07:47:24 -07004201 // Hide the key guard if a visible window explicitly specifies that it wants to be
4202 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004203 if (mKeyguardDelegate != null && mStatusBar != null) {
4204 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4205 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004206 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004207 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004208 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004209 changes |= FINISH_LAYOUT_REDO_LAYOUT
4210 | FINISH_LAYOUT_REDO_CONFIG
4211 | FINISH_LAYOUT_REDO_WALLPAPER;
4212 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004213 if (mKeyguardDelegate.isShowing()) {
4214 mHandler.post(new Runnable() {
4215 @Override
4216 public void run() {
4217 mKeyguardDelegate.keyguardDone(false, false);
4218 }
4219 });
4220 }
4221 } else if (mHideLockScreen) {
4222 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004223 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004224 changes |= FINISH_LAYOUT_REDO_LAYOUT
4225 | FINISH_LAYOUT_REDO_CONFIG
4226 | FINISH_LAYOUT_REDO_WALLPAPER;
4227 }
4228 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
4229 // This is the case of keyguard isSecure() and not mHideLockScreen.
4230 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4231 // Only launch the next keyguard unlock window once per window.
4232 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004233 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004234 changes |= FINISH_LAYOUT_REDO_LAYOUT
4235 | FINISH_LAYOUT_REDO_CONFIG
4236 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004237 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004238 mHandler.post(new Runnable() {
4239 @Override
4240 public void run() {
4241 mKeyguardDelegate.dismiss();
4242 }
4243 });
4244 }
4245 } else {
4246 mWinDismissingKeyguard = null;
4247 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004248 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004249 changes |= FINISH_LAYOUT_REDO_LAYOUT
4250 | FINISH_LAYOUT_REDO_CONFIG
4251 | FINISH_LAYOUT_REDO_WALLPAPER;
4252 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004253 }
4254 }
Joe Onorato664644d2011-01-23 17:53:23 -08004255
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004256 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004257 // If the navigation bar has been hidden or shown, we need to do another
4258 // layout pass to update that window.
4259 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4260 }
Joe Onorato664644d2011-01-23 17:53:23 -08004261
Mike Lockwood28569302010-01-28 11:54:40 -05004262 // update since mAllowLockscreenWhenOn might have changed
4263 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004264 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004265 }
4266
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004267 /**
Jim Millerab954542014-10-10 18:21:49 -07004268 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004269 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004270 * @return Whether the flags have changed and we have to redo the layout.
4271 */
Jim Millerab954542014-10-10 18:21:49 -07004272 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4273 boolean wasOccluded = mKeyguardOccluded;
4274 boolean showing = mKeyguardDelegate.isShowing();
4275 if (wasOccluded && !isOccluded && showing) {
4276 mKeyguardOccluded = false;
4277 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004278 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4279 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4280 return true;
Jim Millerab954542014-10-10 18:21:49 -07004281 } else if (!wasOccluded && isOccluded && showing) {
4282 mKeyguardOccluded = true;
4283 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004284 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4285 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4286 return true;
4287 } else {
4288 return false;
4289 }
4290 }
4291
4292 private boolean isStatusBarKeyguard() {
4293 return mStatusBar != null
4294 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4295 }
4296
Jose Lima9546b202014-07-02 17:21:51 -07004297 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004298 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004299 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004300 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004301 return false;
4302 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004303 return true;
4304 }
4305
Jose Lima9546b202014-07-02 17:21:51 -07004306 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004307 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004308 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004309 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004310 // If the navigation bar has been hidden or shown, we need to do another
4311 // layout pass to update that window.
4312 return FINISH_LAYOUT_REDO_LAYOUT;
4313 }
4314 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004315 }
4316
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004317 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004318 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004319 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4320 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004321 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4322 if (newLidState == mLidState) {
4323 return;
4324 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004325
Jeff Brownc458ce92012-04-30 14:58:40 -07004326 mLidState = newLidState;
4327 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004328 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004329
4330 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004331 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004332 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004333 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004334 }
4335 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004336
Michael Wright3818c922014-09-02 13:59:07 -07004337 @Override
4338 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4339 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4340 if (mCameraLensCoverState == lensCoverState) {
4341 return;
4342 }
4343 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4344 lensCoverState == CAMERA_LENS_UNCOVERED) {
4345 Intent intent;
4346 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4347 mKeyguardDelegate.isShowing();
4348 if (keyguardActive) {
4349 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4350 } else {
4351 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4352 }
Bryce Lee584a4452014-10-21 15:55:55 -07004353 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Michael Wright3818c922014-09-02 13:59:07 -07004354 mContext.startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
4355 }
4356 mCameraLensCoverState = lensCoverState;
4357 }
4358
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004359 void setHdmiPlugged(boolean plugged) {
4360 if (mHdmiPlugged != plugged) {
4361 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004362 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004363 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004364 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004365 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004366 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004367 }
4368 }
4369
Joe Onoratoea495d42011-04-06 11:41:11 -07004370 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004371 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004372 // watch for HDMI plug messages if the hdmi switch exists
4373 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4374 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4375
Joe Onoratoea495d42011-04-06 11:41:11 -07004376 final String filename = "/sys/class/switch/hdmi/state";
4377 FileReader reader = null;
4378 try {
4379 reader = new FileReader(filename);
4380 char[] buf = new char[15];
4381 int n = reader.read(buf);
4382 if (n > 1) {
4383 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4384 }
4385 } catch (IOException ex) {
4386 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4387 } catch (NumberFormatException ex) {
4388 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4389 } finally {
4390 if (reader != null) {
4391 try {
4392 reader.close();
4393 } catch (IOException ex) {
4394 }
Joe Onoratodc100302011-01-11 17:07:41 -08004395 }
4396 }
4397 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004398 // This dance forces the code in setHdmiPlugged to run.
4399 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4400 mHdmiPlugged = !plugged;
4401 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004402 }
4403
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004404 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004405 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004406
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004407 final Runnable mScreenshotTimeout = new Runnable() {
4408 @Override public void run() {
4409 synchronized (mScreenshotLock) {
4410 if (mScreenshotConnection != null) {
4411 mContext.unbindService(mScreenshotConnection);
4412 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004413 }
Winson Chung9112ec32011-06-27 13:15:32 -07004414 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004415 }
4416 };
4417
4418 // Assume this is called from the Handler thread.
4419 private void takeScreenshot() {
4420 synchronized (mScreenshotLock) {
4421 if (mScreenshotConnection != null) {
4422 return;
4423 }
4424 ComponentName cn = new ComponentName("com.android.systemui",
4425 "com.android.systemui.screenshot.TakeScreenshotService");
4426 Intent intent = new Intent();
4427 intent.setComponent(cn);
4428 ServiceConnection conn = new ServiceConnection() {
4429 @Override
4430 public void onServiceConnected(ComponentName name, IBinder service) {
4431 synchronized (mScreenshotLock) {
4432 if (mScreenshotConnection != this) {
4433 return;
4434 }
4435 Messenger messenger = new Messenger(service);
4436 Message msg = Message.obtain(null, 1);
4437 final ServiceConnection myConn = this;
4438 Handler h = new Handler(mHandler.getLooper()) {
4439 @Override
4440 public void handleMessage(Message msg) {
4441 synchronized (mScreenshotLock) {
4442 if (mScreenshotConnection == myConn) {
4443 mContext.unbindService(mScreenshotConnection);
4444 mScreenshotConnection = null;
4445 mHandler.removeCallbacks(mScreenshotTimeout);
4446 }
4447 }
4448 }
4449 };
4450 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004451 msg.arg1 = msg.arg2 = 0;
4452 if (mStatusBar != null && mStatusBar.isVisibleLw())
4453 msg.arg1 = 1;
4454 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4455 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004456 try {
4457 messenger.send(msg);
4458 } catch (RemoteException e) {
4459 }
4460 }
4461 }
4462 @Override
4463 public void onServiceDisconnected(ComponentName name) {}
4464 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004465 if (mContext.bindServiceAsUser(
4466 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004467 mScreenshotConnection = conn;
4468 mHandler.postDelayed(mScreenshotTimeout, 10000);
4469 }
4470 }
Winson Chung9112ec32011-06-27 13:15:32 -07004471 }
4472
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004473 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004474 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004475 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004476 if (!mSystemBooted) {
4477 // If we have not yet booted, don't let key events do anything.
4478 return 0;
4479 }
4480
Jeff Brown037c33e2014-04-09 00:31:55 -07004481 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004482 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4483 final boolean canceled = event.isCanceled();
4484 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004485
Jeff Brown3122e442010-10-11 23:32:49 -07004486 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004487
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004488 // If screen is off then we treat the case where the keyguard is open but hidden
4489 // the same as if it were open and in front.
4490 // This will prevent any keys other than the power button from waking the screen
4491 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004492 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004493 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004494 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004495 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004496
Jeff Brown40013652012-05-16 21:22:36 -07004497 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004498 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004499 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004500 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004501 }
4502
Jeff Brown037c33e2014-04-09 00:31:55 -07004503 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004504 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004505 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4506 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004507 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004508 // When the device is interactive or the key is injected pass the
4509 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004510 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004511 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004512 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4513 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4514 // to the application but preserve its wake key status to make sure we still move
4515 // from dozing to fully interactive if we would normally go from off to fully
4516 // interactive.
4517 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004518 } else {
4519 // When the screen is off and the key is not injected, determine whether
4520 // to wake the device but don't pass the key to the application.
4521 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004522 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4523 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004524 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004525 }
4526
Justin Kohd378ad72013-04-01 12:18:26 -07004527 // If the key would be handled globally, just return the result, don't worry about special
4528 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004529 if (isValidGlobalKey(keyCode)
4530 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004531 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004532 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004533 }
Justin Kohd378ad72013-04-01 12:18:26 -07004534 return result;
4535 }
4536
Jeff Brownbae8e772014-06-12 19:59:45 -07004537 boolean useHapticFeedback = down
4538 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4539 && event.getRepeatCount() == 0;
4540
Jeff Brown4d396052010-10-29 21:50:21 -07004541 // Handle special keys.
4542 switch (keyCode) {
4543 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004544 case KeyEvent.KEYCODE_VOLUME_UP:
4545 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004546 if (mUseTvRouting) {
4547 // On TVs volume keys never go to the foreground app
4548 result &= ~ACTION_PASS_TO_USER;
4549 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004550 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4551 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004552 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004553 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004554 mScreenshotChordVolumeDownKeyTriggered = true;
4555 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4556 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004557 cancelPendingPowerKeyAction();
4558 interceptScreenshotChord();
4559 }
4560 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004561 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004562 cancelPendingScreenshotChordAction();
4563 }
4564 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4565 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004566 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004567 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004568 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004569 cancelPendingPowerKeyAction();
4570 cancelPendingScreenshotChordAction();
4571 }
4572 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004573 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004574 cancelPendingScreenshotChordAction();
4575 }
4576 }
Jeff Brown4d396052010-10-29 21:50:21 -07004577 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004578 TelecomManager telecomManager = getTelecommService();
4579 if (telecomManager != null) {
4580 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004581 // If an incoming call is ringing, either VOLUME key means
4582 // "silence ringer". We handle these keys here, rather than
4583 // in the InCallScreen, to make sure we'll respond to them
4584 // even if the InCallScreen hasn't come to the foreground yet.
4585 // Look for the DOWN event here, to agree with the "fallback"
4586 // behavior in the InCallScreen.
4587 Log.i(TAG, "interceptKeyBeforeQueueing:"
4588 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004589
Santos Cordon6848f722014-05-21 15:22:12 -07004590 // Silence the ringer. (It's safe to call this
4591 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004592 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004593
Santos Cordon6848f722014-05-21 15:22:12 -07004594 // And *don't* pass this key thru to the current activity
4595 // (which is probably the InCallScreen.)
4596 result &= ~ACTION_PASS_TO_USER;
4597 break;
4598 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004599 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004600 && (result & ACTION_PASS_TO_USER) == 0) {
4601 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004602 // the application, just pass it to the session service.
4603
4604 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004605 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004606 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004607 }
4608 }
4609
RoboErik430fc482014-06-12 15:49:20 -07004610 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004611 if (mUseTvRouting) {
4612 dispatchDirectAudioEvent(event);
4613 } else {
4614 // If we aren't passing to the user and no one else
4615 // handled it send it to the session manager to
4616 // figure out.
4617 MediaSessionLegacyHelper.getHelper(mContext)
4618 .sendVolumeKeyEvent(event, true);
4619 }
Jeff Brown4d396052010-10-29 21:50:21 -07004620 break;
4621 }
4622 }
4623 break;
4624 }
4625
4626 case KeyEvent.KEYCODE_ENDCALL: {
4627 result &= ~ACTION_PASS_TO_USER;
4628 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004629 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004630 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004631 if (telecomManager != null) {
4632 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004633 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004634 if (interactive && !hungUp) {
4635 mEndCallKeyHandled = false;
4636 mHandler.postDelayed(mEndCallLongPress,
4637 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4638 } else {
4639 mEndCallKeyHandled = true;
4640 }
Jeff Brown4d396052010-10-29 21:50:21 -07004641 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004642 if (!mEndCallKeyHandled) {
4643 mHandler.removeCallbacks(mEndCallLongPress);
4644 if (!canceled) {
4645 if ((mEndcallBehavior
4646 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4647 if (goHome()) {
4648 break;
4649 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004650 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004651 if ((mEndcallBehavior
4652 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4653 mPowerManager.goToSleep(event.getEventTime(),
4654 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4655 isWakeKey = false;
4656 }
Jeff Brown4d396052010-10-29 21:50:21 -07004657 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004658 }
Jeff Brown4d396052010-10-29 21:50:21 -07004659 }
4660 break;
4661 }
4662
4663 case KeyEvent.KEYCODE_POWER: {
4664 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004665 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004666 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004667 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004668 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004669 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004670 }
4671 break;
4672 }
4673
Jeff Brown6212a492014-03-07 13:58:47 -08004674 case KeyEvent.KEYCODE_SLEEP: {
4675 result &= ~ACTION_PASS_TO_USER;
Jeff Brownbae8e772014-06-12 19:59:45 -07004676 if (!mPowerManager.isInteractive()) {
4677 useHapticFeedback = false; // suppress feedback if already non-interactive
4678 }
Jeff Brownc12035c2014-08-13 18:52:25 -07004679 mPowerManager.goToSleep(event.getEventTime(),
4680 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown6212a492014-03-07 13:58:47 -08004681 isWakeKey = false;
4682 break;
4683 }
4684
4685 case KeyEvent.KEYCODE_WAKEUP: {
4686 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004687 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004688 break;
4689 }
4690
Jeff Brown4d396052010-10-29 21:50:21 -07004691 case KeyEvent.KEYCODE_MEDIA_PLAY:
4692 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4693 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004694 case KeyEvent.KEYCODE_HEADSETHOOK:
4695 case KeyEvent.KEYCODE_MUTE:
4696 case KeyEvent.KEYCODE_MEDIA_STOP:
4697 case KeyEvent.KEYCODE_MEDIA_NEXT:
4698 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4699 case KeyEvent.KEYCODE_MEDIA_REWIND:
4700 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004701 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4702 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004703 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4704 // If the global session is active pass all media keys to it
4705 // instead of the active window.
4706 result &= ~ACTION_PASS_TO_USER;
4707 }
Jeff Brown4d396052010-10-29 21:50:21 -07004708 if ((result & ACTION_PASS_TO_USER) == 0) {
4709 // Only do this if we would otherwise not pass it to the user. In that
4710 // case, the PhoneWindow class will do the same thing, except it will
4711 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004712 // Note that we need to make a copy of the key event here because the
4713 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004714 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004715 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4716 new KeyEvent(event));
4717 msg.setAsynchronous(true);
4718 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004719 }
4720 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004721 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004722
Jeff Brown4d396052010-10-29 21:50:21 -07004723 case KeyEvent.KEYCODE_CALL: {
4724 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004725 TelecomManager telecomManager = getTelecommService();
4726 if (telecomManager != null) {
4727 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004728 Log.i(TAG, "interceptKeyBeforeQueueing:"
4729 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004730 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004731
Santos Cordon6848f722014-05-21 15:22:12 -07004732 // And *don't* pass this key thru to the current activity
4733 // (which is presumably the InCallScreen.)
4734 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004735 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004736 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004737 }
Jeff Brown4d396052010-10-29 21:50:21 -07004738 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004739 }
Michael Wright869a67c2014-08-26 19:33:06 -07004740 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4741 // Only do this if we would otherwise not pass it to the user. In that case,
4742 // interceptKeyBeforeDispatching would apply a similar but different policy in
4743 // order to invoke voice assist actions. Note that we need to make a copy of the
4744 // key event here because the original key event will be recycled when we return.
4745 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4746 mBroadcastWakeLock.acquire();
4747 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4748 keyguardActive ? 1 : 0, 0);
4749 msg.setAsynchronous(true);
4750 msg.sendToTarget();
4751 }
4752 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004753 }
Jeff Brown26875502014-01-30 21:47:47 -08004754
Jeff Brownbae8e772014-06-12 19:59:45 -07004755 if (useHapticFeedback) {
4756 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4757 }
4758
Jeff Brown26875502014-01-30 21:47:47 -08004759 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004760 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004761 }
Bryce Lee584a4452014-10-21 15:55:55 -07004762
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004763 return result;
4764 }
4765
Jeff Brown1c2e4942012-11-06 16:32:01 -08004766 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004767 * Returns true if the key can have global actions attached to it.
4768 * We reserve all power management keys for the system since they require
4769 * very careful handling.
4770 */
4771 private static boolean isValidGlobalKey(int keyCode) {
4772 switch (keyCode) {
4773 case KeyEvent.KEYCODE_POWER:
4774 case KeyEvent.KEYCODE_WAKEUP:
4775 case KeyEvent.KEYCODE_SLEEP:
4776 return false;
4777 default:
4778 return true;
4779 }
4780 }
4781
4782 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08004783 * When the screen is off we ignore some keys that might otherwise typically
4784 * be considered wake keys. We filter them out here.
4785 *
4786 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4787 * is always considered a wake key.
4788 */
4789 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4790 switch (keyCode) {
4791 // ignore volume keys unless docked
4792 case KeyEvent.KEYCODE_VOLUME_UP:
4793 case KeyEvent.KEYCODE_VOLUME_DOWN:
4794 case KeyEvent.KEYCODE_VOLUME_MUTE:
4795 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4796
4797 // ignore media and camera keys
4798 case KeyEvent.KEYCODE_MUTE:
4799 case KeyEvent.KEYCODE_HEADSETHOOK:
4800 case KeyEvent.KEYCODE_MEDIA_PLAY:
4801 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4802 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4803 case KeyEvent.KEYCODE_MEDIA_STOP:
4804 case KeyEvent.KEYCODE_MEDIA_NEXT:
4805 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4806 case KeyEvent.KEYCODE_MEDIA_REWIND:
4807 case KeyEvent.KEYCODE_MEDIA_RECORD:
4808 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004809 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004810 case KeyEvent.KEYCODE_CAMERA:
4811 return false;
4812 }
4813 return true;
4814 }
4815
4816
Jeff Brown56194eb2011-03-02 19:23:13 -08004817 /** {@inheritDoc} */
4818 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004819 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4820 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08004821 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
4822 return 0;
4823 }
Michael Wright70af00a2014-09-03 19:30:20 -07004824 }
Bryce Lee5c138322014-11-03 08:26:09 -08004825
Michael Wright70af00a2014-09-03 19:30:20 -07004826 if (shouldDispatchInputWhenNonInteractive()) {
4827 return ACTION_PASS_TO_USER;
4828 }
Bryce Lee5c138322014-11-03 08:26:09 -08004829
Bryce Lee812d7022014-11-10 13:33:28 -08004830 // If we have not passed the action up and we are in theater mode without dreaming,
4831 // there will be no dream to intercept the touch and wake into ambient. The device should
4832 // wake up in this case.
4833 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
4834 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
4835 }
4836
Jeff Brown037c33e2014-04-09 00:31:55 -07004837 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004838 }
4839
Michael Wright70af00a2014-09-03 19:30:20 -07004840 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08004841 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07004842 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
4843 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08004844 return true;
4845 }
4846
4847 // Send events to a dozing dream even if the screen is off since the dream
4848 // is in control of the state of the screen.
4849 IDreamManager dreamManager = getDreamManager();
4850
4851 try {
4852 if (dreamManager != null && dreamManager.isDreaming()) {
4853 return true;
4854 }
4855 } catch (RemoteException e) {
4856 Slog.e(TAG, "RemoteException when checking if dreaming", e);
4857 }
4858
4859 // Otherwise, consume events since the user can't see what is being
4860 // interacted with.
4861 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07004862 }
4863
RoboErik001c59c2015-01-26 15:53:51 -08004864 private void dispatchDirectAudioEvent(KeyEvent event) {
4865 if (event.getAction() != KeyEvent.ACTION_DOWN) {
4866 return;
4867 }
4868 int keyCode = event.getKeyCode();
4869 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND;
4870 String pkgName = mContext.getOpPackageName();
4871 switch (keyCode) {
4872 case KeyEvent.KEYCODE_VOLUME_UP:
4873 try {
John Spurlockee5ad722015-03-03 16:17:21 -05004874 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
4875 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
RoboErik001c59c2015-01-26 15:53:51 -08004876 } catch (RemoteException e) {
4877 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
4878 }
4879 break;
4880 case KeyEvent.KEYCODE_VOLUME_DOWN:
4881 try {
John Spurlockee5ad722015-03-03 16:17:21 -05004882 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
4883 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
RoboErik001c59c2015-01-26 15:53:51 -08004884 } catch (RemoteException e) {
4885 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
4886 }
4887 break;
4888 case KeyEvent.KEYCODE_VOLUME_MUTE:
4889 try {
4890 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05004891 getAudioService().adjustSuggestedStreamVolume(
4892 AudioManager.ADJUST_TOGGLE_MUTE,
4893 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
RoboErik001c59c2015-01-26 15:53:51 -08004894 }
4895 } catch (RemoteException e) {
4896 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
4897 }
4898 break;
4899 }
4900 }
4901
Jeff Brown40013652012-05-16 21:22:36 -07004902 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4903 if (DEBUG_INPUT) {
4904 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004905 }
4906
Jeff Brown40013652012-05-16 21:22:36 -07004907 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4908 if (DEBUG_INPUT) {
4909 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4910 }
4911
4912 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4913 mHavePendingMediaKeyRepeatWithWakeLock = false;
4914 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4915 }
4916
4917 dispatchMediaKeyWithWakeLockToAudioService(event);
4918
4919 if (event.getAction() == KeyEvent.ACTION_DOWN
4920 && event.getRepeatCount() == 0) {
4921 mHavePendingMediaKeyRepeatWithWakeLock = true;
4922
4923 Message msg = mHandler.obtainMessage(
4924 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4925 msg.setAsynchronous(true);
4926 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4927 } else {
4928 mBroadcastWakeLock.release();
4929 }
4930 }
4931
4932 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4933 mHavePendingMediaKeyRepeatWithWakeLock = false;
4934
4935 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4936 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4937 if (DEBUG_INPUT) {
4938 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4939 }
4940
4941 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4942 mBroadcastWakeLock.release();
4943 }
4944
4945 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4946 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07004947 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004948 }
4949 }
4950
Michael Wright869a67c2014-08-26 19:33:06 -07004951 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
4952 Intent voiceIntent =
4953 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
4954 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
4955 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
4956 mBroadcastWakeLock.release();
4957 }
4958
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004959 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004960 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004961 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004962 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4963 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4964 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004965 } else {
4966 try {
4967 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4968 ServiceManager.getService(Context.UI_MODE_SERVICE));
4969 mUiMode = uiModeService.getCurrentModeType();
4970 } catch (RemoteException e) {
4971 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004972 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004973 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004974 synchronized (mLock) {
4975 updateOrientationListenerLp();
4976 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004977 }
4978 };
4979
Jeff Brown6aaf2952012-10-05 16:01:08 -07004980 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4981 @Override
4982 public void onReceive(Context context, Intent intent) {
4983 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004984 if (mKeyguardDelegate != null) {
4985 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004986 }
4987 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004988 if (mKeyguardDelegate != null) {
4989 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004990 }
4991 }
4992 }
4993 };
4994
Christopher Tate5e08af02012-09-21 17:17:22 -07004995 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4996 @Override
4997 public void onReceive(Context context, Intent intent) {
4998 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4999 // tickle the settings observer: this first ensures that we're
5000 // observing the relevant settings for the newly-active user,
5001 // and then updates our own bookkeeping based on the now-
5002 // current user.
5003 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005004
5005 // force a re-application of focused window sysui visibility.
5006 // the window may never have been shown for this user
5007 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005008 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005009 mLastSystemUiFlags = 0;
5010 updateSystemUiVisibilityLw();
5011 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005012 }
5013 }
5014 };
5015
John Spurlockd9b70bd2014-02-06 17:02:44 -05005016 private final Runnable mRequestTransientNav = new Runnable() {
5017 @Override
5018 public void run() {
5019 requestTransientBars(mNavigationBar);
5020 }
5021 };
5022
John Spurlocke1f366f2013-08-05 12:22:40 -04005023 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005024 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005025 if (!isUserSetupComplete()) {
5026 // Swipe-up for navigation bar is disabled during setup
5027 return;
5028 }
John Spurlock27735a42013-08-14 17:57:38 -04005029 boolean sb = mStatusBarController.checkShowTransientBarLw();
5030 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005031 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005032 // Don't show status bar when swiping on already visible navigation bar
5033 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005034 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005035 return;
5036 }
John Spurlock27735a42013-08-14 17:57:38 -04005037 if (sb) mStatusBarController.showTransient();
5038 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005039 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005040 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005041 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005042 }
5043 }
5044
Jeff Brown3ee549c2014-09-22 20:14:39 -07005045 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005046 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07005047 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005048 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07005049 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005050
5051 // We must get this work done here because the power manager will drop
5052 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005053 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005054 mAwake = false;
5055 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005056 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005057 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005058 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005059 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005060
5061 if (mKeyguardDelegate != null) {
5062 mKeyguardDelegate.onScreenTurnedOff(why);
5063 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005064 }
5065
Jeff Brown13f00f02014-10-31 14:45:50 -07005066 private void wakeUpFromPowerKey(long eventTime) {
5067 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5068 }
5069
Bryce Lee5c138322014-11-03 08:26:09 -08005070 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Lee584a4452014-10-21 15:55:55 -07005071 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005072 return false;
Bryce Lee584a4452014-10-21 15:55:55 -07005073 }
5074
5075 mPowerManager.wakeUp(wakeTime);
Bryce Lee5c138322014-11-03 08:26:09 -08005076 return true;
Bryce Lee584a4452014-10-21 15:55:55 -07005077 }
5078
Jeff Brown3ee549c2014-09-22 20:14:39 -07005079 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005080 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07005081 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005082 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07005083 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005084
Jeff Brown3ee549c2014-09-22 20:14:39 -07005085 // Since goToSleep performs these functions synchronously, we must
5086 // do the same here. We cannot post this work to a handler because
5087 // that might cause it to become reordered with respect to what
5088 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005089 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005090 mAwake = true;
5091 mKeyguardDrawComplete = false;
5092 if (mKeyguardDelegate != null) {
5093 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5094 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5095 }
5096
Jeff Browna20dda42014-05-27 20:57:24 -07005097 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005098 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005099 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005100 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005101
Jim Miller5ecd8112013-01-09 18:50:26 -08005102 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07005103 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005104 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005105 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005106 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005107 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005108 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005109 }
5110
Jeff Brown36c4db82014-09-19 12:05:31 -07005111 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005112 synchronized (mLock) {
5113 if (!mAwake || mKeyguardDrawComplete) {
5114 return; // spurious
5115 }
5116
Jeff Brown36c4db82014-09-19 12:05:31 -07005117 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005118 if (mKeyguardDelegate != null) {
5119 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5120 }
5121 }
5122
5123 finishScreenTurningOn();
5124 }
5125
5126 // Called on the DisplayManager's DisplayPowerController thread.
5127 @Override
5128 public void screenTurnedOff() {
5129 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5130
5131 synchronized (mLock) {
5132 mScreenOnEarly = false;
5133 mScreenOnFully = false;
5134 mWindowManagerDrawComplete = false;
5135 mScreenOnListener = null;
5136 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005137 }
5138 }
5139
Jeff Brown3ee549c2014-09-22 20:14:39 -07005140 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005141 @Override
5142 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005143 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005144
Jeff Brown3ee549c2014-09-22 20:14:39 -07005145 synchronized (mLock) {
5146 mScreenOnEarly = true;
5147 mScreenOnFully = false;
5148 mWindowManagerDrawComplete = false;
5149 mScreenOnListener = screenOnListener;
5150 updateOrientationListenerLp();
5151 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005152
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005153 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5154 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005155 // ... eventually calls finishWindowsDrawn
5156 }
5157
Jeff Brown36c4db82014-09-19 12:05:31 -07005158 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005159 synchronized (mLock) {
5160 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5161 return; // spurious
5162 }
5163
Jeff Brown36c4db82014-09-19 12:05:31 -07005164 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005165 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005166
5167 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005168 }
5169
Craig Mautner8a0da012014-05-31 15:13:37 -07005170 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005171 final ScreenOnListener listener;
5172 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005173 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005174 if (DEBUG_WAKEUP) Slog.d(TAG,
5175 "finishScreenTurningOn: mAwake=" + mAwake
5176 + ", mScreenOnEarly=" + mScreenOnEarly
5177 + ", mScreenOnFully=" + mScreenOnFully
5178 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5179 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5180
5181 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5182 || (mAwake && !mKeyguardDrawComplete)) {
5183 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005184 }
5185
Jeff Brown3ee549c2014-09-22 20:14:39 -07005186 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5187 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005188 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005189 mScreenOnFully = true;
5190
5191 // Remember the first time we draw the keyguard so we know when we're done with
5192 // the main part of booting and can enable the screen and hide boot messages.
5193 if (!mKeyguardDrawnOnce && mAwake) {
5194 mKeyguardDrawnOnce = true;
5195 enableScreen = true;
5196 if (mBootMessageNeedsHiding) {
5197 mBootMessageNeedsHiding = false;
5198 hideBootMessages();
5199 }
5200 } else {
5201 enableScreen = false;
5202 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005203 }
5204
Jeff Brown3ee549c2014-09-22 20:14:39 -07005205 if (listener != null) {
5206 listener.onScreenOn();
5207 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005208
Jeff Brown3ee549c2014-09-22 20:14:39 -07005209 if (enableScreen) {
5210 try {
5211 mWindowManager.enableScreenIfNeeded();
5212 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005213 }
Craig Mautnera631d492014-08-05 15:16:01 -07005214 }
5215 }
5216
5217 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005218 synchronized (mLock) {
5219 if (!mKeyguardDrawnOnce) {
5220 mBootMessageNeedsHiding = true;
5221 return; // keyguard hasn't drawn the first time yet, not done booting
5222 }
Craig Mautnera631d492014-08-05 15:16:01 -07005223 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005224
5225 if (mBootMsgDialog != null) {
5226 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5227 mBootMsgDialog.dismiss();
5228 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005229 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005230 }
5231
5232 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005233 public boolean isScreenOn() {
5234 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005235 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005236
Dianne Hackborn08743722009-12-21 12:16:51 -08005237 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005238 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005239 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005240 if (mKeyguardDelegate != null) {
5241 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005242 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005243 }
5244
5245 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005246 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005247 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005248 if (mKeyguardDelegate != null) {
5249 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005250 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005251 }
5252
Jim Millerab954542014-10-10 18:21:49 -07005253 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005254 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005255 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005256 }
5257
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005258 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005259 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005260 public boolean isKeyguardLocked() {
5261 return keyguardOn();
5262 }
5263
5264 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005265 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005266 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005267 if (mKeyguardDelegate == null) return false;
5268 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005269 }
5270
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005271 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005272 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005273 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005274 if (mKeyguardDelegate == null) return false;
5275 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005276 }
5277
Jose Lima9546b202014-07-02 17:21:51 -07005278 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005279 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005280 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005281 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005282 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005283 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005284 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005285 // ask the keyguard to prompt the user to authenticate if necessary
5286 mKeyguardDelegate.dismiss();
5287 }
5288 });
5289 }
5290 }
5291
5292 public void notifyActivityDrawnForKeyguardLw() {
5293 if (mKeyguardDelegate != null) {
5294 mHandler.post(new Runnable() {
5295 @Override
5296 public void run() {
5297 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005298 }
5299 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005300 }
5301 }
5302
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005303 @Override
5304 public boolean isKeyguardDrawnLw() {
5305 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005306 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005307 }
5308 }
5309
Jorim Jaggi0d674622014-05-21 01:34:15 +02005310 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005311 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005312 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005313 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005314 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005315 }
5316 }
5317
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005318 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005319 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005320 }
5321
5322 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005323 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005324 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005325
Jeff Brown01a98dd2011-09-20 15:08:29 -07005326 @Override
5327 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005328 if (false) {
5329 Slog.v(TAG, "rotationForOrientationLw(orient="
5330 + orientation + ", last=" + lastRotation
5331 + "); user=" + mUserRotation + " "
5332 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5333 ? "USER_ROTATION_LOCKED" : "")
5334 );
5335 }
5336
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005337 if (mForceDefaultOrientation) {
5338 return Surface.ROTATION_0;
5339 }
5340
The Android Open Source Project0727d222009-03-11 12:11:58 -07005341 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005342 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5343 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005344 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005345 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005346
Jeff Browndec6cf42011-11-15 14:08:20 -08005347 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005348 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005349 // Ignore sensor when lid switch is open and rotation is forced.
5350 preferredRotation = mLidOpenRotation;
5351 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005352 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005353 // Ignore sensor when in car dock unless explicitly enabled.
5354 // This case can override the behavior of NOSENSOR, and can also
5355 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005356 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005357 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005358 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5359 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5360 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005361 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005362 // Ignore sensor when in desk dock unless explicitly enabled.
5363 // This case can override the behavior of NOSENSOR, and can also
5364 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005365 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005366 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005367 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5368 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005369 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005370 preferredRotation = mDemoHdmiRotation;
5371 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5372 && mUndockedHdmiRotation >= 0) {
5373 // Ignore sensor when plugged into HDMI and an undocked orientation has
5374 // been specified in the configuration (only for legacy devices without
5375 // full multi-display support).
5376 // Note that the dock orientation overrides the HDMI orientation.
5377 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005378 } else if (mDemoRotationLock) {
5379 // Ignore sensor when demo rotation lock is enabled.
5380 // Note that the dock orientation and HDMI rotation lock override this.
5381 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005382 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5383 // Application just wants to remain locked in the last rotation.
5384 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005385 } else if (!mSupportAutoRotation) {
5386 // If we don't support auto-rotation then bail out here and ignore
5387 // the sensor and any rotation lock settings.
5388 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005389 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005390 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005391 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5392 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5393 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5394 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005395 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5396 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5397 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5398 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5399 // Otherwise, use sensor only if requested by the application or enabled
5400 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005401 if (mAllowAllRotations < 0) {
5402 // Can't read this during init() because the context doesn't
5403 // have display metrics at that time so we cannot determine
5404 // tablet vs. phone then.
5405 mAllowAllRotations = mContext.getResources().getBoolean(
5406 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5407 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005408 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005409 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005410 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5411 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005412 preferredRotation = sensorRotation;
5413 } else {
5414 preferredRotation = lastRotation;
5415 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005416 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5417 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5418 // Apply rotation lock. Does not apply to NOSENSOR.
5419 // The idea is that the user rotation expresses a weak preference for the direction
5420 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5421 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005422 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005423 } else {
5424 // No overriding preference.
5425 // We will do exactly what the application asked us to do.
5426 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005427 }
5428
Dianne Hackborne5439f22010-10-02 16:53:50 -07005429 switch (orientation) {
5430 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005431 // Return portrait unless overridden.
5432 if (isAnyPortrait(preferredRotation)) {
5433 return preferredRotation;
5434 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005435 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005436
Jeff Brown01a98dd2011-09-20 15:08:29 -07005437 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005438 // Return landscape unless overridden.
5439 if (isLandscapeOrSeascape(preferredRotation)) {
5440 return preferredRotation;
5441 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005442 return mLandscapeRotation;
5443
5444 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005445 // Return reverse portrait unless overridden.
5446 if (isAnyPortrait(preferredRotation)) {
5447 return preferredRotation;
5448 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005449 return mUpsideDownRotation;
5450
5451 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005452 // Return seascape unless overridden.
5453 if (isLandscapeOrSeascape(preferredRotation)) {
5454 return preferredRotation;
5455 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005456 return mSeascapeRotation;
5457
5458 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005459 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005460 // Return either landscape rotation.
5461 if (isLandscapeOrSeascape(preferredRotation)) {
5462 return preferredRotation;
5463 }
5464 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005465 return lastRotation;
5466 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005467 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005468
Jeff Brown01a98dd2011-09-20 15:08:29 -07005469 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005470 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005471 // Return either portrait rotation.
5472 if (isAnyPortrait(preferredRotation)) {
5473 return preferredRotation;
5474 }
5475 if (isAnyPortrait(lastRotation)) {
5476 return lastRotation;
5477 }
5478 return mPortraitRotation;
5479
5480 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005481 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5482 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005483 if (preferredRotation >= 0) {
5484 return preferredRotation;
5485 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005486 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005487 }
5488 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005489 }
5490
Jeff Brown01a98dd2011-09-20 15:08:29 -07005491 @Override
5492 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5493 switch (orientation) {
5494 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5495 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5496 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5497 return isAnyPortrait(rotation);
5498
5499 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5500 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5501 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5502 return isLandscapeOrSeascape(rotation);
5503
5504 default:
5505 return true;
5506 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005507 }
5508
Jeff Brownc0347aa2011-09-23 17:26:09 -07005509 @Override
5510 public void setRotationLw(int rotation) {
5511 mOrientationListener.setCurrentRotation(rotation);
5512 }
5513
Jeff Brown01a98dd2011-09-20 15:08:29 -07005514 private boolean isLandscapeOrSeascape(int rotation) {
5515 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005516 }
5517
Jeff Brown01a98dd2011-09-20 15:08:29 -07005518 private boolean isAnyPortrait(int rotation) {
5519 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005520 }
5521
Jose Lima9546b202014-07-02 17:21:51 -07005522 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005523 public int getUserRotationMode() {
5524 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005525 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5526 WindowManagerPolicy.USER_ROTATION_FREE :
5527 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005528 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005529
5530 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005531 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005532 public void setUserRotationMode(int mode, int rot) {
5533 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005534
5535 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005536 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005537 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005538 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005539 rot,
5540 UserHandle.USER_CURRENT);
5541 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005542 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005543 0,
5544 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005545 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005546 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005547 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005548 1,
5549 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005550 }
5551 }
5552
Jose Lima9546b202014-07-02 17:21:51 -07005553 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005554 public void setSafeMode(boolean safeMode) {
5555 mSafeMode = safeMode;
5556 performHapticFeedbackLw(null, safeMode
5557 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5558 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005559 }
Craig Mautnereda67292013-04-28 13:50:14 -07005560
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005561 static long[] getLongIntArray(Resources r, int resid) {
5562 int[] ar = r.getIntArray(resid);
5563 if (ar == null) {
5564 return null;
5565 }
5566 long[] out = new long[ar.length];
5567 for (int i=0; i<ar.length; i++) {
5568 out[i] = ar[i];
5569 }
5570 return out;
5571 }
Craig Mautnereda67292013-04-28 13:50:14 -07005572
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005573 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005574 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005575 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005576 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005577 mKeyguardDelegate.onSystemReady();
5578
Michael Wright3818c922014-09-02 13:59:07 -07005579 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005580 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005581 synchronized (mLock) {
5582 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005583 mSystemReady = true;
5584 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005585 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005586 public void run() {
5587 updateSettings();
5588 }
5589 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005590 }
5591 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005592
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005593 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005594 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005595 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005596 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005597 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005598 mKeyguardDelegate.onBootCompleted();
5599 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005600 synchronized (mLock) {
5601 mSystemBooted = true;
5602 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005603 wakingUp();
5604 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005605 }
5606
Dianne Hackborn661cd522011-08-22 00:26:20 -07005607 ProgressDialog mBootMsgDialog = null;
5608
5609 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005610 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005611 public void showBootMessage(final CharSequence msg, final boolean always) {
5612 mHandler.post(new Runnable() {
5613 @Override public void run() {
5614 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005615 int theme;
5616 if (mContext.getPackageManager().hasSystemFeature(
5617 PackageManager.FEATURE_WATCH)) {
5618 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5619 } else if (mContext.getPackageManager().hasSystemFeature(
5620 PackageManager.FEATURE_TELEVISION)) {
5621 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5622 } else {
5623 theme = 0;
5624 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005625
5626 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005627 // This dialog will consume all events coming in to
5628 // it, to avoid it trying to do things too early in boot.
5629 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5630 return true;
5631 }
5632 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5633 return true;
5634 }
5635 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5636 return true;
5637 }
5638 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5639 return true;
5640 }
5641 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5642 return true;
5643 }
5644 @Override public boolean dispatchPopulateAccessibilityEvent(
5645 AccessibilityEvent event) {
5646 return true;
5647 }
5648 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005649 if (mContext.getPackageManager().isUpgrade()) {
5650 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5651 } else {
5652 mBootMsgDialog.setTitle(R.string.android_start_title);
5653 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005654 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5655 mBootMsgDialog.setIndeterminate(true);
5656 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005657 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005658 mBootMsgDialog.getWindow().addFlags(
5659 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5660 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5661 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005662 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5663 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5664 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005665 mBootMsgDialog.setCancelable(false);
5666 mBootMsgDialog.show();
5667 }
5668 mBootMsgDialog.setMessage(msg);
5669 }
5670 });
5671 }
5672
5673 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005674 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005675 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005676 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005677 }
5678
Mike Lockwood28569302010-01-28 11:54:40 -05005679 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005680 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005681 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005682 // ***************************************
5683 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5684 // ***************************************
5685 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5686 // WITH ITS LOCKS HELD.
5687 //
5688 // This code must be VERY careful about the locks
5689 // it acquires.
5690 // In fact, the current code acquires way too many,
5691 // and probably has lurking deadlocks.
5692
Mike Lockwood28569302010-01-28 11:54:40 -05005693 synchronized (mScreenLockTimeout) {
5694 if (mLockScreenTimerActive) {
5695 // reset the timer
5696 mHandler.removeCallbacks(mScreenLockTimeout);
5697 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5698 }
5699 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005700 }
5701
Adam Cohenf7522022012-10-03 20:03:18 -07005702 class ScreenLockTimeout implements Runnable {
5703 Bundle options;
5704
5705 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005706 public void run() {
5707 synchronized (this) {
5708 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005709 if (mKeyguardDelegate != null) {
5710 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005711 }
Mike Lockwood28569302010-01-28 11:54:40 -05005712 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005713 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005714 }
5715 }
Mike Lockwood28569302010-01-28 11:54:40 -05005716
Adam Cohenf7522022012-10-03 20:03:18 -07005717 public void setLockOptions(Bundle options) {
5718 this.options = options;
5719 }
5720 }
5721
5722 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5723
Jose Lima9546b202014-07-02 17:21:51 -07005724 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005725 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005726 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5727 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005728 if (options != null) {
5729 // In case multiple calls are made to lockNow, we don't wipe out the options
5730 // until the runnable actually executes.
5731 mScreenLockTimeout.setLockOptions(options);
5732 }
Jim Miller93c518e2012-01-17 15:55:31 -08005733 mHandler.post(mScreenLockTimeout);
5734 }
5735
Mike Lockwood28569302010-01-28 11:54:40 -05005736 private void updateLockScreenTimeout() {
5737 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005738 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005739 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005740 if (mLockScreenTimerActive != enable) {
5741 if (enable) {
5742 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5743 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5744 } else {
5745 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5746 mHandler.removeCallbacks(mScreenLockTimeout);
5747 }
5748 mLockScreenTimerActive = enable;
5749 }
5750 }
5751 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005752
5753 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005754 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005755 public void enableScreenAfterBoot() {
5756 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005757 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005758 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005759 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005760
Jeff Brownc458ce92012-04-30 14:58:40 -07005761 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005762 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005763 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005764 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005765 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005766 }
Jeff Browna20dda42014-05-27 20:57:24 -07005767
5768 synchronized (mLock) {
5769 updateWakeGestureListenerLp();
5770 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005771 }
5772
Jeff Brown4f5fa282014-06-12 19:19:15 -07005773 void updateUiMode() {
5774 if (mUiModeManager == null) {
5775 mUiModeManager = IUiModeManager.Stub.asInterface(
5776 ServiceManager.getService(Context.UI_MODE_SERVICE));
5777 }
5778 try {
5779 mUiMode = mUiModeManager.getCurrentModeType();
5780 } catch (RemoteException e) {
5781 }
5782 }
5783
Jeff Brown01a98dd2011-09-20 15:08:29 -07005784 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005785 try {
5786 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005787 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5788 } catch (RemoteException e) {
5789 // Ignore
5790 }
5791 }
5792
5793 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5794 try {
5795 //set orientation on WindowManager
5796 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005797 } catch (RemoteException e) {
5798 // Ignore
5799 }
5800 }
5801
Daniel Sandler6396c722013-04-16 20:19:09 -04005802 /**
5803 * Return an Intent to launch the currently active dock app as home. Returns
5804 * null if the standard home should be launched, which is the case if any of the following is
5805 * true:
5806 * <ul>
5807 * <li>The device is not in either car mode or desk mode
5808 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5809 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5810 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5811 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5812 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005813 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005814 */
5815 Intent createHomeDockIntent() {
5816 Intent intent = null;
5817
5818 // What home does is based on the mode, not the dock state. That
5819 // is, when in car mode you should be taken to car home regardless
5820 // of whether we are actually in a car dock.
5821 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5822 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5823 intent = mCarDockIntent;
5824 }
5825 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5826 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5827 intent = mDeskDockIntent;
5828 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005829 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5830 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5831 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5832 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5833 // Always launch dock home from home when watch is docked, if it exists.
5834 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005835 }
5836
5837 if (intent == null) {
5838 return null;
5839 }
5840
5841 ActivityInfo ai = null;
5842 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5843 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005844 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005845 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005846 if (info != null) {
5847 ai = info.activityInfo;
5848 }
5849 if (ai != null
5850 && ai.metaData != null
5851 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5852 intent = new Intent(intent);
5853 intent.setClassName(ai.packageName, ai.name);
5854 return intent;
5855 }
5856
5857 return null;
5858 }
5859
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005860 void startDockOrHome(boolean fromHomeKey) {
John Spurlockc8b46ca2013-04-08 12:59:26 -04005861 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04005862
5863 Intent dock = createHomeDockIntent();
5864 if (dock != null) {
5865 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005866 if (fromHomeKey) {
5867 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5868 }
Daniel Sandler6396c722013-04-16 20:19:09 -04005869 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
5870 return;
5871 } catch (ActivityNotFoundException e) {
5872 }
5873 }
5874
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005875 Intent intent;
5876
5877 if (fromHomeKey) {
5878 intent = new Intent(mHomeIntent);
5879 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5880 } else {
5881 intent = mHomeIntent;
5882 }
5883
5884 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005885 }
Craig Mautnereda67292013-04-28 13:50:14 -07005886
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005887 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005888 * goes to the home screen
5889 * @return whether it did anything
5890 */
5891 boolean goHome() {
5892 if (false) {
5893 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005894 try {
5895 ActivityManagerNative.getDefault().stopAppSwitches();
5896 } catch (RemoteException e) {
5897 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005898 sendCloseSystemWindows();
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005899 startDockOrHome(false /*fromHomeKey*/);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005900 } else {
5901 // This code brings home to the front or, if it is already
5902 // at the front, puts the device to sleep.
5903 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08005904 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
5905 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
5906 Log.d(TAG, "UTS-TEST-MODE");
5907 } else {
5908 ActivityManagerNative.getDefault().stopAppSwitches();
5909 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04005910 Intent dock = createHomeDockIntent();
5911 if (dock != null) {
5912 int result = ActivityManagerNative.getDefault()
5913 .startActivityAsUser(null, null, dock,
5914 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
5915 null, null, 0,
5916 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005917 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04005918 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5919 return false;
5920 }
5921 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005922 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005923 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005924 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005925 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005926 null, null, 0,
5927 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005928 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005929 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005930 return false;
5931 }
5932 } catch (RemoteException ex) {
5933 // bummer, the activity manager, which is in this process, is dead
5934 }
5935 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005936 return true;
5937 }
Craig Mautnereda67292013-04-28 13:50:14 -07005938
5939 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005940 public void setCurrentOrientationLw(int newOrientation) {
5941 synchronized (mLock) {
5942 if (newOrientation != mCurrentAppOrientation) {
5943 mCurrentAppOrientation = newOrientation;
5944 updateOrientationListenerLp();
5945 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005946 }
5947 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005948
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005949 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5950 if (!isGlobalAccessibilityGestureEnabled()) {
5951 return;
5952 }
5953 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5954 Context.AUDIO_SERVICE);
5955 if (audioManager.isSilentMode()) {
5956 return;
5957 }
5958 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5959 Settings.System.DEFAULT_NOTIFICATION_URI);
5960 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5961 ringTone.play();
5962 }
Craig Mautnereda67292013-04-28 13:50:14 -07005963
Bryce Lee584a4452014-10-21 15:55:55 -07005964 private boolean isTheaterModeEnabled() {
5965 return Settings.Global.getInt(mContext.getContentResolver(),
5966 Settings.Global.THEATER_MODE_ON, 0) == 1;
5967 }
5968
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005969 private boolean isGlobalAccessibilityGestureEnabled() {
5970 return Settings.Global.getInt(mContext.getContentResolver(),
5971 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5972 }
5973
Craig Mautnereda67292013-04-28 13:50:14 -07005974 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005975 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005976 if (!mVibrator.hasVibrator()) {
5977 return false;
5978 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005979 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5980 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07005981 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005982 return false;
5983 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005984 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005985 switch (effectId) {
5986 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005987 pattern = mLongPressVibePattern;
5988 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005989 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005990 pattern = mVirtualKeyVibePattern;
5991 break;
5992 case HapticFeedbackConstants.KEYBOARD_TAP:
5993 pattern = mKeyboardTapVibePattern;
5994 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07005995 case HapticFeedbackConstants.CLOCK_TICK:
5996 pattern = mClockTickVibePattern;
5997 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07005998 case HapticFeedbackConstants.CALENDAR_DATE:
5999 pattern = mCalendarDateVibePattern;
6000 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006001 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006002 pattern = mSafeModeDisabledVibePattern;
6003 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006004 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006005 pattern = mSafeModeEnabledVibePattern;
6006 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006007 default:
6008 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006009 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006010 int owningUid;
6011 String owningPackage;
6012 if (win != null) {
6013 owningUid = win.getOwningUid();
6014 owningPackage = win.getOwningPackage();
6015 } else {
6016 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006017 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006018 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006019 if (pattern.length == 1) {
6020 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006021 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006022 } else {
6023 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006024 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006025 }
6026 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006027 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006028
6029 @Override
6030 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006031 }
6032
Jeff Brownc38c9be2012-10-04 13:16:19 -07006033 @Override
6034 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006035 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006036 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006037 }
6038 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006039
Dianne Hackborndf89e652011-10-06 22:35:11 -07006040 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006041 // If there is no window focused, there will be nobody to handle the events
6042 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006043 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6044 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006045 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006046 return 0;
6047 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006048 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006049 // We are updating at a point where the keyguard has gotten
6050 // focus, but we were last in a state where the top window is
6051 // hiding it. This is probably because the keyguard as been
6052 // shown while the top window was displayed, so we want to ignore
6053 // it here because this is just a very transient change and it
6054 // will quickly lose focus once it correctly gets hidden.
6055 return 0;
6056 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006057
John Spurlock1db8b682014-02-18 11:18:59 -05006058 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006059 & ~mResettingSystemUiFlags
6060 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006061 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006062 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006063 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006064 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006065 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006066 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006067 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006068 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006069 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006070 return 0;
6071 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006072 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006073 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006074 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006075 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006076 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006077 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006078 try {
6079 IStatusBarService statusbar = getStatusBarService();
6080 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006081 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006082 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006083 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006084 } catch (RemoteException e) {
6085 // re-acquire status bar service next time it is needed.
6086 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006087 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006088 }
6089 });
6090 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006091 }
6092
Adrian Rooscd3884d2015-02-18 17:25:23 +01006093 private int updateLightStatusBarLw(int vis) {
6094 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6095 ? mStatusBar
6096 : mTopFullscreenOpaqueOrDimmingWindowState;
6097
6098 if (statusColorWin != null) {
6099 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6100 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6101 // its light flag.
6102 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6103 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6104 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6105 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6106 // Otherwise if it's dimming, clear the light flag.
6107 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6108 }
6109 }
6110 return vis;
6111 }
6112
John Spurlock79da8332013-09-20 12:04:47 -04006113 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006114 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006115 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6116 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006117 : mTopFullscreenOpaqueWindowState;
6118 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6119 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6120
John Spurlock27735a42013-08-14 17:57:38 -04006121 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04006122 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006123 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006124 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6125 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006126 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006127 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6128 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006129 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006130 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6131 }
John Spurlockbd957402013-10-03 11:38:39 -04006132 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006133 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006134
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006135 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006136 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6137 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006138 }
6139
John Spurlock27735a42013-08-14 17:57:38 -04006140 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006141 boolean immersiveSticky =
6142 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006143 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006144 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006145 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006146 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6147 boolean hideStatusBarSysui =
6148 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006149 boolean hideNavBarSysui =
6150 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006151
John Spurlock27735a42013-08-14 17:57:38 -04006152 boolean transientStatusBarAllowed =
6153 mStatusBar != null && (
6154 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006155 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006156 || statusBarHasFocus);
6157
John Spurlockf1a36642013-10-12 17:50:42 -04006158 boolean transientNavBarAllowed =
6159 mNavigationBar != null &&
6160 hideNavBarSysui && immersiveSticky;
6161
John Spurlockf25706f2013-11-07 18:02:43 -05006162 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006163 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006164 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006165 && !transientNavBarAllowed;
6166 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006167 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006168 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006169 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006170 }
John Spurlock27735a42013-08-14 17:57:38 -04006171
6172 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6173
6174 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006175 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6176 boolean newImmersiveMode = isImmersiveMode(vis);
6177 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006178 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006179 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6180 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006181 }
John Spurlock27735a42013-08-14 17:57:38 -04006182
John Spurlockf1a36642013-10-12 17:50:42 -04006183 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6184
John Spurlocke1f366f2013-08-05 12:22:40 -04006185 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006186 }
6187
John Spurlockf1a36642013-10-12 17:50:42 -04006188 private void clearClearableFlagsLw() {
6189 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6190 if (newVal != mResettingSystemUiFlags) {
6191 mResettingSystemUiFlags = newVal;
6192 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6193 }
6194 }
6195
6196 private boolean isImmersiveMode(int vis) {
6197 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006198 return mNavigationBar != null
6199 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006200 && (vis & flags) != 0
6201 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006202 }
6203
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006204 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006205 * @return whether the navigation or status bar can be made translucent
6206 *
6207 * This should return true unless touch exploration is not enabled or
6208 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006209 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006210 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006211 return mTranslucentDecorEnabled
6212 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006213 }
6214
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006215 // Use this instead of checking config_showNavigationBar so that it can be consistently
6216 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006217 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006218 public boolean hasNavigationBar() {
6219 return mHasNavigationBar;
6220 }
6221
satok1bc0a492012-04-25 22:47:12 +09006222 @Override
6223 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6224 mLastInputMethodWindow = ime;
6225 mLastInputMethodTargetWindow = target;
6226 }
6227
Craig Mautnerf1b67412012-09-19 13:18:29 -07006228 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006229 public int getInputMethodWindowVisibleHeightLw() {
6230 return mDockBottom - mCurBottom;
6231 }
6232
6233 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006234 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006235 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006236 if (mKeyguardDelegate != null) {
6237 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006238 }
John Spurlock13451a22012-09-28 14:40:41 -04006239 if (mStatusBarService != null) {
6240 try {
6241 mStatusBarService.setCurrentUser(newUserId);
6242 } catch (RemoteException e) {
6243 // oh well
6244 }
6245 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006246 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006247 }
6248
6249 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006250 public boolean canMagnifyWindow(int windowType) {
6251 switch (windowType) {
6252 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6253 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6254 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6255 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6256 return false;
6257 }
6258 }
6259 return true;
6260 }
6261
6262 @Override
6263 public boolean isTopLevelWindow(int windowType) {
6264 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6265 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6266 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6267 }
6268 return true;
6269 }
6270
Jim Miller4eeb4f62012-11-08 00:04:29 -08006271 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006272 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006273 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006274 pw.print(" mSystemReady="); pw.print(mSystemReady);
6275 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006276 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006277 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006278 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006279 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006280 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6281 || mForceClearedSystemUiFlags != 0) {
6282 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6283 pw.print(Integer.toHexString(mLastSystemUiFlags));
6284 pw.print(" mResettingSystemUiFlags=0x");
6285 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6286 pw.print(" mForceClearedSystemUiFlags=0x");
6287 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006288 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006289 if (mLastFocusNeedsMenu) {
6290 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6291 pw.println(mLastFocusNeedsMenu);
6292 }
Jeff Browna20dda42014-05-27 20:57:24 -07006293 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6294 pw.println(mWakeGestureEnabledSetting);
6295
Jeff Brownbcdfc622014-03-06 19:13:04 -08006296 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006297 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6298 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006299 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6300 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6301 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6302 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006303 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006304 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006305 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6306 pw.print(mCarDockEnablesAccelerometer);
6307 pw.print(" mDeskDockEnablesAccelerometer=");
6308 pw.println(mDeskDockEnablesAccelerometer);
6309 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6310 pw.print(mLidKeyboardAccessibility);
6311 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006312 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006313 pw.print(prefix);
6314 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6315 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006316 pw.print(prefix);
6317 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6318 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006319 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006320 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6321 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6322 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6323 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6324 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6325 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6326 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006327 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6328 pw.print(","); pw.print(mOverscanScreenTop);
6329 pw.print(") "); pw.print(mOverscanScreenWidth);
6330 pw.print("x"); pw.println(mOverscanScreenHeight);
6331 if (mOverscanLeft != 0 || mOverscanTop != 0
6332 || mOverscanRight != 0 || mOverscanBottom != 0) {
6333 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6334 pw.print(" top="); pw.print(mOverscanTop);
6335 pw.print(" right="); pw.print(mOverscanRight);
6336 pw.print(" bottom="); pw.println(mOverscanBottom);
6337 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006338 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6339 pw.print(mRestrictedOverscanScreenLeft);
6340 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6341 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6342 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006343 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6344 pw.print(","); pw.print(mUnrestrictedScreenTop);
6345 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6346 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6347 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6348 pw.print(","); pw.print(mRestrictedScreenTop);
6349 pw.print(") "); pw.print(mRestrictedScreenWidth);
6350 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006351 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6352 pw.print(","); pw.print(mStableFullscreenTop);
6353 pw.print(")-("); pw.print(mStableFullscreenRight);
6354 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006355 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6356 pw.print(","); pw.print(mStableTop);
6357 pw.print(")-("); pw.print(mStableRight);
6358 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006359 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6360 pw.print(","); pw.print(mSystemTop);
6361 pw.print(")-("); pw.print(mSystemRight);
6362 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006363 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6364 pw.print(","); pw.print(mCurTop);
6365 pw.print(")-("); pw.print(mCurRight);
6366 pw.print(","); pw.print(mCurBottom); pw.println(")");
6367 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6368 pw.print(","); pw.print(mContentTop);
6369 pw.print(")-("); pw.print(mContentRight);
6370 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006371 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6372 pw.print(","); pw.print(mVoiceContentTop);
6373 pw.print(")-("); pw.print(mVoiceContentRight);
6374 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006375 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6376 pw.print(","); pw.print(mDockTop);
6377 pw.print(")-("); pw.print(mDockRight);
6378 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006379 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6380 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006381 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6382 pw.print(" mShowingDream="); pw.print(mShowingDream);
6383 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006384 if (mLastInputMethodWindow != null) {
6385 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6386 pw.println(mLastInputMethodWindow);
6387 }
6388 if (mLastInputMethodTargetWindow != null) {
6389 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6390 pw.println(mLastInputMethodTargetWindow);
6391 }
6392 if (mStatusBar != null) {
6393 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006394 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6395 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006396 }
6397 if (mNavigationBar != null) {
6398 pw.print(prefix); pw.print("mNavigationBar=");
6399 pw.println(mNavigationBar);
6400 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006401 if (mFocusedWindow != null) {
6402 pw.print(prefix); pw.print("mFocusedWindow=");
6403 pw.println(mFocusedWindow);
6404 }
6405 if (mFocusedApp != null) {
6406 pw.print(prefix); pw.print("mFocusedApp=");
6407 pw.println(mFocusedApp);
6408 }
6409 if (mWinDismissingKeyguard != null) {
6410 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6411 pw.println(mWinDismissingKeyguard);
6412 }
6413 if (mTopFullscreenOpaqueWindowState != null) {
6414 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6415 pw.println(mTopFullscreenOpaqueWindowState);
6416 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006417 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6418 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6419 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6420 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006421 if (mForcingShowNavBar) {
6422 pw.print(prefix); pw.print("mForcingShowNavBar=");
6423 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6424 pw.println(mForcingShowNavBarLayer);
6425 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006426 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006427 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006428 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6429 pw.print(" mForceStatusBarFromKeyguard=");
6430 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006431 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006432 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006433 pw.print(" mHomePressed="); pw.println(mHomePressed);
6434 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6435 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6436 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6437 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6438 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6439 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6440 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6441 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6442 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6443 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006444 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6445 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6446 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006447
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006448 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006449 mStatusBarController.dump(pw, prefix);
6450 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006451 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006452
Jeff Browna20dda42014-05-27 20:57:24 -07006453 if (mWakeGestureListener != null) {
6454 mWakeGestureListener.dump(pw, prefix);
6455 }
Jeff Brown600f0032014-05-22 17:06:00 -07006456 if (mOrientationListener != null) {
6457 mOrientationListener.dump(pw, prefix);
6458 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006459 if (mBurnInProtectionHelper != null) {
6460 mBurnInProtectionHelper.dump(prefix, pw);
6461 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006462 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006463}