blob: 9746142ebb5fc3507cf8f502ca0dd33e8a4846b8 [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;
383 boolean mUseMasterVolume;
Craig Mautner967212c2013-04-13 21:10:58 -0700384
Jeff Brown70825162012-03-28 17:27:48 -0700385 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800386
387 // The last window we were told about in focusChanged.
388 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800389 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800390
Jeff Brown70825162012-03-28 17:27:48 -0700391 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800392
Dianne Hackbornc652de82013-02-15 16:32:56 -0800393 // The current size of the screen; really; extends into the overscan area of
394 // the screen and doesn't account for any system elements like the status bar.
395 int mOverscanScreenLeft, mOverscanScreenTop;
396 int mOverscanScreenWidth, mOverscanScreenHeight;
397 // The current visible size of the screen; really; (ir)regardless of whether the status
398 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800399 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
400 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800401 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
402 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
403 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700404 // The current size of the screen; these may be different than (0,0)-(dw,dh)
405 // if the status bar can't be hidden; in that case it effectively carves out
406 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800407 int mRestrictedScreenLeft, mRestrictedScreenTop;
408 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700409 // During layout, the current screen borders accounting for any currently
410 // visible system UI elements.
411 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700412 // For applications requesting stable content insets, these are them.
413 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700414 // For applications requesting stable content insets but have also set the
415 // fullscreen window flag, these are the stable dimensions without the status bar.
416 int mStableFullscreenLeft, mStableFullscreenTop;
417 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800418 // During layout, the current screen borders with all outer decoration
419 // (status bar, input method dock) accounted for.
420 int mCurLeft, mCurTop, mCurRight, mCurBottom;
421 // During layout, the frame in which content should be displayed
422 // to the user, accounting for all screen decoration except for any
423 // space they deem as available for other content. This is usually
424 // the same as mCur*, but may be larger if the screen decor has supplied
425 // content insets.
426 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700427 // During layout, the frame in which voice content should be displayed
428 // to the user, accounting for all screen decoration except for any
429 // space they deem as available for other content.
430 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800431 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800432 // windows are placed.
433 int mDockLeft, mDockTop, mDockRight, mDockBottom;
434 // During layout, the layer at which the doc window is placed.
435 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700436 // During layout, this is the layer of the status bar.
437 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700438 int mLastSystemUiFlags;
439 // Bits that we are in the process of clearing, so we want to prevent
440 // them from being set by applications until everything has been updated
441 // to have them clear.
442 int mResettingSystemUiFlags = 0;
443 // Bits that we are currently always keeping cleared.
444 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800445 // What we last reported to system UI about whether the compatibility
446 // menu needs to be displayed.
447 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700448
449 FakeWindow mHideNavFakeWindow = null;
450
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800451 static final Rect mTmpParentFrame = new Rect();
452 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800453 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800454 static final Rect mTmpContentFrame = new Rect();
455 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400456 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700457 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700458 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700459
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800460 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100461 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700462 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200463 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400464 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800465 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700466 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700467 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800468 boolean mForcingShowNavBar;
469 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700470
471 // States of keyguard dismiss.
472 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
473 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
474 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
475 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
476
477 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
478 * be done once per window. */
479 private WindowState mWinDismissingKeyguard;
480
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700481 /** The window that is currently showing "over" the keyguard. If there is an app window
482 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
483 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
484 * the wallpaper. */
485 private WindowState mWinShowWhenLocked;
486
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700487 boolean mShowingLockscreen;
488 boolean mShowingDream;
489 boolean mDreamingLockscreen;
Jim Millerab954542014-10-10 18:21:49 -0700490 boolean mKeyguardSecure;
491 boolean mKeyguardSecureIncludingHidden;
492 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800493 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700494 boolean mHomeConsumed;
495 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800496 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700497 Intent mCarDockIntent;
498 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700499 boolean mSearchKeyShortcutPending;
500 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700501 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700502 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800503
Mike Lockwood28569302010-01-28 11:54:40 -0500504 // support for activating the lock screen while the screen is on
505 boolean mAllowLockscreenWhenOn;
506 int mLockScreenTimeout;
507 boolean mLockScreenTimerActive;
508
David Brownbaf8d092010-03-08 21:52:59 -0800509 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800510 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800511
512 // Behavior of POWER button while in-call and screen on.
513 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
514 int mIncallPowerBehavior;
515
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700516 Display mDisplay;
517
Dianne Hackborn9d132642011-04-21 17:26:39 -0700518 int mLandscapeRotation = 0; // default landscape rotation
519 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
520 int mPortraitRotation = 0; // default portrait rotation
521 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700522
Dianne Hackbornc652de82013-02-15 16:32:56 -0800523 int mOverscanLeft = 0;
524 int mOverscanTop = 0;
525 int mOverscanRight = 0;
526 int mOverscanBottom = 0;
527
Joe Onorato46b0d682010-11-22 17:37:27 -0800528 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700529 private int mLongPressOnHomeBehavior;
530
531 // What we do when the user double-taps on home
532 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800533
Bryce Lee584a4452014-10-21 15:55:55 -0700534 // Allowed theater mode wake actions
535 private boolean mAllowTheaterModeWakeFromKey;
536 private boolean mAllowTheaterModeWakeFromPowerKey;
537 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800538 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700539 private boolean mAllowTheaterModeWakeFromCameraLens;
540 private boolean mAllowTheaterModeWakeFromLidSwitch;
541 private boolean mAllowTheaterModeWakeFromWakeGesture;
542
Bryce Lee55e846d2014-11-04 12:43:44 -0800543 // Whether to go to sleep entering theater mode from power button
544 private boolean mGoToSleepOnButtonPressTheaterMode;
545
Winson Chung9112ec32011-06-27 13:15:32 -0700546 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700547 // Time to volume and power must be pressed within this interval of each other.
548 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700549 // Increase the chord delay when taking a screenshot from the keyguard
550 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800551 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700552 private boolean mScreenshotChordVolumeDownKeyTriggered;
553 private long mScreenshotChordVolumeDownKeyTime;
554 private boolean mScreenshotChordVolumeDownKeyConsumed;
555 private boolean mScreenshotChordVolumeUpKeyTriggered;
556 private boolean mScreenshotChordPowerKeyTriggered;
557 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700558
Michael Wrightb854e242013-02-05 17:54:02 -0800559 /* The number of steps between min and max brightness */
560 private static final int BRIGHTNESS_STEPS = 10;
561
Christopher Tate5e08af02012-09-21 17:17:22 -0700562 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800563 ShortcutManager mShortcutManager;
564 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700565 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700566 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800567
Craig Mautnerd625ab22013-09-06 13:40:31 -0700568 private int mCurrentUserId;
569
Justin Kohd378ad72013-04-01 12:18:26 -0700570 // Maps global key codes to the components that will handle them.
571 private GlobalKeyManager mGlobalKeyManager;
572
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700573 // Fallback actions by key code.
574 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
575 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800576
Jorim Jaggi76a16232014-08-08 17:00:47 +0200577 private final LogDecelerateInterpolator mLogDecelerateInterpolator
578 = new LogDecelerateInterpolator(100, 0);
579
Jeff Brown70825162012-03-28 17:27:48 -0700580 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
581 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700582 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
583 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700584 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
585 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
586 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700587 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700588 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700589 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700590 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700591 private static final int MSG_POWER_DELAYED_PRESS = 13;
592 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown70825162012-03-28 17:27:48 -0700593
594 private class PolicyHandler extends Handler {
595 @Override
596 public void handleMessage(Message msg) {
597 switch (msg.what) {
598 case MSG_ENABLE_POINTER_LOCATION:
599 enablePointerLocation();
600 break;
601 case MSG_DISABLE_POINTER_LOCATION:
602 disablePointerLocation();
603 break;
Jeff Brown40013652012-05-16 21:22:36 -0700604 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
605 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
606 break;
607 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
608 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
609 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700610 case MSG_DISPATCH_SHOW_RECENTS:
611 showRecentApps(false);
612 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700613 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
614 showGlobalActionsInternal();
615 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700616 case MSG_KEYGUARD_DRAWN_COMPLETE:
617 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700618 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700619 break;
620 case MSG_KEYGUARD_DRAWN_TIMEOUT:
621 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700622 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700623 break;
624 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
625 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700626 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700627 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700628 case MSG_HIDE_BOOT_MESSAGE:
629 handleHideBootMessage();
630 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700631 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
632 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
633 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700634 case MSG_POWER_DELAYED_PRESS:
635 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
636 finishPowerKeyPress();
637 break;
638 case MSG_POWER_LONG_PRESS:
639 powerLongPress();
640 break;
Jeff Brown70825162012-03-28 17:27:48 -0700641 }
642 }
643 }
644
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800645 private UEventObserver mHDMIObserver = new UEventObserver() {
646 @Override
647 public void onUEvent(UEventObserver.UEvent event) {
648 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
649 }
650 };
651
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800652 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800653 SettingsObserver(Handler handler) {
654 super(handler);
655 }
David Brownbaf8d092010-03-08 21:52:59 -0800656
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800657 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700658 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800659 ContentResolver resolver = mContext.getContentResolver();
660 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700661 Settings.System.END_BUTTON_BEHAVIOR), false, this,
662 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800663 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700664 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
665 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700666 resolver.registerContentObserver(Settings.Secure.getUriFor(
667 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
668 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800669 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700670 Settings.System.ACCELEROMETER_ROTATION), false, this,
671 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500672 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700673 Settings.System.USER_ROTATION), false, this,
674 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400675 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700676 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
677 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800678 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700679 Settings.System.POINTER_LOCATION), false, this,
680 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800681 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700682 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
683 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500684 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400685 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700686 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500687 resolver.registerContentObserver(Settings.Global.getUriFor(
688 Settings.Global.POLICY_CONTROL), false, this,
689 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800690 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800691 }
692
693 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800694 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700695 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800696 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800697 }
Craig Mautner967212c2013-04-13 21:10:58 -0700698
Jeff Browna20dda42014-05-27 20:57:24 -0700699 class MyWakeGestureListener extends WakeGestureListener {
700 MyWakeGestureListener(Context context, Handler handler) {
701 super(context, handler);
702 }
703
704 @Override
705 public void onWakeUp() {
706 synchronized (mLock) {
707 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700708 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700709 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700710 }
711 }
712 }
713 }
714
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800715 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800716 MyOrientationListener(Context context, Handler handler) {
717 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800718 }
Craig Mautner967212c2013-04-13 21:10:58 -0700719
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800720 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700721 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700722 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700723 updateRotation(false);
724 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800725 }
726 MyOrientationListener mOrientationListener;
727
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100728 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400729
John Spurlock27735a42013-08-14 17:57:38 -0400730 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400731 View.NAVIGATION_BAR_TRANSIENT,
732 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400733 View.NAVIGATION_BAR_TRANSLUCENT,
734 StatusBarManager.WINDOW_NAVIGATION_BAR,
735 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400736
John Spurlockf1a36642013-10-12 17:50:42 -0400737 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400738
Craig Mautner037aa8d2013-06-07 10:35:44 -0700739 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400740
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700741 IStatusBarService getStatusBarService() {
742 synchronized (mServiceAquireLock) {
743 if (mStatusBarService == null) {
744 mStatusBarService = IStatusBarService.Stub.asInterface(
745 ServiceManager.getService("statusbar"));
746 }
747 return mStatusBarService;
748 }
749 }
750
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700751 /*
752 * We always let the sensor be switched on by default except when
753 * the user has explicitly disabled sensor based rotation or when the
754 * screen is switched off.
755 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700756 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800757 if (mSupportAutoRotation) {
758 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
759 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
760 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
761 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
762 // If the application has explicitly requested to follow the
763 // orientation, then we need to turn the sensor on.
764 return true;
765 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800766 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700767 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800768 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
769 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
770 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400771 // enable accelerometer if we are docked in a dock that enables accelerometer
772 // orientation management,
773 return true;
774 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700775 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800776 // If the setting for using the sensor by default is enabled, then
777 // we will always leave it on. Note that the user could go to
778 // a window that forces an orientation that does not use the
779 // sensor and in theory we could turn it off... however, when next
780 // turning it on we won't have a good value for the current
781 // orientation for a little bit, which can cause orientation
782 // changes to lag, so we'd like to keep it always on. (It will
783 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700784 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800785 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800786 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800787 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700788
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800789 /*
790 * Various use cases for invoking this function
791 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700792 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800793 * if not already enabled
794 * screen turned on and current app does not have sensor orientation, disable listeners if
795 * already enabled
796 * screen turning on and current app has sensor based orientation, enable listeners if needed
797 * screen turning on and current app has nosensor based orientation, do nothing
798 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700799 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800800 if (!mOrientationListener.canDetectOrientation()) {
801 // If sensor is turned off or nonexistent for some reason
802 return;
803 }
804 //Could have been invoked due to screen turning on or off or
805 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700806 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
807 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
808 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800809 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700810 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700811 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800812 disable = false;
813 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700814 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800815 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700816 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800817 mOrientationSensorEnabled = true;
818 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700819 }
820 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800821 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700822 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800823 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700824 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800825 mOrientationSensorEnabled = false;
826 }
827 }
828
Jeff Brown13f00f02014-10-31 14:45:50 -0700829 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
830 // Hold a wake lock until the power key is released.
831 if (!mPowerKeyWakeLock.isHeld()) {
832 mPowerKeyWakeLock.acquire();
833 }
834
835 // Cancel multi-press detection timeout.
836 if (mPowerKeyPressCounter != 0) {
837 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
838 }
839
840 // Detect user pressing the power button in panic when an application has
841 // taken over the whole screen.
842 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800843 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700844 if (panic) {
845 mHandler.post(mRequestTransientNav);
846 }
847
848 // Latch power key state to detect screenshot chord.
849 if (interactive && !mScreenshotChordPowerKeyTriggered
850 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
851 mScreenshotChordPowerKeyTriggered = true;
852 mScreenshotChordPowerKeyTime = event.getDownTime();
853 interceptScreenshotChord();
854 }
855
856 // Stop ringing or end call if configured to do so when power is pressed.
857 TelecomManager telecomManager = getTelecommService();
858 boolean hungUp = false;
859 if (telecomManager != null) {
860 if (telecomManager.isRinging()) {
861 // Pressing Power while there's a ringing incoming
862 // call should silence the ringer.
863 telecomManager.silenceRinger();
864 } else if ((mIncallPowerBehavior
865 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
866 && telecomManager.isInCall() && interactive) {
867 // Otherwise, if "Power button ends call" is enabled,
868 // the Power button will hang up any current active call.
869 hungUp = telecomManager.endCall();
870 }
871 }
872
873 // If the power key has still not yet been handled, then detect short
874 // press, long press, or multi press and decide what to do.
875 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
876 || mScreenshotChordVolumeUpKeyTriggered;
877 if (!mPowerKeyHandled) {
878 if (interactive) {
879 // When interactive, we're already awake.
880 // Wait for a long press or for the button to be released to decide what to do.
881 if (hasLongPressOnPowerBehavior()) {
882 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
883 msg.setAsynchronous(true);
884 mHandler.sendMessageDelayed(msg,
885 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
886 }
887 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800888 wakeUpFromPowerKey(event.getDownTime());
Jeff Brown13f00f02014-10-31 14:45:50 -0700889 final int maxCount = getMaxMultiPressPowerCount();
Bryce Leed9268e32014-11-17 17:40:59 -0800890
Jeff Brown13f00f02014-10-31 14:45:50 -0700891 if (maxCount <= 1) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700892 mPowerKeyHandled = true;
Bryce Leed9268e32014-11-17 17:40:59 -0800893 } else {
894 mBeganFromNonInteractive = true;
Jeff Brown13f00f02014-10-31 14:45:50 -0700895 }
896 }
Jeff Brown4d396052010-10-29 21:50:21 -0700897 }
898 }
899
Jeff Brown13f00f02014-10-31 14:45:50 -0700900 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
901 final boolean handled = canceled || mPowerKeyHandled;
902 mScreenshotChordPowerKeyTriggered = false;
903 cancelPendingScreenshotChordAction();
904 cancelPendingPowerKeyAction();
905
906 if (!handled) {
907 // Figure out how to handle the key now that it has been released.
908 mPowerKeyPressCounter += 1;
909
910 final int maxCount = getMaxMultiPressPowerCount();
911 final long eventTime = event.getDownTime();
912 if (mPowerKeyPressCounter < maxCount) {
913 // This could be a multi-press. Wait a little bit longer to confirm.
914 // Continue holding the wake lock.
915 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
916 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
917 msg.setAsynchronous(true);
918 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
919 return;
920 }
921
922 // No other actions. Handle it immediately.
923 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700924 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700925
926 // Done. Reset our state.
927 finishPowerKeyPress();
928 }
929
930 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800931 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700932 mPowerKeyPressCounter = 0;
933 if (mPowerKeyWakeLock.isHeld()) {
934 mPowerKeyWakeLock.release();
935 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700936 }
937
938 private void cancelPendingPowerKeyAction() {
939 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700940 mPowerKeyHandled = true;
941 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700942 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700943 }
944
945 private void powerPress(long eventTime, boolean interactive, int count) {
946 if (mScreenOnEarly && !mScreenOnFully) {
947 Slog.i(TAG, "Suppressed redundant power key press while "
948 + "already in the process of turning the screen on.");
949 return;
Jeff Brownff204712011-10-25 21:27:54 -0700950 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700951
952 if (count == 2) {
953 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
954 } else if (count == 3) {
955 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -0800956 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700957 switch (mShortPressOnPowerBehavior) {
958 case SHORT_PRESS_POWER_NOTHING:
959 break;
960 case SHORT_PRESS_POWER_GO_TO_SLEEP:
961 mPowerManager.goToSleep(eventTime,
962 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
963 break;
964 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
965 mPowerManager.goToSleep(eventTime,
966 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
967 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
968 break;
969 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
970 mPowerManager.goToSleep(eventTime,
971 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
972 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
973 launchHomeFromHotKey();
974 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800975 case SHORT_PRESS_POWER_GO_HOME:
976 launchHomeFromHotKey();
977 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700978 }
979 }
980 }
981
982 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
983 switch (behavior) {
984 case MULTI_PRESS_POWER_NOTHING:
985 break;
986 case MULTI_PRESS_POWER_THEATER_MODE:
987 if (isTheaterModeEnabled()) {
988 Slog.i(TAG, "Toggling theater mode off.");
989 Settings.Global.putInt(mContext.getContentResolver(),
990 Settings.Global.THEATER_MODE_ON, 0);
991 if (!interactive) {
992 wakeUpFromPowerKey(eventTime);
993 }
994 } else {
995 Slog.i(TAG, "Toggling theater mode on.");
996 Settings.Global.putInt(mContext.getContentResolver(),
997 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -0800998
999 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001000 mPowerManager.goToSleep(eventTime,
1001 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1002 }
1003 }
1004 break;
1005 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001006 Slog.i(TAG, "Starting brightness boost.");
1007 if (!interactive) {
1008 wakeUpFromPowerKey(eventTime);
1009 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001010 mPowerManager.boostScreenBrightness(eventTime);
1011 break;
1012 }
1013 }
1014
1015 private int getMaxMultiPressPowerCount() {
1016 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1017 return 3;
1018 }
1019 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1020 return 2;
1021 }
1022 return 1;
1023 }
1024
1025 private void powerLongPress() {
1026 final int behavior = getResolvedLongPressOnPowerBehavior();
1027 switch (behavior) {
1028 case LONG_PRESS_POWER_NOTHING:
1029 break;
1030 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1031 mPowerKeyHandled = true;
1032 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1033 performAuditoryFeedbackForAccessibilityIfNeed();
1034 }
1035 showGlobalActionsInternal();
1036 break;
1037 case LONG_PRESS_POWER_SHUT_OFF:
1038 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1039 mPowerKeyHandled = true;
1040 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1041 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1042 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1043 break;
1044 }
1045 }
1046
1047 private int getResolvedLongPressOnPowerBehavior() {
1048 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1049 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1050 }
1051 return mLongPressOnPowerBehavior;
1052 }
1053
1054 private boolean hasLongPressOnPowerBehavior() {
1055 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001056 }
1057
1058 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001059 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001060 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1061 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001062 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001063 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1064 && now <= mScreenshotChordPowerKeyTime
1065 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1066 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001067 cancelPendingPowerKeyAction();
1068
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001069 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001070 }
1071 }
1072 }
1073
Winson Chung1cea2f32012-10-08 20:42:01 -07001074 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001075 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001076 // Double the time it takes to take a screenshot from the keyguard
1077 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001078 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001079 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001080 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001081 }
1082
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001083 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001084 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001085 }
1086
Jeff Brown13f00f02014-10-31 14:45:50 -07001087 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001088 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001089 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001090 mEndCallKeyHandled = true;
1091 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1092 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001093 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001094 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001095 }
1096 };
1097
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001098 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001099 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001100 public void run() {
1101 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001102 }
1103 };
1104
Alan Viverettee34560b22014-07-10 14:50:06 -07001105 @Override
1106 public void showGlobalActions() {
1107 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1108 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1109 }
1110
1111 void showGlobalActionsInternal() {
1112 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001113 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001114 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001115 }
Jim Millerab954542014-10-10 18:21:49 -07001116 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001117 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1118 if (keyguardShowing) {
1119 // since it took two seconds of long press to bring this up,
1120 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001121 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001122 }
1123 }
1124
1125 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001126 return Settings.Global.getInt(
1127 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001128 }
1129
Maurice Lam99c6e072014-04-28 18:24:28 -07001130 boolean isUserSetupComplete() {
1131 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1132 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1133 }
1134
Jeff Brown13f00f02014-10-31 14:45:50 -07001135 private void handleShortPressOnHome() {
1136 // If there's a dream running then use home to escape the dream
1137 // but don't actually go home.
1138 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1139 mDreamManagerInternal.stopDream(false /*immediate*/);
1140 return;
1141 }
1142
1143 // Go home!
1144 launchHomeFromHotKey();
1145 }
1146
Patrick Dubroyece94522011-02-23 18:35:01 -08001147 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -08001148 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001149 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001150 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001151
Jeff Browncaca8812013-05-09 13:34:33 -07001152 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1153 toggleRecentApps();
1154 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1155 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -07001156 }
1157 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001158 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001159
Jeff Browncaca8812013-05-09 13:34:33 -07001160 private void handleDoubleTapOnHome() {
1161 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1162 mHomeConsumed = true;
1163 toggleRecentApps();
1164 }
1165 }
1166
1167 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1168 @Override
1169 public void run() {
1170 if (mHomeDoubleTapPending) {
1171 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001172 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001173 }
1174 }
1175 };
1176
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001177 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001178 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001179 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001180 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001181 mContext = context;
1182 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001183 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001184 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001185 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001186 if (context.getResources().getBoolean(
1187 com.android.internal.R.bool.config_enableBurnInProtection)){
1188 mBurnInProtectionHelper = new BurnInProtectionHelper(context);
1189 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001190
Jeff Brown70825162012-03-28 17:27:48 -07001191 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001192 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001193 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001194 try {
1195 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1196 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001197 mSettingsObserver = new SettingsObserver(mHandler);
1198 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001199 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001200 mUiMode = context.getResources().getInteger(
1201 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001202 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1203 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1204 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1205 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001206 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1207 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1208 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1209 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1210 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1211 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1212 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1213 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001214
Jeff Brown96307042012-07-27 15:51:34 -07001215 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1216 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001217 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001218 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1219 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001220 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001221 mSupportAutoRotation = mContext.getResources().getBoolean(
1222 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001223 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001224 com.android.internal.R.integer.config_lidOpenRotation);
1225 mCarDockRotation = readRotation(
1226 com.android.internal.R.integer.config_carDockRotation);
1227 mDeskDockRotation = readRotation(
1228 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001229 mUndockedHdmiRotation = readRotation(
1230 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001231 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1232 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1233 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1234 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001235 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1236 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1237 mLidNavigationAccessibility = mContext.getResources().getInteger(
1238 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001239 mLidControlsSleep = mContext.getResources().getBoolean(
1240 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001241 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1242 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001243
1244 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1245 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1246 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1247 || mContext.getResources().getBoolean(
1248 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1249 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1250 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001251 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1252 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001253 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1254 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1255 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1256 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1257 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1258 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1259
Bryce Lee55e846d2014-11-04 12:43:44 -08001260 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1261 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1262
Jeff Brown13f00f02014-10-31 14:45:50 -07001263 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1264 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1265 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1266 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1267 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1268 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1269 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1270 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
1271
John Spurlock61560172015-02-06 19:46:04 -05001272 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001273 mUseMasterVolume = mContext.getResources().getBoolean(
1274 com.android.internal.R.bool.config_useMasterVolume);
1275
Jeff Brownf71343d2013-05-31 17:59:11 -07001276 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001277
Svetoslav8e3feb12014-02-24 13:46:47 -08001278 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1279 Context.ACCESSIBILITY_SERVICE);
1280
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001281 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001282 IntentFilter filter = new IntentFilter();
1283 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1284 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1285 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1286 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001287 filter.addAction(Intent.ACTION_DOCK_EVENT);
1288 Intent intent = context.registerReceiver(mDockReceiver, filter);
1289 if (intent != null) {
1290 // Retrieve current sticky dock event broadcast.
1291 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1292 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1293 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001294
Jeff Brown6aaf2952012-10-05 16:01:08 -07001295 // register for dream-related broadcasts
1296 filter = new IntentFilter();
1297 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1298 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1299 context.registerReceiver(mDreamReceiver, filter);
1300
Christopher Tate5e08af02012-09-21 17:17:22 -07001301 // register for multiuser-relevant broadcasts
1302 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1303 context.registerReceiver(mMultiuserReceiver, filter);
1304
John Spurlock57306e62013-04-22 09:48:49 -04001305 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001306 mSystemGestures = new SystemGesturesPointerEventListener(context,
1307 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001308 @Override
1309 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001310 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001311 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001312 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001313 }
1314 @Override
1315 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001316 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001317 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001318 }
1319 }
1320 @Override
1321 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001322 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001323 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001324 }
1325 }
1326 @Override
1327 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001328 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001329 }
1330 });
John Spurlockf1a36642013-10-12 17:50:42 -04001331 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001332 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001333
Jeff Brownc2346132012-04-13 01:55:38 -07001334 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001335 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1336 com.android.internal.R.array.config_longPressVibePattern);
1337 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1338 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001339 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1340 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001341 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1342 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001343 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1344 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001345 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1346 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1347 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1348 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001349
Christopher Tatee90585f2012-03-05 18:56:25 -08001350 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1351 com.android.internal.R.bool.config_enableScreenshotChord);
1352
Justin Kohd378ad72013-04-01 12:18:26 -07001353 mGlobalKeyManager = new GlobalKeyManager(mContext);
1354
Joe Onoratoea495d42011-04-06 11:41:11 -07001355 // Controls rotation and the like.
1356 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001357
1358 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001359 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001360 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001361 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001362
1363 mWindowManagerInternal.registerAppTransitionListener(
1364 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001365 }
1366
Jeff Brownf71343d2013-05-31 17:59:11 -07001367 /**
1368 * Read values from config.xml that may be overridden depending on
1369 * the configuration of the device.
1370 * eg. Disable long press on home goes to recents on sw600dp.
1371 */
1372 private void readConfigurationDependentBehaviors() {
1373 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1374 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1375 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1376 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1377 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1378 }
1379
1380 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1381 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1382 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1383 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1384 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1385 }
1386 }
1387
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001388 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001389 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001390 // This method might be called before the policy has been fully initialized
1391 // or for other displays we don't care about.
1392 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1393 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001394 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001395 mDisplay = display;
1396
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001397 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001398 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001399 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001400 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001401 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001402 mLandscapeRotation = Surface.ROTATION_0;
1403 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001404 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001405 mPortraitRotation = Surface.ROTATION_90;
1406 mUpsideDownRotation = Surface.ROTATION_270;
1407 } else {
1408 mPortraitRotation = Surface.ROTATION_270;
1409 mUpsideDownRotation = Surface.ROTATION_90;
1410 }
1411 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001412 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001413 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001414 mPortraitRotation = Surface.ROTATION_0;
1415 mUpsideDownRotation = 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 mLandscapeRotation = Surface.ROTATION_270;
1418 mSeascapeRotation = Surface.ROTATION_90;
1419 } else {
1420 mLandscapeRotation = Surface.ROTATION_90;
1421 mSeascapeRotation = Surface.ROTATION_270;
1422 }
1423 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001424
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001425 mStatusBarHeight =
1426 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001427
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001428 // Height of the navigation bar when presented horizontally at bottom
1429 mNavigationBarHeightForRotation[mPortraitRotation] =
1430 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001431 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001432 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001433 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1434 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001435
1436 // Width of the navigation bar when presented vertically along one side
1437 mNavigationBarWidthForRotation[mPortraitRotation] =
1438 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1439 mNavigationBarWidthForRotation[mLandscapeRotation] =
1440 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001441 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001442
1443 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001444 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001445 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001446
Devin Kimd7b12b42014-05-05 14:34:58 -07001447 // Allow the navigation bar to move on non-square small devices (phones).
1448 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001449
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001450 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001451 // Allow a system property to override this. Used by the emulator.
1452 // See also hasNavigationBar().
1453 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1454 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001455 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001456 } else if ("0".equals(navBarOverride)) {
1457 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001458 }
1459
Jeff Brown27f1d672012-10-17 18:32:34 -07001460 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1461 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001462 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001463 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001464 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001465 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001466 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001467 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001468
Chong Zhangae6119ff2014-11-11 18:54:39 -08001469 // For demo purposes, allow the rotation of the remote display to be controlled.
1470 // By default, remote display locks rotation to landscape.
1471 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1472 mDemoRotation = mPortraitRotation;
1473 } else {
1474 mDemoRotation = mLandscapeRotation;
1475 }
1476 mDemoRotationLock = SystemProperties.getBoolean(
1477 "persist.demo.rotationlock", false);
1478
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001479 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1480 // http://developer.android.com/guide/practices/screens_support.html#range
1481 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1482 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1483 // For debug purposes the next line turns this feature off with:
1484 // $ adb shell setprop config.override_forced_orient true
1485 // $ adb shell wm size reset
1486 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1487 }
1488
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001489 /**
1490 * @return whether the navigation bar can be hidden, e.g. the device has a
1491 * navigation bar and touch exploration is not enabled
1492 */
1493 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001494 return mHasNavigationBar
1495 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001496 }
1497
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001498 @Override
1499 public boolean isDefaultOrientationForced() {
1500 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001501 }
1502
Dianne Hackbornc652de82013-02-15 16:32:56 -08001503 @Override
1504 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1505 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1506 mOverscanLeft = left;
1507 mOverscanTop = top;
1508 mOverscanRight = right;
1509 mOverscanBottom = bottom;
1510 }
1511 }
1512
Dianne Hackbornc777e072010-02-12 13:07:59 -08001513 public void updateSettings() {
1514 ContentResolver resolver = mContext.getContentResolver();
1515 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001516 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001517 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001518 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001519 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1520 UserHandle.USER_CURRENT);
1521 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001522 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001523 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1524 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001525
Jeff Browna20dda42014-05-27 20:57:24 -07001526 // Configure wake gesture.
1527 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1528 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1529 UserHandle.USER_CURRENT) != 0;
1530 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1531 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1532 updateWakeGestureListenerLp();
1533 }
1534
Jeff Brown207673cd2012-06-05 17:47:11 -07001535 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001536 int userRotation = Settings.System.getIntForUser(resolver,
1537 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1538 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001539 if (mUserRotation != userRotation) {
1540 mUserRotation = userRotation;
1541 updateRotation = true;
1542 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001543 int userRotationMode = Settings.System.getIntForUser(resolver,
1544 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001545 WindowManagerPolicy.USER_ROTATION_FREE :
1546 WindowManagerPolicy.USER_ROTATION_LOCKED;
1547 if (mUserRotationMode != userRotationMode) {
1548 mUserRotationMode = userRotationMode;
1549 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001550 updateOrientationListenerLp();
1551 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001552
Dianne Hackbornc777e072010-02-12 13:07:59 -08001553 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001554 int pointerLocation = Settings.System.getIntForUser(resolver,
1555 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001556 if (mPointerLocationMode != pointerLocation) {
1557 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001558 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1559 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001560 }
1561 }
1562 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001563 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1564 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1565 String imId = Settings.Secure.getStringForUser(resolver,
1566 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001567 boolean hasSoftInput = imId != null && imId.length() > 0;
1568 if (mHasSoftInput != hasSoftInput) {
1569 mHasSoftInput = hasSoftInput;
1570 updateRotation = true;
1571 }
John Spurlockf1a36642013-10-12 17:50:42 -04001572 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001573 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001574 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001575 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001576 }
1577 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001578 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001579 }
Jeff Brown70825162012-03-28 17:27:48 -07001580 }
1581
Jeff Browna20dda42014-05-27 20:57:24 -07001582 private void updateWakeGestureListenerLp() {
1583 if (shouldEnableWakeGestureLp()) {
1584 mWakeGestureListener.requestWakeUpTrigger();
1585 } else {
1586 mWakeGestureListener.cancelWakeUpTrigger();
1587 }
1588 }
1589
1590 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001591 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001592 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1593 && mWakeGestureListener.isSupported();
1594 }
1595
Jeff Brown70825162012-03-28 17:27:48 -07001596 private void enablePointerLocation() {
1597 if (mPointerLocationView == null) {
1598 mPointerLocationView = new PointerLocationView(mContext);
1599 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001600 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1601 WindowManager.LayoutParams.MATCH_PARENT,
1602 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001603 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001604 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1605 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1606 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1607 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001608 if (ActivityManager.isHighEndGfx()) {
1609 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1610 lp.privateFlags |=
1611 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1612 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001613 lp.format = PixelFormat.TRANSLUCENT;
1614 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001615 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001616 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001617 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001618 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001619 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001620 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001621 }
Jeff Brown70825162012-03-28 17:27:48 -07001622
1623 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001624 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001625 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1626 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001627 wm.removeView(mPointerLocationView);
1628 mPointerLocationView = null;
1629 }
1630 }
1631
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001632 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001633 try {
1634 int rotation = mContext.getResources().getInteger(resID);
1635 switch (rotation) {
1636 case 0:
1637 return Surface.ROTATION_0;
1638 case 90:
1639 return Surface.ROTATION_90;
1640 case 180:
1641 return Surface.ROTATION_180;
1642 case 270:
1643 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001644 }
1645 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001646 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001647 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001648 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001649 }
1650
1651 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001652 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001653 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001654 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001655
1656 outAppOp[0] = AppOpsManager.OP_NONE;
1657
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001658 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1659 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1660 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1661 return WindowManagerGlobal.ADD_INVALID_TYPE;
1662 }
1663
1664 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1665 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001666 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001667 }
1668 String permission = null;
1669 switch (type) {
1670 case TYPE_TOAST:
1671 // XXX right now the app process has complete control over
1672 // this... should introduce a token to let the system
1673 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001674 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001675 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001676 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001677 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001678 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001679 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001680 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001681 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001682 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001683 break;
1684 case TYPE_PHONE:
1685 case TYPE_PRIORITY_PHONE:
1686 case TYPE_SYSTEM_ALERT:
1687 case TYPE_SYSTEM_ERROR:
1688 case TYPE_SYSTEM_OVERLAY:
1689 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001690 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001691 break;
1692 default:
1693 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1694 }
1695 if (permission != null) {
1696 if (mContext.checkCallingOrSelfPermission(permission)
1697 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001698 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001699 }
1700 }
Jeff Brown98365d72012-08-19 20:30:52 -07001701 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001702 }
Craig Mautner88400d32012-09-30 12:35:45 -07001703
1704 @Override
1705 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1706
1707 // If this switch statement is modified, modify the comment in the declarations of
1708 // the type in {@link WindowManager.LayoutParams} as well.
1709 switch (attrs.type) {
1710 default:
1711 // These are the windows that by default are shown only to the user that created
1712 // them. If this needs to be overridden, set
1713 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1714 // {@link WindowManager.LayoutParams}. Note that permission
1715 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1716 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1717 return true;
1718 }
1719 break;
1720
1721 // These are the windows that by default are shown to all users. However, to
1722 // protect against spoofing, check permissions below.
1723 case TYPE_APPLICATION_STARTING:
1724 case TYPE_BOOT_PROGRESS:
1725 case TYPE_DISPLAY_OVERLAY:
1726 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001727 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001728 case TYPE_KEYGUARD_DIALOG:
1729 case TYPE_MAGNIFICATION_OVERLAY:
1730 case TYPE_NAVIGATION_BAR:
1731 case TYPE_NAVIGATION_BAR_PANEL:
1732 case TYPE_PHONE:
1733 case TYPE_POINTER:
1734 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001735 case TYPE_SEARCH_BAR:
1736 case TYPE_STATUS_BAR:
1737 case TYPE_STATUS_BAR_PANEL:
1738 case TYPE_STATUS_BAR_SUB_PANEL:
1739 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001740 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001741 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001742 break;
1743 }
1744
1745 // Check if third party app has set window to system window type.
1746 return mContext.checkCallingOrSelfPermission(
1747 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1748 != PackageManager.PERMISSION_GRANTED;
1749 }
1750
Craig Mautner967212c2013-04-13 21:10:58 -07001751 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001752 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1753 switch (attrs.type) {
1754 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001755 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001756 // These types of windows can't receive input events.
1757 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1758 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001759 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001760 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001761 case TYPE_STATUS_BAR:
1762
1763 // If the Keyguard is in a hidden state (occluded by another window), we force to
1764 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1765 // the keyguard as occluded wouldn't set these flags again.
1766 // See {@link #processKeyguardSetHiddenResultLw}.
1767 if (mKeyguardHidden) {
1768 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1769 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1770 }
1771 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001772 }
Adrian Roos38502112014-04-09 21:04:11 +02001773
1774 if (attrs.type != TYPE_STATUS_BAR) {
1775 // The status bar is the only window allowed to exhibit keyguard behavior.
1776 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1777 }
Adrian Roosea562512014-05-05 13:33:03 +02001778
1779 if (ActivityManager.isHighEndGfx()
1780 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001781 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001782 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1783 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001784 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001785
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001786 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001787 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001788 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001789
Michael Wright3818c922014-09-02 13:59:07 -07001790 private void readCameraLensCoverState() {
1791 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1792 }
1793
Jeff Browndaa37532012-05-01 15:54:03 -07001794 private boolean isHidden(int accessibilityMode) {
1795 switch (accessibilityMode) {
1796 case 1:
1797 return mLidState == LID_CLOSED;
1798 case 2:
1799 return mLidState == LID_OPEN;
1800 default:
1801 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001802 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001803 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001804
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001805 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001806 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001807 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1808 int navigationPresence) {
1809 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1810
Jeff Brownf71343d2013-05-31 17:59:11 -07001811 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001812 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001813 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001814
Jeff Browndaa37532012-05-01 15:54:03 -07001815 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1816 || (keyboardPresence == PRESENCE_INTERNAL
1817 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001818 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001819 if (!mHasSoftInput) {
1820 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1821 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001822 }
1823
Jeff Browndaa37532012-05-01 15:54:03 -07001824 if (config.navigation == Configuration.NAVIGATION_NONAV
1825 || (navigationPresence == PRESENCE_INTERNAL
1826 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001827 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001828 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001829 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001830
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001831 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001832 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001833 public int windowTypeToLayerLw(int type) {
1834 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001835 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001836 }
1837 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001838 case TYPE_PRIVATE_PRESENTATION:
1839 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001840 case TYPE_WALLPAPER:
1841 // wallpaper is at the bottom, though the window manager may move it.
1842 return 2;
1843 case TYPE_PHONE:
1844 return 3;
1845 case TYPE_SEARCH_BAR:
1846 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001847 case TYPE_VOICE_INTERACTION:
1848 // voice interaction layer is almost immediately above apps.
1849 return 5;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001850 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001851 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001852 case TYPE_TOAST:
1853 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001854 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001855 case TYPE_PRIORITY_PHONE:
1856 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001857 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001858 case TYPE_DREAM:
1859 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001860 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001861 case TYPE_SYSTEM_ALERT:
1862 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001863 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001864 case TYPE_INPUT_METHOD:
1865 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001866 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001867 case TYPE_INPUT_METHOD_DIALOG:
1868 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001869 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001870 case TYPE_KEYGUARD_SCRIM:
1871 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001872 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001873 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001874 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001875 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001876 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001877 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001878 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001879 case TYPE_KEYGUARD_DIALOG:
1880 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001881 case TYPE_VOLUME_OVERLAY:
1882 // the on-screen volume indicator and controller shown when the user
1883 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001884 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001885 case TYPE_SYSTEM_OVERLAY:
1886 // the on-screen volume indicator and controller shown when the user
1887 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001888 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001889 case TYPE_NAVIGATION_BAR:
1890 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001891 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001892 case TYPE_NAVIGATION_BAR_PANEL:
1893 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001894 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001895 case TYPE_SYSTEM_ERROR:
1896 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001897 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001898 case TYPE_MAGNIFICATION_OVERLAY:
1899 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001900 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001901 case TYPE_DISPLAY_OVERLAY:
1902 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001903 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001904 case TYPE_DRAG:
1905 // the drag layer: input for drag-and-drop is associated with this window,
1906 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001907 return 25;
Svetoslav3a5c7212014-10-14 09:54:26 -07001908 case TYPE_ACCESSIBILITY_OVERLAY:
1909 // overlay put by accessibility services to intercept user interaction
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001910 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07001911 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001912 return 27;
Svetoslav3a5c7212014-10-14 09:54:26 -07001913 case TYPE_BOOT_PROGRESS:
1914 return 28;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001915 case TYPE_POINTER:
1916 // the (mouse) pointer layer
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001917 return 29;
Svetoslav3a5c7212014-10-14 09:54:26 -07001918 case TYPE_HIDDEN_NAV_CONSUMER:
1919 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001920 }
1921 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001922 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001923 }
1924
1925 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001926 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001927 public int subWindowTypeToLayerLw(int type) {
1928 switch (type) {
1929 case TYPE_APPLICATION_PANEL:
1930 case TYPE_APPLICATION_ATTACHED_DIALOG:
1931 return APPLICATION_PANEL_SUBLAYER;
1932 case TYPE_APPLICATION_MEDIA:
1933 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001934 case TYPE_APPLICATION_MEDIA_OVERLAY:
1935 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001936 case TYPE_APPLICATION_SUB_PANEL:
1937 return APPLICATION_SUB_PANEL_SUBLAYER;
1938 }
1939 Log.e(TAG, "Unknown sub-window type: " + type);
1940 return 0;
1941 }
1942
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001943 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001944 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001945 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001946 }
1947
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001948 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001949 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001950 if (mHasNavigationBar) {
1951 // For a basic navigation bar, when we are in landscape mode we place
1952 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001953 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1954 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001955 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001956 }
1957 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001958 }
1959
Jose Lima9546b202014-07-02 17:21:51 -07001960 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001961 public int getNonDecorDisplayHeight(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 portrait mode we place
1964 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001965 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1966 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001967 }
1968 }
1969 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001970 }
1971
Jose Lima9546b202014-07-02 17:21:51 -07001972 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001973 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1974 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001975 }
1976
Jose Lima9546b202014-07-02 17:21:51 -07001977 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001978 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001979 // There is a separate status bar at the top of the display. We don't count that as part
1980 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001981 // we do want to exclude it since applications can't generally use that part
1982 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001983 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001984 }
1985
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001986 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07001987 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
1988 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07001989 (isKeyguardHostWindow(attrs) &&
1990 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02001991 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001992 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001993
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001994 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02001995 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
1996 return attrs.type == TYPE_STATUS_BAR;
1997 }
1998
1999 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002000 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002001 switch (attrs.type) {
2002 case TYPE_STATUS_BAR:
2003 case TYPE_NAVIGATION_BAR:
2004 case TYPE_WALLPAPER:
2005 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002006 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002007 return false;
2008 default:
2009 return true;
2010 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002011 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002012
Craig Mautner7d7808f2014-09-11 18:02:38 -07002013 @Override
2014 public WindowState getWinShowWhenLockedLw() {
2015 return mWinShowWhenLocked;
2016 }
2017
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002018 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002019 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002020 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2021 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002022 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002023 if (!SHOW_STARTING_ANIMATIONS) {
2024 return null;
2025 }
2026 if (packageName == null) {
2027 return null;
2028 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002029
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002030 WindowManager wm = null;
2031 View view = null;
2032
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002033 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002034 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002035 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2036 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2037 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002038 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002039 try {
2040 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002041 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002042 } catch (PackageManager.NameNotFoundException e) {
2043 // Ignore
2044 }
2045 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002046
Jorim Jaggib10e33f2015-02-04 21:57:40 +01002047 Window win = new PhoneWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002048 final TypedArray ta = win.getWindowStyle();
2049 if (ta.getBoolean(
2050 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2051 || ta.getBoolean(
2052 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002053 return null;
2054 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002055
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002056 Resources r = context.getResources();
2057 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002058
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002059 win.setType(
2060 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
2061 // Force the window flags: this is a fake window, so it is not really
2062 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2063 // flag because we do know that the next window will take input
2064 // focus, so we want to get the IME window up on top of us right away.
2065 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002066 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002067 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2068 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2069 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002070 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002071 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2072 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2073 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002074
Adam Powell04fe6eb2013-05-31 14:39:48 -07002075 win.setDefaultIcon(icon);
2076 win.setDefaultLogo(logo);
2077
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002078 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002079 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002080
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002081 final WindowManager.LayoutParams params = win.getAttributes();
2082 params.token = appToken;
2083 params.packageName = packageName;
2084 params.windowAnimations = win.getWindowStyle().getResourceId(
2085 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002086 params.privateFlags |=
2087 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002088 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002089
2090 if (!compatInfo.supportsScreen()) {
2091 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2092 }
2093
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002094 params.setTitle("Starting " + packageName);
2095
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002096 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2097 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002098
2099 if (win.isFloating()) {
2100 // Whoops, there is no way to display an animation/preview
2101 // of such a thing! After all that work... let's skip it.
2102 // (Note that we must do this here because it is in
2103 // getDecorView() where the theme is evaluated... maybe
2104 // we should peek the floating attribute from the theme
2105 // earlier.)
2106 return null;
2107 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002108
Craig Mautner6fbda632012-07-03 09:26:39 -07002109 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002110 TAG, "Adding starting window for " + packageName
2111 + " / " + appToken + ": "
2112 + (view.getParent() != null ? view : null));
2113
2114 wm.addView(view, params);
2115
2116 // Only return the view if it was successfully added to the
2117 // window manager... which we can tell by it having a parent.
2118 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002119 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002120 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002121 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2122 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002123 } catch (RuntimeException e) {
2124 // don't crash if something else bad happens, for example a
2125 // failure loading resources because we are loading from an app
2126 // on external storage that has been unmounted.
2127 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002128 } finally {
2129 if (view != null && view.getParent() == null) {
2130 Log.w(TAG, "view not successfully added to wm, removing view");
2131 wm.removeViewImmediate(view);
2132 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002133 }
2134
2135 return null;
2136 }
2137
2138 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002139 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002140 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002141 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2142 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002143
2144 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002145 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002146 wm.removeView(window);
2147 }
2148 }
2149
2150 /**
2151 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002152 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002153 * Currently enforces that three window types are singletons:
2154 * <ul>
2155 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002156 * <li>KEYGUARD_TYPE</li>
2157 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002158 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002159 * @param win The window to be added
2160 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002161 *
Jeff Brown98365d72012-08-19 20:30:52 -07002162 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2163 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002164 */
Jose Lima9546b202014-07-02 17:21:51 -07002165 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002166 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2167 switch (attrs.type) {
2168 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002169 mContext.enforceCallingOrSelfPermission(
2170 android.Manifest.permission.STATUS_BAR_SERVICE,
2171 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002172 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002173 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002174 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002175 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002176 }
2177 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002178 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002179 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002180 case TYPE_NAVIGATION_BAR:
2181 mContext.enforceCallingOrSelfPermission(
2182 android.Manifest.permission.STATUS_BAR_SERVICE,
2183 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002184 if (mNavigationBar != null) {
2185 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002186 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002187 }
2188 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002189 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002190 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002191 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002192 break;
Jim Millere898ac52012-04-06 17:10:57 -07002193 case TYPE_NAVIGATION_BAR_PANEL:
2194 mContext.enforceCallingOrSelfPermission(
2195 android.Manifest.permission.STATUS_BAR_SERVICE,
2196 "PhoneWindowManager");
2197 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08002198 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002199 mContext.enforceCallingOrSelfPermission(
2200 android.Manifest.permission.STATUS_BAR_SERVICE,
2201 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08002202 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002203 case TYPE_STATUS_BAR_SUB_PANEL:
2204 mContext.enforceCallingOrSelfPermission(
2205 android.Manifest.permission.STATUS_BAR_SERVICE,
2206 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002207 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002208 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002209 if (mKeyguardScrim != null) {
2210 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2211 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002212 mKeyguardScrim = win;
2213 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002214 }
Jeff Brown98365d72012-08-19 20:30:52 -07002215 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002216 }
2217
2218 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002219 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002220 public void removeWindowLw(WindowState win) {
2221 if (mStatusBar == win) {
2222 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002223 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002224 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002225 } else if (mKeyguardScrim == win) {
2226 Log.v(TAG, "Removing keyguard scrim");
2227 mKeyguardScrim = null;
2228 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002229 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002230 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002231 }
2232 }
2233
2234 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002235
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002236 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002237 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002238 public int selectAnimationLw(WindowState win, int transit) {
2239 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2240 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002241 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002242 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002243 if (transit == TRANSIT_EXIT
2244 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002245 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002246 } else if (transit == TRANSIT_ENTER
2247 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002248 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002249 }
2250 } else if (win == mNavigationBar) {
2251 // This can be on either the bottom or the right.
2252 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002253 if (transit == TRANSIT_EXIT
2254 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002255 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002256 } else if (transit == TRANSIT_ENTER
2257 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002258 return R.anim.dock_bottom_enter;
2259 }
2260 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002261 if (transit == TRANSIT_EXIT
2262 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002263 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002264 } else if (transit == TRANSIT_ENTER
2265 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002266 return R.anim.dock_right_enter;
2267 }
2268 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002269 }
2270
2271 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002272 if (win.hasAppShownWindows()) {
2273 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2274 return com.android.internal.R.anim.app_starting_exit;
2275 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002276 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002277 && transit == TRANSIT_ENTER) {
2278 // Special case: we are animating in a dream, while the keyguard
2279 // is shown. We don't want an animation on the dream, because
2280 // we need it shown immediately with the keyguard animating away
2281 // to reveal it.
2282 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002283 }
2284
2285 return 0;
2286 }
2287
Craig Mautner3c174372013-02-21 17:54:37 -08002288 @Override
2289 public void selectRotationAnimationLw(int anim[]) {
2290 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2291 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2292 + (mTopFullscreenOpaqueWindowState == null ?
2293 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2294 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2295 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2296 case ROTATION_ANIMATION_CROSSFADE:
2297 anim[0] = R.anim.rotation_animation_xfade_exit;
2298 anim[1] = R.anim.rotation_animation_enter;
2299 break;
2300 case ROTATION_ANIMATION_JUMPCUT:
2301 anim[0] = R.anim.rotation_animation_jump_exit;
2302 anim[1] = R.anim.rotation_animation_enter;
2303 break;
2304 case ROTATION_ANIMATION_ROTATE:
2305 default:
2306 anim[0] = anim[1] = 0;
2307 break;
2308 }
2309 } else {
2310 anim[0] = anim[1] = 0;
2311 }
2312 }
2313
2314 @Override
2315 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2316 boolean forceDefault) {
2317 switch (exitAnimId) {
2318 case R.anim.rotation_animation_xfade_exit:
2319 case R.anim.rotation_animation_jump_exit:
2320 // These are the only cases that matter.
2321 if (forceDefault) {
2322 return false;
2323 }
2324 int anim[] = new int[2];
2325 selectRotationAnimationLw(anim);
2326 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2327 default:
2328 return true;
2329 }
2330 }
2331
2332 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002333 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2334 boolean goingToNotificationShade) {
2335 if (goingToNotificationShade) {
2336 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002337 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002338
2339 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2340 R.anim.lock_screen_behind_enter_wallpaper :
2341 R.anim.lock_screen_behind_enter);
2342
2343 // TODO: Use XML interpolators when we have log interpolators available in XML.
2344 final List<Animation> animations = set.getAnimations();
2345 for (int i = animations.size() - 1; i >= 0; --i) {
2346 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2347 }
2348
2349 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002350 }
2351
2352
2353 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002354 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2355 if (goingToNotificationShade) {
2356 return null;
2357 } else {
2358 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2359 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002360 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002361
2362 private static void awakenDreams() {
2363 IDreamManager dreamManager = getDreamManager();
2364 if (dreamManager != null) {
2365 try {
2366 dreamManager.awaken();
2367 } catch (RemoteException e) {
2368 // fine, stay asleep then
2369 }
2370 }
2371 }
2372
2373 static IDreamManager getDreamManager() {
2374 return IDreamManager.Stub.asInterface(
2375 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2376 }
2377
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002378 TelecomManager getTelecommService() {
2379 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002380 }
2381
Jeff Brown4d396052010-10-29 21:50:21 -07002382 static IAudioService getAudioService() {
2383 IAudioService audioService = IAudioService.Stub.asInterface(
2384 ServiceManager.checkService(Context.AUDIO_SERVICE));
2385 if (audioService == null) {
2386 Log.w(TAG, "Unable to find IAudioService interface.");
2387 }
2388 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002389 }
2390
2391 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002392 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002393 }
2394
2395 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2396 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2397 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2398 };
2399
2400 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002401 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002402 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002403 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002404 final int keyCode = event.getKeyCode();
2405 final int repeatCount = event.getRepeatCount();
2406 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002407 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002408 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2409 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002410
Jeff Brown40013652012-05-16 21:22:36 -07002411 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002412 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002413 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2414 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002415 }
2416
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002417 // If we think we might have a volume down & power key chord on the way
2418 // but we're not sure, then tell the dispatcher to wait a little while and
2419 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002420 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002421 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002422 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002423 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2424 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002425 if (now < timeoutTime) {
2426 return timeoutTime - now;
2427 }
2428 }
2429 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002430 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002431 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002432 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002433 }
2434 return -1;
2435 }
2436 }
2437
Michael Wright6a62e552014-06-03 19:19:48 -07002438 // Cancel any pending meta actions if we see any other keys being pressed between the down
2439 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002440 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002441 mPendingMetaAction = false;
2442 }
2443
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002444 // First we always handle the home key here, so applications
2445 // can never break it, although if keyguard is on, we do let
2446 // it handle it, because that gives us the correct 5 second
2447 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002448 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002449
Jeff Brown49ed71d2010-12-06 17:13:33 -08002450 // If we have released the home key, and didn't do anything else
2451 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002452 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002453 cancelPreloadRecentApps();
2454
Jeff Brown49ed71d2010-12-06 17:13:33 -08002455 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002456 if (mHomeConsumed) {
2457 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002458 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002459 }
Jeff Browncaca8812013-05-09 13:34:33 -07002460
2461 if (canceled) {
2462 Log.i(TAG, "Ignoring HOME; event canceled.");
2463 return -1;
2464 }
2465
Yorke Lee4f803242014-12-15 23:22:06 +00002466 // If an incoming call is ringing, HOME is totally disabled.
2467 // (The user is already on the InCallUI at this point,
2468 // and his ONLY options are to answer or reject the call.)
2469 TelecomManager telecomManager = getTelecommService();
2470 if (telecomManager != null && telecomManager.isRinging()) {
2471 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2472 return -1;
2473 }
2474
Jeff Browncaca8812013-05-09 13:34:33 -07002475 // Delay handling home if a double-tap is possible.
2476 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2477 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2478 mHomeDoubleTapPending = true;
2479 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2480 ViewConfiguration.getDoubleTapTimeout());
2481 return -1;
2482 }
2483
Jeff Brown13f00f02014-10-31 14:45:50 -07002484 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002485 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002486 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002487
2488 // If a system window has focus, then it doesn't make sense
2489 // right now to interact with applications.
2490 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2491 if (attrs != null) {
2492 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002493 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2494 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2495 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002496 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002497 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002498 }
2499 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2500 for (int i=0; i<typeCount; i++) {
2501 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2502 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002503 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002504 }
2505 }
2506 }
Jeff Browncaca8812013-05-09 13:34:33 -07002507
2508 // Remember that home is pressed and handle special actions.
2509 if (repeatCount == 0) {
2510 mHomePressed = true;
2511 if (mHomeDoubleTapPending) {
2512 mHomeDoubleTapPending = false;
2513 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2514 handleDoubleTapOnHome();
2515 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2516 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2517 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002518 }
Jeff Browncaca8812013-05-09 13:34:33 -07002519 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2520 if (!keyguardOn) {
2521 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002522 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002523 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002524 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002525 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002526 // Hijack modified menu keys for debugging features
2527 final int chordBug = KeyEvent.META_SHIFT_ON;
2528
2529 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002530 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002531 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002532 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2533 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002534 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002535 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002536 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002537 Intent service = new Intent();
2538 service.setClassName(mContext, "com.android.server.LoadAverageService");
2539 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002540 boolean shown = Settings.Global.getInt(
2541 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002542 if (!shown) {
2543 mContext.startService(service);
2544 } else {
2545 mContext.stopService(service);
2546 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002547 Settings.Global.putInt(
2548 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002549 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002550 }
2551 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002552 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002553 if (down) {
2554 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002555 mSearchKeyShortcutPending = true;
2556 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002557 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002558 } else {
2559 mSearchKeyShortcutPending = false;
2560 if (mConsumeSearchKeyUp) {
2561 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002562 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002563 }
2564 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002565 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002566 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002567 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002568 if (down && repeatCount == 0) {
2569 preloadRecentApps();
2570 } else if (!down) {
2571 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002572 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002573 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002574 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002575 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2576 if (down) {
2577 if (repeatCount == 0) {
2578 mAssistKeyLongPressed = false;
2579 } else if (repeatCount == 1) {
2580 mAssistKeyLongPressed = true;
2581 if (!keyguardOn) {
2582 launchAssistLongPressAction();
2583 }
2584 }
2585 } else {
2586 if (mAssistKeyLongPressed) {
2587 mAssistKeyLongPressed = false;
2588 } else {
2589 if (!keyguardOn) {
2590 launchAssistAction();
2591 }
2592 }
2593 }
2594 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002595 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2596 if (!down) {
2597 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002598 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002599 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2600 } else {
2601 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002602 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002603 }
2604 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
2605 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002606 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2607 if (down && repeatCount == 0) {
2608 mHandler.post(mScreenshotRunnable);
2609 }
2610 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002611 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2612 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2613 if (down) {
2614 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2615
2616 // Disable autobrightness if it's on
2617 int auto = Settings.System.getIntForUser(
2618 mContext.getContentResolver(),
2619 Settings.System.SCREEN_BRIGHTNESS_MODE,
2620 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2621 UserHandle.USER_CURRENT_OR_SELF);
2622 if (auto != 0) {
2623 Settings.System.putIntForUser(mContext.getContentResolver(),
2624 Settings.System.SCREEN_BRIGHTNESS_MODE,
2625 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2626 UserHandle.USER_CURRENT_OR_SELF);
2627 }
2628
2629 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2630 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2631 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2632 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2633 Settings.System.SCREEN_BRIGHTNESS,
2634 mPowerManager.getDefaultScreenBrightnessSetting(),
2635 UserHandle.USER_CURRENT_OR_SELF);
2636 brightness += step;
2637 // Make sure we don't go beyond the limits.
2638 brightness = Math.min(max, brightness);
2639 brightness = Math.max(min, brightness);
2640
2641 Settings.System.putIntForUser(mContext.getContentResolver(),
2642 Settings.System.SCREEN_BRIGHTNESS, brightness,
2643 UserHandle.USER_CURRENT_OR_SELF);
Alan Viverette5a399492014-07-14 16:19:38 -07002644 mContext.startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
2645 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002646 }
2647 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002648 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002649 if (down) {
2650 mPendingMetaAction = true;
2651 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002652 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002653 }
2654 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002655 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002656
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002657 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002658 // Any printing key that is chorded with Search should be consumed
2659 // even if no shortcut was invoked. This prevents text from being
2660 // inadvertently inserted when using a keyboard that has built-in macro
2661 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002662 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002663 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2664 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002665 mConsumeSearchKeyUp = true;
2666 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002667 if (down && repeatCount == 0 && !keyguardOn) {
2668 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2669 if (shortcutIntent != null) {
2670 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002671 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002672 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002673 } catch (ActivityNotFoundException ex) {
2674 Slog.w(TAG, "Dropping shortcut key combination because "
2675 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002676 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002677 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002678 } else {
2679 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002680 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002681 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002682 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002683 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002684 }
2685 }
2686
Jeff Brown68b909d2011-12-07 16:36:01 -08002687 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002688 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002689 && (metaState & KeyEvent.META_META_ON) != 0) {
2690 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002691 if (kcm.isPrintingKey(keyCode)) {
2692 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2693 metaState & ~(KeyEvent.META_META_ON
2694 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2695 if (shortcutIntent != null) {
2696 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2697 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002698 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002699 } catch (ActivityNotFoundException ex) {
2700 Slog.w(TAG, "Dropping shortcut key combination because "
2701 + "the activity to which it is registered was not found: "
2702 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2703 }
2704 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002705 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002706 }
2707 }
2708
Jeff Brown6651a632011-11-28 12:59:11 -08002709 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002710 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002711 String category = sApplicationLaunchKeyCategories.get(keyCode);
2712 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002713 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002714 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2715 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002716 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002717 } catch (ActivityNotFoundException ex) {
2718 Slog.w(TAG, "Dropping application launch key because "
2719 + "the activity to which it is registered was not found: "
2720 + "keyCode=" + keyCode + ", category=" + category, ex);
2721 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002722 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002723 }
2724 }
2725
Michael Wright61c46752014-08-21 16:57:33 -07002726 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002727 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002728 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002729 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002730 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002731 mRecentAppsHeldModifiers = shiftlessModifiers;
2732 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002733 return -1;
2734 }
2735 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002736 } else if (!down && mRecentAppsHeldModifiers != 0
2737 && (metaState & mRecentAppsHeldModifiers) == 0) {
2738 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002739 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002740 }
2741
Jeff Browncf39bdf2012-05-18 14:41:19 -07002742 // Handle keyboard language switching.
2743 if (down && repeatCount == 0
2744 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2745 || (keyCode == KeyEvent.KEYCODE_SPACE
2746 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2747 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2748 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2749 return -1;
2750 }
2751 if (mLanguageSwitchKeyPressed && !down
2752 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2753 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2754 mLanguageSwitchKeyPressed = false;
2755 return -1;
2756 }
2757
Jeff Brown13f00f02014-10-31 14:45:50 -07002758 if (isValidGlobalKey(keyCode)
2759 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002760 return -1;
2761 }
2762
Michael Wright6a62e552014-06-03 19:19:48 -07002763 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002764 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002765 return -1;
2766 }
2767
Jeff Brown68b909d2011-12-07 16:36:01 -08002768 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002769 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002770 }
2771
Jeff Brown3915bb82010-11-05 15:02:16 -07002772 /** {@inheritDoc} */
2773 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002774 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002775 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002776 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002777 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2778 + ", flags=" + event.getFlags()
2779 + ", keyCode=" + event.getKeyCode()
2780 + ", scanCode=" + event.getScanCode()
2781 + ", metaState=" + event.getMetaState()
2782 + ", repeatCount=" + event.getRepeatCount()
2783 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002784 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002785
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002786 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002787 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2788 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002789 final int keyCode = event.getKeyCode();
2790 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002791 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2792 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002793
Jeff Brown54875002011-04-06 15:33:01 -07002794 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002795 final FallbackAction fallbackAction;
2796 if (initialDown) {
2797 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2798 } else {
2799 fallbackAction = mFallbackActions.get(keyCode);
2800 }
2801
2802 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002803 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002804 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2805 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002806 }
2807
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002808 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2809 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002810 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002811 event.getAction(), fallbackAction.keyCode,
2812 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002813 event.getDeviceId(), event.getScanCode(),
2814 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002815
2816 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2817 fallbackEvent.recycle();
2818 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002819 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002820
2821 if (initialDown) {
2822 mFallbackActions.put(keyCode, fallbackAction);
2823 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2824 mFallbackActions.remove(keyCode);
2825 fallbackAction.recycle();
2826 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002827 }
2828 }
2829
Jeff Brown40013652012-05-16 21:22:36 -07002830 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002831 if (fallbackEvent == null) {
2832 Slog.d(TAG, "No fallback.");
2833 } else {
2834 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2835 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002836 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002837 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002838 }
2839
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002840 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002841 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002842 if ((actions & ACTION_PASS_TO_USER) != 0) {
2843 long delayMillis = interceptKeyBeforeDispatching(
2844 win, fallbackEvent, policyFlags);
2845 if (delayMillis == 0) {
2846 return true;
2847 }
2848 }
2849 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002850 }
2851
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002852 private void launchAssistLongPressAction() {
2853 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2854 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2855
2856 // launch the search activity
2857 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2858 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2859 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002860 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002861 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002862 SearchManager searchManager = getSearchManager();
2863 if (searchManager != null) {
2864 searchManager.stopSearch();
2865 }
Michael Wright43e27f72013-04-10 14:06:48 -07002866 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002867 } catch (ActivityNotFoundException e) {
2868 Slog.w(TAG, "No activity to handle assist long press action.", e);
2869 }
2870 }
2871
2872 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002873 launchAssistAction(null);
2874 }
2875
2876 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002877 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002878 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002879 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002880 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002881 if (hint != null) {
2882 intent.putExtra(hint, true);
2883 }
Jim Miller45308b12012-06-18 19:23:39 -07002884 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2885 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2886 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2887 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002888 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002889 } catch (ActivityNotFoundException e) {
2890 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002891 }
2892 }
2893 }
2894
2895 private SearchManager getSearchManager() {
2896 if (mSearchManager == null) {
2897 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2898 }
2899 return mSearchManager;
2900 }
2901
Jeff Browncaca8812013-05-09 13:34:33 -07002902 private void preloadRecentApps() {
2903 mPreloadedRecentApps = true;
2904 try {
2905 IStatusBarService statusbar = getStatusBarService();
2906 if (statusbar != null) {
2907 statusbar.preloadRecentApps();
2908 }
2909 } catch (RemoteException e) {
2910 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2911 // re-acquire status bar service next time it is needed.
2912 mStatusBarService = null;
2913 }
2914 }
2915
2916 private void cancelPreloadRecentApps() {
2917 if (mPreloadedRecentApps) {
2918 mPreloadedRecentApps = false;
2919 try {
2920 IStatusBarService statusbar = getStatusBarService();
2921 if (statusbar != null) {
2922 statusbar.cancelPreloadRecentApps();
2923 }
2924 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002925 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07002926 // re-acquire status bar service next time it is needed.
2927 mStatusBarService = null;
2928 }
2929 }
2930 }
2931
2932 private void toggleRecentApps() {
2933 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07002934 try {
2935 IStatusBarService statusbar = getStatusBarService();
2936 if (statusbar != null) {
2937 statusbar.toggleRecentApps();
2938 }
2939 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002940 Slog.e(TAG, "RemoteException when toggling recent apps", e);
2941 // re-acquire status bar service next time it is needed.
2942 mStatusBarService = null;
2943 }
2944 }
2945
Craig Mautner84984fa2014-06-19 11:19:20 -07002946 @Override
2947 public void showRecentApps() {
2948 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
2949 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
2950 }
2951
Winson Chung1e8d71b2014-05-16 17:05:22 -07002952 private void showRecentApps(boolean triggeredFromAltTab) {
2953 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2954 try {
2955 IStatusBarService statusbar = getStatusBarService();
2956 if (statusbar != null) {
2957 statusbar.showRecentApps(triggeredFromAltTab);
2958 }
2959 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07002960 Slog.e(TAG, "RemoteException when showing recent apps", e);
2961 // re-acquire status bar service next time it is needed.
2962 mStatusBarService = null;
2963 }
2964 }
2965
Winson Chungcdcd4872014-08-05 18:00:13 -07002966 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002967 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2968 try {
2969 IStatusBarService statusbar = getStatusBarService();
2970 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07002971 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07002972 }
2973 } catch (RemoteException e) {
2974 Slog.e(TAG, "RemoteException when closing recent apps", e);
2975 // re-acquire status bar service next time it is needed.
2976 mStatusBarService = null;
2977 }
2978 }
2979
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002980 /**
2981 * A home key -> launch home action was detected. Take the appropriate action
2982 * given the situation with the keyguard.
2983 */
2984 void launchHomeFromHotKey() {
Jim Millerab954542014-10-10 18:21:49 -07002985 if (isKeyguardShowingAndNotOccluded()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002986 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002987 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002988 // when in keyguard restricted mode, must first verify unlock
2989 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002990 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
Jose Lima9546b202014-07-02 17:21:51 -07002991 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002992 public void onKeyguardExitResult(boolean success) {
2993 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002994 try {
2995 ActivityManagerNative.getDefault().stopAppSwitches();
2996 } catch (RemoteException e) {
2997 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002998 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08002999 startDockOrHome(true /*fromHomeKey*/);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003000 }
3001 }
3002 });
3003 } else {
3004 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003005 try {
3006 ActivityManagerNative.getDefault().stopAppSwitches();
3007 } catch (RemoteException e) {
3008 }
Winson Chungd543c1b2014-06-23 15:06:45 -07003009 if (mRecentsVisible) {
3010 // Hide Recents and notify it to launch Home
3011 awakenDreams();
3012 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Winson Chungcdcd4872014-08-05 18:00:13 -07003013 hideRecentApps(false, true);
Winson Chungd543c1b2014-06-23 15:06:45 -07003014 } else {
3015 // Otherwise, just launch Home
3016 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08003017 startDockOrHome(true /*fromHomeKey*/);
Winson Chungd543c1b2014-06-23 15:06:45 -07003018 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003019 }
3020 }
3021
John Spurlock04db1762013-05-13 12:46:41 -04003022 private final Runnable mClearHideNavigationFlag = new Runnable() {
3023 @Override
3024 public void run() {
3025 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3026 // Clear flags.
3027 mForceClearedSystemUiFlags &=
3028 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3029 }
3030 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003031 }
3032 };
3033
3034 /**
3035 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3036 * to determine when the nav bar should be shown and prevent applications from
3037 * receiving those touches.
3038 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003039 final class HideNavInputEventReceiver extends InputEventReceiver {
3040 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3041 super(inputChannel, looper);
3042 }
3043
Dianne Hackborndf89e652011-10-06 22:35:11 -07003044 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003045 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003046 boolean handled = false;
3047 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003048 if (event instanceof MotionEvent
3049 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3050 final MotionEvent motionEvent = (MotionEvent)event;
3051 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003052 // When the user taps down, we re-show the nav bar.
3053 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003054 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003055 // Any user activity always causes us to show the
3056 // navigation controls, if they had been hidden.
3057 // We also clear the low profile and only content
3058 // flags so that tapping on the screen will atomically
3059 // restore all currently hidden screen decorations.
3060 int newVal = mResettingSystemUiFlags |
3061 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3062 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3063 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003064 if (mResettingSystemUiFlags != newVal) {
3065 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003066 changed = true;
3067 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003068 // We don't allow the system's nav bar to be hidden
3069 // again for 1 second, to prevent applications from
3070 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003071 newVal = mForceClearedSystemUiFlags |
3072 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003073 if (mForceClearedSystemUiFlags != newVal) {
3074 mForceClearedSystemUiFlags = newVal;
3075 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003076 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003077 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003078 }
3079 if (changed) {
3080 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3081 }
3082 }
3083 }
3084 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003085 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003086 }
3087 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003088 }
3089 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3090 new InputEventReceiver.Factory() {
3091 @Override
3092 public InputEventReceiver createInputEventReceiver(
3093 InputChannel inputChannel, Looper looper) {
3094 return new HideNavInputEventReceiver(inputChannel, looper);
3095 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003096 };
3097
3098 @Override
3099 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003100 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3101 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003102 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003103
Dianne Hackborndf89e652011-10-06 22:35:11 -07003104 // Reset any bits in mForceClearingStatusBarVisibility that
3105 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003106 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003107 // Clear any bits in the new visibility that are currently being
3108 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003109 return visibility & ~mResettingSystemUiFlags
3110 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003111 }
3112
Craig Mautner69b08182012-09-05 13:07:13 -07003113 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003114 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3115 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003116 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003117 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3118 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003119
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003120 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003121 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003122 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003123 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003124 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003125 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3126 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3127 } else {
3128 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3129 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3130 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003131 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3132 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003133 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003134 availRight - mStableFullscreenRight,
3135 availBottom - mStableFullscreenBottom);
3136 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003137 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003138 availRight - mStableRight, availBottom - mStableBottom);
3139 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003140 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003141 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003142 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003143 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003144 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003145 availRight - mCurRight, availBottom - mCurBottom);
3146 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003147 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003148 availRight - mCurRight, availBottom - mCurBottom);
3149 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003150
3151 outStableInsets.set(mStableLeft, mStableTop,
3152 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003153 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003154 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003155 outContentInsets.setEmpty();
3156 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003157 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003158
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003159 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003160 @Override
3161 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3162 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003163 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3164 if (isDefaultDisplay) {
3165 switch (displayRotation) {
3166 case Surface.ROTATION_90:
3167 overscanLeft = mOverscanTop;
3168 overscanTop = mOverscanRight;
3169 overscanRight = mOverscanBottom;
3170 overscanBottom = mOverscanLeft;
3171 break;
3172 case Surface.ROTATION_180:
3173 overscanLeft = mOverscanRight;
3174 overscanTop = mOverscanBottom;
3175 overscanRight = mOverscanLeft;
3176 overscanBottom = mOverscanTop;
3177 break;
3178 case Surface.ROTATION_270:
3179 overscanLeft = mOverscanBottom;
3180 overscanTop = mOverscanLeft;
3181 overscanRight = mOverscanTop;
3182 overscanBottom = mOverscanRight;
3183 break;
3184 default:
3185 overscanLeft = mOverscanLeft;
3186 overscanTop = mOverscanTop;
3187 overscanRight = mOverscanRight;
3188 overscanBottom = mOverscanBottom;
3189 break;
3190 }
3191 } else {
3192 overscanLeft = 0;
3193 overscanTop = 0;
3194 overscanRight = 0;
3195 overscanBottom = 0;
3196 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003197 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3198 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3199 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3200 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003201 mSystemLeft = 0;
3202 mSystemTop = 0;
3203 mSystemRight = displayWidth;
3204 mSystemBottom = displayHeight;
3205 mUnrestrictedScreenLeft = overscanLeft;
3206 mUnrestrictedScreenTop = overscanTop;
3207 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3208 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3209 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3210 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003211 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3212 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003213 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003214 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003215 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003216 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003217 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003218 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003219 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003220 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003221 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003222 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003223
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003224 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3225 final Rect pf = mTmpParentFrame;
3226 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003227 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003228 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003229 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003230 pf.left = df.left = of.left = vf.left = mDockLeft;
3231 pf.top = df.top = of.top = vf.top = mDockTop;
3232 pf.right = df.right = of.right = vf.right = mDockRight;
3233 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003234 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003235
Craig Mautner69b08182012-09-05 13:07:13 -07003236 if (isDefaultDisplay) {
3237 // For purposes of putting out fake window up to steal focus, we will
3238 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003239 final int sysui = mLastSystemUiFlags;
3240 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003241 boolean navTranslucent = (sysui
3242 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003243 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3244 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3245 boolean navAllowedHidden = immersive || immersiveSticky;
3246 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003247 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3248 if (!isKeyguardShowing) {
3249 navTranslucent &= areTranslucentBarsAllowed();
3250 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003251
Craig Mautner69b08182012-09-05 13:07:13 -07003252 // When the navigation bar isn't visible, we put up a fake
3253 // input window to catch all touch events. This way we can
3254 // detect when the user presses anywhere to bring back the nav
3255 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003256 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07003257 if (mHideNavFakeWindow != null) {
3258 mHideNavFakeWindow.dismiss();
3259 mHideNavFakeWindow = null;
3260 }
3261 } else if (mHideNavFakeWindow == null) {
3262 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
3263 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07003264 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07003265 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003266 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003267
Craig Mautner69b08182012-09-05 13:07:13 -07003268 // For purposes of positioning and showing the nav bar, if we have
3269 // decided that it can't be hidden (because of the screen aspect ratio),
3270 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003271 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003272
John Spurlockad3e6cb2013-04-30 08:47:43 -04003273 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003274 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003275 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003276 // Force the navigation bar to its appropriate place and
3277 // size. We need to do this directly, instead of relying on
3278 // it to bubble up from the nav bar, because this needs to
3279 // change atomically with screen rotations.
3280 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3281 if (mNavigationBarOnBottom) {
3282 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003283 int top = displayHeight - overscanBottom
3284 - mNavigationBarHeightForRotation[displayRotation];
3285 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003286 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003287 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003288 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003289 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003290 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003291 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003292 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3293 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003294 } else {
3295 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003296 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003297 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003298 if (navVisible && !navTranslucent && !navAllowedHidden
3299 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003300 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003301 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003302 // and not in the process of animating on or off, then
3303 // we can tell the app that it is covered by it.
3304 mSystemBottom = mTmpNavigationFrame.top;
3305 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003306 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003307 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003308 int left = displayWidth - overscanRight
3309 - mNavigationBarWidthForRotation[displayRotation];
3310 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003311 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003312 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003313 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003314 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003315 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003316 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003317 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3318 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003319 } else {
3320 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003321 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003322 }
John Spurlockbd957402013-10-03 11:38:39 -04003323 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3324 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003325 // If the nav bar is currently requested to be visible,
3326 // and not in the process of animating on or off, then
3327 // we can tell the app that it is covered by it.
3328 mSystemRight = mTmpNavigationFrame.left;
3329 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003330 }
Craig Mautner69b08182012-09-05 13:07:13 -07003331 // Make sure the content and current rectangles are updated to
3332 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003333 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3334 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3335 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3336 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003337 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3338 // And compute the final frame.
3339 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003340 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3341 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003342 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003343 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003344 updateSysUiVisibility = true;
3345 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003346 }
Craig Mautnereda67292013-04-28 13:50:14 -07003347 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003348 mDockLeft, mDockTop, mDockRight, mDockBottom));
3349
3350 // decide where the status bar goes ahead of time
3351 if (mStatusBar != null) {
3352 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003353 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3354 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3355 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3356 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3357 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003358 vf.left = mStableLeft;
3359 vf.top = mStableTop;
3360 vf.right = mStableRight;
3361 vf.bottom = mStableBottom;
3362
3363 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3364
3365 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003366 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003367
3368 // For layout, the status bar is always at the top with our fixed height.
3369 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3370
John Spurlocke1f366f2013-08-05 12:22:40 -04003371 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003372 boolean statusBarTranslucent = (sysui
3373 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003374 if (!isKeyguardShowing) {
3375 statusBarTranslucent &= areTranslucentBarsAllowed();
3376 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003377
Craig Mautner69b08182012-09-05 13:07:13 -07003378 // If the status bar is hidden, we don't want to cause
3379 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003380 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003381 // Status bar may go away, so the screen area it occupies
3382 // is available to apps but just covering them when the
3383 // status bar is visible.
3384 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3385
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003386 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3387 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3388 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3389 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003390
Craig Mautnereda67292013-04-28 13:50:14 -07003391 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003392 String.format(
3393 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3394 mDockLeft, mDockTop, mDockRight, mDockBottom,
3395 mContentLeft, mContentTop, mContentRight, mContentBottom,
3396 mCurLeft, mCurTop, mCurRight, mCurBottom));
3397 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003398 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003399 && !statusBarTransient && !statusBarTranslucent
3400 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003401 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003402 // and not in the process of animating on or off, then
3403 // we can tell the app that it is covered by it.
3404 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3405 }
John Spurlock27735a42013-08-14 17:57:38 -04003406 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003407 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003408 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003409 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003410 if (updateSysUiVisibility) {
3411 updateSystemUiVisibilityLw();
3412 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003413 }
3414 }
3415
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003416 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003417 @Override
John Spurlock46646232013-09-30 22:32:42 -04003418 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003419 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
3420 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
3421 return 0;
3422 }
3423
Craig Mautner967212c2013-04-13 21:10:58 -07003424 @Override
3425 public void getContentRectLw(Rect r) {
3426 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3427 }
3428
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003429 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3430 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003431 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3432 // Here's a special case: if this attached window is a panel that is
3433 // above the dock window, and the window it is attached to is below
3434 // the dock window, then the frames we computed for the window it is
3435 // attached to can not be used because the dock is effectively part
3436 // of the underlying window and the attached window is floating on top
3437 // of the whole thing. So, we ignore the attached window and explicitly
3438 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003439 df.left = of.left = cf.left = vf.left = mDockLeft;
3440 df.top = of.top = cf.top = vf.top = mDockTop;
3441 df.right = of.right = cf.right = vf.right = mDockRight;
3442 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003443 } else {
3444 // The effective display frame of the attached window depends on
3445 // whether it is taking care of insetting its content. If not,
3446 // we need to use the parent's content frame so that the entire
3447 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003448 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003449 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003450 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003451 // Set the content frame of the attached window to the parent's decor frame
3452 // (same as content frame when IME isn't present) if specifically requested by
3453 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3454 // Otherwise, use the overscan frame.
3455 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3456 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003457 } else {
3458 // If the window is resizing, then we want to base the content
3459 // frame on our attached content frame to resize... however,
3460 // things can be tricky if the attached window is NOT in resize
3461 // mode, in which case its content frame will be larger.
3462 // Ungh. So to deal with that, make sure the content frame
3463 // we end up using is not covering the IM dock.
3464 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003465 if (attached.isVoiceInteraction()) {
3466 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3467 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3468 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3469 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3470 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003471 if (cf.left < mContentLeft) cf.left = mContentLeft;
3472 if (cf.top < mContentTop) cf.top = mContentTop;
3473 if (cf.right > mContentRight) cf.right = mContentRight;
3474 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3475 }
3476 }
3477 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003478 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003479 vf.set(attached.getVisibleFrameLw());
3480 }
3481 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3482 // window should be positioned relative to its parent or the entire
3483 // screen.
3484 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3485 ? attached.getFrameLw() : df);
3486 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003487
3488 private void applyStableConstraints(int sysui, int fl, Rect r) {
3489 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3490 // If app is requesting a stable layout, don't let the
3491 // content insets go below the stable values.
3492 if ((fl & FLAG_FULLSCREEN) != 0) {
3493 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3494 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3495 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3496 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3497 } else {
3498 if (r.left < mStableLeft) r.left = mStableLeft;
3499 if (r.top < mStableTop) r.top = mStableTop;
3500 if (r.right > mStableRight) r.right = mStableRight;
3501 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3502 }
3503 }
3504 }
3505
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003506 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003507 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003508 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003509 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003510 final WindowManager.LayoutParams attrs = win.getAttrs();
3511 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3512 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003513 return;
3514 }
Craig Mautner69b08182012-09-05 13:07:13 -07003515 final boolean isDefaultDisplay = win.isDefaultDisplay();
3516 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003517 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3518 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003519 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003520 offsetInputMethodWindowLw(mLastInputMethodWindow);
3521 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003522
John Spurlockc6d1c602014-01-17 15:22:06 -05003523 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003524 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003525 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003526
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003527 final Rect pf = mTmpParentFrame;
3528 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003529 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003530 final Rect cf = mTmpContentFrame;
3531 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003532 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003533 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003534 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003535
3536 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003537 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003538
Craig Mautnerf683b562012-10-02 11:10:57 -07003539 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3540
Adrian Roosfa104232014-06-20 16:10:14 -07003541 if (isDefaultDisplay) {
3542 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3543 } else {
3544 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3545 }
3546
Craig Mautner69b08182012-09-05 13:07:13 -07003547 if (!isDefaultDisplay) {
3548 if (attached != null) {
3549 // If this window is attached to another, our display
3550 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003551 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003552 } else {
3553 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003554 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3555 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3556 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003557 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003558 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003559 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003560 }
Dianne Hackbornae6688b2015-02-11 17:02:41 -08003561 } else if (attrs.type == TYPE_INPUT_METHOD || attrs.type == TYPE_VOICE_INTERACTION) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003562 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3563 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3564 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003565 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003566 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003567 // ...with content insets above the nav bar
3568 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003569 // IM dock windows always go to the bottom of the screen.
3570 attrs.gravity = Gravity.BOTTOM;
3571 mDockLayer = win.getSurfaceLayer();
Jorim Jaggie0700182014-08-21 01:12:37 +02003572 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3573 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3574 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3575 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3576 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3577 cf.left = vf.left = mStableLeft;
3578 cf.top = vf.top = mStableTop;
3579 cf.right = vf.right = mStableRight;
3580 vf.bottom = mStableBottom;
3581 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003582 } else {
John Spurlock46646232013-09-30 22:32:42 -04003583
3584 // Default policy decor for the default display
3585 dcf.left = mSystemLeft;
3586 dcf.top = mSystemTop;
3587 dcf.right = mSystemRight;
3588 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003589 final boolean inheritTranslucentDecor = (attrs.privateFlags
3590 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003591 final boolean isAppWindow =
3592 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3593 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3594 final boolean topAtRest =
3595 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3596 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003597 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3598 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003599 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3600 && (fl & WindowManager.LayoutParams.
3601 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003602 // Ensure policy decor includes status bar
3603 dcf.top = mStableTop;
3604 }
John Spurlockbd957402013-10-03 11:38:39 -04003605 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003606 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3607 && (fl & WindowManager.LayoutParams.
3608 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003609 // Ensure policy decor includes navigation bar
3610 dcf.bottom = mStableBottom;
3611 dcf.right = mStableRight;
3612 }
3613 }
3614
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003615 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3616 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003617 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003618 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003619 // This is the case for a normal activity window: we want it
3620 // to cover all of the screen space, and it can take care of
3621 // moving its contents to account for screen decorations that
3622 // intrude into that space.
3623 if (attached != null) {
3624 // If this window is attached to another, our display
3625 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003626 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003627 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003628 if (attrs.type == TYPE_STATUS_BAR_PANEL
3629 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003630 // Status bar panels are the only windows who can go on top of
3631 // the status bar. They are protected by the STATUS_BAR_SERVICE
3632 // permission, so they have the same privileges as the status
3633 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003634 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003635 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003636
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003637 pf.left = df.left = of.left = hasNavBar
3638 ? mDockLeft : mUnrestrictedScreenLeft;
3639 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3640 pf.right = df.right = of.right = hasNavBar
3641 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3642 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3643 pf.bottom = df.bottom = of.bottom = hasNavBar
3644 ? mRestrictedScreenTop+mRestrictedScreenHeight
3645 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003646
Craig Mautnereda67292013-04-28 13:50:14 -07003647 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003648 "Laying out status bar window: (%d,%d - %d,%d)",
3649 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003650 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003651 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3652 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3653 // Asking to layout into the overscan region, so give it that pure
3654 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003655 pf.left = df.left = of.left = mOverscanScreenLeft;
3656 pf.top = df.top = of.top = mOverscanScreenTop;
3657 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3658 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3659 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003660 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003661 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003662 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3663 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003664 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003665 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003666 // only do this for application windows to ensure no window that
3667 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003668 pf.left = df.left = mOverscanScreenLeft;
3669 pf.top = df.top = mOverscanScreenTop;
3670 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3671 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003672 // We need to tell the app about where the frame inside the overscan
3673 // is, so it can inset its content by that amount -- it didn't ask
3674 // to actually extend itself into the overscan region.
3675 of.left = mUnrestrictedScreenLeft;
3676 of.top = mUnrestrictedScreenTop;
3677 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3678 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003679 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003680 pf.left = df.left = mRestrictedOverscanScreenLeft;
3681 pf.top = df.top = mRestrictedOverscanScreenTop;
3682 pf.right = df.right = mRestrictedOverscanScreenLeft
3683 + mRestrictedOverscanScreenWidth;
3684 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3685 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003686 // We need to tell the app about where the frame inside the overscan
3687 // is, so it can inset its content by that amount -- it didn't ask
3688 // to actually extend itself into the overscan region.
3689 of.left = mUnrestrictedScreenLeft;
3690 of.top = mUnrestrictedScreenTop;
3691 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3692 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003693 }
Craig Mautner69b08182012-09-05 13:07:13 -07003694
John Spurlock46646232013-09-30 22:32:42 -04003695 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003696 if (win.isVoiceInteraction()) {
3697 cf.left = mVoiceContentLeft;
3698 cf.top = mVoiceContentTop;
3699 cf.right = mVoiceContentRight;
3700 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003701 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003702 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3703 cf.left = mDockLeft;
3704 cf.top = mDockTop;
3705 cf.right = mDockRight;
3706 cf.bottom = mDockBottom;
3707 } else {
3708 cf.left = mContentLeft;
3709 cf.top = mContentTop;
3710 cf.right = mContentRight;
3711 cf.bottom = mContentBottom;
3712 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003713 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003714 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003715 // Full screen windows are always given a layout that is as if the
3716 // status bar and other transient decors are gone. This is to avoid
3717 // bad states when moving from a window that is not hding the
3718 // status bar to one that is.
3719 cf.left = mRestrictedScreenLeft;
3720 cf.top = mRestrictedScreenTop;
3721 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3722 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003723 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003724 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003725 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3726 vf.left = mCurLeft;
3727 vf.top = mCurTop;
3728 vf.right = mCurRight;
3729 vf.bottom = mCurBottom;
3730 } else {
3731 vf.set(cf);
3732 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003733 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003734 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3735 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3736 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003737 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3738 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003739 // A window that has requested to fill the entire screen just
3740 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003741 if (attrs.type == TYPE_STATUS_BAR_PANEL
3742 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003743 pf.left = df.left = of.left = cf.left = hasNavBar
3744 ? mDockLeft : mUnrestrictedScreenLeft;
3745 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3746 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003747 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003748 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003749 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003750 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003751 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003752 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003753 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3754 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003755 } else if (attrs.type == TYPE_NAVIGATION_BAR
3756 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003757 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003758 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3759 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3760 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3761 + mUnrestrictedScreenWidth;
3762 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3763 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003764 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003765 "Laying out navigation bar window: (%d,%d - %d,%d)",
3766 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003767 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3768 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003769 && ((fl & FLAG_FULLSCREEN) != 0)) {
3770 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003771 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3772 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3773 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3774 + mOverscanScreenWidth;
3775 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3776 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003777 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003778 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003779 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3780 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3781 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3782 + mOverscanScreenWidth;
3783 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3784 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003785 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003786 // The wallpaper also has Real Ultimate Power, but we want to tell
3787 // it about the overscan area.
3788 pf.left = df.left = mOverscanScreenLeft;
3789 pf.top = df.top = mOverscanScreenTop;
3790 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3791 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3792 of.left = cf.left = mUnrestrictedScreenLeft;
3793 of.top = cf.top = mUnrestrictedScreenTop;
3794 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3795 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003796 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003797 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3798 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3799 // Asking to layout into the overscan region, so give it that pure
3800 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003801 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3802 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3803 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003804 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003805 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003806 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003807 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003808 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003809 && (attrs.type == TYPE_STATUS_BAR
3810 || attrs.type == TYPE_TOAST
John Spurlock34e13d92013-08-10 06:52:28 -04003811 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3812 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003813 // Asking for layout as if the nav bar is hidden, lets the
3814 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003815 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003816 // can be above the nav bar can do this.
3817 // XXX This assumes that an app asking for this will also
3818 // ask for layout in only content. We can't currently figure out
3819 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003820 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3821 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3822 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3823 + mUnrestrictedScreenWidth;
3824 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3825 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003826 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003827 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3828 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3829 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3830 + mRestrictedScreenWidth;
3831 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3832 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003833 }
Craig Mautner69b08182012-09-05 13:07:13 -07003834
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003835 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003836
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003837 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3838 vf.left = mCurLeft;
3839 vf.top = mCurTop;
3840 vf.right = mCurRight;
3841 vf.bottom = mCurBottom;
3842 } else {
3843 vf.set(cf);
3844 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003845 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003846 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3847 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003848 // A child window should be placed inside of the same visible
3849 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003850 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003851 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003852 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3853 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003854 // Otherwise, a normal window must be placed inside the content
3855 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003856 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3857 // Status bar panels are the only windows who can go on top of
3858 // the status bar. They are protected by the STATUS_BAR_SERVICE
3859 // permission, so they have the same privileges as the status
3860 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003861 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3862 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3863 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3864 + mRestrictedScreenWidth;
3865 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3866 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003867 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3868 || attrs.type == TYPE_VOLUME_OVERLAY) {
3869 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003870 pf.left = df.left = of.left = cf.left = mStableLeft;
3871 pf.top = df.top = of.top = cf.top = mStableTop;
3872 pf.right = df.right = of.right = cf.right = mStableRight;
3873 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003874 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003875 pf.left = mContentLeft;
3876 pf.top = mContentTop;
3877 pf.right = mContentRight;
3878 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003879 if (win.isVoiceInteraction()) {
3880 df.left = of.left = cf.left = mVoiceContentLeft;
3881 df.top = of.top = cf.top = mVoiceContentTop;
3882 df.right = of.right = cf.right = mVoiceContentRight;
3883 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3884 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003885 df.left = of.left = cf.left = mDockLeft;
3886 df.top = of.top = cf.top = mDockTop;
3887 df.right = of.right = cf.right = mDockRight;
3888 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003889 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003890 df.left = of.left = cf.left = mContentLeft;
3891 df.top = of.top = cf.top = mContentTop;
3892 df.right = of.right = cf.right = mContentRight;
3893 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003894 }
3895 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3896 vf.left = mCurLeft;
3897 vf.top = mCurTop;
3898 vf.right = mCurRight;
3899 vf.bottom = mCurBottom;
3900 } else {
3901 vf.set(cf);
3902 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003903 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003904 }
3905 }
Craig Mautner69b08182012-09-05 13:07:13 -07003906
Craig Mautnerb816bed2013-07-23 10:26:17 -07003907 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3908 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003909 df.left = df.top = -10000;
3910 df.right = df.bottom = 10000;
3911 if (attrs.type != TYPE_WALLPAPER) {
3912 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3913 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
3914 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003915 }
3916
Craig Mautnereda67292013-04-28 13:50:14 -07003917 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003918 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07003919 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003920 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003921 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003922 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003923 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07003924 + " dcf=" + dcf.toShortString()
3925 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003926
Adrian Roosfa104232014-06-20 16:10:14 -07003927 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07003928
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003929 // Dock windows carve out the bottom of the screen, so normal windows
3930 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003931 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3932 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003933 setLastInputMethodWindowLw(null, null);
3934 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003935 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003936 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
3937 && !win.getGivenInsetsPendingLw()) {
3938 offsetVoiceInputWindowLw(win);
3939 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003940 }
3941
satok1bc0a492012-04-25 22:47:12 +09003942 private void offsetInputMethodWindowLw(WindowState win) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08003943 int top = win.getDisplayFrameLw().top;
satok1bc0a492012-04-25 22:47:12 +09003944 top += win.getGivenContentInsetsLw().top;
3945 if (mContentBottom > top) {
3946 mContentBottom = top;
3947 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003948 if (mVoiceContentBottom > top) {
3949 mVoiceContentBottom = top;
3950 }
satok1bc0a492012-04-25 22:47:12 +09003951 top = win.getVisibleFrameLw().top;
3952 top += win.getGivenVisibleInsetsLw().top;
3953 if (mCurBottom > top) {
3954 mCurBottom = top;
3955 }
Craig Mautnereda67292013-04-28 13:50:14 -07003956 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003957 + mDockBottom + " mContentBottom="
3958 + mContentBottom + " mCurBottom=" + mCurBottom);
3959 }
3960
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003961 private void offsetVoiceInputWindowLw(WindowState win) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08003962 int top = win.getDisplayFrameLw().top;
3963 top += win.getGivenContentInsetsLw().top;
3964 if (mVoiceContentBottom > top) {
3965 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003966 }
3967 }
3968
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003969 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003970 @Override
3971 public void finishLayoutLw() {
3972 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003973 }
3974
3975 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003976 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003977 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003978 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01003979 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003980 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02003981 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003982 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003983 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003984 mForcingShowNavBar = false;
3985 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07003986
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003987 mHideLockScreen = false;
3988 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003989 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003990 mShowingLockscreen = false;
3991 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003992 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07003993 mKeyguardSecure = isKeyguardSecure();
3994 mKeyguardSecureIncludingHidden = mKeyguardSecure
3995 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003996 }
3997
3998 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003999 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004000 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004001 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4002 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004003 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004004 if (mTopFullscreenOpaqueWindowState == null
4005 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4006 mForcingShowNavBar = true;
4007 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004008 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004009 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004010 mForceStatusBarFromKeyguard = true;
4011 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004012 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004013 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004014 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004015 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004016 mForceStatusBarFromKeyguard = true;
4017 } else {
4018 mForceStatusBar = true;
4019 }
4020 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004021 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004022 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004023 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004024 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Craig Mautner7d7808f2014-09-11 18:02:38 -07004025 && attrs.type < FIRST_SYSTEM_WINDOW;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004026 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004027 // If the lockscreen was showing when the dream started then wait
4028 // for the dream to draw before hiding the lockscreen.
4029 if (!mDreamingLockscreen
4030 || (win.isVisibleLw() && win.hasDrawnLw())) {
4031 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004032 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004033 }
4034 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004035
Craig Mautner00156ec2014-03-06 22:29:02 -08004036 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07004037 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerab55e522014-03-03 13:26:03 -08004038 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004039 final IApplicationToken appToken = win.getAppToken();
4040 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004041 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004042 mAppsToBeHidden.remove(appToken);
4043 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004044 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004045 if (dismissKeyguard && !mKeyguardSecure) {
4046 mAppsThatDismissKeyguard.add(appToken);
4047 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004048 mWinShowWhenLocked = win;
4049 mHideLockScreen = true;
4050 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004051 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004052 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004053 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004054 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004055 mAppsToBeHidden.add(appToken);
4056 } else {
4057 mAppsToBeHidden.remove(appToken);
4058 }
4059 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004060 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004061 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004062 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004063 if (attrs.x == 0 && attrs.y == 0
4064 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4065 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4066 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4067 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004068 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4069 mTopFullscreenOpaqueOrDimmingWindowState = win;
4070 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004071 if (!mAppsThatDismissKeyguard.isEmpty() &&
4072 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4073 if (DEBUG_LAYOUT) Slog.v(TAG,
4074 "Setting mDismissKeyguard true by win " + win);
4075 mDismissKeyguard = mWinDismissingKeyguard == win ?
4076 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
4077 mWinDismissingKeyguard = win;
Jim Millerab954542014-10-10 18:21:49 -07004078 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004079 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4080 if (DEBUG_LAYOUT) Slog.v(TAG,
4081 "Setting mHideLockScreen to true by win " + win);
4082 mHideLockScreen = true;
4083 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004084 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004085 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004086 mAllowLockscreenWhenOn = true;
4087 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004088 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004089
4090 if (mWinShowWhenLocked != null &&
4091 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
4092 win.hideLw(false);
4093 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004094 }
4095 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004096 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4097 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4098 && win.isDimming()) {
4099 mTopFullscreenOpaqueOrDimmingWindowState = win;
4100 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004101 }
4102
4103 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004104 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004105 public int finishPostLayoutPolicyLw() {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004106 if (mWinShowWhenLocked != null &&
4107 mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) {
4108 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4109 // fullscreen window.
4110 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4111 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4112 mTopFullscreenOpaqueWindowState.hideLw(false);
4113 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4114 }
4115
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004116 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004117 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004118
4119 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4120 ? mTopFullscreenOpaqueWindowState.getAttrs()
4121 : null;
4122
Jeff Brownc8018eb2012-10-29 21:33:27 -07004123 // If we are not currently showing a dream then remember the current
4124 // lockscreen state. We will use this to determine whether the dream
4125 // started while the lockscreen was showing and remember this state
4126 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004127 if (!mShowingDream) {
4128 mDreamingLockscreen = mShowingLockscreen;
4129 }
4130
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004131 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004132 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004133 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004134 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004135 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07004136 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004137 if (mStatusBarController.setBarShowingLw(true)) {
4138 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4139 }
Craig Mautner81defc72013-10-29 11:10:42 -07004140 // Maintain fullscreen layout until incoming animation is complete.
4141 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004142 // Transient status bar on the lockscreen is not allowed
4143 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4144 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4145 mLastSystemUiFlags, mLastSystemUiFlags);
4146 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004147 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004148 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004149 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004150 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004151 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004152 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004153 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004154 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004155 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004156 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004157 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004158 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004159 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4160 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004161 if (mStatusBarController.isTransientShowing()) {
4162 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004163 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4164 }
4165 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004166 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004167 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004168 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004169 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004170 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004171 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004172 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004173 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004174 if (mStatusBarController.setBarShowingLw(true)) {
4175 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4176 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004177 }
4178 }
4179 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004180
Craig Mautner81defc72013-10-29 11:10:42 -07004181 if (mTopIsFullscreen != topIsFullscreen) {
4182 if (!topIsFullscreen) {
4183 // Force another layout when status bar becomes fully shown.
4184 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4185 }
4186 mTopIsFullscreen = topIsFullscreen;
4187 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004188
Craig Mautner39834192012-09-02 07:47:24 -07004189 // Hide the key guard if a visible window explicitly specifies that it wants to be
4190 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004191 if (mKeyguardDelegate != null && mStatusBar != null) {
4192 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4193 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004194 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004195 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004196 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004197 changes |= FINISH_LAYOUT_REDO_LAYOUT
4198 | FINISH_LAYOUT_REDO_CONFIG
4199 | FINISH_LAYOUT_REDO_WALLPAPER;
4200 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004201 if (mKeyguardDelegate.isShowing()) {
4202 mHandler.post(new Runnable() {
4203 @Override
4204 public void run() {
4205 mKeyguardDelegate.keyguardDone(false, false);
4206 }
4207 });
4208 }
4209 } else if (mHideLockScreen) {
4210 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004211 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004212 changes |= FINISH_LAYOUT_REDO_LAYOUT
4213 | FINISH_LAYOUT_REDO_CONFIG
4214 | FINISH_LAYOUT_REDO_WALLPAPER;
4215 }
4216 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
4217 // This is the case of keyguard isSecure() and not mHideLockScreen.
4218 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4219 // Only launch the next keyguard unlock window once per window.
4220 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004221 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004222 changes |= FINISH_LAYOUT_REDO_LAYOUT
4223 | FINISH_LAYOUT_REDO_CONFIG
4224 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004225 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004226 mHandler.post(new Runnable() {
4227 @Override
4228 public void run() {
4229 mKeyguardDelegate.dismiss();
4230 }
4231 });
4232 }
4233 } else {
4234 mWinDismissingKeyguard = null;
4235 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004236 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004237 changes |= FINISH_LAYOUT_REDO_LAYOUT
4238 | FINISH_LAYOUT_REDO_CONFIG
4239 | FINISH_LAYOUT_REDO_WALLPAPER;
4240 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004241 }
4242 }
Joe Onorato664644d2011-01-23 17:53:23 -08004243
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004244 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004245 // If the navigation bar has been hidden or shown, we need to do another
4246 // layout pass to update that window.
4247 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4248 }
Joe Onorato664644d2011-01-23 17:53:23 -08004249
Mike Lockwood28569302010-01-28 11:54:40 -05004250 // update since mAllowLockscreenWhenOn might have changed
4251 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004252 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004253 }
4254
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004255 /**
Jim Millerab954542014-10-10 18:21:49 -07004256 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004257 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004258 * @return Whether the flags have changed and we have to redo the layout.
4259 */
Jim Millerab954542014-10-10 18:21:49 -07004260 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4261 boolean wasOccluded = mKeyguardOccluded;
4262 boolean showing = mKeyguardDelegate.isShowing();
4263 if (wasOccluded && !isOccluded && showing) {
4264 mKeyguardOccluded = false;
4265 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004266 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4267 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4268 return true;
Jim Millerab954542014-10-10 18:21:49 -07004269 } else if (!wasOccluded && isOccluded && showing) {
4270 mKeyguardOccluded = true;
4271 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004272 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4273 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4274 return true;
4275 } else {
4276 return false;
4277 }
4278 }
4279
4280 private boolean isStatusBarKeyguard() {
4281 return mStatusBar != null
4282 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4283 }
4284
Jose Lima9546b202014-07-02 17:21:51 -07004285 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004286 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004287 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004288 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004289 return false;
4290 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004291 return true;
4292 }
4293
Jose Lima9546b202014-07-02 17:21:51 -07004294 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004295 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004296 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004297 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004298 // If the navigation bar has been hidden or shown, we need to do another
4299 // layout pass to update that window.
4300 return FINISH_LAYOUT_REDO_LAYOUT;
4301 }
4302 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004303 }
4304
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004305 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004306 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004307 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4308 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004309 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4310 if (newLidState == mLidState) {
4311 return;
4312 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004313
Jeff Brownc458ce92012-04-30 14:58:40 -07004314 mLidState = newLidState;
4315 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004316 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004317
4318 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004319 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004320 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004321 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004322 }
4323 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004324
Michael Wright3818c922014-09-02 13:59:07 -07004325 @Override
4326 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4327 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4328 if (mCameraLensCoverState == lensCoverState) {
4329 return;
4330 }
4331 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4332 lensCoverState == CAMERA_LENS_UNCOVERED) {
4333 Intent intent;
4334 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4335 mKeyguardDelegate.isShowing();
4336 if (keyguardActive) {
4337 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4338 } else {
4339 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4340 }
Bryce Lee584a4452014-10-21 15:55:55 -07004341 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Michael Wright3818c922014-09-02 13:59:07 -07004342 mContext.startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
4343 }
4344 mCameraLensCoverState = lensCoverState;
4345 }
4346
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004347 void setHdmiPlugged(boolean plugged) {
4348 if (mHdmiPlugged != plugged) {
4349 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004350 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004351 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004352 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004353 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004354 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004355 }
4356 }
4357
Joe Onoratoea495d42011-04-06 11:41:11 -07004358 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004359 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004360 // watch for HDMI plug messages if the hdmi switch exists
4361 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4362 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4363
Joe Onoratoea495d42011-04-06 11:41:11 -07004364 final String filename = "/sys/class/switch/hdmi/state";
4365 FileReader reader = null;
4366 try {
4367 reader = new FileReader(filename);
4368 char[] buf = new char[15];
4369 int n = reader.read(buf);
4370 if (n > 1) {
4371 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4372 }
4373 } catch (IOException ex) {
4374 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4375 } catch (NumberFormatException ex) {
4376 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4377 } finally {
4378 if (reader != null) {
4379 try {
4380 reader.close();
4381 } catch (IOException ex) {
4382 }
Joe Onoratodc100302011-01-11 17:07:41 -08004383 }
4384 }
4385 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004386 // This dance forces the code in setHdmiPlugged to run.
4387 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4388 mHdmiPlugged = !plugged;
4389 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004390 }
4391
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004392 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004393 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004394
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004395 final Runnable mScreenshotTimeout = new Runnable() {
4396 @Override public void run() {
4397 synchronized (mScreenshotLock) {
4398 if (mScreenshotConnection != null) {
4399 mContext.unbindService(mScreenshotConnection);
4400 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004401 }
Winson Chung9112ec32011-06-27 13:15:32 -07004402 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004403 }
4404 };
4405
4406 // Assume this is called from the Handler thread.
4407 private void takeScreenshot() {
4408 synchronized (mScreenshotLock) {
4409 if (mScreenshotConnection != null) {
4410 return;
4411 }
4412 ComponentName cn = new ComponentName("com.android.systemui",
4413 "com.android.systemui.screenshot.TakeScreenshotService");
4414 Intent intent = new Intent();
4415 intent.setComponent(cn);
4416 ServiceConnection conn = new ServiceConnection() {
4417 @Override
4418 public void onServiceConnected(ComponentName name, IBinder service) {
4419 synchronized (mScreenshotLock) {
4420 if (mScreenshotConnection != this) {
4421 return;
4422 }
4423 Messenger messenger = new Messenger(service);
4424 Message msg = Message.obtain(null, 1);
4425 final ServiceConnection myConn = this;
4426 Handler h = new Handler(mHandler.getLooper()) {
4427 @Override
4428 public void handleMessage(Message msg) {
4429 synchronized (mScreenshotLock) {
4430 if (mScreenshotConnection == myConn) {
4431 mContext.unbindService(mScreenshotConnection);
4432 mScreenshotConnection = null;
4433 mHandler.removeCallbacks(mScreenshotTimeout);
4434 }
4435 }
4436 }
4437 };
4438 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004439 msg.arg1 = msg.arg2 = 0;
4440 if (mStatusBar != null && mStatusBar.isVisibleLw())
4441 msg.arg1 = 1;
4442 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4443 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004444 try {
4445 messenger.send(msg);
4446 } catch (RemoteException e) {
4447 }
4448 }
4449 }
4450 @Override
4451 public void onServiceDisconnected(ComponentName name) {}
4452 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004453 if (mContext.bindServiceAsUser(
4454 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004455 mScreenshotConnection = conn;
4456 mHandler.postDelayed(mScreenshotTimeout, 10000);
4457 }
4458 }
Winson Chung9112ec32011-06-27 13:15:32 -07004459 }
4460
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004461 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004462 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004463 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004464 if (!mSystemBooted) {
4465 // If we have not yet booted, don't let key events do anything.
4466 return 0;
4467 }
4468
Jeff Brown037c33e2014-04-09 00:31:55 -07004469 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004470 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4471 final boolean canceled = event.isCanceled();
4472 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004473
Jeff Brown3122e442010-10-11 23:32:49 -07004474 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004475
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004476 // If screen is off then we treat the case where the keyguard is open but hidden
4477 // the same as if it were open and in front.
4478 // This will prevent any keys other than the power button from waking the screen
4479 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004480 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004481 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004482 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004483 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004484
Jeff Brown40013652012-05-16 21:22:36 -07004485 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004486 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004487 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004488 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004489 }
4490
Jeff Brown037c33e2014-04-09 00:31:55 -07004491 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004492 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004493 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4494 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004495 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004496 // When the device is interactive or the key is injected pass the
4497 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004498 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004499 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004500 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4501 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4502 // to the application but preserve its wake key status to make sure we still move
4503 // from dozing to fully interactive if we would normally go from off to fully
4504 // interactive.
4505 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004506 } else {
4507 // When the screen is off and the key is not injected, determine whether
4508 // to wake the device but don't pass the key to the application.
4509 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004510 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4511 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004512 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004513 }
4514
Justin Kohd378ad72013-04-01 12:18:26 -07004515 // If the key would be handled globally, just return the result, don't worry about special
4516 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004517 if (isValidGlobalKey(keyCode)
4518 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004519 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004520 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004521 }
Justin Kohd378ad72013-04-01 12:18:26 -07004522 return result;
4523 }
4524
Jeff Brownbae8e772014-06-12 19:59:45 -07004525 boolean useHapticFeedback = down
4526 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4527 && event.getRepeatCount() == 0;
4528
Jeff Brown4d396052010-10-29 21:50:21 -07004529 // Handle special keys.
4530 switch (keyCode) {
4531 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004532 case KeyEvent.KEYCODE_VOLUME_UP:
4533 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004534 if (mUseTvRouting) {
4535 // On TVs volume keys never go to the foreground app
4536 result &= ~ACTION_PASS_TO_USER;
4537 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004538 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4539 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004540 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004541 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004542 mScreenshotChordVolumeDownKeyTriggered = true;
4543 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4544 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004545 cancelPendingPowerKeyAction();
4546 interceptScreenshotChord();
4547 }
4548 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004549 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004550 cancelPendingScreenshotChordAction();
4551 }
4552 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4553 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004554 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004555 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004556 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004557 cancelPendingPowerKeyAction();
4558 cancelPendingScreenshotChordAction();
4559 }
4560 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004561 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004562 cancelPendingScreenshotChordAction();
4563 }
4564 }
Jeff Brown4d396052010-10-29 21:50:21 -07004565 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004566 TelecomManager telecomManager = getTelecommService();
4567 if (telecomManager != null) {
4568 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004569 // If an incoming call is ringing, either VOLUME key means
4570 // "silence ringer". We handle these keys here, rather than
4571 // in the InCallScreen, to make sure we'll respond to them
4572 // even if the InCallScreen hasn't come to the foreground yet.
4573 // Look for the DOWN event here, to agree with the "fallback"
4574 // behavior in the InCallScreen.
4575 Log.i(TAG, "interceptKeyBeforeQueueing:"
4576 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004577
Santos Cordon6848f722014-05-21 15:22:12 -07004578 // Silence the ringer. (It's safe to call this
4579 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004580 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004581
Santos Cordon6848f722014-05-21 15:22:12 -07004582 // And *don't* pass this key thru to the current activity
4583 // (which is probably the InCallScreen.)
4584 result &= ~ACTION_PASS_TO_USER;
4585 break;
4586 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004587 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004588 && (result & ACTION_PASS_TO_USER) == 0) {
4589 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004590 // the application, just pass it to the session service.
4591
4592 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004593 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004594 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004595 }
4596 }
4597
RoboErik430fc482014-06-12 15:49:20 -07004598 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004599 if (mUseTvRouting) {
4600 dispatchDirectAudioEvent(event);
4601 } else {
4602 // If we aren't passing to the user and no one else
4603 // handled it send it to the session manager to
4604 // figure out.
4605 MediaSessionLegacyHelper.getHelper(mContext)
4606 .sendVolumeKeyEvent(event, true);
4607 }
Jeff Brown4d396052010-10-29 21:50:21 -07004608 break;
4609 }
4610 }
4611 break;
4612 }
4613
4614 case KeyEvent.KEYCODE_ENDCALL: {
4615 result &= ~ACTION_PASS_TO_USER;
4616 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004617 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004618 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004619 if (telecomManager != null) {
4620 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004621 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004622 if (interactive && !hungUp) {
4623 mEndCallKeyHandled = false;
4624 mHandler.postDelayed(mEndCallLongPress,
4625 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4626 } else {
4627 mEndCallKeyHandled = true;
4628 }
Jeff Brown4d396052010-10-29 21:50:21 -07004629 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004630 if (!mEndCallKeyHandled) {
4631 mHandler.removeCallbacks(mEndCallLongPress);
4632 if (!canceled) {
4633 if ((mEndcallBehavior
4634 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4635 if (goHome()) {
4636 break;
4637 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004638 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004639 if ((mEndcallBehavior
4640 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4641 mPowerManager.goToSleep(event.getEventTime(),
4642 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4643 isWakeKey = false;
4644 }
Jeff Brown4d396052010-10-29 21:50:21 -07004645 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004646 }
Jeff Brown4d396052010-10-29 21:50:21 -07004647 }
4648 break;
4649 }
4650
4651 case KeyEvent.KEYCODE_POWER: {
4652 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004653 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004654 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004655 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004656 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004657 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004658 }
4659 break;
4660 }
4661
Jeff Brown6212a492014-03-07 13:58:47 -08004662 case KeyEvent.KEYCODE_SLEEP: {
4663 result &= ~ACTION_PASS_TO_USER;
Jeff Brownbae8e772014-06-12 19:59:45 -07004664 if (!mPowerManager.isInteractive()) {
4665 useHapticFeedback = false; // suppress feedback if already non-interactive
4666 }
Jeff Brownc12035c2014-08-13 18:52:25 -07004667 mPowerManager.goToSleep(event.getEventTime(),
4668 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown6212a492014-03-07 13:58:47 -08004669 isWakeKey = false;
4670 break;
4671 }
4672
4673 case KeyEvent.KEYCODE_WAKEUP: {
4674 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004675 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004676 break;
4677 }
4678
Jeff Brown4d396052010-10-29 21:50:21 -07004679 case KeyEvent.KEYCODE_MEDIA_PLAY:
4680 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4681 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004682 case KeyEvent.KEYCODE_HEADSETHOOK:
4683 case KeyEvent.KEYCODE_MUTE:
4684 case KeyEvent.KEYCODE_MEDIA_STOP:
4685 case KeyEvent.KEYCODE_MEDIA_NEXT:
4686 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4687 case KeyEvent.KEYCODE_MEDIA_REWIND:
4688 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004689 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4690 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004691 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4692 // If the global session is active pass all media keys to it
4693 // instead of the active window.
4694 result &= ~ACTION_PASS_TO_USER;
4695 }
Jeff Brown4d396052010-10-29 21:50:21 -07004696 if ((result & ACTION_PASS_TO_USER) == 0) {
4697 // Only do this if we would otherwise not pass it to the user. In that
4698 // case, the PhoneWindow class will do the same thing, except it will
4699 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004700 // Note that we need to make a copy of the key event here because the
4701 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004702 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004703 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4704 new KeyEvent(event));
4705 msg.setAsynchronous(true);
4706 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004707 }
4708 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004709 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004710
Jeff Brown4d396052010-10-29 21:50:21 -07004711 case KeyEvent.KEYCODE_CALL: {
4712 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004713 TelecomManager telecomManager = getTelecommService();
4714 if (telecomManager != null) {
4715 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004716 Log.i(TAG, "interceptKeyBeforeQueueing:"
4717 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004718 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004719
Santos Cordon6848f722014-05-21 15:22:12 -07004720 // And *don't* pass this key thru to the current activity
4721 // (which is presumably the InCallScreen.)
4722 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004723 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004724 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004725 }
Jeff Brown4d396052010-10-29 21:50:21 -07004726 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004727 }
Michael Wright869a67c2014-08-26 19:33:06 -07004728 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4729 // Only do this if we would otherwise not pass it to the user. In that case,
4730 // interceptKeyBeforeDispatching would apply a similar but different policy in
4731 // order to invoke voice assist actions. Note that we need to make a copy of the
4732 // key event here because the original key event will be recycled when we return.
4733 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4734 mBroadcastWakeLock.acquire();
4735 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4736 keyguardActive ? 1 : 0, 0);
4737 msg.setAsynchronous(true);
4738 msg.sendToTarget();
4739 }
4740 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004741 }
Jeff Brown26875502014-01-30 21:47:47 -08004742
Jeff Brownbae8e772014-06-12 19:59:45 -07004743 if (useHapticFeedback) {
4744 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4745 }
4746
Jeff Brown26875502014-01-30 21:47:47 -08004747 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004748 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004749 }
Bryce Lee584a4452014-10-21 15:55:55 -07004750
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004751 return result;
4752 }
4753
Jeff Brown1c2e4942012-11-06 16:32:01 -08004754 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004755 * Returns true if the key can have global actions attached to it.
4756 * We reserve all power management keys for the system since they require
4757 * very careful handling.
4758 */
4759 private static boolean isValidGlobalKey(int keyCode) {
4760 switch (keyCode) {
4761 case KeyEvent.KEYCODE_POWER:
4762 case KeyEvent.KEYCODE_WAKEUP:
4763 case KeyEvent.KEYCODE_SLEEP:
4764 return false;
4765 default:
4766 return true;
4767 }
4768 }
4769
4770 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08004771 * When the screen is off we ignore some keys that might otherwise typically
4772 * be considered wake keys. We filter them out here.
4773 *
4774 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4775 * is always considered a wake key.
4776 */
4777 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4778 switch (keyCode) {
4779 // ignore volume keys unless docked
4780 case KeyEvent.KEYCODE_VOLUME_UP:
4781 case KeyEvent.KEYCODE_VOLUME_DOWN:
4782 case KeyEvent.KEYCODE_VOLUME_MUTE:
4783 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4784
4785 // ignore media and camera keys
4786 case KeyEvent.KEYCODE_MUTE:
4787 case KeyEvent.KEYCODE_HEADSETHOOK:
4788 case KeyEvent.KEYCODE_MEDIA_PLAY:
4789 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4790 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4791 case KeyEvent.KEYCODE_MEDIA_STOP:
4792 case KeyEvent.KEYCODE_MEDIA_NEXT:
4793 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4794 case KeyEvent.KEYCODE_MEDIA_REWIND:
4795 case KeyEvent.KEYCODE_MEDIA_RECORD:
4796 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004797 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004798 case KeyEvent.KEYCODE_CAMERA:
4799 return false;
4800 }
4801 return true;
4802 }
4803
4804
Jeff Brown56194eb2011-03-02 19:23:13 -08004805 /** {@inheritDoc} */
4806 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004807 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4808 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08004809 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
4810 return 0;
4811 }
Michael Wright70af00a2014-09-03 19:30:20 -07004812 }
Bryce Lee5c138322014-11-03 08:26:09 -08004813
Michael Wright70af00a2014-09-03 19:30:20 -07004814 if (shouldDispatchInputWhenNonInteractive()) {
4815 return ACTION_PASS_TO_USER;
4816 }
Bryce Lee5c138322014-11-03 08:26:09 -08004817
Bryce Lee812d7022014-11-10 13:33:28 -08004818 // If we have not passed the action up and we are in theater mode without dreaming,
4819 // there will be no dream to intercept the touch and wake into ambient. The device should
4820 // wake up in this case.
4821 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
4822 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
4823 }
4824
Jeff Brown037c33e2014-04-09 00:31:55 -07004825 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004826 }
4827
Michael Wright70af00a2014-09-03 19:30:20 -07004828 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08004829 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07004830 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
4831 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08004832 return true;
4833 }
4834
4835 // Send events to a dozing dream even if the screen is off since the dream
4836 // is in control of the state of the screen.
4837 IDreamManager dreamManager = getDreamManager();
4838
4839 try {
4840 if (dreamManager != null && dreamManager.isDreaming()) {
4841 return true;
4842 }
4843 } catch (RemoteException e) {
4844 Slog.e(TAG, "RemoteException when checking if dreaming", e);
4845 }
4846
4847 // Otherwise, consume events since the user can't see what is being
4848 // interacted with.
4849 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07004850 }
4851
RoboErik001c59c2015-01-26 15:53:51 -08004852 private void dispatchDirectAudioEvent(KeyEvent event) {
4853 if (event.getAction() != KeyEvent.ACTION_DOWN) {
4854 return;
4855 }
4856 int keyCode = event.getKeyCode();
4857 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND;
4858 String pkgName = mContext.getOpPackageName();
4859 switch (keyCode) {
4860 case KeyEvent.KEYCODE_VOLUME_UP:
4861 try {
4862 if (mUseMasterVolume) {
4863 getAudioService().adjustMasterVolume(AudioManager.ADJUST_RAISE, flags,
4864 pkgName);
4865 } else {
4866 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
4867 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
4868 }
4869 } catch (RemoteException e) {
4870 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
4871 }
4872 break;
4873 case KeyEvent.KEYCODE_VOLUME_DOWN:
4874 try {
4875 if (mUseMasterVolume) {
4876 getAudioService().adjustMasterVolume(AudioManager.ADJUST_LOWER, flags,
4877 pkgName);
4878 } else {
4879 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
4880 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
4881 }
4882 } catch (RemoteException e) {
4883 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
4884 }
4885 break;
4886 case KeyEvent.KEYCODE_VOLUME_MUTE:
4887 try {
4888 if (event.getRepeatCount() == 0) {
4889 if (mUseMasterVolume) {
4890 getAudioService().adjustMasterVolume(AudioManager.ADJUST_TOGGLE_MUTE,
4891 flags, pkgName);
4892 } else {
4893 getAudioService().adjustSuggestedStreamVolume(
4894 AudioManager.ADJUST_TOGGLE_MUTE,
4895 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
4896 }
4897 }
4898 } catch (RemoteException e) {
4899 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
4900 }
4901 break;
4902 }
4903 }
4904
Jeff Brown40013652012-05-16 21:22:36 -07004905 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4906 if (DEBUG_INPUT) {
4907 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004908 }
4909
Jeff Brown40013652012-05-16 21:22:36 -07004910 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4911 if (DEBUG_INPUT) {
4912 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4913 }
4914
4915 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4916 mHavePendingMediaKeyRepeatWithWakeLock = false;
4917 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4918 }
4919
4920 dispatchMediaKeyWithWakeLockToAudioService(event);
4921
4922 if (event.getAction() == KeyEvent.ACTION_DOWN
4923 && event.getRepeatCount() == 0) {
4924 mHavePendingMediaKeyRepeatWithWakeLock = true;
4925
4926 Message msg = mHandler.obtainMessage(
4927 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4928 msg.setAsynchronous(true);
4929 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4930 } else {
4931 mBroadcastWakeLock.release();
4932 }
4933 }
4934
4935 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4936 mHavePendingMediaKeyRepeatWithWakeLock = false;
4937
4938 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4939 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4940 if (DEBUG_INPUT) {
4941 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4942 }
4943
4944 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4945 mBroadcastWakeLock.release();
4946 }
4947
4948 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4949 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07004950 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004951 }
4952 }
4953
Michael Wright869a67c2014-08-26 19:33:06 -07004954 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
4955 Intent voiceIntent =
4956 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
4957 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
4958 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
4959 mBroadcastWakeLock.release();
4960 }
4961
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004962 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004963 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004964 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004965 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4966 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4967 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004968 } else {
4969 try {
4970 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4971 ServiceManager.getService(Context.UI_MODE_SERVICE));
4972 mUiMode = uiModeService.getCurrentModeType();
4973 } catch (RemoteException e) {
4974 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004975 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004976 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004977 synchronized (mLock) {
4978 updateOrientationListenerLp();
4979 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004980 }
4981 };
4982
Jeff Brown6aaf2952012-10-05 16:01:08 -07004983 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4984 @Override
4985 public void onReceive(Context context, Intent intent) {
4986 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004987 if (mKeyguardDelegate != null) {
4988 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004989 }
4990 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004991 if (mKeyguardDelegate != null) {
4992 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004993 }
4994 }
4995 }
4996 };
4997
Christopher Tate5e08af02012-09-21 17:17:22 -07004998 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4999 @Override
5000 public void onReceive(Context context, Intent intent) {
5001 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5002 // tickle the settings observer: this first ensures that we're
5003 // observing the relevant settings for the newly-active user,
5004 // and then updates our own bookkeeping based on the now-
5005 // current user.
5006 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005007
5008 // force a re-application of focused window sysui visibility.
5009 // the window may never have been shown for this user
5010 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005011 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005012 mLastSystemUiFlags = 0;
5013 updateSystemUiVisibilityLw();
5014 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005015 }
5016 }
5017 };
5018
John Spurlockd9b70bd2014-02-06 17:02:44 -05005019 private final Runnable mRequestTransientNav = new Runnable() {
5020 @Override
5021 public void run() {
5022 requestTransientBars(mNavigationBar);
5023 }
5024 };
5025
John Spurlocke1f366f2013-08-05 12:22:40 -04005026 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005027 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005028 if (!isUserSetupComplete()) {
5029 // Swipe-up for navigation bar is disabled during setup
5030 return;
5031 }
John Spurlock27735a42013-08-14 17:57:38 -04005032 boolean sb = mStatusBarController.checkShowTransientBarLw();
5033 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005034 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005035 // Don't show status bar when swiping on already visible navigation bar
5036 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005037 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005038 return;
5039 }
John Spurlock27735a42013-08-14 17:57:38 -04005040 if (sb) mStatusBarController.showTransient();
5041 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005042 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005043 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005044 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005045 }
5046 }
5047
Jeff Brown3ee549c2014-09-22 20:14:39 -07005048 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005049 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07005050 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005051 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07005052 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005053
5054 // We must get this work done here because the power manager will drop
5055 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005056 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005057 mAwake = false;
5058 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005059 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005060 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005061 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005062 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005063
5064 if (mKeyguardDelegate != null) {
5065 mKeyguardDelegate.onScreenTurnedOff(why);
5066 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005067 }
5068
Jeff Brown13f00f02014-10-31 14:45:50 -07005069 private void wakeUpFromPowerKey(long eventTime) {
5070 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5071 }
5072
Bryce Lee5c138322014-11-03 08:26:09 -08005073 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Lee584a4452014-10-21 15:55:55 -07005074 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005075 return false;
Bryce Lee584a4452014-10-21 15:55:55 -07005076 }
5077
5078 mPowerManager.wakeUp(wakeTime);
Bryce Lee5c138322014-11-03 08:26:09 -08005079 return true;
Bryce Lee584a4452014-10-21 15:55:55 -07005080 }
5081
Jeff Brown3ee549c2014-09-22 20:14:39 -07005082 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005083 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07005084 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005085 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07005086 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005087
Jeff Brown3ee549c2014-09-22 20:14:39 -07005088 // Since goToSleep performs these functions synchronously, we must
5089 // do the same here. We cannot post this work to a handler because
5090 // that might cause it to become reordered with respect to what
5091 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005092 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005093 mAwake = true;
5094 mKeyguardDrawComplete = false;
5095 if (mKeyguardDelegate != null) {
5096 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5097 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5098 }
5099
Jeff Browna20dda42014-05-27 20:57:24 -07005100 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005101 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005102 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005103 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005104
Jim Miller5ecd8112013-01-09 18:50:26 -08005105 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07005106 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005107 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005108 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005109 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005110 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005111 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005112 }
5113
Jeff Brown36c4db82014-09-19 12:05:31 -07005114 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005115 synchronized (mLock) {
5116 if (!mAwake || mKeyguardDrawComplete) {
5117 return; // spurious
5118 }
5119
Jeff Brown36c4db82014-09-19 12:05:31 -07005120 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005121 if (mKeyguardDelegate != null) {
5122 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5123 }
5124 }
5125
5126 finishScreenTurningOn();
5127 }
5128
5129 // Called on the DisplayManager's DisplayPowerController thread.
5130 @Override
5131 public void screenTurnedOff() {
5132 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5133
5134 synchronized (mLock) {
5135 mScreenOnEarly = false;
5136 mScreenOnFully = false;
5137 mWindowManagerDrawComplete = false;
5138 mScreenOnListener = null;
5139 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005140 }
5141 }
5142
Jeff Brown3ee549c2014-09-22 20:14:39 -07005143 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005144 @Override
5145 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005146 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005147
Jeff Brown3ee549c2014-09-22 20:14:39 -07005148 synchronized (mLock) {
5149 mScreenOnEarly = true;
5150 mScreenOnFully = false;
5151 mWindowManagerDrawComplete = false;
5152 mScreenOnListener = screenOnListener;
5153 updateOrientationListenerLp();
5154 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005155
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005156 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5157 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005158 // ... eventually calls finishWindowsDrawn
5159 }
5160
Jeff Brown36c4db82014-09-19 12:05:31 -07005161 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005162 synchronized (mLock) {
5163 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5164 return; // spurious
5165 }
5166
Jeff Brown36c4db82014-09-19 12:05:31 -07005167 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005168 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005169
5170 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005171 }
5172
Craig Mautner8a0da012014-05-31 15:13:37 -07005173 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005174 final ScreenOnListener listener;
5175 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005176 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005177 if (DEBUG_WAKEUP) Slog.d(TAG,
5178 "finishScreenTurningOn: mAwake=" + mAwake
5179 + ", mScreenOnEarly=" + mScreenOnEarly
5180 + ", mScreenOnFully=" + mScreenOnFully
5181 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5182 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5183
5184 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5185 || (mAwake && !mKeyguardDrawComplete)) {
5186 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005187 }
5188
Jeff Brown3ee549c2014-09-22 20:14:39 -07005189 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5190 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005191 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005192 mScreenOnFully = true;
5193
5194 // Remember the first time we draw the keyguard so we know when we're done with
5195 // the main part of booting and can enable the screen and hide boot messages.
5196 if (!mKeyguardDrawnOnce && mAwake) {
5197 mKeyguardDrawnOnce = true;
5198 enableScreen = true;
5199 if (mBootMessageNeedsHiding) {
5200 mBootMessageNeedsHiding = false;
5201 hideBootMessages();
5202 }
5203 } else {
5204 enableScreen = false;
5205 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005206 }
5207
Jeff Brown3ee549c2014-09-22 20:14:39 -07005208 if (listener != null) {
5209 listener.onScreenOn();
5210 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005211
Jeff Brown3ee549c2014-09-22 20:14:39 -07005212 if (enableScreen) {
5213 try {
5214 mWindowManager.enableScreenIfNeeded();
5215 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005216 }
Craig Mautnera631d492014-08-05 15:16:01 -07005217 }
5218 }
5219
5220 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005221 synchronized (mLock) {
5222 if (!mKeyguardDrawnOnce) {
5223 mBootMessageNeedsHiding = true;
5224 return; // keyguard hasn't drawn the first time yet, not done booting
5225 }
Craig Mautnera631d492014-08-05 15:16:01 -07005226 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005227
5228 if (mBootMsgDialog != null) {
5229 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5230 mBootMsgDialog.dismiss();
5231 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005232 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005233 }
5234
5235 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005236 public boolean isScreenOn() {
5237 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005238 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005239
Dianne Hackborn08743722009-12-21 12:16:51 -08005240 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005241 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005242 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005243 if (mKeyguardDelegate != null) {
5244 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005245 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005246 }
5247
5248 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005249 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005250 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005251 if (mKeyguardDelegate != null) {
5252 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005253 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005254 }
5255
Jim Millerab954542014-10-10 18:21:49 -07005256 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005257 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005258 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005259 }
5260
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005261 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005262 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005263 public boolean isKeyguardLocked() {
5264 return keyguardOn();
5265 }
5266
5267 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005268 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005269 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005270 if (mKeyguardDelegate == null) return false;
5271 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005272 }
5273
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005274 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005275 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005276 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005277 if (mKeyguardDelegate == null) return false;
5278 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005279 }
5280
Jose Lima9546b202014-07-02 17:21:51 -07005281 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005282 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005283 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005284 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005285 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005286 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005287 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005288 // ask the keyguard to prompt the user to authenticate if necessary
5289 mKeyguardDelegate.dismiss();
5290 }
5291 });
5292 }
5293 }
5294
5295 public void notifyActivityDrawnForKeyguardLw() {
5296 if (mKeyguardDelegate != null) {
5297 mHandler.post(new Runnable() {
5298 @Override
5299 public void run() {
5300 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005301 }
5302 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005303 }
5304 }
5305
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005306 @Override
5307 public boolean isKeyguardDrawnLw() {
5308 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005309 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005310 }
5311 }
5312
Jorim Jaggi0d674622014-05-21 01:34:15 +02005313 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005314 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005315 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005316 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005317 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005318 }
5319 }
5320
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005321 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005322 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005323 }
5324
5325 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005326 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005327 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005328
Jeff Brown01a98dd2011-09-20 15:08:29 -07005329 @Override
5330 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005331 if (false) {
5332 Slog.v(TAG, "rotationForOrientationLw(orient="
5333 + orientation + ", last=" + lastRotation
5334 + "); user=" + mUserRotation + " "
5335 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5336 ? "USER_ROTATION_LOCKED" : "")
5337 );
5338 }
5339
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005340 if (mForceDefaultOrientation) {
5341 return Surface.ROTATION_0;
5342 }
5343
The Android Open Source Project0727d222009-03-11 12:11:58 -07005344 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005345 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5346 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005347 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005348 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005349
Jeff Browndec6cf42011-11-15 14:08:20 -08005350 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005351 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005352 // Ignore sensor when lid switch is open and rotation is forced.
5353 preferredRotation = mLidOpenRotation;
5354 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005355 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005356 // Ignore sensor when in car dock unless explicitly enabled.
5357 // This case can override the behavior of NOSENSOR, and can also
5358 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005359 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005360 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005361 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5362 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5363 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005364 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005365 // Ignore sensor when in desk dock unless explicitly enabled.
5366 // This case can override the behavior of NOSENSOR, and can also
5367 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005368 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005369 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005370 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5371 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005372 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005373 preferredRotation = mDemoHdmiRotation;
5374 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5375 && mUndockedHdmiRotation >= 0) {
5376 // Ignore sensor when plugged into HDMI and an undocked orientation has
5377 // been specified in the configuration (only for legacy devices without
5378 // full multi-display support).
5379 // Note that the dock orientation overrides the HDMI orientation.
5380 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005381 } else if (mDemoRotationLock) {
5382 // Ignore sensor when demo rotation lock is enabled.
5383 // Note that the dock orientation and HDMI rotation lock override this.
5384 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005385 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5386 // Application just wants to remain locked in the last rotation.
5387 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005388 } else if (!mSupportAutoRotation) {
5389 // If we don't support auto-rotation then bail out here and ignore
5390 // the sensor and any rotation lock settings.
5391 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005392 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005393 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005394 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5395 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5396 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5397 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005398 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5399 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5400 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5401 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5402 // Otherwise, use sensor only if requested by the application or enabled
5403 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005404 if (mAllowAllRotations < 0) {
5405 // Can't read this during init() because the context doesn't
5406 // have display metrics at that time so we cannot determine
5407 // tablet vs. phone then.
5408 mAllowAllRotations = mContext.getResources().getBoolean(
5409 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5410 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005411 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005412 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005413 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5414 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005415 preferredRotation = sensorRotation;
5416 } else {
5417 preferredRotation = lastRotation;
5418 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005419 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5420 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5421 // Apply rotation lock. Does not apply to NOSENSOR.
5422 // The idea is that the user rotation expresses a weak preference for the direction
5423 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5424 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005425 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005426 } else {
5427 // No overriding preference.
5428 // We will do exactly what the application asked us to do.
5429 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005430 }
5431
Dianne Hackborne5439f22010-10-02 16:53:50 -07005432 switch (orientation) {
5433 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005434 // Return portrait unless overridden.
5435 if (isAnyPortrait(preferredRotation)) {
5436 return preferredRotation;
5437 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005438 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005439
Jeff Brown01a98dd2011-09-20 15:08:29 -07005440 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005441 // Return landscape unless overridden.
5442 if (isLandscapeOrSeascape(preferredRotation)) {
5443 return preferredRotation;
5444 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005445 return mLandscapeRotation;
5446
5447 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005448 // Return reverse portrait unless overridden.
5449 if (isAnyPortrait(preferredRotation)) {
5450 return preferredRotation;
5451 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005452 return mUpsideDownRotation;
5453
5454 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005455 // Return seascape unless overridden.
5456 if (isLandscapeOrSeascape(preferredRotation)) {
5457 return preferredRotation;
5458 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005459 return mSeascapeRotation;
5460
5461 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005462 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005463 // Return either landscape rotation.
5464 if (isLandscapeOrSeascape(preferredRotation)) {
5465 return preferredRotation;
5466 }
5467 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005468 return lastRotation;
5469 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005470 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005471
Jeff Brown01a98dd2011-09-20 15:08:29 -07005472 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005473 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005474 // Return either portrait rotation.
5475 if (isAnyPortrait(preferredRotation)) {
5476 return preferredRotation;
5477 }
5478 if (isAnyPortrait(lastRotation)) {
5479 return lastRotation;
5480 }
5481 return mPortraitRotation;
5482
5483 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005484 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5485 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005486 if (preferredRotation >= 0) {
5487 return preferredRotation;
5488 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005489 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005490 }
5491 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005492 }
5493
Jeff Brown01a98dd2011-09-20 15:08:29 -07005494 @Override
5495 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5496 switch (orientation) {
5497 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5498 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5499 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5500 return isAnyPortrait(rotation);
5501
5502 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5503 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5504 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5505 return isLandscapeOrSeascape(rotation);
5506
5507 default:
5508 return true;
5509 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005510 }
5511
Jeff Brownc0347aa2011-09-23 17:26:09 -07005512 @Override
5513 public void setRotationLw(int rotation) {
5514 mOrientationListener.setCurrentRotation(rotation);
5515 }
5516
Jeff Brown01a98dd2011-09-20 15:08:29 -07005517 private boolean isLandscapeOrSeascape(int rotation) {
5518 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005519 }
5520
Jeff Brown01a98dd2011-09-20 15:08:29 -07005521 private boolean isAnyPortrait(int rotation) {
5522 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005523 }
5524
Jose Lima9546b202014-07-02 17:21:51 -07005525 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005526 public int getUserRotationMode() {
5527 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005528 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5529 WindowManagerPolicy.USER_ROTATION_FREE :
5530 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005531 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005532
5533 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005534 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005535 public void setUserRotationMode(int mode, int rot) {
5536 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005537
5538 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005539 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005540 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005541 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005542 rot,
5543 UserHandle.USER_CURRENT);
5544 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005545 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005546 0,
5547 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005548 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005549 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005550 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005551 1,
5552 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005553 }
5554 }
5555
Jose Lima9546b202014-07-02 17:21:51 -07005556 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005557 public void setSafeMode(boolean safeMode) {
5558 mSafeMode = safeMode;
5559 performHapticFeedbackLw(null, safeMode
5560 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5561 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005562 }
Craig Mautnereda67292013-04-28 13:50:14 -07005563
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005564 static long[] getLongIntArray(Resources r, int resid) {
5565 int[] ar = r.getIntArray(resid);
5566 if (ar == null) {
5567 return null;
5568 }
5569 long[] out = new long[ar.length];
5570 for (int i=0; i<ar.length; i++) {
5571 out[i] = ar[i];
5572 }
5573 return out;
5574 }
Craig Mautnereda67292013-04-28 13:50:14 -07005575
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005576 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005577 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005578 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005579 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005580 mKeyguardDelegate.onSystemReady();
5581
Michael Wright3818c922014-09-02 13:59:07 -07005582 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005583 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005584 synchronized (mLock) {
5585 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005586 mSystemReady = true;
5587 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005588 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005589 public void run() {
5590 updateSettings();
5591 }
5592 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005593 }
5594 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005595
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005596 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005597 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005598 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005599 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005600 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005601 mKeyguardDelegate.onBootCompleted();
5602 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005603 synchronized (mLock) {
5604 mSystemBooted = true;
5605 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005606 wakingUp();
5607 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005608 }
5609
Dianne Hackborn661cd522011-08-22 00:26:20 -07005610 ProgressDialog mBootMsgDialog = null;
5611
5612 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005613 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005614 public void showBootMessage(final CharSequence msg, final boolean always) {
5615 mHandler.post(new Runnable() {
5616 @Override public void run() {
5617 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005618 int theme;
5619 if (mContext.getPackageManager().hasSystemFeature(
5620 PackageManager.FEATURE_WATCH)) {
5621 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5622 } else if (mContext.getPackageManager().hasSystemFeature(
5623 PackageManager.FEATURE_TELEVISION)) {
5624 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5625 } else {
5626 theme = 0;
5627 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005628
5629 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005630 // This dialog will consume all events coming in to
5631 // it, to avoid it trying to do things too early in boot.
5632 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5633 return true;
5634 }
5635 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5636 return true;
5637 }
5638 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5639 return true;
5640 }
5641 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5642 return true;
5643 }
5644 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5645 return true;
5646 }
5647 @Override public boolean dispatchPopulateAccessibilityEvent(
5648 AccessibilityEvent event) {
5649 return true;
5650 }
5651 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005652 if (mContext.getPackageManager().isUpgrade()) {
5653 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5654 } else {
5655 mBootMsgDialog.setTitle(R.string.android_start_title);
5656 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005657 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5658 mBootMsgDialog.setIndeterminate(true);
5659 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005660 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005661 mBootMsgDialog.getWindow().addFlags(
5662 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5663 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5664 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005665 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5666 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5667 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005668 mBootMsgDialog.setCancelable(false);
5669 mBootMsgDialog.show();
5670 }
5671 mBootMsgDialog.setMessage(msg);
5672 }
5673 });
5674 }
5675
5676 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005677 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005678 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005679 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005680 }
5681
Mike Lockwood28569302010-01-28 11:54:40 -05005682 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005683 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005684 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005685 // ***************************************
5686 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5687 // ***************************************
5688 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5689 // WITH ITS LOCKS HELD.
5690 //
5691 // This code must be VERY careful about the locks
5692 // it acquires.
5693 // In fact, the current code acquires way too many,
5694 // and probably has lurking deadlocks.
5695
Mike Lockwood28569302010-01-28 11:54:40 -05005696 synchronized (mScreenLockTimeout) {
5697 if (mLockScreenTimerActive) {
5698 // reset the timer
5699 mHandler.removeCallbacks(mScreenLockTimeout);
5700 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5701 }
5702 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005703 }
5704
Adam Cohenf7522022012-10-03 20:03:18 -07005705 class ScreenLockTimeout implements Runnable {
5706 Bundle options;
5707
5708 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005709 public void run() {
5710 synchronized (this) {
5711 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005712 if (mKeyguardDelegate != null) {
5713 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005714 }
Mike Lockwood28569302010-01-28 11:54:40 -05005715 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005716 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005717 }
5718 }
Mike Lockwood28569302010-01-28 11:54:40 -05005719
Adam Cohenf7522022012-10-03 20:03:18 -07005720 public void setLockOptions(Bundle options) {
5721 this.options = options;
5722 }
5723 }
5724
5725 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5726
Jose Lima9546b202014-07-02 17:21:51 -07005727 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005728 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005729 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5730 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005731 if (options != null) {
5732 // In case multiple calls are made to lockNow, we don't wipe out the options
5733 // until the runnable actually executes.
5734 mScreenLockTimeout.setLockOptions(options);
5735 }
Jim Miller93c518e2012-01-17 15:55:31 -08005736 mHandler.post(mScreenLockTimeout);
5737 }
5738
Mike Lockwood28569302010-01-28 11:54:40 -05005739 private void updateLockScreenTimeout() {
5740 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005741 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005742 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005743 if (mLockScreenTimerActive != enable) {
5744 if (enable) {
5745 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5746 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5747 } else {
5748 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5749 mHandler.removeCallbacks(mScreenLockTimeout);
5750 }
5751 mLockScreenTimerActive = enable;
5752 }
5753 }
5754 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005755
5756 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005757 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005758 public void enableScreenAfterBoot() {
5759 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005760 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005761 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005762 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005763
Jeff Brownc458ce92012-04-30 14:58:40 -07005764 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005765 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005766 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005767 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005768 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005769 }
Jeff Browna20dda42014-05-27 20:57:24 -07005770
5771 synchronized (mLock) {
5772 updateWakeGestureListenerLp();
5773 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005774 }
5775
Jeff Brown4f5fa282014-06-12 19:19:15 -07005776 void updateUiMode() {
5777 if (mUiModeManager == null) {
5778 mUiModeManager = IUiModeManager.Stub.asInterface(
5779 ServiceManager.getService(Context.UI_MODE_SERVICE));
5780 }
5781 try {
5782 mUiMode = mUiModeManager.getCurrentModeType();
5783 } catch (RemoteException e) {
5784 }
5785 }
5786
Jeff Brown01a98dd2011-09-20 15:08:29 -07005787 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005788 try {
5789 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005790 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5791 } catch (RemoteException e) {
5792 // Ignore
5793 }
5794 }
5795
5796 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5797 try {
5798 //set orientation on WindowManager
5799 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005800 } catch (RemoteException e) {
5801 // Ignore
5802 }
5803 }
5804
Daniel Sandler6396c722013-04-16 20:19:09 -04005805 /**
5806 * Return an Intent to launch the currently active dock app as home. Returns
5807 * null if the standard home should be launched, which is the case if any of the following is
5808 * true:
5809 * <ul>
5810 * <li>The device is not in either car mode or desk mode
5811 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5812 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5813 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5814 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5815 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005816 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005817 */
5818 Intent createHomeDockIntent() {
5819 Intent intent = null;
5820
5821 // What home does is based on the mode, not the dock state. That
5822 // is, when in car mode you should be taken to car home regardless
5823 // of whether we are actually in a car dock.
5824 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5825 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5826 intent = mCarDockIntent;
5827 }
5828 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5829 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5830 intent = mDeskDockIntent;
5831 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005832 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5833 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5834 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5835 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5836 // Always launch dock home from home when watch is docked, if it exists.
5837 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005838 }
5839
5840 if (intent == null) {
5841 return null;
5842 }
5843
5844 ActivityInfo ai = null;
5845 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5846 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005847 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005848 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005849 if (info != null) {
5850 ai = info.activityInfo;
5851 }
5852 if (ai != null
5853 && ai.metaData != null
5854 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5855 intent = new Intent(intent);
5856 intent.setClassName(ai.packageName, ai.name);
5857 return intent;
5858 }
5859
5860 return null;
5861 }
5862
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005863 void startDockOrHome(boolean fromHomeKey) {
John Spurlockc8b46ca2013-04-08 12:59:26 -04005864 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04005865
5866 Intent dock = createHomeDockIntent();
5867 if (dock != null) {
5868 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005869 if (fromHomeKey) {
5870 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5871 }
Daniel Sandler6396c722013-04-16 20:19:09 -04005872 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
5873 return;
5874 } catch (ActivityNotFoundException e) {
5875 }
5876 }
5877
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005878 Intent intent;
5879
5880 if (fromHomeKey) {
5881 intent = new Intent(mHomeIntent);
5882 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5883 } else {
5884 intent = mHomeIntent;
5885 }
5886
5887 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005888 }
Craig Mautnereda67292013-04-28 13:50:14 -07005889
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005890 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005891 * goes to the home screen
5892 * @return whether it did anything
5893 */
5894 boolean goHome() {
5895 if (false) {
5896 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005897 try {
5898 ActivityManagerNative.getDefault().stopAppSwitches();
5899 } catch (RemoteException e) {
5900 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005901 sendCloseSystemWindows();
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005902 startDockOrHome(false /*fromHomeKey*/);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005903 } else {
5904 // This code brings home to the front or, if it is already
5905 // at the front, puts the device to sleep.
5906 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08005907 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
5908 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
5909 Log.d(TAG, "UTS-TEST-MODE");
5910 } else {
5911 ActivityManagerNative.getDefault().stopAppSwitches();
5912 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04005913 Intent dock = createHomeDockIntent();
5914 if (dock != null) {
5915 int result = ActivityManagerNative.getDefault()
5916 .startActivityAsUser(null, null, dock,
5917 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
5918 null, null, 0,
5919 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005920 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04005921 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5922 return false;
5923 }
5924 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005925 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005926 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005927 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005928 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005929 null, null, 0,
5930 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005931 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005932 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005933 return false;
5934 }
5935 } catch (RemoteException ex) {
5936 // bummer, the activity manager, which is in this process, is dead
5937 }
5938 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005939 return true;
5940 }
Craig Mautnereda67292013-04-28 13:50:14 -07005941
5942 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005943 public void setCurrentOrientationLw(int newOrientation) {
5944 synchronized (mLock) {
5945 if (newOrientation != mCurrentAppOrientation) {
5946 mCurrentAppOrientation = newOrientation;
5947 updateOrientationListenerLp();
5948 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005949 }
5950 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005951
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005952 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5953 if (!isGlobalAccessibilityGestureEnabled()) {
5954 return;
5955 }
5956 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5957 Context.AUDIO_SERVICE);
5958 if (audioManager.isSilentMode()) {
5959 return;
5960 }
5961 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5962 Settings.System.DEFAULT_NOTIFICATION_URI);
5963 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5964 ringTone.play();
5965 }
Craig Mautnereda67292013-04-28 13:50:14 -07005966
Bryce Lee584a4452014-10-21 15:55:55 -07005967 private boolean isTheaterModeEnabled() {
5968 return Settings.Global.getInt(mContext.getContentResolver(),
5969 Settings.Global.THEATER_MODE_ON, 0) == 1;
5970 }
5971
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005972 private boolean isGlobalAccessibilityGestureEnabled() {
5973 return Settings.Global.getInt(mContext.getContentResolver(),
5974 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5975 }
5976
Craig Mautnereda67292013-04-28 13:50:14 -07005977 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005978 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005979 if (!mVibrator.hasVibrator()) {
5980 return false;
5981 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005982 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5983 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07005984 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005985 return false;
5986 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005987 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005988 switch (effectId) {
5989 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005990 pattern = mLongPressVibePattern;
5991 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005992 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005993 pattern = mVirtualKeyVibePattern;
5994 break;
5995 case HapticFeedbackConstants.KEYBOARD_TAP:
5996 pattern = mKeyboardTapVibePattern;
5997 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07005998 case HapticFeedbackConstants.CLOCK_TICK:
5999 pattern = mClockTickVibePattern;
6000 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006001 case HapticFeedbackConstants.CALENDAR_DATE:
6002 pattern = mCalendarDateVibePattern;
6003 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006004 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006005 pattern = mSafeModeDisabledVibePattern;
6006 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006007 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006008 pattern = mSafeModeEnabledVibePattern;
6009 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006010 default:
6011 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006012 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006013 int owningUid;
6014 String owningPackage;
6015 if (win != null) {
6016 owningUid = win.getOwningUid();
6017 owningPackage = win.getOwningPackage();
6018 } else {
6019 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006020 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006021 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006022 if (pattern.length == 1) {
6023 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006024 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006025 } else {
6026 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006027 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006028 }
6029 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006030 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006031
6032 @Override
6033 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006034 }
6035
Jeff Brownc38c9be2012-10-04 13:16:19 -07006036 @Override
6037 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006038 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006039 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006040 }
6041 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006042
Dianne Hackborndf89e652011-10-06 22:35:11 -07006043 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006044 // If there is no window focused, there will be nobody to handle the events
6045 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006046 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6047 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006048 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006049 return 0;
6050 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006051 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006052 // We are updating at a point where the keyguard has gotten
6053 // focus, but we were last in a state where the top window is
6054 // hiding it. This is probably because the keyguard as been
6055 // shown while the top window was displayed, so we want to ignore
6056 // it here because this is just a very transient change and it
6057 // will quickly lose focus once it correctly gets hidden.
6058 return 0;
6059 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006060
John Spurlock1db8b682014-02-18 11:18:59 -05006061 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006062 & ~mResettingSystemUiFlags
6063 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006064 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006065 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006066 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006067 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006068 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006069 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006070 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006071 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006072 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006073 return 0;
6074 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006075 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006076 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006077 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006078 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006079 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006080 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006081 try {
6082 IStatusBarService statusbar = getStatusBarService();
6083 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006084 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006085 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006086 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006087 } catch (RemoteException e) {
6088 // re-acquire status bar service next time it is needed.
6089 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006090 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006091 }
6092 });
6093 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006094 }
6095
Adrian Rooscd3884d2015-02-18 17:25:23 +01006096 private int updateLightStatusBarLw(int vis) {
6097 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6098 ? mStatusBar
6099 : mTopFullscreenOpaqueOrDimmingWindowState;
6100
6101 if (statusColorWin != null) {
6102 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6103 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6104 // its light flag.
6105 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6106 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6107 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6108 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6109 // Otherwise if it's dimming, clear the light flag.
6110 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6111 }
6112 }
6113 return vis;
6114 }
6115
John Spurlock79da8332013-09-20 12:04:47 -04006116 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006117 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006118 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6119 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006120 : mTopFullscreenOpaqueWindowState;
6121 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6122 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6123
John Spurlock27735a42013-08-14 17:57:38 -04006124 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04006125 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006126 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006127 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6128 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006129 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006130 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6131 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006132 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006133 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6134 }
John Spurlockbd957402013-10-03 11:38:39 -04006135 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006136 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006137
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006138 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006139 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6140 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006141 }
6142
John Spurlock27735a42013-08-14 17:57:38 -04006143 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006144 boolean immersiveSticky =
6145 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006146 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006147 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006148 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006149 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6150 boolean hideStatusBarSysui =
6151 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006152 boolean hideNavBarSysui =
6153 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006154
John Spurlock27735a42013-08-14 17:57:38 -04006155 boolean transientStatusBarAllowed =
6156 mStatusBar != null && (
6157 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006158 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006159 || statusBarHasFocus);
6160
John Spurlockf1a36642013-10-12 17:50:42 -04006161 boolean transientNavBarAllowed =
6162 mNavigationBar != null &&
6163 hideNavBarSysui && immersiveSticky;
6164
John Spurlockf25706f2013-11-07 18:02:43 -05006165 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006166 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006167 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006168 && !transientNavBarAllowed;
6169 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006170 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006171 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006172 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006173 }
John Spurlock27735a42013-08-14 17:57:38 -04006174
6175 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6176
6177 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006178 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6179 boolean newImmersiveMode = isImmersiveMode(vis);
6180 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006181 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006182 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6183 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006184 }
John Spurlock27735a42013-08-14 17:57:38 -04006185
John Spurlockf1a36642013-10-12 17:50:42 -04006186 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6187
John Spurlocke1f366f2013-08-05 12:22:40 -04006188 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006189 }
6190
John Spurlockf1a36642013-10-12 17:50:42 -04006191 private void clearClearableFlagsLw() {
6192 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6193 if (newVal != mResettingSystemUiFlags) {
6194 mResettingSystemUiFlags = newVal;
6195 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6196 }
6197 }
6198
6199 private boolean isImmersiveMode(int vis) {
6200 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006201 return mNavigationBar != null
6202 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006203 && (vis & flags) != 0
6204 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006205 }
6206
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006207 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006208 * @return whether the navigation or status bar can be made translucent
6209 *
6210 * This should return true unless touch exploration is not enabled or
6211 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006212 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006213 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006214 return mTranslucentDecorEnabled
6215 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006216 }
6217
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006218 // Use this instead of checking config_showNavigationBar so that it can be consistently
6219 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006220 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006221 public boolean hasNavigationBar() {
6222 return mHasNavigationBar;
6223 }
6224
satok1bc0a492012-04-25 22:47:12 +09006225 @Override
6226 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6227 mLastInputMethodWindow = ime;
6228 mLastInputMethodTargetWindow = target;
6229 }
6230
Craig Mautnerf1b67412012-09-19 13:18:29 -07006231 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006232 public int getInputMethodWindowVisibleHeightLw() {
6233 return mDockBottom - mCurBottom;
6234 }
6235
6236 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006237 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006238 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006239 if (mKeyguardDelegate != null) {
6240 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006241 }
John Spurlock13451a22012-09-28 14:40:41 -04006242 if (mStatusBarService != null) {
6243 try {
6244 mStatusBarService.setCurrentUser(newUserId);
6245 } catch (RemoteException e) {
6246 // oh well
6247 }
6248 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006249 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006250 }
6251
6252 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006253 public boolean canMagnifyWindow(int windowType) {
6254 switch (windowType) {
6255 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6256 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6257 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6258 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6259 return false;
6260 }
6261 }
6262 return true;
6263 }
6264
6265 @Override
6266 public boolean isTopLevelWindow(int windowType) {
6267 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6268 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6269 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6270 }
6271 return true;
6272 }
6273
Jim Miller4eeb4f62012-11-08 00:04:29 -08006274 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006275 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006276 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006277 pw.print(" mSystemReady="); pw.print(mSystemReady);
6278 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006279 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006280 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006281 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006282 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006283 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6284 || mForceClearedSystemUiFlags != 0) {
6285 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6286 pw.print(Integer.toHexString(mLastSystemUiFlags));
6287 pw.print(" mResettingSystemUiFlags=0x");
6288 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6289 pw.print(" mForceClearedSystemUiFlags=0x");
6290 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006291 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006292 if (mLastFocusNeedsMenu) {
6293 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6294 pw.println(mLastFocusNeedsMenu);
6295 }
Jeff Browna20dda42014-05-27 20:57:24 -07006296 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6297 pw.println(mWakeGestureEnabledSetting);
6298
Jeff Brownbcdfc622014-03-06 19:13:04 -08006299 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006300 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6301 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006302 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6303 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6304 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6305 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006306 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006307 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006308 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6309 pw.print(mCarDockEnablesAccelerometer);
6310 pw.print(" mDeskDockEnablesAccelerometer=");
6311 pw.println(mDeskDockEnablesAccelerometer);
6312 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6313 pw.print(mLidKeyboardAccessibility);
6314 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006315 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006316 pw.print(prefix);
6317 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6318 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006319 pw.print(prefix);
6320 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6321 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006322 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006323 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6324 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6325 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6326 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6327 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6328 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6329 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006330 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6331 pw.print(","); pw.print(mOverscanScreenTop);
6332 pw.print(") "); pw.print(mOverscanScreenWidth);
6333 pw.print("x"); pw.println(mOverscanScreenHeight);
6334 if (mOverscanLeft != 0 || mOverscanTop != 0
6335 || mOverscanRight != 0 || mOverscanBottom != 0) {
6336 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6337 pw.print(" top="); pw.print(mOverscanTop);
6338 pw.print(" right="); pw.print(mOverscanRight);
6339 pw.print(" bottom="); pw.println(mOverscanBottom);
6340 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006341 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6342 pw.print(mRestrictedOverscanScreenLeft);
6343 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6344 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6345 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006346 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6347 pw.print(","); pw.print(mUnrestrictedScreenTop);
6348 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6349 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6350 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6351 pw.print(","); pw.print(mRestrictedScreenTop);
6352 pw.print(") "); pw.print(mRestrictedScreenWidth);
6353 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006354 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6355 pw.print(","); pw.print(mStableFullscreenTop);
6356 pw.print(")-("); pw.print(mStableFullscreenRight);
6357 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006358 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6359 pw.print(","); pw.print(mStableTop);
6360 pw.print(")-("); pw.print(mStableRight);
6361 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006362 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6363 pw.print(","); pw.print(mSystemTop);
6364 pw.print(")-("); pw.print(mSystemRight);
6365 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006366 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6367 pw.print(","); pw.print(mCurTop);
6368 pw.print(")-("); pw.print(mCurRight);
6369 pw.print(","); pw.print(mCurBottom); pw.println(")");
6370 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6371 pw.print(","); pw.print(mContentTop);
6372 pw.print(")-("); pw.print(mContentRight);
6373 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006374 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6375 pw.print(","); pw.print(mVoiceContentTop);
6376 pw.print(")-("); pw.print(mVoiceContentRight);
6377 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006378 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6379 pw.print(","); pw.print(mDockTop);
6380 pw.print(")-("); pw.print(mDockRight);
6381 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006382 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6383 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006384 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6385 pw.print(" mShowingDream="); pw.print(mShowingDream);
6386 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006387 if (mLastInputMethodWindow != null) {
6388 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6389 pw.println(mLastInputMethodWindow);
6390 }
6391 if (mLastInputMethodTargetWindow != null) {
6392 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6393 pw.println(mLastInputMethodTargetWindow);
6394 }
6395 if (mStatusBar != null) {
6396 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006397 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6398 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006399 }
6400 if (mNavigationBar != null) {
6401 pw.print(prefix); pw.print("mNavigationBar=");
6402 pw.println(mNavigationBar);
6403 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006404 if (mFocusedWindow != null) {
6405 pw.print(prefix); pw.print("mFocusedWindow=");
6406 pw.println(mFocusedWindow);
6407 }
6408 if (mFocusedApp != null) {
6409 pw.print(prefix); pw.print("mFocusedApp=");
6410 pw.println(mFocusedApp);
6411 }
6412 if (mWinDismissingKeyguard != null) {
6413 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6414 pw.println(mWinDismissingKeyguard);
6415 }
6416 if (mTopFullscreenOpaqueWindowState != null) {
6417 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6418 pw.println(mTopFullscreenOpaqueWindowState);
6419 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006420 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6421 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6422 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6423 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006424 if (mForcingShowNavBar) {
6425 pw.print(prefix); pw.print("mForcingShowNavBar=");
6426 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6427 pw.println(mForcingShowNavBarLayer);
6428 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006429 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006430 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006431 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6432 pw.print(" mForceStatusBarFromKeyguard=");
6433 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006434 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006435 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006436 pw.print(" mHomePressed="); pw.println(mHomePressed);
6437 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6438 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6439 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6440 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6441 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6442 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6443 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6444 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6445 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6446 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006447 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6448 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6449 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006450
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006451 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006452 mStatusBarController.dump(pw, prefix);
6453 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006454 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006455
Jeff Browna20dda42014-05-27 20:57:24 -07006456 if (mWakeGestureListener != null) {
6457 mWakeGestureListener.dump(pw, prefix);
6458 }
Jeff Brown600f0032014-05-22 17:06:00 -07006459 if (mOrientationListener != null) {
6460 mOrientationListener.dump(pw, prefix);
6461 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006462 if (mBurnInProtectionHelper != null) {
6463 mBurnInProtectionHelper.dump(prefix, pw);
6464 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006465 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006466}