blob: 0ac679e176ef37f5390a6a131c00e1ba4d936cb0 [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16package com.android.internal.policy.impl;
17
Dianne Hackborna4972e92012-03-14 10:38:05 -070018import android.app.ActivityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080019import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080020import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040021import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070022import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070023import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040024import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080025import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070026import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080027import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040028import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080029import android.content.ContentResolver;
30import android.content.Context;
31import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070032import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070033import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080034import android.content.pm.ActivityInfo;
35import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040036import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070037import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080038import android.content.res.Configuration;
39import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070040import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080042import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080043import android.graphics.Rect;
John Spurlock7b414672014-07-18 13:02:39 -040044import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080045import android.media.AudioManager;
46import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070047import android.media.Ringtone;
48import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070049import android.media.session.MediaSessionLegacyHelper;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070050import android.os.Bundle;
Jeff Brown9a538ee2012-08-20 14:56:57 -070051import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080052import android.os.Handler;
53import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080054import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070055import android.os.Message;
56import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080057import android.os.PowerManager;
58import android.os.RemoteException;
59import android.os.ServiceManager;
60import android.os.SystemClock;
61import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080062import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070063import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080064import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070065import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080066import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070067import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040068import android.service.dreams.DreamService;
69import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070070import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070071import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070072import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080073import android.util.EventLog;
74import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070075import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080076import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070077import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080078import android.view.Gravity;
79import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080080import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080081import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070082import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070083import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080084import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080085import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080086import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080087import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080088import android.view.KeyEvent;
89import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080090import android.view.Surface;
91import android.view.View;
92import android.view.ViewConfiguration;
93import android.view.Window;
94import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -080095import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -070096import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -080097import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -080098import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -080099import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800100import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200101import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800102import android.view.animation.AnimationUtils;
103
104import com.android.internal.R;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100105import com.android.internal.policy.IKeyguardService;
106import com.android.internal.policy.IKeyguardServiceConstants;
Craig Mautnerae446592012-12-06 19:05:05 -0800107import com.android.internal.policy.PolicyManager;
Jim Miller5ecd8112013-01-09 18:50:26 -0800108import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate;
Craig Mautner8a0da012014-05-31 15:13:37 -0700109import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800110import com.android.internal.statusbar.IStatusBarService;
Craig Mautnerae446592012-12-06 19:05:05 -0800111import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700112import com.android.server.LocalServices;
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 Mautnerae446592012-12-06 19:05:05 -0800119
Dianne Hackbornc652de82013-02-15 16:32:56 -0800120import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700121import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
122import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
123import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700124import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
125import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
126import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800127
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800128/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700129 * WindowManagerPolicy implementation for the Android phone UI. This
130 * introduces a new method suffix, Lp, for an internal lock of the
131 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400132 * 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 -0700133 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800134 */
135public class PhoneWindowManager implements WindowManagerPolicy {
136 static final String TAG = "WindowManager";
137 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700138 static final boolean localLOGV = false;
The Android Open Source Project11267662009-03-18 17:39:47 -0700139 static final boolean DEBUG_LAYOUT = false;
Jeff Brown40013652012-05-16 21:22:36 -0700140 static final boolean DEBUG_INPUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700141 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700142 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800143 static final boolean SHOW_STARTING_ANIMATIONS = true;
144 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400145
Daniel Sandler6396c722013-04-16 20:19:09 -0400146 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
147 // No longer recommended for desk docks; still useful in car docks.
148 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
149 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
150
Jeff Brown6d8fd272014-05-20 21:24:38 -0700151 static final int SHORT_PRESS_POWER_NOTHING = 0;
152 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
153 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
154 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
155
Joe Onoratod208e702010-10-08 16:22:43 -0400156 static final int LONG_PRESS_POWER_NOTHING = 0;
157 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
158 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700159 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700160
Jeff Brown13f00f02014-10-31 14:45:50 -0700161 static final int MULTI_PRESS_POWER_NOTHING = 0;
162 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
163 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
164
Michael Jurka3b1fc472011-06-13 10:54:40 -0700165 // These need to match the documentation/constant in
166 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800167 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800168 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700169 static final int LONG_PRESS_HOME_ASSIST = 2;
170
171 static final int DOUBLE_TAP_HOME_NOTHING = 0;
172 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800173
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700174 static final int APPLICATION_MEDIA_SUBLAYER = -2;
175 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800176 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800177 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700178
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800179 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
180 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
181 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500182 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700183 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800184
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700185 /**
186 * These are the system UI flags that, when changing, can cause the layout
187 * of the screen to change.
188 */
189 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400190 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400191 | View.SYSTEM_UI_FLAG_FULLSCREEN
192 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200193 | View.NAVIGATION_BAR_TRANSLUCENT
194 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700195
John Spurlock7b414672014-07-18 13:02:39 -0400196 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
197 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
198 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
199 .build();
200
Jim Miller5ecd8112013-01-09 18:50:26 -0800201 /**
202 * Keyguard stuff
203 */
204 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100205 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700206 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800207
Jeff Brown6651a632011-11-28 12:59:11 -0800208 /* Table of Application Launch keys. Maps from key codes to intent categories.
209 *
210 * These are special keys that are used to launch particular kinds of applications,
211 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
212 * usage page. We don't support quite that many yet...
213 */
214 static SparseArray<String> sApplicationLaunchKeyCategories;
215 static {
216 sApplicationLaunchKeyCategories = new SparseArray<String>();
217 sApplicationLaunchKeyCategories.append(
218 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
219 sApplicationLaunchKeyCategories.append(
220 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
221 sApplicationLaunchKeyCategories.append(
222 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
223 sApplicationLaunchKeyCategories.append(
224 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
225 sApplicationLaunchKeyCategories.append(
226 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
227 sApplicationLaunchKeyCategories.append(
228 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
229 }
230
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700231 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
232 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
233
Dianne Hackborndf89e652011-10-06 22:35:11 -0700234 /**
235 * Lock protecting internal state. Must not call out into window
236 * manager with lock held. (This lock will be acquired in places
237 * where the window manager is calling in with its own lock held.)
238 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800239 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700240
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800241 Context mContext;
242 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700243 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700244 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700245 PowerManager mPowerManager;
Jose Lima9546b202014-07-02 17:21:51 -0700246 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400247 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700248 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700249 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800250 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700251 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800252 AccessibilityManager mAccessibilityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800253
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700254 // Vibrator pattern for haptic feedback of a long press.
255 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700256
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700257 // Vibrator pattern for haptic feedback of virtual key press.
258 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700259
Amith Yamasanic33cb712010-02-10 15:21:49 -0800260 // Vibrator pattern for a short vibration.
261 long[] mKeyboardTapVibePattern;
262
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700263 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
264 long[] mClockTickVibePattern;
265
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700266 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
267 long[] mCalendarDateVibePattern;
268
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700269 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
270 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700271
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700272 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
273 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700274
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800275 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
276 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400277
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800278 boolean mSafeMode;
279 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700280 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400281 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400282 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700283 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400284 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
285 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
286 int[] mNavigationBarHeightForRotation = new int[4];
287 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400288
Craig Mautnera631d492014-08-05 15:16:01 -0700289 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800290 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700291 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700292 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700293 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700294 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
295 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
296 }
297 };
298 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
299 @Override
300 public void onShown(IBinder windowToken) {
301 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
302 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
303 }
304 };
305
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800306 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800307 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900308 WindowState mLastInputMethodWindow = null;
309 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800310
Jeff Brown13f00f02014-10-31 14:45:50 -0700311 // FIXME This state is shared between the input reader and handler thread.
312 // Technically it's broken and buggy but it has been like this for many years
313 // and we have not yet seen any problems. Someday we'll rewrite this logic
314 // so that only one thread is involved in handling input policy. Unfortunately
315 // it's on a critical path for power management so we can't just post the work to the
316 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
317 // to hold wakelocks during dispatch and eliminating the critical path.
318 volatile boolean mPowerKeyHandled;
319 volatile int mPowerKeyPressCounter;
320 volatile boolean mEndCallKeyHandled;
321
Winson Chungd42a6cf2014-06-03 16:24:04 -0700322 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700323 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700324 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800325
Jeff Brown2e7760e2012-04-11 15:14:55 -0700326 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700327 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700328 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800329
Dianne Hackbornc777e072010-02-12 13:07:59 -0800330 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700331 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800332 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700333 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400334 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700335 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700336 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400337 int mCarDockRotation;
338 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700339 int mUndockedHdmiRotation;
340 int mDemoHdmiRotation;
341 boolean mDemoHdmiRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400342
Jeff Browna20dda42014-05-27 20:57:24 -0700343 boolean mWakeGestureEnabledSetting;
344 MyWakeGestureListener mWakeGestureListener;
345
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700346 // Default display does not rotate, apps that require non-default orientation will have to
347 // have the orientation emulated.
348 private boolean mForceDefaultOrientation = false;
349
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400350 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
351 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700352 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400353
Jeff Brownbcdfc622014-03-06 19:13:04 -0800354 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700355 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400356 boolean mCarDockEnablesAccelerometer;
357 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700358 int mLidKeyboardAccessibility;
359 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700360 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700361 int mShortPressOnPowerBehavior;
362 int mLongPressOnPowerBehavior;
363 int mDoublePressOnPowerBehavior;
364 int mTriplePressOnPowerBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700365 boolean mAwake;
366 boolean mScreenOnEarly;
367 boolean mScreenOnFully;
368 ScreenOnListener mScreenOnListener;
369 boolean mKeyguardDrawComplete;
370 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800371 boolean mOrientationSensorEnabled = false;
372 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800373 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400374 boolean mTranslucentDecorEnabled = true;
Craig Mautner967212c2013-04-13 21:10:58 -0700375
Jeff Brown70825162012-03-28 17:27:48 -0700376 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800377
378 // The last window we were told about in focusChanged.
379 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800380 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800381
Jeff Brown70825162012-03-28 17:27:48 -0700382 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800383
Dianne Hackbornc652de82013-02-15 16:32:56 -0800384 // The current size of the screen; really; extends into the overscan area of
385 // the screen and doesn't account for any system elements like the status bar.
386 int mOverscanScreenLeft, mOverscanScreenTop;
387 int mOverscanScreenWidth, mOverscanScreenHeight;
388 // The current visible size of the screen; really; (ir)regardless of whether the status
389 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800390 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
391 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800392 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
393 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
394 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700395 // The current size of the screen; these may be different than (0,0)-(dw,dh)
396 // if the status bar can't be hidden; in that case it effectively carves out
397 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800398 int mRestrictedScreenLeft, mRestrictedScreenTop;
399 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700400 // During layout, the current screen borders accounting for any currently
401 // visible system UI elements.
402 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700403 // For applications requesting stable content insets, these are them.
404 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700405 // For applications requesting stable content insets but have also set the
406 // fullscreen window flag, these are the stable dimensions without the status bar.
407 int mStableFullscreenLeft, mStableFullscreenTop;
408 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800409 // During layout, the current screen borders with all outer decoration
410 // (status bar, input method dock) accounted for.
411 int mCurLeft, mCurTop, mCurRight, mCurBottom;
412 // During layout, the frame in which content should be displayed
413 // to the user, accounting for all screen decoration except for any
414 // space they deem as available for other content. This is usually
415 // the same as mCur*, but may be larger if the screen decor has supplied
416 // content insets.
417 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700418 // During layout, the frame in which voice content should be displayed
419 // to the user, accounting for all screen decoration except for any
420 // space they deem as available for other content.
421 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800422 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800423 // windows are placed.
424 int mDockLeft, mDockTop, mDockRight, mDockBottom;
425 // During layout, the layer at which the doc window is placed.
426 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700427 // During layout, this is the layer of the status bar.
428 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700429 int mLastSystemUiFlags;
430 // Bits that we are in the process of clearing, so we want to prevent
431 // them from being set by applications until everything has been updated
432 // to have them clear.
433 int mResettingSystemUiFlags = 0;
434 // Bits that we are currently always keeping cleared.
435 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800436 // What we last reported to system UI about whether the compatibility
437 // menu needs to be displayed.
438 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700439
440 FakeWindow mHideNavFakeWindow = null;
441
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800442 static final Rect mTmpParentFrame = new Rect();
443 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800444 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800445 static final Rect mTmpContentFrame = new Rect();
446 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400447 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700448 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700449 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700450
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800451 WindowState mTopFullscreenOpaqueWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700452 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200453 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400454 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800455 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700456 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700457 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800458 boolean mForcingShowNavBar;
459 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700460
461 // States of keyguard dismiss.
462 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
463 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
464 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
465 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
466
467 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
468 * be done once per window. */
469 private WindowState mWinDismissingKeyguard;
470
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700471 /** The window that is currently showing "over" the keyguard. If there is an app window
472 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
473 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
474 * the wallpaper. */
475 private WindowState mWinShowWhenLocked;
476
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700477 boolean mShowingLockscreen;
478 boolean mShowingDream;
479 boolean mDreamingLockscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800480 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700481 boolean mHomeConsumed;
482 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800483 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700484 Intent mCarDockIntent;
485 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700486 boolean mSearchKeyShortcutPending;
487 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700488 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700489 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800490
Mike Lockwood28569302010-01-28 11:54:40 -0500491 // support for activating the lock screen while the screen is on
492 boolean mAllowLockscreenWhenOn;
493 int mLockScreenTimeout;
494 boolean mLockScreenTimerActive;
495
David Brownbaf8d092010-03-08 21:52:59 -0800496 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800497 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800498
499 // Behavior of POWER button while in-call and screen on.
500 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
501 int mIncallPowerBehavior;
502
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700503 Display mDisplay;
504
Dianne Hackborn9d132642011-04-21 17:26:39 -0700505 int mLandscapeRotation = 0; // default landscape rotation
506 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
507 int mPortraitRotation = 0; // default portrait rotation
508 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700509
Dianne Hackbornc652de82013-02-15 16:32:56 -0800510 int mOverscanLeft = 0;
511 int mOverscanTop = 0;
512 int mOverscanRight = 0;
513 int mOverscanBottom = 0;
514
Joe Onorato46b0d682010-11-22 17:37:27 -0800515 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700516 private int mLongPressOnHomeBehavior;
517
518 // What we do when the user double-taps on home
519 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800520
Bryce Lee584a4452014-10-21 15:55:55 -0700521 // Allowed theater mode wake actions
522 private boolean mAllowTheaterModeWakeFromKey;
523 private boolean mAllowTheaterModeWakeFromPowerKey;
524 private boolean mAllowTheaterModeWakeFromMotion;
525 private boolean mAllowTheaterModeWakeFromCameraLens;
526 private boolean mAllowTheaterModeWakeFromLidSwitch;
527 private boolean mAllowTheaterModeWakeFromWakeGesture;
528
Winson Chung9112ec32011-06-27 13:15:32 -0700529 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700530 // Time to volume and power must be pressed within this interval of each other.
531 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700532 // Increase the chord delay when taking a screenshot from the keyguard
533 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800534 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700535 private boolean mScreenshotChordVolumeDownKeyTriggered;
536 private long mScreenshotChordVolumeDownKeyTime;
537 private boolean mScreenshotChordVolumeDownKeyConsumed;
538 private boolean mScreenshotChordVolumeUpKeyTriggered;
539 private boolean mScreenshotChordPowerKeyTriggered;
540 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700541
Michael Wrightb854e242013-02-05 17:54:02 -0800542 /* The number of steps between min and max brightness */
543 private static final int BRIGHTNESS_STEPS = 10;
544
Christopher Tate5e08af02012-09-21 17:17:22 -0700545 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800546 ShortcutManager mShortcutManager;
547 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700548 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700549 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800550
Craig Mautnerd625ab22013-09-06 13:40:31 -0700551 private int mCurrentUserId;
552
Justin Kohd378ad72013-04-01 12:18:26 -0700553 // Maps global key codes to the components that will handle them.
554 private GlobalKeyManager mGlobalKeyManager;
555
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700556 // Fallback actions by key code.
557 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
558 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800559
Jorim Jaggi76a16232014-08-08 17:00:47 +0200560 private final LogDecelerateInterpolator mLogDecelerateInterpolator
561 = new LogDecelerateInterpolator(100, 0);
562
Jeff Brown70825162012-03-28 17:27:48 -0700563 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
564 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700565 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
566 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700567 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
568 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
569 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700570 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700571 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700572 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700573 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700574 private static final int MSG_POWER_DELAYED_PRESS = 13;
575 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown70825162012-03-28 17:27:48 -0700576
577 private class PolicyHandler extends Handler {
578 @Override
579 public void handleMessage(Message msg) {
580 switch (msg.what) {
581 case MSG_ENABLE_POINTER_LOCATION:
582 enablePointerLocation();
583 break;
584 case MSG_DISABLE_POINTER_LOCATION:
585 disablePointerLocation();
586 break;
Jeff Brown40013652012-05-16 21:22:36 -0700587 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
588 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
589 break;
590 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
591 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
592 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700593 case MSG_DISPATCH_SHOW_RECENTS:
594 showRecentApps(false);
595 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700596 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
597 showGlobalActionsInternal();
598 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700599 case MSG_KEYGUARD_DRAWN_COMPLETE:
600 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700601 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700602 break;
603 case MSG_KEYGUARD_DRAWN_TIMEOUT:
604 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700605 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700606 break;
607 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
608 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700609 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700610 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700611 case MSG_HIDE_BOOT_MESSAGE:
612 handleHideBootMessage();
613 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700614 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
615 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
616 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700617 case MSG_POWER_DELAYED_PRESS:
618 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
619 finishPowerKeyPress();
620 break;
621 case MSG_POWER_LONG_PRESS:
622 powerLongPress();
623 break;
Jeff Brown70825162012-03-28 17:27:48 -0700624 }
625 }
626 }
627
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800628 private UEventObserver mHDMIObserver = new UEventObserver() {
629 @Override
630 public void onUEvent(UEventObserver.UEvent event) {
631 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
632 }
633 };
634
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800635 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800636 SettingsObserver(Handler handler) {
637 super(handler);
638 }
David Brownbaf8d092010-03-08 21:52:59 -0800639
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800640 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700641 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800642 ContentResolver resolver = mContext.getContentResolver();
643 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700644 Settings.System.END_BUTTON_BEHAVIOR), false, this,
645 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800646 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700647 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
648 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700649 resolver.registerContentObserver(Settings.Secure.getUriFor(
650 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
651 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800652 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700653 Settings.System.ACCELEROMETER_ROTATION), false, this,
654 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500655 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700656 Settings.System.USER_ROTATION), false, this,
657 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400658 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700659 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
660 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800661 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700662 Settings.System.POINTER_LOCATION), false, this,
663 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800664 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700665 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
666 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500667 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400668 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700669 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500670 resolver.registerContentObserver(Settings.Global.getUriFor(
671 Settings.Global.POLICY_CONTROL), false, this,
672 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800673 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800674 }
675
676 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800677 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700678 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800679 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800680 }
Craig Mautner967212c2013-04-13 21:10:58 -0700681
Jeff Browna20dda42014-05-27 20:57:24 -0700682 class MyWakeGestureListener extends WakeGestureListener {
683 MyWakeGestureListener(Context context, Handler handler) {
684 super(context, handler);
685 }
686
687 @Override
688 public void onWakeUp() {
689 synchronized (mLock) {
690 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700691 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700692 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700693 }
694 }
695 }
696 }
697
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800698 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800699 MyOrientationListener(Context context, Handler handler) {
700 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800701 }
Craig Mautner967212c2013-04-13 21:10:58 -0700702
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800703 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700704 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700705 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700706 updateRotation(false);
707 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800708 }
709 MyOrientationListener mOrientationListener;
710
John Spurlock27735a42013-08-14 17:57:38 -0400711 private final BarController mStatusBarController = new BarController("StatusBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400712 View.STATUS_BAR_TRANSIENT,
713 View.STATUS_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400714 View.STATUS_BAR_TRANSLUCENT,
715 StatusBarManager.WINDOW_STATUS_BAR,
716 WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
John Spurlock5b9145b2013-08-20 15:13:47 -0400717
John Spurlock27735a42013-08-14 17:57:38 -0400718 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400719 View.NAVIGATION_BAR_TRANSIENT,
720 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400721 View.NAVIGATION_BAR_TRANSLUCENT,
722 StatusBarManager.WINDOW_NAVIGATION_BAR,
723 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400724
John Spurlockf1a36642013-10-12 17:50:42 -0400725 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400726
Craig Mautner037aa8d2013-06-07 10:35:44 -0700727 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400728
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700729 IStatusBarService getStatusBarService() {
730 synchronized (mServiceAquireLock) {
731 if (mStatusBarService == null) {
732 mStatusBarService = IStatusBarService.Stub.asInterface(
733 ServiceManager.getService("statusbar"));
734 }
735 return mStatusBarService;
736 }
737 }
738
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700739 /*
740 * We always let the sensor be switched on by default except when
741 * the user has explicitly disabled sensor based rotation or when the
742 * screen is switched off.
743 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700744 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800745 if (mSupportAutoRotation) {
746 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
747 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
748 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
749 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
750 // If the application has explicitly requested to follow the
751 // orientation, then we need to turn the sensor on.
752 return true;
753 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800754 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700755 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800756 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
757 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
758 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400759 // enable accelerometer if we are docked in a dock that enables accelerometer
760 // orientation management,
761 return true;
762 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700763 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800764 // If the setting for using the sensor by default is enabled, then
765 // we will always leave it on. Note that the user could go to
766 // a window that forces an orientation that does not use the
767 // sensor and in theory we could turn it off... however, when next
768 // turning it on we won't have a good value for the current
769 // orientation for a little bit, which can cause orientation
770 // changes to lag, so we'd like to keep it always on. (It will
771 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700772 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800773 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800774 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800775 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700776
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800777 /*
778 * Various use cases for invoking this function
779 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700780 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800781 * if not already enabled
782 * screen turned on and current app does not have sensor orientation, disable listeners if
783 * already enabled
784 * screen turning on and current app has sensor based orientation, enable listeners if needed
785 * screen turning on and current app has nosensor based orientation, do nothing
786 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700787 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800788 if (!mOrientationListener.canDetectOrientation()) {
789 // If sensor is turned off or nonexistent for some reason
790 return;
791 }
792 //Could have been invoked due to screen turning on or off or
793 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700794 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
795 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
796 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800797 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700798 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700799 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800800 disable = false;
801 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700802 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800803 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700804 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800805 mOrientationSensorEnabled = true;
806 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700807 }
808 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800809 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700810 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800811 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700812 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800813 mOrientationSensorEnabled = false;
814 }
815 }
816
Jeff Brown13f00f02014-10-31 14:45:50 -0700817 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
818 // Hold a wake lock until the power key is released.
819 if (!mPowerKeyWakeLock.isHeld()) {
820 mPowerKeyWakeLock.acquire();
821 }
822
823 // Cancel multi-press detection timeout.
824 if (mPowerKeyPressCounter != 0) {
825 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
826 }
827
828 // Detect user pressing the power button in panic when an application has
829 // taken over the whole screen.
830 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
831 event.getDownTime(), isImmersiveMode(mLastSystemUiFlags));
832 if (panic) {
833 mHandler.post(mRequestTransientNav);
834 }
835
836 // Latch power key state to detect screenshot chord.
837 if (interactive && !mScreenshotChordPowerKeyTriggered
838 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
839 mScreenshotChordPowerKeyTriggered = true;
840 mScreenshotChordPowerKeyTime = event.getDownTime();
841 interceptScreenshotChord();
842 }
843
844 // Stop ringing or end call if configured to do so when power is pressed.
845 TelecomManager telecomManager = getTelecommService();
846 boolean hungUp = false;
847 if (telecomManager != null) {
848 if (telecomManager.isRinging()) {
849 // Pressing Power while there's a ringing incoming
850 // call should silence the ringer.
851 telecomManager.silenceRinger();
852 } else if ((mIncallPowerBehavior
853 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
854 && telecomManager.isInCall() && interactive) {
855 // Otherwise, if "Power button ends call" is enabled,
856 // the Power button will hang up any current active call.
857 hungUp = telecomManager.endCall();
858 }
859 }
860
861 // If the power key has still not yet been handled, then detect short
862 // press, long press, or multi press and decide what to do.
863 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
864 || mScreenshotChordVolumeUpKeyTriggered;
865 if (!mPowerKeyHandled) {
866 if (interactive) {
867 // When interactive, we're already awake.
868 // Wait for a long press or for the button to be released to decide what to do.
869 if (hasLongPressOnPowerBehavior()) {
870 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
871 msg.setAsynchronous(true);
872 mHandler.sendMessageDelayed(msg,
873 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
874 }
875 } else {
876 // When non-interactive, we ordinarily wake up immediately and
877 // consume the key. However on some devices we need to support multi-press
878 // without waking so we will delay handling for later in that case
879 // (at the cost of increased latency).
880 final int maxCount = getMaxMultiPressPowerCount();
881 if (maxCount <= 1) {
882 // No other actions. We can wake immediately.
883 wakeUpFromPowerKey(event.getDownTime());
884 mPowerKeyHandled = true;
885 }
886 }
Jeff Brown4d396052010-10-29 21:50:21 -0700887 }
888 }
889
Jeff Brown13f00f02014-10-31 14:45:50 -0700890 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
891 final boolean handled = canceled || mPowerKeyHandled;
892 mScreenshotChordPowerKeyTriggered = false;
893 cancelPendingScreenshotChordAction();
894 cancelPendingPowerKeyAction();
895
896 if (!handled) {
897 // Figure out how to handle the key now that it has been released.
898 mPowerKeyPressCounter += 1;
899
900 final int maxCount = getMaxMultiPressPowerCount();
901 final long eventTime = event.getDownTime();
902 if (mPowerKeyPressCounter < maxCount) {
903 // This could be a multi-press. Wait a little bit longer to confirm.
904 // Continue holding the wake lock.
905 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
906 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
907 msg.setAsynchronous(true);
908 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
909 return;
910 }
911
912 // No other actions. Handle it immediately.
913 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700914 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700915
916 // Done. Reset our state.
917 finishPowerKeyPress();
918 }
919
920 private void finishPowerKeyPress() {
921 mPowerKeyPressCounter = 0;
922 if (mPowerKeyWakeLock.isHeld()) {
923 mPowerKeyWakeLock.release();
924 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700925 }
926
927 private void cancelPendingPowerKeyAction() {
928 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700929 mPowerKeyHandled = true;
930 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700931 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700932 }
933
934 private void powerPress(long eventTime, boolean interactive, int count) {
935 if (mScreenOnEarly && !mScreenOnFully) {
936 Slog.i(TAG, "Suppressed redundant power key press while "
937 + "already in the process of turning the screen on.");
938 return;
Jeff Brownff204712011-10-25 21:27:54 -0700939 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700940
941 if (count == 2) {
942 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
943 } else if (count == 3) {
944 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
945 } else if (!interactive) {
946 wakeUpFromPowerKey(eventTime);
947 } else {
948 switch (mShortPressOnPowerBehavior) {
949 case SHORT_PRESS_POWER_NOTHING:
950 break;
951 case SHORT_PRESS_POWER_GO_TO_SLEEP:
952 mPowerManager.goToSleep(eventTime,
953 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
954 break;
955 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
956 mPowerManager.goToSleep(eventTime,
957 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
958 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
959 break;
960 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
961 mPowerManager.goToSleep(eventTime,
962 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
963 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
964 launchHomeFromHotKey();
965 break;
966 }
967 }
968 }
969
970 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
971 switch (behavior) {
972 case MULTI_PRESS_POWER_NOTHING:
973 break;
974 case MULTI_PRESS_POWER_THEATER_MODE:
975 if (isTheaterModeEnabled()) {
976 Slog.i(TAG, "Toggling theater mode off.");
977 Settings.Global.putInt(mContext.getContentResolver(),
978 Settings.Global.THEATER_MODE_ON, 0);
979 if (!interactive) {
980 wakeUpFromPowerKey(eventTime);
981 }
982 } else {
983 Slog.i(TAG, "Toggling theater mode on.");
984 Settings.Global.putInt(mContext.getContentResolver(),
985 Settings.Global.THEATER_MODE_ON, 1);
986 if (interactive) {
987 mPowerManager.goToSleep(eventTime,
988 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
989 }
990 }
991 break;
992 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
993 mPowerManager.boostScreenBrightness(eventTime);
994 break;
995 }
996 }
997
998 private int getMaxMultiPressPowerCount() {
999 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1000 return 3;
1001 }
1002 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1003 return 2;
1004 }
1005 return 1;
1006 }
1007
1008 private void powerLongPress() {
1009 final int behavior = getResolvedLongPressOnPowerBehavior();
1010 switch (behavior) {
1011 case LONG_PRESS_POWER_NOTHING:
1012 break;
1013 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1014 mPowerKeyHandled = true;
1015 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1016 performAuditoryFeedbackForAccessibilityIfNeed();
1017 }
1018 showGlobalActionsInternal();
1019 break;
1020 case LONG_PRESS_POWER_SHUT_OFF:
1021 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1022 mPowerKeyHandled = true;
1023 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1024 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1025 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1026 break;
1027 }
1028 }
1029
1030 private int getResolvedLongPressOnPowerBehavior() {
1031 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1032 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1033 }
1034 return mLongPressOnPowerBehavior;
1035 }
1036
1037 private boolean hasLongPressOnPowerBehavior() {
1038 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001039 }
1040
1041 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001042 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001043 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1044 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001045 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001046 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1047 && now <= mScreenshotChordPowerKeyTime
1048 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1049 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001050 cancelPendingPowerKeyAction();
1051
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001052 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001053 }
1054 }
1055 }
1056
Winson Chung1cea2f32012-10-08 20:42:01 -07001057 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001058 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001059 // Double the time it takes to take a screenshot from the keyguard
1060 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001061 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001062 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001063 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001064 }
1065
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001066 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001067 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001068 }
1069
Jeff Brown13f00f02014-10-31 14:45:50 -07001070 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001071 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001072 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001073 mEndCallKeyHandled = true;
1074 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1075 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001076 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001077 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001078 }
1079 };
1080
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001081 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001082 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001083 public void run() {
1084 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001085 }
1086 };
1087
Alan Viverettee34560b22014-07-10 14:50:06 -07001088 @Override
1089 public void showGlobalActions() {
1090 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1091 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1092 }
1093
1094 void showGlobalActionsInternal() {
1095 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001096 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001097 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001098 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -07001099 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001100 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1101 if (keyguardShowing) {
1102 // since it took two seconds of long press to bring this up,
1103 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001104 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001105 }
1106 }
1107
1108 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001109 return Settings.Global.getInt(
1110 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001111 }
1112
Maurice Lam99c6e072014-04-28 18:24:28 -07001113 boolean isUserSetupComplete() {
1114 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1115 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1116 }
1117
Jeff Brown13f00f02014-10-31 14:45:50 -07001118 private void handleShortPressOnHome() {
1119 // If there's a dream running then use home to escape the dream
1120 // but don't actually go home.
1121 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1122 mDreamManagerInternal.stopDream(false /*immediate*/);
1123 return;
1124 }
1125
1126 // Go home!
1127 launchHomeFromHotKey();
1128 }
1129
Patrick Dubroyece94522011-02-23 18:35:01 -08001130 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -08001131 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001132 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001133 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001134
Jeff Browncaca8812013-05-09 13:34:33 -07001135 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1136 toggleRecentApps();
1137 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1138 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -07001139 }
1140 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001141 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001142
Jeff Browncaca8812013-05-09 13:34:33 -07001143 private void handleDoubleTapOnHome() {
1144 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1145 mHomeConsumed = true;
1146 toggleRecentApps();
1147 }
1148 }
1149
1150 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1151 @Override
1152 public void run() {
1153 if (mHomeDoubleTapPending) {
1154 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001155 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001156 }
1157 }
1158 };
1159
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001160 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001161 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001162 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001163 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001164 mContext = context;
1165 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001166 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001167 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001168 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Craig Mautner8a0da012014-05-31 15:13:37 -07001169
Jeff Brown70825162012-03-28 17:27:48 -07001170 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001171 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001172 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001173 try {
1174 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1175 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001176 mSettingsObserver = new SettingsObserver(mHandler);
1177 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001178 mShortcutManager = new ShortcutManager(context, mHandler);
1179 mShortcutManager.observe();
Daniel Sandler6396c722013-04-16 20:19:09 -04001180 mUiMode = context.getResources().getInteger(
1181 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001182 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1183 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1184 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1185 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001186 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1187 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1188 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1189 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1190 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1191 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1192 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1193 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001194
Jeff Brown96307042012-07-27 15:51:34 -07001195 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1196 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001197 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001198 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1199 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001200 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001201 mSupportAutoRotation = mContext.getResources().getBoolean(
1202 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001203 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001204 com.android.internal.R.integer.config_lidOpenRotation);
1205 mCarDockRotation = readRotation(
1206 com.android.internal.R.integer.config_carDockRotation);
1207 mDeskDockRotation = readRotation(
1208 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001209 mUndockedHdmiRotation = readRotation(
1210 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001211 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1212 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1213 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1214 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001215 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1216 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1217 mLidNavigationAccessibility = mContext.getResources().getInteger(
1218 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001219 mLidControlsSleep = mContext.getResources().getBoolean(
1220 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001221 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1222 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001223
1224 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1225 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1226 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1227 || mContext.getResources().getBoolean(
1228 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1229 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1230 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
1231 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1232 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1233 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1234 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1235 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1236 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1237
Jeff Brown13f00f02014-10-31 14:45:50 -07001238 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1239 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1240 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1241 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1242 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1243 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1244 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1245 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
1246
Jeff Brownf71343d2013-05-31 17:59:11 -07001247 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001248
Svetoslav8e3feb12014-02-24 13:46:47 -08001249 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1250 Context.ACCESSIBILITY_SERVICE);
1251
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001252 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001253 IntentFilter filter = new IntentFilter();
1254 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1255 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1256 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1257 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001258 filter.addAction(Intent.ACTION_DOCK_EVENT);
1259 Intent intent = context.registerReceiver(mDockReceiver, filter);
1260 if (intent != null) {
1261 // Retrieve current sticky dock event broadcast.
1262 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1263 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1264 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001265
Jeff Brown6aaf2952012-10-05 16:01:08 -07001266 // register for dream-related broadcasts
1267 filter = new IntentFilter();
1268 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1269 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1270 context.registerReceiver(mDreamReceiver, filter);
1271
Christopher Tate5e08af02012-09-21 17:17:22 -07001272 // register for multiuser-relevant broadcasts
1273 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1274 context.registerReceiver(mMultiuserReceiver, filter);
1275
John Spurlock57306e62013-04-22 09:48:49 -04001276 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001277 mSystemGestures = new SystemGesturesPointerEventListener(context,
1278 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001279 @Override
1280 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001281 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001282 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001283 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001284 }
1285 @Override
1286 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001287 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001288 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001289 }
1290 }
1291 @Override
1292 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001293 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001294 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001295 }
1296 }
1297 @Override
1298 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001299 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001300 }
1301 });
John Spurlockf1a36642013-10-12 17:50:42 -04001302 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001303 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001304
Jeff Brownc2346132012-04-13 01:55:38 -07001305 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001306 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1307 com.android.internal.R.array.config_longPressVibePattern);
1308 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1309 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001310 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1311 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001312 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1313 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001314 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1315 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001316 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1317 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1318 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1319 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001320
Christopher Tatee90585f2012-03-05 18:56:25 -08001321 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1322 com.android.internal.R.bool.config_enableScreenshotChord);
1323
Justin Kohd378ad72013-04-01 12:18:26 -07001324 mGlobalKeyManager = new GlobalKeyManager(mContext);
1325
Joe Onoratoea495d42011-04-06 11:41:11 -07001326 // Controls rotation and the like.
1327 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001328
1329 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001330 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001331 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001332 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001333 }
1334
Jeff Brownf71343d2013-05-31 17:59:11 -07001335 /**
1336 * Read values from config.xml that may be overridden depending on
1337 * the configuration of the device.
1338 * eg. Disable long press on home goes to recents on sw600dp.
1339 */
1340 private void readConfigurationDependentBehaviors() {
1341 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1342 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1343 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1344 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1345 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1346 }
1347
1348 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1349 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1350 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1351 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1352 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1353 }
1354 }
1355
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001356 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001357 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001358 // This method might be called before the policy has been fully initialized
1359 // or for other displays we don't care about.
1360 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1361 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001362 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001363 mDisplay = display;
1364
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001365 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001366 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001367 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001368 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001369 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001370 mLandscapeRotation = Surface.ROTATION_0;
1371 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001372 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001373 mPortraitRotation = Surface.ROTATION_90;
1374 mUpsideDownRotation = Surface.ROTATION_270;
1375 } else {
1376 mPortraitRotation = Surface.ROTATION_270;
1377 mUpsideDownRotation = Surface.ROTATION_90;
1378 }
1379 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001380 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001381 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001382 mPortraitRotation = Surface.ROTATION_0;
1383 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001384 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001385 mLandscapeRotation = Surface.ROTATION_270;
1386 mSeascapeRotation = Surface.ROTATION_90;
1387 } else {
1388 mLandscapeRotation = Surface.ROTATION_90;
1389 mSeascapeRotation = Surface.ROTATION_270;
1390 }
1391 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001392
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001393 mStatusBarHeight =
1394 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001395
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001396 // Height of the navigation bar when presented horizontally at bottom
1397 mNavigationBarHeightForRotation[mPortraitRotation] =
1398 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001399 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001400 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001401 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1402 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001403
1404 // Width of the navigation bar when presented vertically along one side
1405 mNavigationBarWidthForRotation[mPortraitRotation] =
1406 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1407 mNavigationBarWidthForRotation[mLandscapeRotation] =
1408 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001409 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001410
1411 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001412 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001413 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001414
Craig Mautnerd4ec33242013-07-22 10:37:43 -07001415 // Allow the navigation bar to move on small devices (phones).
1416 mNavigationBarCanMove = shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001417
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001418 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001419 // Allow a system property to override this. Used by the emulator.
1420 // See also hasNavigationBar().
1421 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1422 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001423 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001424 } else if ("0".equals(navBarOverride)) {
1425 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001426 }
1427
Jeff Brown27f1d672012-10-17 18:32:34 -07001428 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1429 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001430 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001431 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001432 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001433 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001434 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001435 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001436
1437 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1438 // http://developer.android.com/guide/practices/screens_support.html#range
1439 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1440 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1441 // For debug purposes the next line turns this feature off with:
1442 // $ adb shell setprop config.override_forced_orient true
1443 // $ adb shell wm size reset
1444 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1445 }
1446
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001447 /**
1448 * @return whether the navigation bar can be hidden, e.g. the device has a
1449 * navigation bar and touch exploration is not enabled
1450 */
1451 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001452 return mHasNavigationBar
1453 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001454 }
1455
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001456 @Override
1457 public boolean isDefaultOrientationForced() {
1458 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001459 }
1460
Dianne Hackbornc652de82013-02-15 16:32:56 -08001461 @Override
1462 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1463 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1464 mOverscanLeft = left;
1465 mOverscanTop = top;
1466 mOverscanRight = right;
1467 mOverscanBottom = bottom;
1468 }
1469 }
1470
Dianne Hackbornc777e072010-02-12 13:07:59 -08001471 public void updateSettings() {
1472 ContentResolver resolver = mContext.getContentResolver();
1473 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001474 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001475 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001476 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001477 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1478 UserHandle.USER_CURRENT);
1479 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001480 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001481 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1482 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001483
Jeff Browna20dda42014-05-27 20:57:24 -07001484 // Configure wake gesture.
1485 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1486 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1487 UserHandle.USER_CURRENT) != 0;
1488 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1489 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1490 updateWakeGestureListenerLp();
1491 }
1492
Jeff Brown207673cd2012-06-05 17:47:11 -07001493 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001494 int userRotation = Settings.System.getIntForUser(resolver,
1495 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1496 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001497 if (mUserRotation != userRotation) {
1498 mUserRotation = userRotation;
1499 updateRotation = true;
1500 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001501 int userRotationMode = Settings.System.getIntForUser(resolver,
1502 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001503 WindowManagerPolicy.USER_ROTATION_FREE :
1504 WindowManagerPolicy.USER_ROTATION_LOCKED;
1505 if (mUserRotationMode != userRotationMode) {
1506 mUserRotationMode = userRotationMode;
1507 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001508 updateOrientationListenerLp();
1509 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001510
Dianne Hackbornc777e072010-02-12 13:07:59 -08001511 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001512 int pointerLocation = Settings.System.getIntForUser(resolver,
1513 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001514 if (mPointerLocationMode != pointerLocation) {
1515 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001516 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1517 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001518 }
1519 }
1520 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001521 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1522 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1523 String imId = Settings.Secure.getStringForUser(resolver,
1524 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001525 boolean hasSoftInput = imId != null && imId.length() > 0;
1526 if (mHasSoftInput != hasSoftInput) {
1527 mHasSoftInput = hasSoftInput;
1528 updateRotation = true;
1529 }
John Spurlockf1a36642013-10-12 17:50:42 -04001530 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001531 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001532 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001533 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001534 }
1535 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001536 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001537 }
Jeff Brown70825162012-03-28 17:27:48 -07001538 }
1539
Jeff Browna20dda42014-05-27 20:57:24 -07001540 private void updateWakeGestureListenerLp() {
1541 if (shouldEnableWakeGestureLp()) {
1542 mWakeGestureListener.requestWakeUpTrigger();
1543 } else {
1544 mWakeGestureListener.cancelWakeUpTrigger();
1545 }
1546 }
1547
1548 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001549 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001550 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1551 && mWakeGestureListener.isSupported();
1552 }
1553
Jeff Brown70825162012-03-28 17:27:48 -07001554 private void enablePointerLocation() {
1555 if (mPointerLocationView == null) {
1556 mPointerLocationView = new PointerLocationView(mContext);
1557 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001558 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1559 WindowManager.LayoutParams.MATCH_PARENT,
1560 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001561 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001562 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1563 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1564 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1565 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001566 if (ActivityManager.isHighEndGfx()) {
1567 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1568 lp.privateFlags |=
1569 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1570 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001571 lp.format = PixelFormat.TRANSLUCENT;
1572 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001573 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001574 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001575 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001576 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001577 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001578 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001579 }
Jeff Brown70825162012-03-28 17:27:48 -07001580
1581 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001582 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001583 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1584 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001585 wm.removeView(mPointerLocationView);
1586 mPointerLocationView = null;
1587 }
1588 }
1589
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001590 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001591 try {
1592 int rotation = mContext.getResources().getInteger(resID);
1593 switch (rotation) {
1594 case 0:
1595 return Surface.ROTATION_0;
1596 case 90:
1597 return Surface.ROTATION_90;
1598 case 180:
1599 return Surface.ROTATION_180;
1600 case 270:
1601 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001602 }
1603 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001604 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001605 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001606 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001607 }
1608
1609 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001610 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001611 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001612 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001613
1614 outAppOp[0] = AppOpsManager.OP_NONE;
1615
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001616 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1617 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001618 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001619 }
1620 String permission = null;
1621 switch (type) {
1622 case TYPE_TOAST:
1623 // XXX right now the app process has complete control over
1624 // this... should introduce a token to let the system
1625 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001626 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001627 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001628 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001629 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001630 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001631 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001632 case TYPE_VOICE_INTERACTION:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001633 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001634 break;
1635 case TYPE_PHONE:
1636 case TYPE_PRIORITY_PHONE:
1637 case TYPE_SYSTEM_ALERT:
1638 case TYPE_SYSTEM_ERROR:
1639 case TYPE_SYSTEM_OVERLAY:
1640 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001641 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001642 break;
1643 default:
1644 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1645 }
1646 if (permission != null) {
1647 if (mContext.checkCallingOrSelfPermission(permission)
1648 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001649 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001650 }
1651 }
Jeff Brown98365d72012-08-19 20:30:52 -07001652 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001653 }
Craig Mautner88400d32012-09-30 12:35:45 -07001654
1655 @Override
1656 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1657
1658 // If this switch statement is modified, modify the comment in the declarations of
1659 // the type in {@link WindowManager.LayoutParams} as well.
1660 switch (attrs.type) {
1661 default:
1662 // These are the windows that by default are shown only to the user that created
1663 // them. If this needs to be overridden, set
1664 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1665 // {@link WindowManager.LayoutParams}. Note that permission
1666 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1667 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1668 return true;
1669 }
1670 break;
1671
1672 // These are the windows that by default are shown to all users. However, to
1673 // protect against spoofing, check permissions below.
1674 case TYPE_APPLICATION_STARTING:
1675 case TYPE_BOOT_PROGRESS:
1676 case TYPE_DISPLAY_OVERLAY:
1677 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001678 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001679 case TYPE_KEYGUARD_DIALOG:
1680 case TYPE_MAGNIFICATION_OVERLAY:
1681 case TYPE_NAVIGATION_BAR:
1682 case TYPE_NAVIGATION_BAR_PANEL:
1683 case TYPE_PHONE:
1684 case TYPE_POINTER:
1685 case TYPE_PRIORITY_PHONE:
1686 case TYPE_RECENTS_OVERLAY:
1687 case TYPE_SEARCH_BAR:
1688 case TYPE_STATUS_BAR:
1689 case TYPE_STATUS_BAR_PANEL:
1690 case TYPE_STATUS_BAR_SUB_PANEL:
1691 case TYPE_SYSTEM_DIALOG:
1692 case TYPE_UNIVERSE_BACKGROUND:
1693 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001694 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001695 break;
1696 }
1697
1698 // Check if third party app has set window to system window type.
1699 return mContext.checkCallingOrSelfPermission(
1700 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1701 != PackageManager.PERMISSION_GRANTED;
1702 }
1703
Craig Mautner967212c2013-04-13 21:10:58 -07001704 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001705 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1706 switch (attrs.type) {
1707 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001708 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001709 // These types of windows can't receive input events.
1710 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1711 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001712 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001713 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001714 case TYPE_STATUS_BAR:
1715
1716 // If the Keyguard is in a hidden state (occluded by another window), we force to
1717 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1718 // the keyguard as occluded wouldn't set these flags again.
1719 // See {@link #processKeyguardSetHiddenResultLw}.
1720 if (mKeyguardHidden) {
1721 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1722 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1723 }
1724 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001725 }
Adrian Roos38502112014-04-09 21:04:11 +02001726
1727 if (attrs.type != TYPE_STATUS_BAR) {
1728 // The status bar is the only window allowed to exhibit keyguard behavior.
1729 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1730 }
Adrian Roosea562512014-05-05 13:33:03 +02001731
1732 if (ActivityManager.isHighEndGfx()
1733 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001734 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001735 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1736 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001737 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001738
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001739 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001740 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001741 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001742
Michael Wright3818c922014-09-02 13:59:07 -07001743 private void readCameraLensCoverState() {
1744 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1745 }
1746
Jeff Browndaa37532012-05-01 15:54:03 -07001747 private boolean isHidden(int accessibilityMode) {
1748 switch (accessibilityMode) {
1749 case 1:
1750 return mLidState == LID_CLOSED;
1751 case 2:
1752 return mLidState == LID_OPEN;
1753 default:
1754 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001755 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001756 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001757
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001758 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001759 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001760 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1761 int navigationPresence) {
1762 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1763
Jeff Brownf71343d2013-05-31 17:59:11 -07001764 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001765 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001766 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001767
Jeff Browndaa37532012-05-01 15:54:03 -07001768 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1769 || (keyboardPresence == PRESENCE_INTERNAL
1770 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001771 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001772 if (!mHasSoftInput) {
1773 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1774 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001775 }
1776
Jeff Browndaa37532012-05-01 15:54:03 -07001777 if (config.navigation == Configuration.NAVIGATION_NONAV
1778 || (navigationPresence == PRESENCE_INTERNAL
1779 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001780 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001781 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001782 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001783
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001784 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001785 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001786 public int windowTypeToLayerLw(int type) {
1787 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001788 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001789 }
1790 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001791 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001792 return 1;
keunyounga446bf02013-06-21 19:07:57 -07001793 case TYPE_PRIVATE_PRESENTATION:
1794 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001795 case TYPE_WALLPAPER:
1796 // wallpaper is at the bottom, though the window manager may move it.
1797 return 2;
1798 case TYPE_PHONE:
1799 return 3;
1800 case TYPE_SEARCH_BAR:
1801 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001802 case TYPE_VOICE_INTERACTION:
1803 // voice interaction layer is almost immediately above apps.
1804 return 5;
Craig Mautner88400d32012-09-30 12:35:45 -07001805 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001806 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001807 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001808 case TYPE_TOAST:
1809 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001810 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001811 case TYPE_PRIORITY_PHONE:
1812 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001813 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001814 case TYPE_DREAM:
1815 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001816 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001817 case TYPE_SYSTEM_ALERT:
1818 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001819 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001820 case TYPE_INPUT_METHOD:
1821 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001822 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001823 case TYPE_INPUT_METHOD_DIALOG:
1824 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001825 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001826 case TYPE_KEYGUARD_SCRIM:
1827 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001828 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001829 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001830 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001831 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001832 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001833 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001834 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001835 case TYPE_KEYGUARD_DIALOG:
1836 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001837 case TYPE_VOLUME_OVERLAY:
1838 // the on-screen volume indicator and controller shown when the user
1839 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001840 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001841 case TYPE_SYSTEM_OVERLAY:
1842 // the on-screen volume indicator and controller shown when the user
1843 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001844 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001845 case TYPE_NAVIGATION_BAR:
1846 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001847 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001848 case TYPE_NAVIGATION_BAR_PANEL:
1849 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001850 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001851 case TYPE_SYSTEM_ERROR:
1852 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001853 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001854 case TYPE_MAGNIFICATION_OVERLAY:
1855 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001856 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001857 case TYPE_DISPLAY_OVERLAY:
1858 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001859 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001860 case TYPE_DRAG:
1861 // the drag layer: input for drag-and-drop is associated with this window,
1862 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001863 return 25;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001864 case TYPE_SECURE_SYSTEM_OVERLAY:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001865 return 26;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001866 case TYPE_BOOT_PROGRESS:
1867 return 27;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001868 case TYPE_POINTER:
1869 // the (mouse) pointer layer
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001870 return 28;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001871 case TYPE_HIDDEN_NAV_CONSUMER:
1872 return 29;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001873 }
1874 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001875 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001876 }
1877
1878 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001879 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001880 public int subWindowTypeToLayerLw(int type) {
1881 switch (type) {
1882 case TYPE_APPLICATION_PANEL:
1883 case TYPE_APPLICATION_ATTACHED_DIALOG:
1884 return APPLICATION_PANEL_SUBLAYER;
1885 case TYPE_APPLICATION_MEDIA:
1886 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001887 case TYPE_APPLICATION_MEDIA_OVERLAY:
1888 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001889 case TYPE_APPLICATION_SUB_PANEL:
1890 return APPLICATION_SUB_PANEL_SUBLAYER;
1891 }
1892 Log.e(TAG, "Unknown sub-window type: " + type);
1893 return 0;
1894 }
1895
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001896 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001897 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001898 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001899 }
1900
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001901 @Override
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001902 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001903 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001904 }
1905
Jose Lima9546b202014-07-02 17:21:51 -07001906 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001907 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001908 if (mHasNavigationBar) {
1909 // For a basic navigation bar, when we are in landscape mode we place
1910 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001911 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1912 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001913 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001914 }
1915 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001916 }
1917
Jose Lima9546b202014-07-02 17:21:51 -07001918 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001919 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001920 if (mHasNavigationBar) {
1921 // For a basic navigation bar, when we are in portrait mode we place
1922 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001923 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1924 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001925 }
1926 }
1927 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001928 }
1929
Jose Lima9546b202014-07-02 17:21:51 -07001930 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001931 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1932 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001933 }
1934
Jose Lima9546b202014-07-02 17:21:51 -07001935 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001936 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001937 // There is a separate status bar at the top of the display. We don't count that as part
1938 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001939 // we do want to exclude it since applications can't generally use that part
1940 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001941 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001942 }
1943
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001944 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07001945 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
1946 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Adrian Roos69e510d2014-07-13 14:57:59 +02001947 (isKeyguardHostWindow(attrs) && isKeyguardSecureIncludingHidden()) ||
1948 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001949 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001950
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001951 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02001952 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
1953 return attrs.type == TYPE_STATUS_BAR;
1954 }
1955
1956 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001957 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001958 switch (attrs.type) {
1959 case TYPE_STATUS_BAR:
1960 case TYPE_NAVIGATION_BAR:
1961 case TYPE_WALLPAPER:
1962 case TYPE_DREAM:
1963 case TYPE_UNIVERSE_BACKGROUND:
Jim Miller5ecd8112013-01-09 18:50:26 -08001964 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001965 return false;
1966 default:
1967 return true;
1968 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001969 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001970
Craig Mautner7d7808f2014-09-11 18:02:38 -07001971 @Override
1972 public WindowState getWinShowWhenLockedLw() {
1973 return mWinShowWhenLocked;
1974 }
1975
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001976 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001977 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001978 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1979 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07001980 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001981 if (!SHOW_STARTING_ANIMATIONS) {
1982 return null;
1983 }
1984 if (packageName == null) {
1985 return null;
1986 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001987
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001988 WindowManager wm = null;
1989 View view = null;
1990
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001991 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001992 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001993 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1994 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1995 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001996 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001997 try {
1998 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001999 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002000 } catch (PackageManager.NameNotFoundException e) {
2001 // Ignore
2002 }
2003 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002004
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002005 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002006 final TypedArray ta = win.getWindowStyle();
2007 if (ta.getBoolean(
2008 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2009 || ta.getBoolean(
2010 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002011 return null;
2012 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002013
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002014 Resources r = context.getResources();
2015 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002016
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002017 win.setType(
2018 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
2019 // Force the window flags: this is a fake window, so it is not really
2020 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2021 // flag because we do know that the next window will take input
2022 // focus, so we want to get the IME window up on top of us right away.
2023 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002024 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002025 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2026 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2027 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002028 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002029 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2030 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2031 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002032
Adam Powell04fe6eb2013-05-31 14:39:48 -07002033 win.setDefaultIcon(icon);
2034 win.setDefaultLogo(logo);
2035
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002036 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002037 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002038
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002039 final WindowManager.LayoutParams params = win.getAttributes();
2040 params.token = appToken;
2041 params.packageName = packageName;
2042 params.windowAnimations = win.getWindowStyle().getResourceId(
2043 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002044 params.privateFlags |=
2045 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002046 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002047
2048 if (!compatInfo.supportsScreen()) {
2049 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2050 }
2051
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002052 params.setTitle("Starting " + packageName);
2053
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002054 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2055 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002056
2057 if (win.isFloating()) {
2058 // Whoops, there is no way to display an animation/preview
2059 // of such a thing! After all that work... let's skip it.
2060 // (Note that we must do this here because it is in
2061 // getDecorView() where the theme is evaluated... maybe
2062 // we should peek the floating attribute from the theme
2063 // earlier.)
2064 return null;
2065 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002066
Craig Mautner6fbda632012-07-03 09:26:39 -07002067 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002068 TAG, "Adding starting window for " + packageName
2069 + " / " + appToken + ": "
2070 + (view.getParent() != null ? view : null));
2071
2072 wm.addView(view, params);
2073
2074 // Only return the view if it was successfully added to the
2075 // window manager... which we can tell by it having a parent.
2076 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002077 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002078 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002079 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2080 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002081 } catch (RuntimeException e) {
2082 // don't crash if something else bad happens, for example a
2083 // failure loading resources because we are loading from an app
2084 // on external storage that has been unmounted.
2085 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002086 } finally {
2087 if (view != null && view.getParent() == null) {
2088 Log.w(TAG, "view not successfully added to wm, removing view");
2089 wm.removeViewImmediate(view);
2090 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002091 }
2092
2093 return null;
2094 }
2095
2096 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002097 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002098 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07002099 if (DEBUG_STARTING_WINDOW) {
2100 RuntimeException e = new RuntimeException("here");
2101 e.fillInStackTrace();
2102 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
2103 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002104
2105 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002106 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002107 wm.removeView(window);
2108 }
2109 }
2110
2111 /**
2112 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002113 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002114 * Currently enforces that three window types are singletons:
2115 * <ul>
2116 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002117 * <li>KEYGUARD_TYPE</li>
2118 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002119 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002120 * @param win The window to be added
2121 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002122 *
Jeff Brown98365d72012-08-19 20:30:52 -07002123 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2124 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002125 */
Jose Lima9546b202014-07-02 17:21:51 -07002126 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002127 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2128 switch (attrs.type) {
2129 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002130 mContext.enforceCallingOrSelfPermission(
2131 android.Manifest.permission.STATUS_BAR_SERVICE,
2132 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002133 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002134 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002135 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002136 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002137 }
2138 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002139 mStatusBarController.setWindow(win);
John Spurlock8fdfe622014-05-21 17:10:10 -04002140 mKeyguardDelegate.hideScrim();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002141 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002142 case TYPE_NAVIGATION_BAR:
2143 mContext.enforceCallingOrSelfPermission(
2144 android.Manifest.permission.STATUS_BAR_SERVICE,
2145 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002146 if (mNavigationBar != null) {
2147 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002148 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002149 }
2150 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002151 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002152 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002153 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002154 break;
Jim Millere898ac52012-04-06 17:10:57 -07002155 case TYPE_NAVIGATION_BAR_PANEL:
2156 mContext.enforceCallingOrSelfPermission(
2157 android.Manifest.permission.STATUS_BAR_SERVICE,
2158 "PhoneWindowManager");
2159 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08002160 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002161 mContext.enforceCallingOrSelfPermission(
2162 android.Manifest.permission.STATUS_BAR_SERVICE,
2163 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08002164 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002165 case TYPE_STATUS_BAR_SUB_PANEL:
2166 mContext.enforceCallingOrSelfPermission(
2167 android.Manifest.permission.STATUS_BAR_SERVICE,
2168 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002169 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002170 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002171 if (mKeyguardScrim != null) {
2172 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2173 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002174 mKeyguardScrim = win;
2175 break;
2176
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002177 }
Jeff Brown98365d72012-08-19 20:30:52 -07002178 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002179 }
2180
2181 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002182 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002183 public void removeWindowLw(WindowState win) {
2184 if (mStatusBar == win) {
2185 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002186 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002187 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002188 } else if (mKeyguardScrim == win) {
2189 Log.v(TAG, "Removing keyguard scrim");
2190 mKeyguardScrim = null;
2191 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002192 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002193 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002194 }
2195 }
2196
2197 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002198
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002199 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002200 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002201 public int selectAnimationLw(WindowState win, int transit) {
2202 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2203 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002204 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002205 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002206 if (transit == TRANSIT_EXIT
2207 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002208 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002209 } else if (transit == TRANSIT_ENTER
2210 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002211 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002212 }
2213 } else if (win == mNavigationBar) {
2214 // This can be on either the bottom or the right.
2215 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002216 if (transit == TRANSIT_EXIT
2217 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002218 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002219 } else if (transit == TRANSIT_ENTER
2220 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002221 return R.anim.dock_bottom_enter;
2222 }
2223 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002224 if (transit == TRANSIT_EXIT
2225 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002226 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002227 } else if (transit == TRANSIT_ENTER
2228 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002229 return R.anim.dock_right_enter;
2230 }
2231 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002232 }
2233
2234 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002235 if (win.hasAppShownWindows()) {
2236 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2237 return com.android.internal.R.anim.app_starting_exit;
2238 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002239 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002240 && transit == TRANSIT_ENTER) {
2241 // Special case: we are animating in a dream, while the keyguard
2242 // is shown. We don't want an animation on the dream, because
2243 // we need it shown immediately with the keyguard animating away
2244 // to reveal it.
2245 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002246 }
2247
2248 return 0;
2249 }
2250
Craig Mautner3c174372013-02-21 17:54:37 -08002251 @Override
2252 public void selectRotationAnimationLw(int anim[]) {
2253 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2254 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2255 + (mTopFullscreenOpaqueWindowState == null ?
2256 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2257 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2258 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2259 case ROTATION_ANIMATION_CROSSFADE:
2260 anim[0] = R.anim.rotation_animation_xfade_exit;
2261 anim[1] = R.anim.rotation_animation_enter;
2262 break;
2263 case ROTATION_ANIMATION_JUMPCUT:
2264 anim[0] = R.anim.rotation_animation_jump_exit;
2265 anim[1] = R.anim.rotation_animation_enter;
2266 break;
2267 case ROTATION_ANIMATION_ROTATE:
2268 default:
2269 anim[0] = anim[1] = 0;
2270 break;
2271 }
2272 } else {
2273 anim[0] = anim[1] = 0;
2274 }
2275 }
2276
2277 @Override
2278 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2279 boolean forceDefault) {
2280 switch (exitAnimId) {
2281 case R.anim.rotation_animation_xfade_exit:
2282 case R.anim.rotation_animation_jump_exit:
2283 // These are the only cases that matter.
2284 if (forceDefault) {
2285 return false;
2286 }
2287 int anim[] = new int[2];
2288 selectRotationAnimationLw(anim);
2289 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2290 default:
2291 return true;
2292 }
2293 }
2294
2295 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002296 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2297 boolean goingToNotificationShade) {
2298 if (goingToNotificationShade) {
2299 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
2300 } else if (onWallpaper) {
Jorim Jaggi76a16232014-08-08 17:00:47 +02002301 Animation a = AnimationUtils.loadAnimation(mContext,
2302 R.anim.lock_screen_behind_enter_wallpaper);
2303 AnimationSet set = (AnimationSet) a;
2304
2305 // TODO: Use XML interpolators when we have log interpolators available in XML.
2306 set.getAnimations().get(0).setInterpolator(mLogDecelerateInterpolator);
2307 set.getAnimations().get(1).setInterpolator(mLogDecelerateInterpolator);
Jorim Jaggi76a16232014-08-08 17:00:47 +02002308 return set;
2309 } else {
2310 Animation a = AnimationUtils.loadAnimation(mContext,
2311 R.anim.lock_screen_behind_enter);
2312 AnimationSet set = (AnimationSet) a;
2313
2314 // TODO: Use XML interpolators when we have log interpolators available in XML.
2315 set.getAnimations().get(0).setInterpolator(mLogDecelerateInterpolator);
2316 return set;
2317 }
2318 }
2319
2320
2321 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002322 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2323 if (goingToNotificationShade) {
2324 return null;
2325 } else {
2326 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2327 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002328 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002329
2330 private static void awakenDreams() {
2331 IDreamManager dreamManager = getDreamManager();
2332 if (dreamManager != null) {
2333 try {
2334 dreamManager.awaken();
2335 } catch (RemoteException e) {
2336 // fine, stay asleep then
2337 }
2338 }
2339 }
2340
2341 static IDreamManager getDreamManager() {
2342 return IDreamManager.Stub.asInterface(
2343 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2344 }
2345
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002346 TelecomManager getTelecommService() {
2347 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002348 }
2349
Jeff Brown4d396052010-10-29 21:50:21 -07002350 static IAudioService getAudioService() {
2351 IAudioService audioService = IAudioService.Stub.asInterface(
2352 ServiceManager.checkService(Context.AUDIO_SERVICE));
2353 if (audioService == null) {
2354 Log.w(TAG, "Unable to find IAudioService interface.");
2355 }
2356 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002357 }
2358
2359 boolean keyguardOn() {
2360 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
2361 }
2362
2363 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2364 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2365 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2366 };
2367
2368 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002369 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002370 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002371 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002372 final int keyCode = event.getKeyCode();
2373 final int repeatCount = event.getRepeatCount();
2374 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002375 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002376 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2377 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002378
Jeff Brown40013652012-05-16 21:22:36 -07002379 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002380 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002381 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2382 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002383 }
2384
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002385 // If we think we might have a volume down & power key chord on the way
2386 // but we're not sure, then tell the dispatcher to wait a little while and
2387 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002388 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002389 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002390 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002391 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2392 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002393 if (now < timeoutTime) {
2394 return timeoutTime - now;
2395 }
2396 }
2397 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002398 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002399 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002400 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002401 }
2402 return -1;
2403 }
2404 }
2405
Michael Wright6a62e552014-06-03 19:19:48 -07002406 // Cancel any pending meta actions if we see any other keys being pressed between the down
2407 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002408 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002409 mPendingMetaAction = false;
2410 }
2411
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002412 // First we always handle the home key here, so applications
2413 // can never break it, although if keyguard is on, we do let
2414 // it handle it, because that gives us the correct 5 second
2415 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002416 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002417
Jeff Brown49ed71d2010-12-06 17:13:33 -08002418 // If we have released the home key, and didn't do anything else
2419 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002420 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002421 cancelPreloadRecentApps();
2422
Jeff Brown49ed71d2010-12-06 17:13:33 -08002423 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002424 if (mHomeConsumed) {
2425 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002426 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002427 }
Jeff Browncaca8812013-05-09 13:34:33 -07002428
2429 if (canceled) {
2430 Log.i(TAG, "Ignoring HOME; event canceled.");
2431 return -1;
2432 }
2433
2434 // If an incoming call is ringing, HOME is totally disabled.
Santos Cordon9eb45932014-06-27 12:28:43 -07002435 // (The user is already on the InCallUI at this point,
Jeff Browncaca8812013-05-09 13:34:33 -07002436 // and his ONLY options are to answer or reject the call.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002437 TelecomManager telecomManager = getTelecommService();
2438 if (telecomManager != null && telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07002439 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2440 return -1;
Jeff Browncaca8812013-05-09 13:34:33 -07002441 }
2442
2443 // Delay handling home if a double-tap is possible.
2444 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2445 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2446 mHomeDoubleTapPending = true;
2447 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2448 ViewConfiguration.getDoubleTapTimeout());
2449 return -1;
2450 }
2451
Jeff Brown13f00f02014-10-31 14:45:50 -07002452 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002453 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002454 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002455
2456 // If a system window has focus, then it doesn't make sense
2457 // right now to interact with applications.
2458 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2459 if (attrs != null) {
2460 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002461 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2462 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2463 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002464 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002465 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002466 }
2467 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2468 for (int i=0; i<typeCount; i++) {
2469 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2470 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002471 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002472 }
2473 }
2474 }
Jeff Browncaca8812013-05-09 13:34:33 -07002475
2476 // Remember that home is pressed and handle special actions.
2477 if (repeatCount == 0) {
2478 mHomePressed = true;
2479 if (mHomeDoubleTapPending) {
2480 mHomeDoubleTapPending = false;
2481 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2482 handleDoubleTapOnHome();
2483 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2484 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2485 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002486 }
Jeff Browncaca8812013-05-09 13:34:33 -07002487 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2488 if (!keyguardOn) {
2489 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002490 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002491 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002492 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002493 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002494 // Hijack modified menu keys for debugging features
2495 final int chordBug = KeyEvent.META_SHIFT_ON;
2496
2497 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002498 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002499 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002500 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2501 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002502 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002503 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002504 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002505 Intent service = new Intent();
2506 service.setClassName(mContext, "com.android.server.LoadAverageService");
2507 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002508 boolean shown = Settings.Global.getInt(
2509 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002510 if (!shown) {
2511 mContext.startService(service);
2512 } else {
2513 mContext.stopService(service);
2514 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002515 Settings.Global.putInt(
2516 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002517 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002518 }
2519 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002520 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002521 if (down) {
2522 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002523 mSearchKeyShortcutPending = true;
2524 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002525 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002526 } else {
2527 mSearchKeyShortcutPending = false;
2528 if (mConsumeSearchKeyUp) {
2529 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002530 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002531 }
2532 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002533 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002534 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002535 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002536 if (down && repeatCount == 0) {
2537 preloadRecentApps();
2538 } else if (!down) {
2539 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002540 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002541 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002542 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002543 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2544 if (down) {
2545 if (repeatCount == 0) {
2546 mAssistKeyLongPressed = false;
2547 } else if (repeatCount == 1) {
2548 mAssistKeyLongPressed = true;
2549 if (!keyguardOn) {
2550 launchAssistLongPressAction();
2551 }
2552 }
2553 } else {
2554 if (mAssistKeyLongPressed) {
2555 mAssistKeyLongPressed = false;
2556 } else {
2557 if (!keyguardOn) {
2558 launchAssistAction();
2559 }
2560 }
2561 }
2562 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002563 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2564 if (!down) {
2565 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002566 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002567 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2568 } else {
2569 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002570 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002571 }
2572 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
2573 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002574 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2575 if (down && repeatCount == 0) {
2576 mHandler.post(mScreenshotRunnable);
2577 }
2578 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002579 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2580 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2581 if (down) {
2582 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2583
2584 // Disable autobrightness if it's on
2585 int auto = Settings.System.getIntForUser(
2586 mContext.getContentResolver(),
2587 Settings.System.SCREEN_BRIGHTNESS_MODE,
2588 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2589 UserHandle.USER_CURRENT_OR_SELF);
2590 if (auto != 0) {
2591 Settings.System.putIntForUser(mContext.getContentResolver(),
2592 Settings.System.SCREEN_BRIGHTNESS_MODE,
2593 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2594 UserHandle.USER_CURRENT_OR_SELF);
2595 }
2596
2597 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2598 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2599 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2600 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2601 Settings.System.SCREEN_BRIGHTNESS,
2602 mPowerManager.getDefaultScreenBrightnessSetting(),
2603 UserHandle.USER_CURRENT_OR_SELF);
2604 brightness += step;
2605 // Make sure we don't go beyond the limits.
2606 brightness = Math.min(max, brightness);
2607 brightness = Math.max(min, brightness);
2608
2609 Settings.System.putIntForUser(mContext.getContentResolver(),
2610 Settings.System.SCREEN_BRIGHTNESS, brightness,
2611 UserHandle.USER_CURRENT_OR_SELF);
Alan Viverette5a399492014-07-14 16:19:38 -07002612 mContext.startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
2613 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002614 }
2615 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002616 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002617 if (down) {
2618 mPendingMetaAction = true;
2619 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002620 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002621 }
2622 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002623 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002624
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002625 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002626 // Any printing key that is chorded with Search should be consumed
2627 // even if no shortcut was invoked. This prevents text from being
2628 // inadvertently inserted when using a keyboard that has built-in macro
2629 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002630 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002631 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2632 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002633 mConsumeSearchKeyUp = true;
2634 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002635 if (down && repeatCount == 0 && !keyguardOn) {
2636 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2637 if (shortcutIntent != null) {
2638 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002639 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002640 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002641 } catch (ActivityNotFoundException ex) {
2642 Slog.w(TAG, "Dropping shortcut key combination because "
2643 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002644 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002645 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002646 } else {
2647 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002648 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002649 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002650 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002651 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002652 }
2653 }
2654
Jeff Brown68b909d2011-12-07 16:36:01 -08002655 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002656 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002657 && (metaState & KeyEvent.META_META_ON) != 0) {
2658 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002659 if (kcm.isPrintingKey(keyCode)) {
2660 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2661 metaState & ~(KeyEvent.META_META_ON
2662 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2663 if (shortcutIntent != null) {
2664 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2665 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002666 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002667 } catch (ActivityNotFoundException ex) {
2668 Slog.w(TAG, "Dropping shortcut key combination because "
2669 + "the activity to which it is registered was not found: "
2670 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2671 }
2672 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002673 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002674 }
2675 }
2676
Jeff Brown6651a632011-11-28 12:59:11 -08002677 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002678 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002679 String category = sApplicationLaunchKeyCategories.get(keyCode);
2680 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002681 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002682 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2683 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002684 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002685 } catch (ActivityNotFoundException ex) {
2686 Slog.w(TAG, "Dropping application launch key because "
2687 + "the activity to which it is registered was not found: "
2688 + "keyCode=" + keyCode + ", category=" + category, ex);
2689 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002690 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002691 }
2692 }
2693
Michael Wright61c46752014-08-21 16:57:33 -07002694 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002695 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002696 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002697 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002698 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002699 mRecentAppsHeldModifiers = shiftlessModifiers;
2700 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002701 return -1;
2702 }
2703 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002704 } else if (!down && mRecentAppsHeldModifiers != 0
2705 && (metaState & mRecentAppsHeldModifiers) == 0) {
2706 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002707 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002708 }
2709
Jeff Browncf39bdf2012-05-18 14:41:19 -07002710 // Handle keyboard language switching.
2711 if (down && repeatCount == 0
2712 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2713 || (keyCode == KeyEvent.KEYCODE_SPACE
2714 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2715 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2716 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2717 return -1;
2718 }
2719 if (mLanguageSwitchKeyPressed && !down
2720 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2721 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2722 mLanguageSwitchKeyPressed = false;
2723 return -1;
2724 }
2725
Jeff Brown13f00f02014-10-31 14:45:50 -07002726 if (isValidGlobalKey(keyCode)
2727 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002728 return -1;
2729 }
2730
Michael Wright6a62e552014-06-03 19:19:48 -07002731 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002732 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002733 return -1;
2734 }
2735
Jeff Brown68b909d2011-12-07 16:36:01 -08002736 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002737 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002738 }
2739
Jeff Brown3915bb82010-11-05 15:02:16 -07002740 /** {@inheritDoc} */
2741 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002742 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002743 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002744 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002745 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2746 + ", flags=" + event.getFlags()
2747 + ", keyCode=" + event.getKeyCode()
2748 + ", scanCode=" + event.getScanCode()
2749 + ", metaState=" + event.getMetaState()
2750 + ", repeatCount=" + event.getRepeatCount()
2751 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002752 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002753
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002754 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002755 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2756 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002757 final int keyCode = event.getKeyCode();
2758 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002759 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2760 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002761
Jeff Brown54875002011-04-06 15:33:01 -07002762 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002763 final FallbackAction fallbackAction;
2764 if (initialDown) {
2765 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2766 } else {
2767 fallbackAction = mFallbackActions.get(keyCode);
2768 }
2769
2770 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002771 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002772 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2773 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002774 }
2775
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002776 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2777 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002778 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002779 event.getAction(), fallbackAction.keyCode,
2780 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002781 event.getDeviceId(), event.getScanCode(),
2782 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002783
2784 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2785 fallbackEvent.recycle();
2786 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002787 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002788
2789 if (initialDown) {
2790 mFallbackActions.put(keyCode, fallbackAction);
2791 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2792 mFallbackActions.remove(keyCode);
2793 fallbackAction.recycle();
2794 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002795 }
2796 }
2797
Jeff Brown40013652012-05-16 21:22:36 -07002798 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002799 if (fallbackEvent == null) {
2800 Slog.d(TAG, "No fallback.");
2801 } else {
2802 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2803 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002804 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002805 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002806 }
2807
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002808 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002809 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002810 if ((actions & ACTION_PASS_TO_USER) != 0) {
2811 long delayMillis = interceptKeyBeforeDispatching(
2812 win, fallbackEvent, policyFlags);
2813 if (delayMillis == 0) {
2814 return true;
2815 }
2816 }
2817 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002818 }
2819
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002820 private void launchAssistLongPressAction() {
2821 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2822 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2823
2824 // launch the search activity
2825 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2826 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2827 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002828 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002829 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002830 SearchManager searchManager = getSearchManager();
2831 if (searchManager != null) {
2832 searchManager.stopSearch();
2833 }
Michael Wright43e27f72013-04-10 14:06:48 -07002834 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002835 } catch (ActivityNotFoundException e) {
2836 Slog.w(TAG, "No activity to handle assist long press action.", e);
2837 }
2838 }
2839
2840 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002841 launchAssistAction(null);
2842 }
2843
2844 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002845 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002846 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002847 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002848 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002849 if (hint != null) {
2850 intent.putExtra(hint, true);
2851 }
Jim Miller45308b12012-06-18 19:23:39 -07002852 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2853 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2854 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2855 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002856 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002857 } catch (ActivityNotFoundException e) {
2858 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002859 }
2860 }
2861 }
2862
2863 private SearchManager getSearchManager() {
2864 if (mSearchManager == null) {
2865 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2866 }
2867 return mSearchManager;
2868 }
2869
Jeff Browncaca8812013-05-09 13:34:33 -07002870 private void preloadRecentApps() {
2871 mPreloadedRecentApps = true;
2872 try {
2873 IStatusBarService statusbar = getStatusBarService();
2874 if (statusbar != null) {
2875 statusbar.preloadRecentApps();
2876 }
2877 } catch (RemoteException e) {
2878 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2879 // re-acquire status bar service next time it is needed.
2880 mStatusBarService = null;
2881 }
2882 }
2883
2884 private void cancelPreloadRecentApps() {
2885 if (mPreloadedRecentApps) {
2886 mPreloadedRecentApps = false;
2887 try {
2888 IStatusBarService statusbar = getStatusBarService();
2889 if (statusbar != null) {
2890 statusbar.cancelPreloadRecentApps();
2891 }
2892 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002893 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07002894 // re-acquire status bar service next time it is needed.
2895 mStatusBarService = null;
2896 }
2897 }
2898 }
2899
2900 private void toggleRecentApps() {
2901 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07002902 try {
2903 IStatusBarService statusbar = getStatusBarService();
2904 if (statusbar != null) {
2905 statusbar.toggleRecentApps();
2906 }
2907 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002908 Slog.e(TAG, "RemoteException when toggling recent apps", e);
2909 // re-acquire status bar service next time it is needed.
2910 mStatusBarService = null;
2911 }
2912 }
2913
Craig Mautner84984fa2014-06-19 11:19:20 -07002914 @Override
2915 public void showRecentApps() {
2916 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
2917 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
2918 }
2919
Winson Chung1e8d71b2014-05-16 17:05:22 -07002920 private void showRecentApps(boolean triggeredFromAltTab) {
2921 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2922 try {
2923 IStatusBarService statusbar = getStatusBarService();
2924 if (statusbar != null) {
2925 statusbar.showRecentApps(triggeredFromAltTab);
2926 }
2927 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07002928 Slog.e(TAG, "RemoteException when showing recent apps", e);
2929 // re-acquire status bar service next time it is needed.
2930 mStatusBarService = null;
2931 }
2932 }
2933
Winson Chungcdcd4872014-08-05 18:00:13 -07002934 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002935 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2936 try {
2937 IStatusBarService statusbar = getStatusBarService();
2938 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07002939 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07002940 }
2941 } catch (RemoteException e) {
2942 Slog.e(TAG, "RemoteException when closing recent apps", e);
2943 // re-acquire status bar service next time it is needed.
2944 mStatusBarService = null;
2945 }
2946 }
2947
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002948 /**
2949 * A home key -> launch home action was detected. Take the appropriate action
2950 * given the situation with the keyguard.
2951 */
2952 void launchHomeFromHotKey() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002953 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotOccluded()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002954 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002955 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002956 // when in keyguard restricted mode, must first verify unlock
2957 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002958 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
Jose Lima9546b202014-07-02 17:21:51 -07002959 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002960 public void onKeyguardExitResult(boolean success) {
2961 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002962 try {
2963 ActivityManagerNative.getDefault().stopAppSwitches();
2964 } catch (RemoteException e) {
2965 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002966 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002967 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002968 }
2969 }
2970 });
2971 } else {
2972 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002973 try {
2974 ActivityManagerNative.getDefault().stopAppSwitches();
2975 } catch (RemoteException e) {
2976 }
Winson Chungd543c1b2014-06-23 15:06:45 -07002977 if (mRecentsVisible) {
2978 // Hide Recents and notify it to launch Home
2979 awakenDreams();
2980 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Winson Chungcdcd4872014-08-05 18:00:13 -07002981 hideRecentApps(false, true);
Winson Chungd543c1b2014-06-23 15:06:45 -07002982 } else {
2983 // Otherwise, just launch Home
2984 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
2985 startDockOrHome();
2986 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002987 }
2988 }
2989
John Spurlock04db1762013-05-13 12:46:41 -04002990 private final Runnable mClearHideNavigationFlag = new Runnable() {
2991 @Override
2992 public void run() {
2993 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2994 // Clear flags.
2995 mForceClearedSystemUiFlags &=
2996 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2997 }
2998 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002999 }
3000 };
3001
3002 /**
3003 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3004 * to determine when the nav bar should be shown and prevent applications from
3005 * receiving those touches.
3006 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003007 final class HideNavInputEventReceiver extends InputEventReceiver {
3008 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3009 super(inputChannel, looper);
3010 }
3011
Dianne Hackborndf89e652011-10-06 22:35:11 -07003012 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003013 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003014 boolean handled = false;
3015 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003016 if (event instanceof MotionEvent
3017 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3018 final MotionEvent motionEvent = (MotionEvent)event;
3019 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003020 // When the user taps down, we re-show the nav bar.
3021 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003022 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003023 // Any user activity always causes us to show the
3024 // navigation controls, if they had been hidden.
3025 // We also clear the low profile and only content
3026 // flags so that tapping on the screen will atomically
3027 // restore all currently hidden screen decorations.
3028 int newVal = mResettingSystemUiFlags |
3029 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3030 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3031 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003032 if (mResettingSystemUiFlags != newVal) {
3033 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003034 changed = true;
3035 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003036 // We don't allow the system's nav bar to be hidden
3037 // again for 1 second, to prevent applications from
3038 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003039 newVal = mForceClearedSystemUiFlags |
3040 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003041 if (mForceClearedSystemUiFlags != newVal) {
3042 mForceClearedSystemUiFlags = newVal;
3043 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003044 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003045 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003046 }
3047 if (changed) {
3048 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3049 }
3050 }
3051 }
3052 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003053 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003054 }
3055 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003056 }
3057 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3058 new InputEventReceiver.Factory() {
3059 @Override
3060 public InputEventReceiver createInputEventReceiver(
3061 InputChannel inputChannel, Looper looper) {
3062 return new HideNavInputEventReceiver(inputChannel, looper);
3063 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003064 };
3065
3066 @Override
3067 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003068 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3069 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003070 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003071
Dianne Hackborndf89e652011-10-06 22:35:11 -07003072 // Reset any bits in mForceClearingStatusBarVisibility that
3073 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003074 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003075 // Clear any bits in the new visibility that are currently being
3076 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003077 return visibility & ~mResettingSystemUiFlags
3078 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003079 }
3080
Craig Mautner69b08182012-09-05 13:07:13 -07003081 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003082 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003083 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003084 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3085 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003086
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003087 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003088 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003089 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003090 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003091 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003092 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3093 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3094 } else {
3095 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3096 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3097 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003098 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3099 if ((fl & FLAG_FULLSCREEN) != 0) {
3100 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
3101 availRight - mStableFullscreenRight,
3102 availBottom - mStableFullscreenBottom);
3103 } else {
3104 contentInset.set(mStableLeft, mStableTop,
3105 availRight - mStableRight, availBottom - mStableBottom);
3106 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003107 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003108 contentInset.setEmpty();
3109 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003110 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
3111 contentInset.set(mCurLeft, mCurTop,
3112 availRight - mCurRight, availBottom - mCurBottom);
3113 } else {
3114 contentInset.set(mCurLeft, mCurTop,
3115 availRight - mCurRight, availBottom - mCurBottom);
3116 }
3117 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003118 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003119 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003120 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003121
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003122 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003123 @Override
3124 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3125 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003126 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3127 if (isDefaultDisplay) {
3128 switch (displayRotation) {
3129 case Surface.ROTATION_90:
3130 overscanLeft = mOverscanTop;
3131 overscanTop = mOverscanRight;
3132 overscanRight = mOverscanBottom;
3133 overscanBottom = mOverscanLeft;
3134 break;
3135 case Surface.ROTATION_180:
3136 overscanLeft = mOverscanRight;
3137 overscanTop = mOverscanBottom;
3138 overscanRight = mOverscanLeft;
3139 overscanBottom = mOverscanTop;
3140 break;
3141 case Surface.ROTATION_270:
3142 overscanLeft = mOverscanBottom;
3143 overscanTop = mOverscanLeft;
3144 overscanRight = mOverscanTop;
3145 overscanBottom = mOverscanRight;
3146 break;
3147 default:
3148 overscanLeft = mOverscanLeft;
3149 overscanTop = mOverscanTop;
3150 overscanRight = mOverscanRight;
3151 overscanBottom = mOverscanBottom;
3152 break;
3153 }
3154 } else {
3155 overscanLeft = 0;
3156 overscanTop = 0;
3157 overscanRight = 0;
3158 overscanBottom = 0;
3159 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003160 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3161 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3162 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3163 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003164 mSystemLeft = 0;
3165 mSystemTop = 0;
3166 mSystemRight = displayWidth;
3167 mSystemBottom = displayHeight;
3168 mUnrestrictedScreenLeft = overscanLeft;
3169 mUnrestrictedScreenTop = overscanTop;
3170 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3171 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3172 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3173 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003174 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3175 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003176 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003177 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003178 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003179 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003180 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003181 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003182 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003183 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003184 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003185 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003186
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003187 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3188 final Rect pf = mTmpParentFrame;
3189 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003190 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003191 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003192 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003193 pf.left = df.left = of.left = vf.left = mDockLeft;
3194 pf.top = df.top = of.top = vf.top = mDockTop;
3195 pf.right = df.right = of.right = vf.right = mDockRight;
3196 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003197 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003198
Craig Mautner69b08182012-09-05 13:07:13 -07003199 if (isDefaultDisplay) {
3200 // For purposes of putting out fake window up to steal focus, we will
3201 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003202 final int sysui = mLastSystemUiFlags;
3203 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003204 boolean navTranslucent = (sysui
3205 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003206 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3207 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3208 boolean navAllowedHidden = immersive || immersiveSticky;
3209 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003210 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3211 if (!isKeyguardShowing) {
3212 navTranslucent &= areTranslucentBarsAllowed();
3213 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003214
Craig Mautner69b08182012-09-05 13:07:13 -07003215 // When the navigation bar isn't visible, we put up a fake
3216 // input window to catch all touch events. This way we can
3217 // detect when the user presses anywhere to bring back the nav
3218 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003219 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07003220 if (mHideNavFakeWindow != null) {
3221 mHideNavFakeWindow.dismiss();
3222 mHideNavFakeWindow = null;
3223 }
3224 } else if (mHideNavFakeWindow == null) {
3225 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
3226 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07003227 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07003228 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003229 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003230
Craig Mautner69b08182012-09-05 13:07:13 -07003231 // For purposes of positioning and showing the nav bar, if we have
3232 // decided that it can't be hidden (because of the screen aspect ratio),
3233 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003234 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003235
John Spurlockad3e6cb2013-04-30 08:47:43 -04003236 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003237 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003238 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003239 // Force the navigation bar to its appropriate place and
3240 // size. We need to do this directly, instead of relying on
3241 // it to bubble up from the nav bar, because this needs to
3242 // change atomically with screen rotations.
3243 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3244 if (mNavigationBarOnBottom) {
3245 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003246 int top = displayHeight - overscanBottom
3247 - mNavigationBarHeightForRotation[displayRotation];
3248 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003249 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003250 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003251 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003252 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003253 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003254 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003255 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3256 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003257 } else {
3258 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003259 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003260 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003261 if (navVisible && !navTranslucent && !navAllowedHidden
3262 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003263 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003264 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003265 // and not in the process of animating on or off, then
3266 // we can tell the app that it is covered by it.
3267 mSystemBottom = mTmpNavigationFrame.top;
3268 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003269 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003270 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003271 int left = displayWidth - overscanRight
3272 - mNavigationBarWidthForRotation[displayRotation];
3273 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003274 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003275 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003276 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003277 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003278 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003279 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003280 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3281 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003282 } else {
3283 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003284 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003285 }
John Spurlockbd957402013-10-03 11:38:39 -04003286 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3287 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003288 // If the nav bar is currently requested to be visible,
3289 // and not in the process of animating on or off, then
3290 // we can tell the app that it is covered by it.
3291 mSystemRight = mTmpNavigationFrame.left;
3292 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003293 }
Craig Mautner69b08182012-09-05 13:07:13 -07003294 // Make sure the content and current rectangles are updated to
3295 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003296 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3297 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3298 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3299 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003300 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3301 // And compute the final frame.
3302 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003303 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3304 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003305 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003306 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003307 updateSysUiVisibility = true;
3308 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003309 }
Craig Mautnereda67292013-04-28 13:50:14 -07003310 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003311 mDockLeft, mDockTop, mDockRight, mDockBottom));
3312
3313 // decide where the status bar goes ahead of time
3314 if (mStatusBar != null) {
3315 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003316 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3317 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3318 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3319 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3320 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003321 vf.left = mStableLeft;
3322 vf.top = mStableTop;
3323 vf.right = mStableRight;
3324 vf.bottom = mStableBottom;
3325
3326 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3327
3328 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003329 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003330
3331 // For layout, the status bar is always at the top with our fixed height.
3332 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3333
John Spurlocke1f366f2013-08-05 12:22:40 -04003334 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003335 boolean statusBarTranslucent = (sysui
3336 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003337 if (!isKeyguardShowing) {
3338 statusBarTranslucent &= areTranslucentBarsAllowed();
3339 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003340
Craig Mautner69b08182012-09-05 13:07:13 -07003341 // If the status bar is hidden, we don't want to cause
3342 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003343 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003344 // Status bar may go away, so the screen area it occupies
3345 // is available to apps but just covering them when the
3346 // status bar is visible.
3347 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3348
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003349 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3350 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3351 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3352 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003353
Craig Mautnereda67292013-04-28 13:50:14 -07003354 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003355 String.format(
3356 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3357 mDockLeft, mDockTop, mDockRight, mDockBottom,
3358 mContentLeft, mContentTop, mContentRight, mContentBottom,
3359 mCurLeft, mCurTop, mCurRight, mCurBottom));
3360 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003361 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003362 && !statusBarTransient && !statusBarTranslucent
3363 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003364 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003365 // and not in the process of animating on or off, then
3366 // we can tell the app that it is covered by it.
3367 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3368 }
John Spurlock27735a42013-08-14 17:57:38 -04003369 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003370 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003371 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003372 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003373 if (updateSysUiVisibility) {
3374 updateSystemUiVisibilityLw();
3375 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003376 }
3377 }
3378
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003379 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003380 @Override
John Spurlock46646232013-09-30 22:32:42 -04003381 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003382 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
3383 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
3384 return 0;
3385 }
3386
Craig Mautner967212c2013-04-13 21:10:58 -07003387 @Override
3388 public void getContentRectLw(Rect r) {
3389 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3390 }
3391
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003392 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3393 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003394 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3395 // Here's a special case: if this attached window is a panel that is
3396 // above the dock window, and the window it is attached to is below
3397 // the dock window, then the frames we computed for the window it is
3398 // attached to can not be used because the dock is effectively part
3399 // of the underlying window and the attached window is floating on top
3400 // of the whole thing. So, we ignore the attached window and explicitly
3401 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003402 df.left = of.left = cf.left = vf.left = mDockLeft;
3403 df.top = of.top = cf.top = vf.top = mDockTop;
3404 df.right = of.right = cf.right = vf.right = mDockRight;
3405 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003406 } else {
3407 // The effective display frame of the attached window depends on
3408 // whether it is taking care of insetting its content. If not,
3409 // we need to use the parent's content frame so that the entire
3410 // window is positioned within that content. Otherwise we can use
3411 // the display frame and let the attached window take care of
3412 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003413 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003414 cf.set(attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003415 } else {
3416 // If the window is resizing, then we want to base the content
3417 // frame on our attached content frame to resize... however,
3418 // things can be tricky if the attached window is NOT in resize
3419 // mode, in which case its content frame will be larger.
3420 // Ungh. So to deal with that, make sure the content frame
3421 // we end up using is not covering the IM dock.
3422 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003423 if (attached.isVoiceInteraction()) {
3424 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3425 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3426 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3427 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3428 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003429 if (cf.left < mContentLeft) cf.left = mContentLeft;
3430 if (cf.top < mContentTop) cf.top = mContentTop;
3431 if (cf.right > mContentRight) cf.right = mContentRight;
3432 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3433 }
3434 }
3435 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003436 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003437 vf.set(attached.getVisibleFrameLw());
3438 }
3439 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3440 // window should be positioned relative to its parent or the entire
3441 // screen.
3442 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3443 ? attached.getFrameLw() : df);
3444 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003445
3446 private void applyStableConstraints(int sysui, int fl, Rect r) {
3447 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3448 // If app is requesting a stable layout, don't let the
3449 // content insets go below the stable values.
3450 if ((fl & FLAG_FULLSCREEN) != 0) {
3451 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3452 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3453 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3454 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3455 } else {
3456 if (r.left < mStableLeft) r.left = mStableLeft;
3457 if (r.top < mStableTop) r.top = mStableTop;
3458 if (r.right > mStableRight) r.right = mStableRight;
3459 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3460 }
3461 }
3462 }
3463
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003464 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003465 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003466 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003467 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003468 final WindowManager.LayoutParams attrs = win.getAttrs();
3469 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3470 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003471 return;
3472 }
Craig Mautner69b08182012-09-05 13:07:13 -07003473 final boolean isDefaultDisplay = win.isDefaultDisplay();
3474 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003475 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3476 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003477 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003478 offsetInputMethodWindowLw(mLastInputMethodWindow);
3479 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003480
John Spurlockc6d1c602014-01-17 15:22:06 -05003481 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003482 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003483 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003484
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003485 final Rect pf = mTmpParentFrame;
3486 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003487 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003488 final Rect cf = mTmpContentFrame;
3489 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003490 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003491 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003492 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003493
3494 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003495 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003496
Craig Mautnerf683b562012-10-02 11:10:57 -07003497 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3498
Adrian Roosfa104232014-06-20 16:10:14 -07003499 if (isDefaultDisplay) {
3500 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3501 } else {
3502 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3503 }
3504
Craig Mautner69b08182012-09-05 13:07:13 -07003505 if (!isDefaultDisplay) {
3506 if (attached != null) {
3507 // If this window is attached to another, our display
3508 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003509 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003510 } else {
3511 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003512 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3513 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3514 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003515 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003516 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003517 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003518 }
3519 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003520 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3521 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3522 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003523 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003524 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003525 // ...with content insets above the nav bar
3526 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003527 // IM dock windows always go to the bottom of the screen.
3528 attrs.gravity = Gravity.BOTTOM;
3529 mDockLayer = win.getSurfaceLayer();
Jorim Jaggie0700182014-08-21 01:12:37 +02003530 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3531 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3532 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3533 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3534 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3535 cf.left = vf.left = mStableLeft;
3536 cf.top = vf.top = mStableTop;
3537 cf.right = vf.right = mStableRight;
3538 vf.bottom = mStableBottom;
3539 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003540 } else {
John Spurlock46646232013-09-30 22:32:42 -04003541
3542 // Default policy decor for the default display
3543 dcf.left = mSystemLeft;
3544 dcf.top = mSystemTop;
3545 dcf.right = mSystemRight;
3546 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003547 final boolean inheritTranslucentDecor = (attrs.privateFlags
3548 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003549 final boolean isAppWindow =
3550 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3551 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3552 final boolean topAtRest =
3553 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3554 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003555 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3556 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003557 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3558 && (fl & WindowManager.LayoutParams.
3559 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003560 // Ensure policy decor includes status bar
3561 dcf.top = mStableTop;
3562 }
John Spurlockbd957402013-10-03 11:38:39 -04003563 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003564 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3565 && (fl & WindowManager.LayoutParams.
3566 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003567 // Ensure policy decor includes navigation bar
3568 dcf.bottom = mStableBottom;
3569 dcf.right = mStableRight;
3570 }
3571 }
3572
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003573 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3574 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003575 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003576 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003577 // This is the case for a normal activity window: we want it
3578 // to cover all of the screen space, and it can take care of
3579 // moving its contents to account for screen decorations that
3580 // intrude into that space.
3581 if (attached != null) {
3582 // If this window is attached to another, our display
3583 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003584 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003585 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003586 if (attrs.type == TYPE_STATUS_BAR_PANEL
3587 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003588 // Status bar panels are the only windows who can go on top of
3589 // the status bar. They are protected by the STATUS_BAR_SERVICE
3590 // permission, so they have the same privileges as the status
3591 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003592 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003593 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003594
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003595 pf.left = df.left = of.left = hasNavBar
3596 ? mDockLeft : mUnrestrictedScreenLeft;
3597 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3598 pf.right = df.right = of.right = hasNavBar
3599 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3600 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3601 pf.bottom = df.bottom = of.bottom = hasNavBar
3602 ? mRestrictedScreenTop+mRestrictedScreenHeight
3603 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003604
Craig Mautnereda67292013-04-28 13:50:14 -07003605 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003606 "Laying out status bar window: (%d,%d - %d,%d)",
3607 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003608 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003609 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3610 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3611 // Asking to layout into the overscan region, so give it that pure
3612 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003613 pf.left = df.left = of.left = mOverscanScreenLeft;
3614 pf.top = df.top = of.top = mOverscanScreenTop;
3615 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3616 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3617 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003618 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003619 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003620 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3621 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003622 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003623 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003624 // only do this for application windows to ensure no window that
3625 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003626 pf.left = df.left = mOverscanScreenLeft;
3627 pf.top = df.top = mOverscanScreenTop;
3628 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3629 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003630 // We need to tell the app about where the frame inside the overscan
3631 // is, so it can inset its content by that amount -- it didn't ask
3632 // to actually extend itself into the overscan region.
3633 of.left = mUnrestrictedScreenLeft;
3634 of.top = mUnrestrictedScreenTop;
3635 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3636 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003637 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003638 pf.left = df.left = mRestrictedOverscanScreenLeft;
3639 pf.top = df.top = mRestrictedOverscanScreenTop;
3640 pf.right = df.right = mRestrictedOverscanScreenLeft
3641 + mRestrictedOverscanScreenWidth;
3642 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3643 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003644 // We need to tell the app about where the frame inside the overscan
3645 // is, so it can inset its content by that amount -- it didn't ask
3646 // to actually extend itself into the overscan region.
3647 of.left = mUnrestrictedScreenLeft;
3648 of.top = mUnrestrictedScreenTop;
3649 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3650 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003651 }
Craig Mautner69b08182012-09-05 13:07:13 -07003652
John Spurlock46646232013-09-30 22:32:42 -04003653 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003654 if (win.isVoiceInteraction()) {
3655 cf.left = mVoiceContentLeft;
3656 cf.top = mVoiceContentTop;
3657 cf.right = mVoiceContentRight;
3658 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003659 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003660 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3661 cf.left = mDockLeft;
3662 cf.top = mDockTop;
3663 cf.right = mDockRight;
3664 cf.bottom = mDockBottom;
3665 } else {
3666 cf.left = mContentLeft;
3667 cf.top = mContentTop;
3668 cf.right = mContentRight;
3669 cf.bottom = mContentBottom;
3670 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003671 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003672 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003673 // Full screen windows are always given a layout that is as if the
3674 // status bar and other transient decors are gone. This is to avoid
3675 // bad states when moving from a window that is not hding the
3676 // status bar to one that is.
3677 cf.left = mRestrictedScreenLeft;
3678 cf.top = mRestrictedScreenTop;
3679 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3680 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003681 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003682 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003683 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3684 vf.left = mCurLeft;
3685 vf.top = mCurTop;
3686 vf.right = mCurRight;
3687 vf.bottom = mCurBottom;
3688 } else {
3689 vf.set(cf);
3690 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003691 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003692 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3693 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3694 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003695 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3696 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003697 // A window that has requested to fill the entire screen just
3698 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003699 if (attrs.type == TYPE_STATUS_BAR_PANEL
3700 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003701 pf.left = df.left = of.left = cf.left = hasNavBar
3702 ? mDockLeft : mUnrestrictedScreenLeft;
3703 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3704 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003705 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003706 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003707 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003708 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003709 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003710 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003711 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3712 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003713 } else if (attrs.type == TYPE_NAVIGATION_BAR
3714 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003715 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003716 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3717 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3718 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3719 + mUnrestrictedScreenWidth;
3720 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3721 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003722 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003723 "Laying out navigation bar window: (%d,%d - %d,%d)",
3724 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003725 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3726 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003727 && ((fl & FLAG_FULLSCREEN) != 0)) {
3728 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003729 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3730 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3731 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3732 + mOverscanScreenWidth;
3733 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3734 + mOverscanScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003735 } else if (attrs.type == TYPE_BOOT_PROGRESS
3736 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003737 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003738 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3739 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3740 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3741 + mOverscanScreenWidth;
3742 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3743 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003744 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003745 // The wallpaper also has Real Ultimate Power, but we want to tell
3746 // it about the overscan area.
3747 pf.left = df.left = mOverscanScreenLeft;
3748 pf.top = df.top = mOverscanScreenTop;
3749 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3750 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3751 of.left = cf.left = mUnrestrictedScreenLeft;
3752 of.top = cf.top = mUnrestrictedScreenTop;
3753 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3754 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003755 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003756 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3757 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3758 // Asking to layout into the overscan region, so give it that pure
3759 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003760 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3761 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3762 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003763 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003764 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003765 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003766 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003767 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003768 && (attrs.type == TYPE_STATUS_BAR
3769 || attrs.type == TYPE_TOAST
John Spurlock34e13d92013-08-10 06:52:28 -04003770 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3771 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003772 // Asking for layout as if the nav bar is hidden, lets the
3773 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003774 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003775 // can be above the nav bar can do this.
3776 // XXX This assumes that an app asking for this will also
3777 // ask for layout in only content. We can't currently figure out
3778 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003779 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3780 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3781 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3782 + mUnrestrictedScreenWidth;
3783 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3784 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003785 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003786 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3787 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3788 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3789 + mRestrictedScreenWidth;
3790 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3791 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003792 }
Craig Mautner69b08182012-09-05 13:07:13 -07003793
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003794 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003795
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003796 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3797 vf.left = mCurLeft;
3798 vf.top = mCurTop;
3799 vf.right = mCurRight;
3800 vf.bottom = mCurBottom;
3801 } else {
3802 vf.set(cf);
3803 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003804 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003805 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3806 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003807 // A child window should be placed inside of the same visible
3808 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003809 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003810 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003811 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3812 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003813 // Otherwise, a normal window must be placed inside the content
3814 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003815 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3816 // Status bar panels are the only windows who can go on top of
3817 // the status bar. They are protected by the STATUS_BAR_SERVICE
3818 // permission, so they have the same privileges as the status
3819 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003820 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3821 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3822 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3823 + mRestrictedScreenWidth;
3824 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3825 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003826 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3827 || attrs.type == TYPE_VOLUME_OVERLAY) {
3828 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003829 pf.left = df.left = of.left = cf.left = mStableLeft;
3830 pf.top = df.top = of.top = cf.top = mStableTop;
3831 pf.right = df.right = of.right = cf.right = mStableRight;
3832 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003833 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003834 pf.left = mContentLeft;
3835 pf.top = mContentTop;
3836 pf.right = mContentRight;
3837 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003838 if (win.isVoiceInteraction()) {
3839 df.left = of.left = cf.left = mVoiceContentLeft;
3840 df.top = of.top = cf.top = mVoiceContentTop;
3841 df.right = of.right = cf.right = mVoiceContentRight;
3842 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3843 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003844 df.left = of.left = cf.left = mDockLeft;
3845 df.top = of.top = cf.top = mDockTop;
3846 df.right = of.right = cf.right = mDockRight;
3847 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003848 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003849 df.left = of.left = cf.left = mContentLeft;
3850 df.top = of.top = cf.top = mContentTop;
3851 df.right = of.right = cf.right = mContentRight;
3852 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003853 }
3854 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3855 vf.left = mCurLeft;
3856 vf.top = mCurTop;
3857 vf.right = mCurRight;
3858 vf.bottom = mCurBottom;
3859 } else {
3860 vf.set(cf);
3861 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003862 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003863 }
3864 }
Craig Mautner69b08182012-09-05 13:07:13 -07003865
Craig Mautnerb816bed2013-07-23 10:26:17 -07003866 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3867 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003868 df.left = df.top = -10000;
3869 df.right = df.bottom = 10000;
3870 if (attrs.type != TYPE_WALLPAPER) {
3871 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3872 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
3873 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003874 }
3875
Craig Mautnereda67292013-04-28 13:50:14 -07003876 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003877 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07003878 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003879 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003880 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003881 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003882 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07003883 + " dcf=" + dcf.toShortString()
3884 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003885
Adrian Roosfa104232014-06-20 16:10:14 -07003886 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07003887
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003888 // Dock windows carve out the bottom of the screen, so normal windows
3889 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003890 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3891 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003892 setLastInputMethodWindowLw(null, null);
3893 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003894 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003895 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
3896 && !win.getGivenInsetsPendingLw()) {
3897 offsetVoiceInputWindowLw(win);
3898 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003899 }
3900
satok1bc0a492012-04-25 22:47:12 +09003901 private void offsetInputMethodWindowLw(WindowState win) {
3902 int top = win.getContentFrameLw().top;
3903 top += win.getGivenContentInsetsLw().top;
3904 if (mContentBottom > top) {
3905 mContentBottom = top;
3906 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003907 if (mVoiceContentBottom > top) {
3908 mVoiceContentBottom = top;
3909 }
satok1bc0a492012-04-25 22:47:12 +09003910 top = win.getVisibleFrameLw().top;
3911 top += win.getGivenVisibleInsetsLw().top;
3912 if (mCurBottom > top) {
3913 mCurBottom = top;
3914 }
Craig Mautnereda67292013-04-28 13:50:14 -07003915 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003916 + mDockBottom + " mContentBottom="
3917 + mContentBottom + " mCurBottom=" + mCurBottom);
3918 }
3919
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003920 private void offsetVoiceInputWindowLw(WindowState win) {
3921 final int gravity = win.getAttrs().gravity;
3922 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3923 << Gravity.AXIS_X_SHIFT)) {
3924 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_X_SHIFT: {
3925 int right = win.getContentFrameLw().right - win.getGivenContentInsetsLw().right;
3926 if (mVoiceContentLeft < right) {
3927 mVoiceContentLeft = right;
3928 }
3929 } break;
3930 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_X_SHIFT: {
3931 int left = win.getContentFrameLw().left - win.getGivenContentInsetsLw().left;
3932 if (mVoiceContentRight < left) {
3933 mVoiceContentRight = left;
3934 }
3935 } break;
3936 }
3937 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3938 << Gravity.AXIS_Y_SHIFT)) {
3939 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_Y_SHIFT: {
3940 int bottom = win.getContentFrameLw().bottom - win.getGivenContentInsetsLw().bottom;
3941 if (mVoiceContentTop < bottom) {
3942 mVoiceContentTop = bottom;
3943 }
3944 } break;
3945 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_Y_SHIFT: {
3946 int top = win.getContentFrameLw().top - win.getGivenContentInsetsLw().top;
3947 if (mVoiceContentBottom < top) {
3948 mVoiceContentBottom = top;
3949 }
3950 } break;
3951 }
3952 }
3953
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003954 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003955 @Override
3956 public void finishLayoutLw() {
3957 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003958 }
3959
3960 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003961 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003962 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003963 mTopFullscreenOpaqueWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003964 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02003965 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003966 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003967 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003968 mForcingShowNavBar = false;
3969 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07003970
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003971 mHideLockScreen = false;
3972 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003973 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003974 mShowingLockscreen = false;
3975 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003976 mWinShowWhenLocked = null;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003977 }
3978
3979 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003980 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003981 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003982 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3983 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05003984 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05003985 if (mTopFullscreenOpaqueWindowState == null
3986 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
3987 mForcingShowNavBar = true;
3988 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003989 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003990 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003991 mForceStatusBarFromKeyguard = true;
3992 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003993 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003994 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003995 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003996 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003997 mForceStatusBarFromKeyguard = true;
3998 } else {
3999 mForceStatusBar = true;
4000 }
4001 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004002 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004003 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004004 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004005 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Craig Mautner7d7808f2014-09-11 18:02:38 -07004006 && attrs.type < FIRST_SYSTEM_WINDOW;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004007 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004008 // If the lockscreen was showing when the dream started then wait
4009 // for the dream to draw before hiding the lockscreen.
4010 if (!mDreamingLockscreen
4011 || (win.isVisibleLw() && win.hasDrawnLw())) {
4012 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004013 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004014 }
4015 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004016
Craig Mautner00156ec2014-03-06 22:29:02 -08004017 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07004018 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004019 final boolean secureKeyguard = isKeyguardSecure();
Craig Mautnerab55e522014-03-03 13:26:03 -08004020 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004021 final IApplicationToken appToken = win.getAppToken();
4022 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004023 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004024 mAppsToBeHidden.remove(appToken);
4025 mAppsThatDismissKeyguard.remove(appToken);
4026 if (mAppsToBeHidden.isEmpty() && isKeyguardSecureIncludingHidden()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004027 mWinShowWhenLocked = win;
4028 mHideLockScreen = true;
4029 mForceStatusBarFromKeyguard = false;
4030 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004031 } else if (dismissKeyguard) {
4032 if (secureKeyguard) {
4033 mAppsToBeHidden.add(appToken);
4034 } else {
4035 mAppsToBeHidden.remove(appToken);
4036 }
4037 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004038 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004039 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004040 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004041 if (attrs.x == 0 && attrs.y == 0
4042 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4043 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4044 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4045 mTopFullscreenOpaqueWindowState = win;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004046 if (!mAppsThatDismissKeyguard.isEmpty() &&
4047 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4048 if (DEBUG_LAYOUT) Slog.v(TAG,
4049 "Setting mDismissKeyguard true by win " + win);
4050 mDismissKeyguard = mWinDismissingKeyguard == win ?
4051 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
4052 mWinDismissingKeyguard = win;
4053 mForceStatusBarFromKeyguard = mShowingLockscreen && secureKeyguard;
4054 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4055 if (DEBUG_LAYOUT) Slog.v(TAG,
4056 "Setting mHideLockScreen to true by win " + win);
4057 mHideLockScreen = true;
4058 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004059 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004060 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004061 mAllowLockscreenWhenOn = true;
4062 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004063 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004064
4065 if (mWinShowWhenLocked != null &&
4066 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
4067 win.hideLw(false);
4068 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004069 }
4070 }
4071 }
4072
4073 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004074 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004075 public int finishPostLayoutPolicyLw() {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004076 if (mWinShowWhenLocked != null &&
4077 mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) {
4078 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4079 // fullscreen window.
4080 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4081 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4082 mTopFullscreenOpaqueWindowState.hideLw(false);
4083 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4084 }
4085
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004086 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004087 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004088
4089 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4090 ? mTopFullscreenOpaqueWindowState.getAttrs()
4091 : null;
4092
Jeff Brownc8018eb2012-10-29 21:33:27 -07004093 // If we are not currently showing a dream then remember the current
4094 // lockscreen state. We will use this to determine whether the dream
4095 // started while the lockscreen was showing and remember this state
4096 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004097 if (!mShowingDream) {
4098 mDreamingLockscreen = mShowingLockscreen;
4099 }
4100
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004101 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004102 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004103 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004104 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004105 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07004106 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004107 if (mStatusBarController.setBarShowingLw(true)) {
4108 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4109 }
Craig Mautner81defc72013-10-29 11:10:42 -07004110 // Maintain fullscreen layout until incoming animation is complete.
4111 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004112 // Transient status bar on the lockscreen is not allowed
4113 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4114 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4115 mLastSystemUiFlags, mLastSystemUiFlags);
4116 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004117 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004118 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004119 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004120 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004121 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004122 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004123 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004124 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004125 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004126 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004127 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
4128 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
4129 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4130 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004131 if (mStatusBarController.isTransientShowing()) {
4132 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004133 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4134 }
4135 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004136 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004137 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004138 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004139 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004140 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004141 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004142 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004143 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004144 if (mStatusBarController.setBarShowingLw(true)) {
4145 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4146 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004147 }
4148 }
4149 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004150
Craig Mautner81defc72013-10-29 11:10:42 -07004151 if (mTopIsFullscreen != topIsFullscreen) {
4152 if (!topIsFullscreen) {
4153 // Force another layout when status bar becomes fully shown.
4154 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4155 }
4156 mTopIsFullscreen = topIsFullscreen;
4157 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004158
Craig Mautner39834192012-09-02 07:47:24 -07004159 // Hide the key guard if a visible window explicitly specifies that it wants to be
4160 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004161 if (mKeyguardDelegate != null && mStatusBar != null) {
4162 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4163 + mHideLockScreen);
4164 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !isKeyguardSecure()) {
4165 mKeyguardHidden = true;
4166 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004167 changes |= FINISH_LAYOUT_REDO_LAYOUT
4168 | FINISH_LAYOUT_REDO_CONFIG
4169 | FINISH_LAYOUT_REDO_WALLPAPER;
4170 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004171 if (mKeyguardDelegate.isShowing()) {
4172 mHandler.post(new Runnable() {
4173 @Override
4174 public void run() {
4175 mKeyguardDelegate.keyguardDone(false, false);
4176 }
4177 });
4178 }
4179 } else if (mHideLockScreen) {
4180 mKeyguardHidden = true;
4181 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
4182 changes |= FINISH_LAYOUT_REDO_LAYOUT
4183 | FINISH_LAYOUT_REDO_CONFIG
4184 | FINISH_LAYOUT_REDO_WALLPAPER;
4185 }
4186 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
4187 // This is the case of keyguard isSecure() and not mHideLockScreen.
4188 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4189 // Only launch the next keyguard unlock window once per window.
4190 mKeyguardHidden = false;
4191 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
4192 changes |= FINISH_LAYOUT_REDO_LAYOUT
4193 | FINISH_LAYOUT_REDO_CONFIG
4194 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004195 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004196 mHandler.post(new Runnable() {
4197 @Override
4198 public void run() {
4199 mKeyguardDelegate.dismiss();
4200 }
4201 });
4202 }
4203 } else {
4204 mWinDismissingKeyguard = null;
4205 mKeyguardHidden = false;
4206 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
4207 changes |= FINISH_LAYOUT_REDO_LAYOUT
4208 | FINISH_LAYOUT_REDO_CONFIG
4209 | FINISH_LAYOUT_REDO_WALLPAPER;
4210 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004211 }
4212 }
Joe Onorato664644d2011-01-23 17:53:23 -08004213
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004214 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004215 // If the navigation bar has been hidden or shown, we need to do another
4216 // layout pass to update that window.
4217 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4218 }
Joe Onorato664644d2011-01-23 17:53:23 -08004219
Mike Lockwood28569302010-01-28 11:54:40 -05004220 // update since mAllowLockscreenWhenOn might have changed
4221 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004222 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004223 }
4224
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004225 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004226 * Processes the result code of {@link IKeyguardService#setOccluded}. This is needed because we
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004227 * immediately need to put the wallpaper directly behind the Keyguard when a window with flag
4228 * {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} gets dismissed. If we
4229 * would wait for Keyguard to change the flags, that would be running asynchronously and thus be
4230 * too late so the user might see the window behind.
4231 *
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004232 * @param setHiddenResult The result code from {@link IKeyguardService#setOccluded}.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004233 * @return Whether the flags have changed and we have to redo the layout.
4234 */
4235 private boolean processKeyguardSetHiddenResultLw(int setHiddenResult) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004236 if (setHiddenResult
4237 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_SET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004238 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4239 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4240 return true;
4241 } else if (setHiddenResult
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004242 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_UNSET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004243 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4244 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4245 return true;
4246 } else {
4247 return false;
4248 }
4249 }
4250
4251 private boolean isStatusBarKeyguard() {
4252 return mStatusBar != null
4253 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4254 }
4255
Jose Lima9546b202014-07-02 17:21:51 -07004256 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004257 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004258 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004259 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004260 return false;
4261 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004262 return true;
4263 }
4264
Jose Lima9546b202014-07-02 17:21:51 -07004265 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004266 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004267 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004268 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004269 // If the navigation bar has been hidden or shown, we need to do another
4270 // layout pass to update that window.
4271 return FINISH_LAYOUT_REDO_LAYOUT;
4272 }
4273 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004274 }
4275
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004276 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004277 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004278 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4279 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004280 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4281 if (newLidState == mLidState) {
4282 return;
4283 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004284
Jeff Brownc458ce92012-04-30 14:58:40 -07004285 mLidState = newLidState;
4286 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004287 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004288
4289 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004290 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004291 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004292 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004293 }
4294 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004295
Michael Wright3818c922014-09-02 13:59:07 -07004296 @Override
4297 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4298 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4299 if (mCameraLensCoverState == lensCoverState) {
4300 return;
4301 }
4302 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4303 lensCoverState == CAMERA_LENS_UNCOVERED) {
4304 Intent intent;
4305 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4306 mKeyguardDelegate.isShowing();
4307 if (keyguardActive) {
4308 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4309 } else {
4310 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4311 }
Bryce Lee584a4452014-10-21 15:55:55 -07004312 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Michael Wright3818c922014-09-02 13:59:07 -07004313 mContext.startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
4314 }
4315 mCameraLensCoverState = lensCoverState;
4316 }
4317
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004318 void setHdmiPlugged(boolean plugged) {
4319 if (mHdmiPlugged != plugged) {
4320 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004321 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004322 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004323 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004324 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004325 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004326 }
4327 }
4328
Joe Onoratoea495d42011-04-06 11:41:11 -07004329 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004330 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004331 // watch for HDMI plug messages if the hdmi switch exists
4332 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4333 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4334
Joe Onoratoea495d42011-04-06 11:41:11 -07004335 final String filename = "/sys/class/switch/hdmi/state";
4336 FileReader reader = null;
4337 try {
4338 reader = new FileReader(filename);
4339 char[] buf = new char[15];
4340 int n = reader.read(buf);
4341 if (n > 1) {
4342 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4343 }
4344 } catch (IOException ex) {
4345 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4346 } catch (NumberFormatException ex) {
4347 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4348 } finally {
4349 if (reader != null) {
4350 try {
4351 reader.close();
4352 } catch (IOException ex) {
4353 }
Joe Onoratodc100302011-01-11 17:07:41 -08004354 }
4355 }
4356 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004357 // This dance forces the code in setHdmiPlugged to run.
4358 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4359 mHdmiPlugged = !plugged;
4360 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004361 }
4362
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004363 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004364 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004365
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004366 final Runnable mScreenshotTimeout = new Runnable() {
4367 @Override public void run() {
4368 synchronized (mScreenshotLock) {
4369 if (mScreenshotConnection != null) {
4370 mContext.unbindService(mScreenshotConnection);
4371 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004372 }
Winson Chung9112ec32011-06-27 13:15:32 -07004373 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004374 }
4375 };
4376
4377 // Assume this is called from the Handler thread.
4378 private void takeScreenshot() {
4379 synchronized (mScreenshotLock) {
4380 if (mScreenshotConnection != null) {
4381 return;
4382 }
4383 ComponentName cn = new ComponentName("com.android.systemui",
4384 "com.android.systemui.screenshot.TakeScreenshotService");
4385 Intent intent = new Intent();
4386 intent.setComponent(cn);
4387 ServiceConnection conn = new ServiceConnection() {
4388 @Override
4389 public void onServiceConnected(ComponentName name, IBinder service) {
4390 synchronized (mScreenshotLock) {
4391 if (mScreenshotConnection != this) {
4392 return;
4393 }
4394 Messenger messenger = new Messenger(service);
4395 Message msg = Message.obtain(null, 1);
4396 final ServiceConnection myConn = this;
4397 Handler h = new Handler(mHandler.getLooper()) {
4398 @Override
4399 public void handleMessage(Message msg) {
4400 synchronized (mScreenshotLock) {
4401 if (mScreenshotConnection == myConn) {
4402 mContext.unbindService(mScreenshotConnection);
4403 mScreenshotConnection = null;
4404 mHandler.removeCallbacks(mScreenshotTimeout);
4405 }
4406 }
4407 }
4408 };
4409 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004410 msg.arg1 = msg.arg2 = 0;
4411 if (mStatusBar != null && mStatusBar.isVisibleLw())
4412 msg.arg1 = 1;
4413 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4414 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004415 try {
4416 messenger.send(msg);
4417 } catch (RemoteException e) {
4418 }
4419 }
4420 }
4421 @Override
4422 public void onServiceDisconnected(ComponentName name) {}
4423 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004424 if (mContext.bindServiceAsUser(
4425 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004426 mScreenshotConnection = conn;
4427 mHandler.postDelayed(mScreenshotTimeout, 10000);
4428 }
4429 }
Winson Chung9112ec32011-06-27 13:15:32 -07004430 }
4431
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004432 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004433 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004434 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004435 if (!mSystemBooted) {
4436 // If we have not yet booted, don't let key events do anything.
4437 return 0;
4438 }
4439
Jeff Brown037c33e2014-04-09 00:31:55 -07004440 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004441 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4442 final boolean canceled = event.isCanceled();
4443 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004444
Jeff Brown3122e442010-10-11 23:32:49 -07004445 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004446
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004447 // If screen is off then we treat the case where the keyguard is open but hidden
4448 // the same as if it were open and in front.
4449 // This will prevent any keys other than the power button from waking the screen
4450 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004451 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004452 (interactive ?
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004453 mKeyguardDelegate.isShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004454 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004455
Jeff Brown40013652012-05-16 21:22:36 -07004456 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004457 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004458 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004459 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004460 }
4461
Jeff Brown037c33e2014-04-09 00:31:55 -07004462 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004463 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004464 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4465 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004466 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004467 // When the device is interactive or the key is injected pass the
4468 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004469 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004470 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004471 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4472 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4473 // to the application but preserve its wake key status to make sure we still move
4474 // from dozing to fully interactive if we would normally go from off to fully
4475 // interactive.
4476 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004477 } else {
4478 // When the screen is off and the key is not injected, determine whether
4479 // to wake the device but don't pass the key to the application.
4480 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004481 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4482 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004483 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004484 }
4485
Justin Kohd378ad72013-04-01 12:18:26 -07004486 // If the key would be handled globally, just return the result, don't worry about special
4487 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004488 if (isValidGlobalKey(keyCode)
4489 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004490 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004491 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004492 }
Justin Kohd378ad72013-04-01 12:18:26 -07004493 return result;
4494 }
4495
Jeff Brownbae8e772014-06-12 19:59:45 -07004496 boolean useHapticFeedback = down
4497 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4498 && event.getRepeatCount() == 0;
4499
Jeff Brown4d396052010-10-29 21:50:21 -07004500 // Handle special keys.
4501 switch (keyCode) {
4502 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004503 case KeyEvent.KEYCODE_VOLUME_UP:
4504 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004505 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4506 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004507 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004508 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004509 mScreenshotChordVolumeDownKeyTriggered = true;
4510 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4511 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004512 cancelPendingPowerKeyAction();
4513 interceptScreenshotChord();
4514 }
4515 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004516 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004517 cancelPendingScreenshotChordAction();
4518 }
4519 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4520 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004521 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004522 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004523 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004524 cancelPendingPowerKeyAction();
4525 cancelPendingScreenshotChordAction();
4526 }
4527 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004528 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004529 cancelPendingScreenshotChordAction();
4530 }
4531 }
Jeff Brown4d396052010-10-29 21:50:21 -07004532 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004533 TelecomManager telecomManager = getTelecommService();
4534 if (telecomManager != null) {
4535 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004536 // If an incoming call is ringing, either VOLUME key means
4537 // "silence ringer". We handle these keys here, rather than
4538 // in the InCallScreen, to make sure we'll respond to them
4539 // even if the InCallScreen hasn't come to the foreground yet.
4540 // Look for the DOWN event here, to agree with the "fallback"
4541 // behavior in the InCallScreen.
4542 Log.i(TAG, "interceptKeyBeforeQueueing:"
4543 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004544
Santos Cordon6848f722014-05-21 15:22:12 -07004545 // Silence the ringer. (It's safe to call this
4546 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004547 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004548
Santos Cordon6848f722014-05-21 15:22:12 -07004549 // And *don't* pass this key thru to the current activity
4550 // (which is probably the InCallScreen.)
4551 result &= ~ACTION_PASS_TO_USER;
4552 break;
4553 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004554 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004555 && (result & ACTION_PASS_TO_USER) == 0) {
4556 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004557 // the application, just pass it to the session service.
4558
4559 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004560 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004561 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004562 }
4563 }
4564
RoboErik430fc482014-06-12 15:49:20 -07004565 if ((result & ACTION_PASS_TO_USER) == 0) {
4566 // If we aren't passing to the user and no one else
4567 // handled it send it to the session manager to figure
4568 // out.
4569 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004570 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07004571 break;
4572 }
4573 }
4574 break;
4575 }
4576
4577 case KeyEvent.KEYCODE_ENDCALL: {
4578 result &= ~ACTION_PASS_TO_USER;
4579 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004580 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004581 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004582 if (telecomManager != null) {
4583 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004584 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004585 if (interactive && !hungUp) {
4586 mEndCallKeyHandled = false;
4587 mHandler.postDelayed(mEndCallLongPress,
4588 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4589 } else {
4590 mEndCallKeyHandled = true;
4591 }
Jeff Brown4d396052010-10-29 21:50:21 -07004592 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004593 if (!mEndCallKeyHandled) {
4594 mHandler.removeCallbacks(mEndCallLongPress);
4595 if (!canceled) {
4596 if ((mEndcallBehavior
4597 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4598 if (goHome()) {
4599 break;
4600 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004601 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004602 if ((mEndcallBehavior
4603 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4604 mPowerManager.goToSleep(event.getEventTime(),
4605 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4606 isWakeKey = false;
4607 }
Jeff Brown4d396052010-10-29 21:50:21 -07004608 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004609 }
Jeff Brown4d396052010-10-29 21:50:21 -07004610 }
4611 break;
4612 }
4613
4614 case KeyEvent.KEYCODE_POWER: {
4615 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004616 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004617 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004618 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004619 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004620 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004621 }
4622 break;
4623 }
4624
Jeff Brown6212a492014-03-07 13:58:47 -08004625 case KeyEvent.KEYCODE_SLEEP: {
4626 result &= ~ACTION_PASS_TO_USER;
Jeff Brownbae8e772014-06-12 19:59:45 -07004627 if (!mPowerManager.isInteractive()) {
4628 useHapticFeedback = false; // suppress feedback if already non-interactive
4629 }
Jeff Brownc12035c2014-08-13 18:52:25 -07004630 mPowerManager.goToSleep(event.getEventTime(),
4631 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown6212a492014-03-07 13:58:47 -08004632 isWakeKey = false;
4633 break;
4634 }
4635
4636 case KeyEvent.KEYCODE_WAKEUP: {
4637 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004638 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004639 break;
4640 }
4641
Jeff Brown4d396052010-10-29 21:50:21 -07004642 case KeyEvent.KEYCODE_MEDIA_PLAY:
4643 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4644 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004645 case KeyEvent.KEYCODE_HEADSETHOOK:
4646 case KeyEvent.KEYCODE_MUTE:
4647 case KeyEvent.KEYCODE_MEDIA_STOP:
4648 case KeyEvent.KEYCODE_MEDIA_NEXT:
4649 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4650 case KeyEvent.KEYCODE_MEDIA_REWIND:
4651 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004652 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4653 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004654 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4655 // If the global session is active pass all media keys to it
4656 // instead of the active window.
4657 result &= ~ACTION_PASS_TO_USER;
4658 }
Jeff Brown4d396052010-10-29 21:50:21 -07004659 if ((result & ACTION_PASS_TO_USER) == 0) {
4660 // Only do this if we would otherwise not pass it to the user. In that
4661 // case, the PhoneWindow class will do the same thing, except it will
4662 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004663 // Note that we need to make a copy of the key event here because the
4664 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004665 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004666 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4667 new KeyEvent(event));
4668 msg.setAsynchronous(true);
4669 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004670 }
4671 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004672 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004673
Jeff Brown4d396052010-10-29 21:50:21 -07004674 case KeyEvent.KEYCODE_CALL: {
4675 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004676 TelecomManager telecomManager = getTelecommService();
4677 if (telecomManager != null) {
4678 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004679 Log.i(TAG, "interceptKeyBeforeQueueing:"
4680 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004681 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004682
Santos Cordon6848f722014-05-21 15:22:12 -07004683 // And *don't* pass this key thru to the current activity
4684 // (which is presumably the InCallScreen.)
4685 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004686 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004687 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004688 }
Jeff Brown4d396052010-10-29 21:50:21 -07004689 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004690 }
Michael Wright869a67c2014-08-26 19:33:06 -07004691 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4692 // Only do this if we would otherwise not pass it to the user. In that case,
4693 // interceptKeyBeforeDispatching would apply a similar but different policy in
4694 // order to invoke voice assist actions. Note that we need to make a copy of the
4695 // key event here because the original key event will be recycled when we return.
4696 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4697 mBroadcastWakeLock.acquire();
4698 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4699 keyguardActive ? 1 : 0, 0);
4700 msg.setAsynchronous(true);
4701 msg.sendToTarget();
4702 }
4703 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004704 }
Jeff Brown26875502014-01-30 21:47:47 -08004705
Jeff Brownbae8e772014-06-12 19:59:45 -07004706 if (useHapticFeedback) {
4707 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4708 }
4709
Jeff Brown26875502014-01-30 21:47:47 -08004710 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004711 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004712 }
Bryce Lee584a4452014-10-21 15:55:55 -07004713
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004714 return result;
4715 }
4716
Jeff Brown1c2e4942012-11-06 16:32:01 -08004717 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004718 * Returns true if the key can have global actions attached to it.
4719 * We reserve all power management keys for the system since they require
4720 * very careful handling.
4721 */
4722 private static boolean isValidGlobalKey(int keyCode) {
4723 switch (keyCode) {
4724 case KeyEvent.KEYCODE_POWER:
4725 case KeyEvent.KEYCODE_WAKEUP:
4726 case KeyEvent.KEYCODE_SLEEP:
4727 return false;
4728 default:
4729 return true;
4730 }
4731 }
4732
4733 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08004734 * When the screen is off we ignore some keys that might otherwise typically
4735 * be considered wake keys. We filter them out here.
4736 *
4737 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4738 * is always considered a wake key.
4739 */
4740 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4741 switch (keyCode) {
4742 // ignore volume keys unless docked
4743 case KeyEvent.KEYCODE_VOLUME_UP:
4744 case KeyEvent.KEYCODE_VOLUME_DOWN:
4745 case KeyEvent.KEYCODE_VOLUME_MUTE:
4746 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4747
4748 // ignore media and camera keys
4749 case KeyEvent.KEYCODE_MUTE:
4750 case KeyEvent.KEYCODE_HEADSETHOOK:
4751 case KeyEvent.KEYCODE_MEDIA_PLAY:
4752 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4753 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4754 case KeyEvent.KEYCODE_MEDIA_STOP:
4755 case KeyEvent.KEYCODE_MEDIA_NEXT:
4756 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4757 case KeyEvent.KEYCODE_MEDIA_REWIND:
4758 case KeyEvent.KEYCODE_MEDIA_RECORD:
4759 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004760 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004761 case KeyEvent.KEYCODE_CAMERA:
4762 return false;
4763 }
4764 return true;
4765 }
4766
4767
Jeff Brown56194eb2011-03-02 19:23:13 -08004768 /** {@inheritDoc} */
4769 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004770 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4771 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08004772 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
4773 return 0;
4774 }
Michael Wright70af00a2014-09-03 19:30:20 -07004775 }
Bryce Lee5c138322014-11-03 08:26:09 -08004776
Michael Wright70af00a2014-09-03 19:30:20 -07004777 if (shouldDispatchInputWhenNonInteractive()) {
4778 return ACTION_PASS_TO_USER;
4779 }
Bryce Lee5c138322014-11-03 08:26:09 -08004780
Jeff Brown037c33e2014-04-09 00:31:55 -07004781 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004782 }
4783
Michael Wright70af00a2014-09-03 19:30:20 -07004784 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08004785 // Send events to keyguard while the screen is on.
4786 if (keyguardIsShowingTq() && mDisplay != null && mDisplay.getState() != Display.STATE_OFF) {
4787 return true;
4788 }
4789
4790 // Send events to a dozing dream even if the screen is off since the dream
4791 // is in control of the state of the screen.
4792 IDreamManager dreamManager = getDreamManager();
4793
4794 try {
4795 if (dreamManager != null && dreamManager.isDreaming()) {
4796 return true;
4797 }
4798 } catch (RemoteException e) {
4799 Slog.e(TAG, "RemoteException when checking if dreaming", e);
4800 }
4801
4802 // Otherwise, consume events since the user can't see what is being
4803 // interacted with.
4804 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07004805 }
4806
Jeff Brown40013652012-05-16 21:22:36 -07004807 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4808 if (DEBUG_INPUT) {
4809 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004810 }
4811
Jeff Brown40013652012-05-16 21:22:36 -07004812 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4813 if (DEBUG_INPUT) {
4814 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4815 }
4816
4817 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4818 mHavePendingMediaKeyRepeatWithWakeLock = false;
4819 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4820 }
4821
4822 dispatchMediaKeyWithWakeLockToAudioService(event);
4823
4824 if (event.getAction() == KeyEvent.ACTION_DOWN
4825 && event.getRepeatCount() == 0) {
4826 mHavePendingMediaKeyRepeatWithWakeLock = true;
4827
4828 Message msg = mHandler.obtainMessage(
4829 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4830 msg.setAsynchronous(true);
4831 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4832 } else {
4833 mBroadcastWakeLock.release();
4834 }
4835 }
4836
4837 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4838 mHavePendingMediaKeyRepeatWithWakeLock = false;
4839
4840 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4841 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4842 if (DEBUG_INPUT) {
4843 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4844 }
4845
4846 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4847 mBroadcastWakeLock.release();
4848 }
4849
4850 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4851 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07004852 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004853 }
4854 }
4855
Michael Wright869a67c2014-08-26 19:33:06 -07004856 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
4857 Intent voiceIntent =
4858 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
4859 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
4860 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
4861 mBroadcastWakeLock.release();
4862 }
4863
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004864 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004865 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004866 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004867 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4868 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4869 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004870 } else {
4871 try {
4872 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4873 ServiceManager.getService(Context.UI_MODE_SERVICE));
4874 mUiMode = uiModeService.getCurrentModeType();
4875 } catch (RemoteException e) {
4876 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004877 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004878 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004879 synchronized (mLock) {
4880 updateOrientationListenerLp();
4881 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004882 }
4883 };
4884
Jeff Brown6aaf2952012-10-05 16:01:08 -07004885 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4886 @Override
4887 public void onReceive(Context context, Intent intent) {
4888 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004889 if (mKeyguardDelegate != null) {
4890 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004891 }
4892 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004893 if (mKeyguardDelegate != null) {
4894 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004895 }
4896 }
4897 }
4898 };
4899
Christopher Tate5e08af02012-09-21 17:17:22 -07004900 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4901 @Override
4902 public void onReceive(Context context, Intent intent) {
4903 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4904 // tickle the settings observer: this first ensures that we're
4905 // observing the relevant settings for the newly-active user,
4906 // and then updates our own bookkeeping based on the now-
4907 // current user.
4908 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004909
4910 // force a re-application of focused window sysui visibility.
4911 // the window may never have been shown for this user
4912 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04004913 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05004914 mLastSystemUiFlags = 0;
4915 updateSystemUiVisibilityLw();
4916 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004917 }
4918 }
4919 };
4920
John Spurlockd9b70bd2014-02-06 17:02:44 -05004921 private final Runnable mRequestTransientNav = new Runnable() {
4922 @Override
4923 public void run() {
4924 requestTransientBars(mNavigationBar);
4925 }
4926 };
4927
John Spurlocke1f366f2013-08-05 12:22:40 -04004928 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04004929 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07004930 if (!isUserSetupComplete()) {
4931 // Swipe-up for navigation bar is disabled during setup
4932 return;
4933 }
John Spurlock27735a42013-08-14 17:57:38 -04004934 boolean sb = mStatusBarController.checkShowTransientBarLw();
4935 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004936 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04004937 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
4938 if (sb ^ nb && barTarget != swipeTarget) {
4939 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04004940 return;
4941 }
John Spurlock27735a42013-08-14 17:57:38 -04004942 if (sb) mStatusBarController.showTransient();
4943 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04004944 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004945 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04004946 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04004947 }
4948 }
4949
Jeff Brown3ee549c2014-09-22 20:14:39 -07004950 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07004951 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004952 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004953 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07004954 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07004955
4956 // We must get this work done here because the power manager will drop
4957 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07004958 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07004959 mAwake = false;
4960 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07004961 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004962 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004963 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004964 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07004965
4966 if (mKeyguardDelegate != null) {
4967 mKeyguardDelegate.onScreenTurnedOff(why);
4968 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004969 }
4970
Jeff Brown13f00f02014-10-31 14:45:50 -07004971 private void wakeUpFromPowerKey(long eventTime) {
4972 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
4973 }
4974
Bryce Lee5c138322014-11-03 08:26:09 -08004975 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Lee584a4452014-10-21 15:55:55 -07004976 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
Bryce Lee5c138322014-11-03 08:26:09 -08004977 return false;
Bryce Lee584a4452014-10-21 15:55:55 -07004978 }
4979
4980 mPowerManager.wakeUp(wakeTime);
Bryce Lee5c138322014-11-03 08:26:09 -08004981 return true;
Bryce Lee584a4452014-10-21 15:55:55 -07004982 }
4983
Jeff Brown3ee549c2014-09-22 20:14:39 -07004984 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07004985 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07004986 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07004987 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07004988 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07004989
Jeff Brown3ee549c2014-09-22 20:14:39 -07004990 // Since goToSleep performs these functions synchronously, we must
4991 // do the same here. We cannot post this work to a handler because
4992 // that might cause it to become reordered with respect to what
4993 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07004994 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07004995 mAwake = true;
4996 mKeyguardDrawComplete = false;
4997 if (mKeyguardDelegate != null) {
4998 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
4999 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5000 }
5001
Jeff Browna20dda42014-05-27 20:57:24 -07005002 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005003 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005004 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005005 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005006
Jim Miller5ecd8112013-01-09 18:50:26 -08005007 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07005008 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005009 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005010 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005011 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005012 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005013 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005014 }
5015
Jeff Brown36c4db82014-09-19 12:05:31 -07005016 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005017 synchronized (mLock) {
5018 if (!mAwake || mKeyguardDrawComplete) {
5019 return; // spurious
5020 }
5021
Jeff Brown36c4db82014-09-19 12:05:31 -07005022 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005023 if (mKeyguardDelegate != null) {
5024 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5025 }
5026 }
5027
5028 finishScreenTurningOn();
5029 }
5030
5031 // Called on the DisplayManager's DisplayPowerController thread.
5032 @Override
5033 public void screenTurnedOff() {
5034 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5035
5036 synchronized (mLock) {
5037 mScreenOnEarly = false;
5038 mScreenOnFully = false;
5039 mWindowManagerDrawComplete = false;
5040 mScreenOnListener = null;
5041 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005042 }
5043 }
5044
Jeff Brown3ee549c2014-09-22 20:14:39 -07005045 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005046 @Override
5047 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005048 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005049
Jeff Brown3ee549c2014-09-22 20:14:39 -07005050 synchronized (mLock) {
5051 mScreenOnEarly = true;
5052 mScreenOnFully = false;
5053 mWindowManagerDrawComplete = false;
5054 mScreenOnListener = screenOnListener;
5055 updateOrientationListenerLp();
5056 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005057
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005058 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5059 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005060 // ... eventually calls finishWindowsDrawn
5061 }
5062
Jeff Brown36c4db82014-09-19 12:05:31 -07005063 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005064 synchronized (mLock) {
5065 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5066 return; // spurious
5067 }
5068
Jeff Brown36c4db82014-09-19 12:05:31 -07005069 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005070 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005071
5072 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005073 }
5074
Craig Mautner8a0da012014-05-31 15:13:37 -07005075 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005076 final ScreenOnListener listener;
5077 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005078 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005079 if (DEBUG_WAKEUP) Slog.d(TAG,
5080 "finishScreenTurningOn: mAwake=" + mAwake
5081 + ", mScreenOnEarly=" + mScreenOnEarly
5082 + ", mScreenOnFully=" + mScreenOnFully
5083 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5084 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5085
5086 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5087 || (mAwake && !mKeyguardDrawComplete)) {
5088 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005089 }
5090
Jeff Brown3ee549c2014-09-22 20:14:39 -07005091 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5092 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005093 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005094 mScreenOnFully = true;
5095
5096 // Remember the first time we draw the keyguard so we know when we're done with
5097 // the main part of booting and can enable the screen and hide boot messages.
5098 if (!mKeyguardDrawnOnce && mAwake) {
5099 mKeyguardDrawnOnce = true;
5100 enableScreen = true;
5101 if (mBootMessageNeedsHiding) {
5102 mBootMessageNeedsHiding = false;
5103 hideBootMessages();
5104 }
5105 } else {
5106 enableScreen = false;
5107 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005108 }
5109
Jeff Brown3ee549c2014-09-22 20:14:39 -07005110 if (listener != null) {
5111 listener.onScreenOn();
5112 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005113
Jeff Brown3ee549c2014-09-22 20:14:39 -07005114 if (enableScreen) {
5115 try {
5116 mWindowManager.enableScreenIfNeeded();
5117 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005118 }
Craig Mautnera631d492014-08-05 15:16:01 -07005119 }
5120 }
5121
5122 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005123 synchronized (mLock) {
5124 if (!mKeyguardDrawnOnce) {
5125 mBootMessageNeedsHiding = true;
5126 return; // keyguard hasn't drawn the first time yet, not done booting
5127 }
Craig Mautnera631d492014-08-05 15:16:01 -07005128 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005129
5130 if (mBootMsgDialog != null) {
5131 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5132 mBootMsgDialog.dismiss();
5133 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005134 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005135 }
5136
5137 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005138 public boolean isScreenOn() {
5139 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005140 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005141
Dianne Hackborn08743722009-12-21 12:16:51 -08005142 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005143 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005144 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005145 if (mKeyguardDelegate != null) {
5146 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005147 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005148 }
5149
5150 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005151 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005152 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005153 if (mKeyguardDelegate != null) {
5154 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005155 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005156 }
5157
Mike Lockwoodf7913302009-11-28 22:27:10 -05005158 private boolean keyguardIsShowingTq() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005159 if (mKeyguardDelegate == null) return false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005160 return mKeyguardDelegate.isShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005161 }
5162
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005163
5164 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005165 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005166 public boolean isKeyguardLocked() {
5167 return keyguardOn();
5168 }
5169
5170 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005171 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005172 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005173 if (mKeyguardDelegate == null) return false;
5174 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005175 }
5176
Craig Mautnerc9457fa2014-06-06 14:27:48 -07005177 // Returns true if keyguard is currently locked whether or not it is currently hidden.
5178 private boolean isKeyguardSecureIncludingHidden() {
5179 return mKeyguardDelegate.isSecure() && mKeyguardDelegate.isShowing();
5180 }
5181
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005182 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005183 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005184 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005185 if (mKeyguardDelegate == null) return false;
5186 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005187 }
5188
Jose Lima9546b202014-07-02 17:21:51 -07005189 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005190 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005191 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05005192 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005193 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005194 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005195 // ask the keyguard to prompt the user to authenticate if necessary
5196 mKeyguardDelegate.dismiss();
5197 }
5198 });
5199 }
5200 }
5201
5202 public void notifyActivityDrawnForKeyguardLw() {
5203 if (mKeyguardDelegate != null) {
5204 mHandler.post(new Runnable() {
5205 @Override
5206 public void run() {
5207 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005208 }
5209 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005210 }
5211 }
5212
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005213 @Override
5214 public boolean isKeyguardDrawnLw() {
5215 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005216 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005217 }
5218 }
5219
Jorim Jaggi0d674622014-05-21 01:34:15 +02005220 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005221 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005222 if (mKeyguardDelegate != null) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005223 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005224 }
5225 }
5226
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005227 void sendCloseSystemWindows() {
5228 sendCloseSystemWindows(mContext, null);
5229 }
5230
5231 void sendCloseSystemWindows(String reason) {
5232 sendCloseSystemWindows(mContext, reason);
5233 }
5234
5235 static void sendCloseSystemWindows(Context context, String reason) {
5236 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005237 try {
5238 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
5239 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005240 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005241 }
5242 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005243
Jeff Brown01a98dd2011-09-20 15:08:29 -07005244 @Override
5245 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005246 if (false) {
5247 Slog.v(TAG, "rotationForOrientationLw(orient="
5248 + orientation + ", last=" + lastRotation
5249 + "); user=" + mUserRotation + " "
5250 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5251 ? "USER_ROTATION_LOCKED" : "")
5252 );
5253 }
5254
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005255 if (mForceDefaultOrientation) {
5256 return Surface.ROTATION_0;
5257 }
5258
The Android Open Source Project0727d222009-03-11 12:11:58 -07005259 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005260 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5261 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005262 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005263 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005264
Jeff Browndec6cf42011-11-15 14:08:20 -08005265 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005266 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005267 // Ignore sensor when lid switch is open and rotation is forced.
5268 preferredRotation = mLidOpenRotation;
5269 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005270 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005271 // Ignore sensor when in car dock unless explicitly enabled.
5272 // This case can override the behavior of NOSENSOR, and can also
5273 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005274 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005275 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005276 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5277 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5278 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005279 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005280 // Ignore sensor when in desk dock unless explicitly enabled.
5281 // This case can override the behavior of NOSENSOR, and can also
5282 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005283 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005284 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005285 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5286 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005287 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005288 preferredRotation = mDemoHdmiRotation;
5289 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5290 && mUndockedHdmiRotation >= 0) {
5291 // Ignore sensor when plugged into HDMI and an undocked orientation has
5292 // been specified in the configuration (only for legacy devices without
5293 // full multi-display support).
5294 // Note that the dock orientation overrides the HDMI orientation.
5295 preferredRotation = mUndockedHdmiRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005296 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5297 // Application just wants to remain locked in the last rotation.
5298 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005299 } else if (!mSupportAutoRotation) {
5300 // If we don't support auto-rotation then bail out here and ignore
5301 // the sensor and any rotation lock settings.
5302 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005303 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005304 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005305 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5306 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5307 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5308 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005309 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5310 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5311 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5312 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5313 // Otherwise, use sensor only if requested by the application or enabled
5314 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005315 if (mAllowAllRotations < 0) {
5316 // Can't read this during init() because the context doesn't
5317 // have display metrics at that time so we cannot determine
5318 // tablet vs. phone then.
5319 mAllowAllRotations = mContext.getResources().getBoolean(
5320 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5321 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005322 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005323 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005324 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5325 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005326 preferredRotation = sensorRotation;
5327 } else {
5328 preferredRotation = lastRotation;
5329 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005330 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5331 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5332 // Apply rotation lock. Does not apply to NOSENSOR.
5333 // The idea is that the user rotation expresses a weak preference for the direction
5334 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5335 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005336 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005337 } else {
5338 // No overriding preference.
5339 // We will do exactly what the application asked us to do.
5340 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005341 }
5342
Dianne Hackborne5439f22010-10-02 16:53:50 -07005343 switch (orientation) {
5344 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005345 // Return portrait unless overridden.
5346 if (isAnyPortrait(preferredRotation)) {
5347 return preferredRotation;
5348 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005349 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005350
Jeff Brown01a98dd2011-09-20 15:08:29 -07005351 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005352 // Return landscape unless overridden.
5353 if (isLandscapeOrSeascape(preferredRotation)) {
5354 return preferredRotation;
5355 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005356 return mLandscapeRotation;
5357
5358 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005359 // Return reverse portrait unless overridden.
5360 if (isAnyPortrait(preferredRotation)) {
5361 return preferredRotation;
5362 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005363 return mUpsideDownRotation;
5364
5365 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005366 // Return seascape unless overridden.
5367 if (isLandscapeOrSeascape(preferredRotation)) {
5368 return preferredRotation;
5369 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005370 return mSeascapeRotation;
5371
5372 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005373 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005374 // Return either landscape rotation.
5375 if (isLandscapeOrSeascape(preferredRotation)) {
5376 return preferredRotation;
5377 }
5378 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005379 return lastRotation;
5380 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005381 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005382
Jeff Brown01a98dd2011-09-20 15:08:29 -07005383 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005384 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005385 // Return either portrait rotation.
5386 if (isAnyPortrait(preferredRotation)) {
5387 return preferredRotation;
5388 }
5389 if (isAnyPortrait(lastRotation)) {
5390 return lastRotation;
5391 }
5392 return mPortraitRotation;
5393
5394 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005395 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5396 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005397 if (preferredRotation >= 0) {
5398 return preferredRotation;
5399 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005400 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005401 }
5402 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005403 }
5404
Jeff Brown01a98dd2011-09-20 15:08:29 -07005405 @Override
5406 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5407 switch (orientation) {
5408 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5409 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5410 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5411 return isAnyPortrait(rotation);
5412
5413 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5414 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5415 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5416 return isLandscapeOrSeascape(rotation);
5417
5418 default:
5419 return true;
5420 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005421 }
5422
Jeff Brownc0347aa2011-09-23 17:26:09 -07005423 @Override
5424 public void setRotationLw(int rotation) {
5425 mOrientationListener.setCurrentRotation(rotation);
5426 }
5427
Jeff Brown01a98dd2011-09-20 15:08:29 -07005428 private boolean isLandscapeOrSeascape(int rotation) {
5429 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005430 }
5431
Jeff Brown01a98dd2011-09-20 15:08:29 -07005432 private boolean isAnyPortrait(int rotation) {
5433 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005434 }
5435
Jose Lima9546b202014-07-02 17:21:51 -07005436 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005437 public int getUserRotationMode() {
5438 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005439 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5440 WindowManagerPolicy.USER_ROTATION_FREE :
5441 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005442 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005443
5444 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005445 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005446 public void setUserRotationMode(int mode, int rot) {
5447 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005448
5449 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005450 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005451 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005452 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005453 rot,
5454 UserHandle.USER_CURRENT);
5455 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005456 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005457 0,
5458 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005459 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005460 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005461 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005462 1,
5463 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005464 }
5465 }
5466
Jose Lima9546b202014-07-02 17:21:51 -07005467 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005468 public void setSafeMode(boolean safeMode) {
5469 mSafeMode = safeMode;
5470 performHapticFeedbackLw(null, safeMode
5471 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5472 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005473 }
Craig Mautnereda67292013-04-28 13:50:14 -07005474
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005475 static long[] getLongIntArray(Resources r, int resid) {
5476 int[] ar = r.getIntArray(resid);
5477 if (ar == null) {
5478 return null;
5479 }
5480 long[] out = new long[ar.length];
5481 for (int i=0; i<ar.length; i++) {
5482 out[i] = ar[i];
5483 }
5484 return out;
5485 }
Craig Mautnereda67292013-04-28 13:50:14 -07005486
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005487 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005488 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005489 public void systemReady() {
Mike Lockwooded8902d2013-11-15 11:01:47 -08005490 mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null);
5491 mKeyguardDelegate.onSystemReady();
5492
Michael Wright3818c922014-09-02 13:59:07 -07005493 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005494 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005495 synchronized (mLock) {
5496 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005497 mSystemReady = true;
5498 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005499 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005500 public void run() {
5501 updateSettings();
5502 }
5503 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005504 }
5505 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005506
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005507 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005508 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005509 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005510 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005511 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005512 mKeyguardDelegate.onBootCompleted();
5513 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005514 synchronized (mLock) {
5515 mSystemBooted = true;
5516 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005517 wakingUp();
5518 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005519 }
5520
Dianne Hackborn661cd522011-08-22 00:26:20 -07005521 ProgressDialog mBootMsgDialog = null;
5522
5523 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005524 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005525 public void showBootMessage(final CharSequence msg, final boolean always) {
5526 mHandler.post(new Runnable() {
5527 @Override public void run() {
5528 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005529 int theme;
5530 if (mContext.getPackageManager().hasSystemFeature(
5531 PackageManager.FEATURE_WATCH)) {
5532 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5533 } else if (mContext.getPackageManager().hasSystemFeature(
5534 PackageManager.FEATURE_TELEVISION)) {
5535 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5536 } else {
5537 theme = 0;
5538 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005539
5540 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005541 // This dialog will consume all events coming in to
5542 // it, to avoid it trying to do things too early in boot.
5543 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5544 return true;
5545 }
5546 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5547 return true;
5548 }
5549 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5550 return true;
5551 }
5552 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5553 return true;
5554 }
5555 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5556 return true;
5557 }
5558 @Override public boolean dispatchPopulateAccessibilityEvent(
5559 AccessibilityEvent event) {
5560 return true;
5561 }
5562 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07005563 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5564 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5565 mBootMsgDialog.setIndeterminate(true);
5566 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005567 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005568 mBootMsgDialog.getWindow().addFlags(
5569 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5570 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5571 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005572 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5573 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5574 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005575 mBootMsgDialog.setCancelable(false);
5576 mBootMsgDialog.show();
5577 }
5578 mBootMsgDialog.setMessage(msg);
5579 }
5580 });
5581 }
5582
5583 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005584 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005585 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005586 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005587 }
5588
Mike Lockwood28569302010-01-28 11:54:40 -05005589 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005590 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005591 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005592 // ***************************************
5593 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5594 // ***************************************
5595 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5596 // WITH ITS LOCKS HELD.
5597 //
5598 // This code must be VERY careful about the locks
5599 // it acquires.
5600 // In fact, the current code acquires way too many,
5601 // and probably has lurking deadlocks.
5602
Mike Lockwood28569302010-01-28 11:54:40 -05005603 synchronized (mScreenLockTimeout) {
5604 if (mLockScreenTimerActive) {
5605 // reset the timer
5606 mHandler.removeCallbacks(mScreenLockTimeout);
5607 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5608 }
5609 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005610 }
5611
Adam Cohenf7522022012-10-03 20:03:18 -07005612 class ScreenLockTimeout implements Runnable {
5613 Bundle options;
5614
5615 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005616 public void run() {
5617 synchronized (this) {
5618 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005619 if (mKeyguardDelegate != null) {
5620 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005621 }
Mike Lockwood28569302010-01-28 11:54:40 -05005622 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005623 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005624 }
5625 }
Mike Lockwood28569302010-01-28 11:54:40 -05005626
Adam Cohenf7522022012-10-03 20:03:18 -07005627 public void setLockOptions(Bundle options) {
5628 this.options = options;
5629 }
5630 }
5631
5632 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5633
Jose Lima9546b202014-07-02 17:21:51 -07005634 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005635 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005636 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5637 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005638 if (options != null) {
5639 // In case multiple calls are made to lockNow, we don't wipe out the options
5640 // until the runnable actually executes.
5641 mScreenLockTimeout.setLockOptions(options);
5642 }
Jim Miller93c518e2012-01-17 15:55:31 -08005643 mHandler.post(mScreenLockTimeout);
5644 }
5645
Mike Lockwood28569302010-01-28 11:54:40 -05005646 private void updateLockScreenTimeout() {
5647 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005648 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005649 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005650 if (mLockScreenTimerActive != enable) {
5651 if (enable) {
5652 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5653 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5654 } else {
5655 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5656 mHandler.removeCallbacks(mScreenLockTimeout);
5657 }
5658 mLockScreenTimerActive = enable;
5659 }
5660 }
5661 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005662
5663 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005664 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005665 public void enableScreenAfterBoot() {
5666 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005667 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005668 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005669 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005670
Jeff Brownc458ce92012-04-30 14:58:40 -07005671 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005672 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005673 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005674 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005675 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005676 }
Jeff Browna20dda42014-05-27 20:57:24 -07005677
5678 synchronized (mLock) {
5679 updateWakeGestureListenerLp();
5680 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005681 }
5682
Jeff Brown4f5fa282014-06-12 19:19:15 -07005683 void updateUiMode() {
5684 if (mUiModeManager == null) {
5685 mUiModeManager = IUiModeManager.Stub.asInterface(
5686 ServiceManager.getService(Context.UI_MODE_SERVICE));
5687 }
5688 try {
5689 mUiMode = mUiModeManager.getCurrentModeType();
5690 } catch (RemoteException e) {
5691 }
5692 }
5693
Jeff Brown01a98dd2011-09-20 15:08:29 -07005694 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005695 try {
5696 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005697 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5698 } catch (RemoteException e) {
5699 // Ignore
5700 }
5701 }
5702
5703 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5704 try {
5705 //set orientation on WindowManager
5706 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005707 } catch (RemoteException e) {
5708 // Ignore
5709 }
5710 }
5711
Daniel Sandler6396c722013-04-16 20:19:09 -04005712 /**
5713 * Return an Intent to launch the currently active dock app as home. Returns
5714 * null if the standard home should be launched, which is the case if any of the following is
5715 * true:
5716 * <ul>
5717 * <li>The device is not in either car mode or desk mode
5718 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5719 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5720 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5721 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5722 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005723 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005724 */
5725 Intent createHomeDockIntent() {
5726 Intent intent = null;
5727
5728 // What home does is based on the mode, not the dock state. That
5729 // is, when in car mode you should be taken to car home regardless
5730 // of whether we are actually in a car dock.
5731 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5732 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5733 intent = mCarDockIntent;
5734 }
5735 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5736 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5737 intent = mDeskDockIntent;
5738 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005739 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5740 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5741 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5742 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5743 // Always launch dock home from home when watch is docked, if it exists.
5744 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005745 }
5746
5747 if (intent == null) {
5748 return null;
5749 }
5750
5751 ActivityInfo ai = null;
5752 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5753 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005754 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005755 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005756 if (info != null) {
5757 ai = info.activityInfo;
5758 }
5759 if (ai != null
5760 && ai.metaData != null
5761 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5762 intent = new Intent(intent);
5763 intent.setClassName(ai.packageName, ai.name);
5764 return intent;
5765 }
5766
5767 return null;
5768 }
5769
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005770 void startDockOrHome() {
John Spurlockc8b46ca2013-04-08 12:59:26 -04005771 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04005772
5773 Intent dock = createHomeDockIntent();
5774 if (dock != null) {
5775 try {
5776 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
5777 return;
5778 } catch (ActivityNotFoundException e) {
5779 }
5780 }
5781
Dianne Hackbornd8883992012-09-07 15:58:52 -07005782 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005783 }
Craig Mautnereda67292013-04-28 13:50:14 -07005784
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005785 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005786 * goes to the home screen
5787 * @return whether it did anything
5788 */
5789 boolean goHome() {
5790 if (false) {
5791 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005792 try {
5793 ActivityManagerNative.getDefault().stopAppSwitches();
5794 } catch (RemoteException e) {
5795 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005796 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005797 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005798 } else {
5799 // This code brings home to the front or, if it is already
5800 // at the front, puts the device to sleep.
5801 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08005802 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
5803 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
5804 Log.d(TAG, "UTS-TEST-MODE");
5805 } else {
5806 ActivityManagerNative.getDefault().stopAppSwitches();
5807 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04005808 Intent dock = createHomeDockIntent();
5809 if (dock != null) {
5810 int result = ActivityManagerNative.getDefault()
5811 .startActivityAsUser(null, null, dock,
5812 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
5813 null, null, 0,
5814 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005815 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04005816 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5817 return false;
5818 }
5819 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005820 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005821 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005822 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005823 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005824 null, null, 0,
5825 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005826 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005827 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005828 return false;
5829 }
5830 } catch (RemoteException ex) {
5831 // bummer, the activity manager, which is in this process, is dead
5832 }
5833 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005834 return true;
5835 }
Craig Mautnereda67292013-04-28 13:50:14 -07005836
5837 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005838 public void setCurrentOrientationLw(int newOrientation) {
5839 synchronized (mLock) {
5840 if (newOrientation != mCurrentAppOrientation) {
5841 mCurrentAppOrientation = newOrientation;
5842 updateOrientationListenerLp();
5843 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005844 }
5845 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005846
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005847 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5848 if (!isGlobalAccessibilityGestureEnabled()) {
5849 return;
5850 }
5851 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5852 Context.AUDIO_SERVICE);
5853 if (audioManager.isSilentMode()) {
5854 return;
5855 }
5856 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5857 Settings.System.DEFAULT_NOTIFICATION_URI);
5858 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5859 ringTone.play();
5860 }
Craig Mautnereda67292013-04-28 13:50:14 -07005861
Bryce Lee584a4452014-10-21 15:55:55 -07005862 private boolean isTheaterModeEnabled() {
5863 return Settings.Global.getInt(mContext.getContentResolver(),
5864 Settings.Global.THEATER_MODE_ON, 0) == 1;
5865 }
5866
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005867 private boolean isGlobalAccessibilityGestureEnabled() {
5868 return Settings.Global.getInt(mContext.getContentResolver(),
5869 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5870 }
5871
Craig Mautnereda67292013-04-28 13:50:14 -07005872 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005873 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005874 if (!mVibrator.hasVibrator()) {
5875 return false;
5876 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005877 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5878 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07005879 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005880 return false;
5881 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005882 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005883 switch (effectId) {
5884 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005885 pattern = mLongPressVibePattern;
5886 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005887 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005888 pattern = mVirtualKeyVibePattern;
5889 break;
5890 case HapticFeedbackConstants.KEYBOARD_TAP:
5891 pattern = mKeyboardTapVibePattern;
5892 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07005893 case HapticFeedbackConstants.CLOCK_TICK:
5894 pattern = mClockTickVibePattern;
5895 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07005896 case HapticFeedbackConstants.CALENDAR_DATE:
5897 pattern = mCalendarDateVibePattern;
5898 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005899 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005900 pattern = mSafeModeDisabledVibePattern;
5901 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005902 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005903 pattern = mSafeModeEnabledVibePattern;
5904 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08005905 default:
5906 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005907 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005908 int owningUid;
5909 String owningPackage;
5910 if (win != null) {
5911 owningUid = win.getOwningUid();
5912 owningPackage = win.getOwningPackage();
5913 } else {
5914 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07005915 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005916 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005917 if (pattern.length == 1) {
5918 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04005919 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005920 } else {
5921 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04005922 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005923 }
5924 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005925 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005926
5927 @Override
5928 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04005929 }
5930
Jeff Brownc38c9be2012-10-04 13:16:19 -07005931 @Override
5932 public void keepScreenOnStoppedLw() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005933 if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08005934 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005935 }
5936 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04005937
Dianne Hackborndf89e652011-10-06 22:35:11 -07005938 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08005939 // If there is no window focused, there will be nobody to handle the events
5940 // anyway, so just hang on in whatever state we're in until things settle down.
John Spurlock79da8332013-09-20 12:04:47 -04005941 WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState;
5942 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005943 return 0;
5944 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005945 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005946 // We are updating at a point where the keyguard has gotten
5947 // focus, but we were last in a state where the top window is
5948 // hiding it. This is probably because the keyguard as been
5949 // shown while the top window was displayed, so we want to ignore
5950 // it here because this is just a very transient change and it
5951 // will quickly lose focus once it correctly gets hidden.
5952 return 0;
5953 }
John Spurlock32beb2c2013-03-11 10:16:47 -04005954
John Spurlock1db8b682014-02-18 11:18:59 -05005955 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07005956 & ~mResettingSystemUiFlags
5957 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005958 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05005959 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005960 }
John Spurlock79da8332013-09-20 12:04:47 -04005961 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005962 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005963 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005964 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04005965 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005966 return 0;
5967 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07005968 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005969 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04005970 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07005971 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005972 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005973 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005974 try {
5975 IStatusBarService statusbar = getStatusBarService();
5976 if (statusbar != null) {
5977 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
5978 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08005979 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005980 } catch (RemoteException e) {
5981 // re-acquire status bar service next time it is needed.
5982 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08005983 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07005984 }
5985 });
5986 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08005987 }
5988
John Spurlock79da8332013-09-20 12:04:47 -04005989 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04005990 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005991 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
5992 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04005993 : mTopFullscreenOpaqueWindowState;
5994 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5995 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5996
John Spurlock27735a42013-08-14 17:57:38 -04005997 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04005998 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04005999 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006000 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6001 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006002 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006003 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock08ffcf52014-07-11 10:13:46 -04006004 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006005 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6006 }
John Spurlockbd957402013-10-03 11:38:39 -04006007 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006008 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006009
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006010 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006011 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6012 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006013 }
6014
John Spurlock27735a42013-08-14 17:57:38 -04006015 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006016 boolean immersiveSticky =
6017 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006018 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006019 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006020 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006021 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6022 boolean hideStatusBarSysui =
6023 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006024 boolean hideNavBarSysui =
6025 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006026
John Spurlock27735a42013-08-14 17:57:38 -04006027 boolean transientStatusBarAllowed =
6028 mStatusBar != null && (
6029 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006030 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006031 || statusBarHasFocus);
6032
John Spurlockf1a36642013-10-12 17:50:42 -04006033 boolean transientNavBarAllowed =
6034 mNavigationBar != null &&
6035 hideNavBarSysui && immersiveSticky;
6036
John Spurlockf25706f2013-11-07 18:02:43 -05006037 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006038 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006039 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006040 && !transientNavBarAllowed;
6041 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006042 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006043 clearClearableFlagsLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04006044 }
John Spurlock27735a42013-08-14 17:57:38 -04006045
6046 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6047
6048 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006049 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6050 boolean newImmersiveMode = isImmersiveMode(vis);
6051 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006052 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006053 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6054 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006055 }
John Spurlock27735a42013-08-14 17:57:38 -04006056
John Spurlockf1a36642013-10-12 17:50:42 -04006057 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6058
John Spurlocke1f366f2013-08-05 12:22:40 -04006059 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006060 }
6061
John Spurlockf1a36642013-10-12 17:50:42 -04006062 private void clearClearableFlagsLw() {
6063 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6064 if (newVal != mResettingSystemUiFlags) {
6065 mResettingSystemUiFlags = newVal;
6066 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6067 }
6068 }
6069
6070 private boolean isImmersiveMode(int vis) {
6071 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006072 return mNavigationBar != null
6073 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006074 && (vis & flags) != 0
6075 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006076 }
6077
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006078 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006079 * @return whether the navigation or status bar can be made translucent
6080 *
6081 * This should return true unless touch exploration is not enabled or
6082 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006083 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006084 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006085 return mTranslucentDecorEnabled
6086 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006087 }
6088
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006089 // Use this instead of checking config_showNavigationBar so that it can be consistently
6090 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006091 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006092 public boolean hasNavigationBar() {
6093 return mHasNavigationBar;
6094 }
6095
satok1bc0a492012-04-25 22:47:12 +09006096 @Override
6097 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6098 mLastInputMethodWindow = ime;
6099 mLastInputMethodTargetWindow = target;
6100 }
6101
Craig Mautnerf1b67412012-09-19 13:18:29 -07006102 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006103 public int getInputMethodWindowVisibleHeightLw() {
6104 return mDockBottom - mCurBottom;
6105 }
6106
6107 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006108 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006109 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006110 if (mKeyguardDelegate != null) {
6111 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006112 }
John Spurlock13451a22012-09-28 14:40:41 -04006113 if (mStatusBarService != null) {
6114 try {
6115 mStatusBarService.setCurrentUser(newUserId);
6116 } catch (RemoteException e) {
6117 // oh well
6118 }
6119 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006120 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006121 }
6122
6123 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006124 public boolean canMagnifyWindow(int windowType) {
6125 switch (windowType) {
6126 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6127 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6128 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6129 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6130 return false;
6131 }
6132 }
6133 return true;
6134 }
6135
6136 @Override
6137 public boolean isTopLevelWindow(int windowType) {
6138 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6139 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6140 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6141 }
6142 return true;
6143 }
6144
Jim Miller4eeb4f62012-11-08 00:04:29 -08006145 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006146 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006147 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006148 pw.print(" mSystemReady="); pw.print(mSystemReady);
6149 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006150 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006151 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006152 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006153 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006154 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6155 || mForceClearedSystemUiFlags != 0) {
6156 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6157 pw.print(Integer.toHexString(mLastSystemUiFlags));
6158 pw.print(" mResettingSystemUiFlags=0x");
6159 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6160 pw.print(" mForceClearedSystemUiFlags=0x");
6161 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006162 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006163 if (mLastFocusNeedsMenu) {
6164 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6165 pw.println(mLastFocusNeedsMenu);
6166 }
Jeff Browna20dda42014-05-27 20:57:24 -07006167 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6168 pw.println(mWakeGestureEnabledSetting);
6169
Jeff Brownbcdfc622014-03-06 19:13:04 -08006170 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006171 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6172 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006173 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6174 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6175 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6176 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006177 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006178 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006179 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6180 pw.print(mCarDockEnablesAccelerometer);
6181 pw.print(" mDeskDockEnablesAccelerometer=");
6182 pw.println(mDeskDockEnablesAccelerometer);
6183 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6184 pw.print(mLidKeyboardAccessibility);
6185 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006186 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006187 pw.print(prefix);
6188 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6189 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006190 pw.print(prefix);
6191 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6192 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006193 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006194 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6195 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6196 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6197 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6198 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6199 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6200 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006201 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6202 pw.print(","); pw.print(mOverscanScreenTop);
6203 pw.print(") "); pw.print(mOverscanScreenWidth);
6204 pw.print("x"); pw.println(mOverscanScreenHeight);
6205 if (mOverscanLeft != 0 || mOverscanTop != 0
6206 || mOverscanRight != 0 || mOverscanBottom != 0) {
6207 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6208 pw.print(" top="); pw.print(mOverscanTop);
6209 pw.print(" right="); pw.print(mOverscanRight);
6210 pw.print(" bottom="); pw.println(mOverscanBottom);
6211 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006212 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6213 pw.print(mRestrictedOverscanScreenLeft);
6214 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6215 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6216 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006217 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6218 pw.print(","); pw.print(mUnrestrictedScreenTop);
6219 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6220 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6221 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6222 pw.print(","); pw.print(mRestrictedScreenTop);
6223 pw.print(") "); pw.print(mRestrictedScreenWidth);
6224 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006225 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6226 pw.print(","); pw.print(mStableFullscreenTop);
6227 pw.print(")-("); pw.print(mStableFullscreenRight);
6228 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006229 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6230 pw.print(","); pw.print(mStableTop);
6231 pw.print(")-("); pw.print(mStableRight);
6232 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006233 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6234 pw.print(","); pw.print(mSystemTop);
6235 pw.print(")-("); pw.print(mSystemRight);
6236 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006237 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6238 pw.print(","); pw.print(mCurTop);
6239 pw.print(")-("); pw.print(mCurRight);
6240 pw.print(","); pw.print(mCurBottom); pw.println(")");
6241 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6242 pw.print(","); pw.print(mContentTop);
6243 pw.print(")-("); pw.print(mContentRight);
6244 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006245 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6246 pw.print(","); pw.print(mVoiceContentTop);
6247 pw.print(")-("); pw.print(mVoiceContentRight);
6248 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006249 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6250 pw.print(","); pw.print(mDockTop);
6251 pw.print(")-("); pw.print(mDockRight);
6252 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006253 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6254 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006255 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6256 pw.print(" mShowingDream="); pw.print(mShowingDream);
6257 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006258 if (mLastInputMethodWindow != null) {
6259 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6260 pw.println(mLastInputMethodWindow);
6261 }
6262 if (mLastInputMethodTargetWindow != null) {
6263 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6264 pw.println(mLastInputMethodTargetWindow);
6265 }
6266 if (mStatusBar != null) {
6267 pw.print(prefix); pw.print("mStatusBar=");
6268 pw.println(mStatusBar);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006269 pw.print(prefix); pw.print("isStatusBarKeyguard=");
6270 pw.print(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006271 }
6272 if (mNavigationBar != null) {
6273 pw.print(prefix); pw.print("mNavigationBar=");
6274 pw.println(mNavigationBar);
6275 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006276 if (mFocusedWindow != null) {
6277 pw.print(prefix); pw.print("mFocusedWindow=");
6278 pw.println(mFocusedWindow);
6279 }
6280 if (mFocusedApp != null) {
6281 pw.print(prefix); pw.print("mFocusedApp=");
6282 pw.println(mFocusedApp);
6283 }
6284 if (mWinDismissingKeyguard != null) {
6285 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6286 pw.println(mWinDismissingKeyguard);
6287 }
6288 if (mTopFullscreenOpaqueWindowState != null) {
6289 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6290 pw.println(mTopFullscreenOpaqueWindowState);
6291 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006292 if (mForcingShowNavBar) {
6293 pw.print(prefix); pw.print("mForcingShowNavBar=");
6294 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6295 pw.println(mForcingShowNavBarLayer);
6296 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006297 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006298 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006299 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6300 pw.print(" mForceStatusBarFromKeyguard=");
6301 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006302 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006303 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006304 pw.print(" mHomePressed="); pw.println(mHomePressed);
6305 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6306 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6307 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6308 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6309 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6310 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6311 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6312 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6313 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6314 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006315 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6316 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6317 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006318
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006319 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006320 mStatusBarController.dump(pw, prefix);
6321 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006322 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006323
Jeff Browna20dda42014-05-27 20:57:24 -07006324 if (mWakeGestureListener != null) {
6325 mWakeGestureListener.dump(pw, prefix);
6326 }
Jeff Brown600f0032014-05-22 17:06:00 -07006327 if (mOrientationListener != null) {
6328 mOrientationListener.dump(pw, prefix);
6329 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006330 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006331}