blob: c75a418989cec265ca0948a2f277e789abed7d59 [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
Jeff Brown37df39a92015-02-25 15:42:31 -08002 * Copyright (C) 2006 The Android Open Source Project
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jorim Jaggib10e33f2015-02-04 21:57:40 +010017package com.android.server.policy;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080018
Dianne Hackborna4972e92012-03-14 10:38:05 -070019import android.app.ActivityManager;
Jeff Brown061ea992015-04-17 19:55:47 -070020import android.app.ActivityManagerInternal;
21import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080022import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080023import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040024import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070025import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070026import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040027import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080028import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070029import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080030import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040031import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080032import android.content.ContentResolver;
33import android.content.Context;
34import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070035import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070036import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080037import android.content.pm.ActivityInfo;
38import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040039import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070040import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.content.res.Configuration;
42import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070043import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080044import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080045import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080046import android.graphics.Rect;
John Spurlock7b414672014-07-18 13:02:39 -040047import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080048import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050049import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080050import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070051import android.media.Ringtone;
52import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070053import android.media.session.MediaSessionLegacyHelper;
Billy Laucbe540f2015-06-25 01:51:44 +010054import android.os.Binder;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070055import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080056import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070057import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080058import android.os.Handler;
59import android.os.IBinder;
Dianne Hackbornb6683c42015-06-18 17:40:33 -070060import android.os.IDeviceIdleController;
Jeff Brown32cbc38552011-12-01 14:01:49 -080061import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070062import android.os.Message;
63import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080064import android.os.PowerManager;
Billy Laucbe540f2015-06-25 01:51:44 +010065import android.os.Process;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080066import android.os.RemoteException;
67import android.os.ServiceManager;
68import android.os.SystemClock;
69import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080070import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070071import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080072import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070073import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080074import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070075import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040076import android.service.dreams.DreamService;
77import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070078import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070079import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070080import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080081import android.util.EventLog;
82import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070083import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080084import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070085import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080086import android.view.Gravity;
87import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080088import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080089import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070090import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070091import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080092import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080093import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080094import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080095import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080096import android.view.KeyEvent;
97import android.view.MotionEvent;
Chris Wren9bb290b2015-06-29 12:02:13 -040098
99import com.android.internal.logging.MetricsLogger;
Adam Powell6711f3b2015-05-06 15:57:09 -0700100import com.android.internal.policy.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800101import android.view.Surface;
102import android.view.View;
103import android.view.ViewConfiguration;
104import android.view.Window;
105import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800106import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700107import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800108import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800109import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800110import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800111import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200112import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800113import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800114import com.android.internal.R;
Craig Mautnerae446592012-12-06 19:05:05 -0800115import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700116import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800117import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700118import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100119import com.android.server.policy.keyguard.KeyguardServiceDelegate;
120import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800121
122import java.io.File;
123import java.io.FileReader;
124import java.io.IOException;
125import java.io.PrintWriter;
Billy Lau060275f2015-07-15 22:29:19 +0100126import java.util.Arrays;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700127import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800128import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800129
Dianne Hackbornc652de82013-02-15 16:32:56 -0800130import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700131import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
132import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
133import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700134import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
135import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
136import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800137
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800138/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700139 * WindowManagerPolicy implementation for the Android phone UI. This
140 * introduces a new method suffix, Lp, for an internal lock of the
141 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400142 * 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 -0700143 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800144 */
145public class PhoneWindowManager implements WindowManagerPolicy {
146 static final String TAG = "WindowManager";
147 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700148 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700149 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700150 static final boolean DEBUG_KEYGUARD = false;
151 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700152 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700153 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800154 static final boolean SHOW_STARTING_ANIMATIONS = true;
155 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400156
Daniel Sandler6396c722013-04-16 20:19:09 -0400157 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
158 // No longer recommended for desk docks; still useful in car docks.
159 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
160 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
161
Jeff Brown6d8fd272014-05-20 21:24:38 -0700162 static final int SHORT_PRESS_POWER_NOTHING = 0;
163 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
164 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
165 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800166 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700167
Joe Onoratod208e702010-10-08 16:22:43 -0400168 static final int LONG_PRESS_POWER_NOTHING = 0;
169 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
170 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700171 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700172
Jeff Brown13f00f02014-10-31 14:45:50 -0700173 static final int MULTI_PRESS_POWER_NOTHING = 0;
174 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
175 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
176
Michael Jurka3b1fc472011-06-13 10:54:40 -0700177 // These need to match the documentation/constant in
178 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800179 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800180 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700181 static final int LONG_PRESS_HOME_ASSIST = 2;
182
183 static final int DOUBLE_TAP_HOME_NOTHING = 0;
184 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800185
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000186 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
187 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
188
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700189 static final int APPLICATION_MEDIA_SUBLAYER = -2;
190 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800191 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800192 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700193 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700194
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800195 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
196 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
197 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500198 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700199 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800200
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700201 /**
202 * These are the system UI flags that, when changing, can cause the layout
203 * of the screen to change.
204 */
205 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400206 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400207 | View.SYSTEM_UI_FLAG_FULLSCREEN
208 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200209 | View.NAVIGATION_BAR_TRANSLUCENT
210 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700211
John Spurlock7b414672014-07-18 13:02:39 -0400212 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
213 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
214 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
215 .build();
216
Adrian Roosddc8b272015-05-21 16:28:27 -0700217 // The panic gesture may become active only after the keyguard is dismissed and the immersive
218 // app shows again. If that doesn't happen for 30s we drop the gesture.
219 private static final long PANIC_GESTURE_EXPIRATION = 30000;
220
Jim Miller5ecd8112013-01-09 18:50:26 -0800221 /**
222 * Keyguard stuff
223 */
224 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100225 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700226 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800227
Jeff Brown6651a632011-11-28 12:59:11 -0800228 /* Table of Application Launch keys. Maps from key codes to intent categories.
229 *
230 * These are special keys that are used to launch particular kinds of applications,
231 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
232 * usage page. We don't support quite that many yet...
233 */
234 static SparseArray<String> sApplicationLaunchKeyCategories;
235 static {
236 sApplicationLaunchKeyCategories = new SparseArray<String>();
237 sApplicationLaunchKeyCategories.append(
238 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
239 sApplicationLaunchKeyCategories.append(
240 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
241 sApplicationLaunchKeyCategories.append(
242 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
243 sApplicationLaunchKeyCategories.append(
244 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
245 sApplicationLaunchKeyCategories.append(
246 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
247 sApplicationLaunchKeyCategories.append(
248 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
249 }
250
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700251 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000252 static final int WAITING_FOR_DRAWN_TIMEOUT = 500;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700253
Dianne Hackborndf89e652011-10-06 22:35:11 -0700254 /**
255 * Lock protecting internal state. Must not call out into window
256 * manager with lock held. (This lock will be acquired in places
257 * where the window manager is calling in with its own lock held.)
258 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800259 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700260
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800261 Context mContext;
262 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700263 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700264 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700265 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700266 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700267 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400268 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700269 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700270 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800271 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700272 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800273 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000274 BurnInProtectionHelper mBurnInProtectionHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100275 AppOpsManager mAppOpsManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800276
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700277 // Vibrator pattern for haptic feedback of a long press.
278 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700279
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700280 // Vibrator pattern for haptic feedback of virtual key press.
281 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700282
Amith Yamasanic33cb712010-02-10 15:21:49 -0800283 // Vibrator pattern for a short vibration.
284 long[] mKeyboardTapVibePattern;
285
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700286 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
287 long[] mClockTickVibePattern;
288
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700289 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
290 long[] mCalendarDateVibePattern;
291
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700292 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
293 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700294
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700295 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
296 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700297
Mady Mellore8608912015-06-05 09:02:55 -0700298 // Vibrator pattern for haptic feedback of a context click.
299 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700300
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800301 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
302 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400303
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800304 boolean mSafeMode;
305 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700306 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400307 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400308 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700309 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400310 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
311 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
312 int[] mNavigationBarHeightForRotation = new int[4];
313 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400314
Craig Mautnera631d492014-08-05 15:16:01 -0700315 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800316 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700317 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700318 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700319 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700320 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
321 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
322 }
323 };
324 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
325 @Override
326 public void onShown(IBinder windowToken) {
327 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
328 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
329 }
330 };
331
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800332 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800333 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900334 WindowState mLastInputMethodWindow = null;
335 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800336
Jeff Brown13f00f02014-10-31 14:45:50 -0700337 // FIXME This state is shared between the input reader and handler thread.
338 // Technically it's broken and buggy but it has been like this for many years
339 // and we have not yet seen any problems. Someday we'll rewrite this logic
340 // so that only one thread is involved in handling input policy. Unfortunately
341 // it's on a critical path for power management so we can't just post the work to the
342 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
343 // to hold wakelocks during dispatch and eliminating the critical path.
344 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800345 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700346 volatile int mPowerKeyPressCounter;
347 volatile boolean mEndCallKeyHandled;
348
Winson Chungd42a6cf2014-06-03 16:24:04 -0700349 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700350 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700351 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800352
Jeff Brown2e7760e2012-04-11 15:14:55 -0700353 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700354 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700355 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800356
Dianne Hackbornc777e072010-02-12 13:07:59 -0800357 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700358 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800359 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700360 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400361 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700362 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700363 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400364 int mCarDockRotation;
365 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700366 int mUndockedHdmiRotation;
367 int mDemoHdmiRotation;
368 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800369 int mDemoRotation;
370 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400371
Jeff Browna20dda42014-05-27 20:57:24 -0700372 boolean mWakeGestureEnabledSetting;
373 MyWakeGestureListener mWakeGestureListener;
374
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700375 // Default display does not rotate, apps that require non-default orientation will have to
376 // have the orientation emulated.
377 private boolean mForceDefaultOrientation = false;
378
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400379 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
380 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700381 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400382
Jeff Brownbcdfc622014-03-06 19:13:04 -0800383 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700384 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400385 boolean mCarDockEnablesAccelerometer;
386 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700387 int mLidKeyboardAccessibility;
388 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700389 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700390 int mShortPressOnPowerBehavior;
391 int mLongPressOnPowerBehavior;
392 int mDoublePressOnPowerBehavior;
393 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000394 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700395 boolean mAwake;
396 boolean mScreenOnEarly;
397 boolean mScreenOnFully;
398 ScreenOnListener mScreenOnListener;
399 boolean mKeyguardDrawComplete;
400 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800401 boolean mOrientationSensorEnabled = false;
402 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800403 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400404 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800405 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700406
Jeff Brown70825162012-03-28 17:27:48 -0700407 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800408
409 // The last window we were told about in focusChanged.
410 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800411 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800412
Jeff Brown70825162012-03-28 17:27:48 -0700413 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800414
Dianne Hackbornc652de82013-02-15 16:32:56 -0800415 // The current size of the screen; really; extends into the overscan area of
416 // the screen and doesn't account for any system elements like the status bar.
417 int mOverscanScreenLeft, mOverscanScreenTop;
418 int mOverscanScreenWidth, mOverscanScreenHeight;
419 // The current visible size of the screen; really; (ir)regardless of whether the status
420 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800421 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
422 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800423 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
424 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
425 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700426 // The current size of the screen; these may be different than (0,0)-(dw,dh)
427 // if the status bar can't be hidden; in that case it effectively carves out
428 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800429 int mRestrictedScreenLeft, mRestrictedScreenTop;
430 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700431 // During layout, the current screen borders accounting for any currently
432 // visible system UI elements.
433 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700434 // For applications requesting stable content insets, these are them.
435 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700436 // For applications requesting stable content insets but have also set the
437 // fullscreen window flag, these are the stable dimensions without the status bar.
438 int mStableFullscreenLeft, mStableFullscreenTop;
439 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800440 // During layout, the current screen borders with all outer decoration
441 // (status bar, input method dock) accounted for.
442 int mCurLeft, mCurTop, mCurRight, mCurBottom;
443 // During layout, the frame in which content should be displayed
444 // to the user, accounting for all screen decoration except for any
445 // space they deem as available for other content. This is usually
446 // the same as mCur*, but may be larger if the screen decor has supplied
447 // content insets.
448 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700449 // During layout, the frame in which voice content should be displayed
450 // to the user, accounting for all screen decoration except for any
451 // space they deem as available for other content.
452 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800453 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800454 // windows are placed.
455 int mDockLeft, mDockTop, mDockRight, mDockBottom;
456 // During layout, the layer at which the doc window is placed.
457 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700458 // During layout, this is the layer of the status bar.
459 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700460 int mLastSystemUiFlags;
461 // Bits that we are in the process of clearing, so we want to prevent
462 // them from being set by applications until everything has been updated
463 // to have them clear.
464 int mResettingSystemUiFlags = 0;
465 // Bits that we are currently always keeping cleared.
466 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800467 // What we last reported to system UI about whether the compatibility
468 // menu needs to be displayed.
469 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700470 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
471 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700472
Selim Cinekf83e8242015-05-19 18:08:14 -0700473 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700474
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800475 static final Rect mTmpParentFrame = new Rect();
476 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800477 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800478 static final Rect mTmpContentFrame = new Rect();
479 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400480 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700481 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700482 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700483 static final Rect mTmpOutsetFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700484
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800485 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100486 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700487 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200488 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400489 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800490 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700491 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700492 private boolean mForceStatusBarTransparent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700493 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800494 boolean mForcingShowNavBar;
495 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700496
497 // States of keyguard dismiss.
498 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
499 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
500 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
501 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
502
503 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
504 * be done once per window. */
505 private WindowState mWinDismissingKeyguard;
506
tingna_sunge785ffa2015-05-12 13:23:15 +0800507 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
508 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
509 * lock SIM card. This variable is used to record the previous keyguard secure state for
510 * monitoring secure state change on window dismissing keyguard. */
511 private boolean mSecureDismissingKeyguard;
512
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700513 /** The window that is currently showing "over" the keyguard. If there is an app window
514 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
515 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
516 * the wallpaper. */
517 private WindowState mWinShowWhenLocked;
518
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700519 boolean mShowingLockscreen;
520 boolean mShowingDream;
521 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700522 boolean mDreamingSleepTokenNeeded;
523 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700524 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700525 boolean mKeyguardSecure;
526 boolean mKeyguardSecureIncludingHidden;
527 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800528 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700529 boolean mHomeConsumed;
530 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800531 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700532 Intent mCarDockIntent;
533 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700534 boolean mSearchKeyShortcutPending;
535 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700536 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700537 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800538
Mike Lockwood28569302010-01-28 11:54:40 -0500539 // support for activating the lock screen while the screen is on
540 boolean mAllowLockscreenWhenOn;
541 int mLockScreenTimeout;
542 boolean mLockScreenTimerActive;
543
David Brownbaf8d092010-03-08 21:52:59 -0800544 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800545 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800546
547 // Behavior of POWER button while in-call and screen on.
548 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
549 int mIncallPowerBehavior;
550
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700551 Display mDisplay;
552
Filip Gruszczynski2987f612015-06-30 15:03:30 -0700553 private int mDisplayRotation;
554
Dianne Hackborn9d132642011-04-21 17:26:39 -0700555 int mLandscapeRotation = 0; // default landscape rotation
556 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
557 int mPortraitRotation = 0; // default portrait rotation
558 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700559
Dianne Hackbornc652de82013-02-15 16:32:56 -0800560 int mOverscanLeft = 0;
561 int mOverscanTop = 0;
562 int mOverscanRight = 0;
563 int mOverscanBottom = 0;
564
Joe Onorato46b0d682010-11-22 17:37:27 -0800565 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700566 private int mLongPressOnHomeBehavior;
567
568 // What we do when the user double-taps on home
569 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800570
Bryce Lee584a4452014-10-21 15:55:55 -0700571 // Allowed theater mode wake actions
572 private boolean mAllowTheaterModeWakeFromKey;
573 private boolean mAllowTheaterModeWakeFromPowerKey;
574 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800575 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700576 private boolean mAllowTheaterModeWakeFromCameraLens;
577 private boolean mAllowTheaterModeWakeFromLidSwitch;
578 private boolean mAllowTheaterModeWakeFromWakeGesture;
579
Bryce Leed3b28402015-03-09 15:49:13 +0000580 // Whether to support long press from power button in non-interactive mode
581 private boolean mSupportLongPressPowerWhenNonInteractive;
582
Bryce Lee55e846d2014-11-04 12:43:44 -0800583 // Whether to go to sleep entering theater mode from power button
584 private boolean mGoToSleepOnButtonPressTheaterMode;
585
Winson Chung9112ec32011-06-27 13:15:32 -0700586 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700587 // Time to volume and power must be pressed within this interval of each other.
588 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700589 // Increase the chord delay when taking a screenshot from the keyguard
590 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800591 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700592 private boolean mScreenshotChordVolumeDownKeyTriggered;
593 private long mScreenshotChordVolumeDownKeyTime;
594 private boolean mScreenshotChordVolumeDownKeyConsumed;
595 private boolean mScreenshotChordVolumeUpKeyTriggered;
596 private boolean mScreenshotChordPowerKeyTriggered;
597 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700598
Michael Wrightb854e242013-02-05 17:54:02 -0800599 /* The number of steps between min and max brightness */
600 private static final int BRIGHTNESS_STEPS = 10;
601
Christopher Tate5e08af02012-09-21 17:17:22 -0700602 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800603 ShortcutManager mShortcutManager;
604 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700605 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700606 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800607
Craig Mautnerd625ab22013-09-06 13:40:31 -0700608 private int mCurrentUserId;
609
Justin Kohd378ad72013-04-01 12:18:26 -0700610 // Maps global key codes to the components that will handle them.
611 private GlobalKeyManager mGlobalKeyManager;
612
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700613 // Fallback actions by key code.
614 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
615 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800616
Jorim Jaggi76a16232014-08-08 17:00:47 +0200617 private final LogDecelerateInterpolator mLogDecelerateInterpolator
618 = new LogDecelerateInterpolator(100, 0);
619
Jeff Brown70825162012-03-28 17:27:48 -0700620 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
621 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700622 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
623 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700624 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
625 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
626 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700627 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700628 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700629 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700630 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700631 private static final int MSG_POWER_DELAYED_PRESS = 13;
632 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700633 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jeff Brown70825162012-03-28 17:27:48 -0700634
635 private class PolicyHandler extends Handler {
636 @Override
637 public void handleMessage(Message msg) {
638 switch (msg.what) {
639 case MSG_ENABLE_POINTER_LOCATION:
640 enablePointerLocation();
641 break;
642 case MSG_DISABLE_POINTER_LOCATION:
643 disablePointerLocation();
644 break;
Jeff Brown40013652012-05-16 21:22:36 -0700645 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
646 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
647 break;
648 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
649 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
650 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700651 case MSG_DISPATCH_SHOW_RECENTS:
652 showRecentApps(false);
653 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700654 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
655 showGlobalActionsInternal();
656 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700657 case MSG_KEYGUARD_DRAWN_COMPLETE:
658 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700659 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700660 break;
661 case MSG_KEYGUARD_DRAWN_TIMEOUT:
662 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700663 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700664 break;
665 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
666 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700667 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700668 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700669 case MSG_HIDE_BOOT_MESSAGE:
670 handleHideBootMessage();
671 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700672 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
673 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
674 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700675 case MSG_POWER_DELAYED_PRESS:
676 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
677 finishPowerKeyPress();
678 break;
679 case MSG_POWER_LONG_PRESS:
680 powerLongPress();
681 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700682 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
683 updateDreamingSleepToken(msg.arg1 != 0);
684 break;
Jeff Brown70825162012-03-28 17:27:48 -0700685 }
686 }
687 }
688
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800689 private UEventObserver mHDMIObserver = new UEventObserver() {
690 @Override
691 public void onUEvent(UEventObserver.UEvent event) {
692 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
693 }
694 };
695
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800696 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800697 SettingsObserver(Handler handler) {
698 super(handler);
699 }
David Brownbaf8d092010-03-08 21:52:59 -0800700
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800701 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700702 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800703 ContentResolver resolver = mContext.getContentResolver();
704 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700705 Settings.System.END_BUTTON_BEHAVIOR), false, this,
706 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800707 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700708 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
709 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700710 resolver.registerContentObserver(Settings.Secure.getUriFor(
711 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
712 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800713 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700714 Settings.System.ACCELEROMETER_ROTATION), false, this,
715 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500716 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700717 Settings.System.USER_ROTATION), false, this,
718 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400719 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700720 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
721 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800722 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700723 Settings.System.POINTER_LOCATION), false, this,
724 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800725 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700726 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
727 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500728 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400729 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700730 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500731 resolver.registerContentObserver(Settings.Global.getUriFor(
732 Settings.Global.POLICY_CONTROL), false, this,
733 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800734 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800735 }
736
737 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800738 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700739 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800740 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800741 }
Craig Mautner967212c2013-04-13 21:10:58 -0700742
Jeff Browna20dda42014-05-27 20:57:24 -0700743 class MyWakeGestureListener extends WakeGestureListener {
744 MyWakeGestureListener(Context context, Handler handler) {
745 super(context, handler);
746 }
747
748 @Override
749 public void onWakeUp() {
750 synchronized (mLock) {
751 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700752 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700753 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700754 }
755 }
756 }
757 }
758
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800759 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800760 MyOrientationListener(Context context, Handler handler) {
761 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800762 }
Craig Mautner967212c2013-04-13 21:10:58 -0700763
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800764 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700765 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700766 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700767 updateRotation(false);
768 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800769 }
770 MyOrientationListener mOrientationListener;
771
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100772 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400773
John Spurlock27735a42013-08-14 17:57:38 -0400774 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400775 View.NAVIGATION_BAR_TRANSIENT,
776 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400777 View.NAVIGATION_BAR_TRANSLUCENT,
778 StatusBarManager.WINDOW_NAVIGATION_BAR,
779 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400780
John Spurlockf1a36642013-10-12 17:50:42 -0400781 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400782
Craig Mautner037aa8d2013-06-07 10:35:44 -0700783 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400784
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700785 IStatusBarService getStatusBarService() {
786 synchronized (mServiceAquireLock) {
787 if (mStatusBarService == null) {
788 mStatusBarService = IStatusBarService.Stub.asInterface(
789 ServiceManager.getService("statusbar"));
790 }
791 return mStatusBarService;
792 }
793 }
794
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700795 /*
796 * We always let the sensor be switched on by default except when
797 * the user has explicitly disabled sensor based rotation or when the
798 * screen is switched off.
799 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700800 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800801 if (mSupportAutoRotation) {
802 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
803 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
804 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
805 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
806 // If the application has explicitly requested to follow the
807 // orientation, then we need to turn the sensor on.
808 return true;
809 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800810 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700811 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800812 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
813 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
814 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400815 // enable accelerometer if we are docked in a dock that enables accelerometer
816 // orientation management,
817 return true;
818 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700819 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800820 // If the setting for using the sensor by default is enabled, then
821 // we will always leave it on. Note that the user could go to
822 // a window that forces an orientation that does not use the
823 // sensor and in theory we could turn it off... however, when next
824 // turning it on we won't have a good value for the current
825 // orientation for a little bit, which can cause orientation
826 // changes to lag, so we'd like to keep it always on. (It will
827 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700828 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800829 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800830 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800831 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700832
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800833 /*
834 * Various use cases for invoking this function
835 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700836 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800837 * if not already enabled
838 * screen turned on and current app does not have sensor orientation, disable listeners if
839 * already enabled
840 * screen turning on and current app has sensor based orientation, enable listeners if needed
841 * screen turning on and current app has nosensor based orientation, do nothing
842 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700843 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800844 if (!mOrientationListener.canDetectOrientation()) {
845 // If sensor is turned off or nonexistent for some reason
846 return;
847 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000848 // Could have been invoked due to screen turning on or off or
849 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -0700850 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
851 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000852 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
853 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
854 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800855 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000856 // Note: We postpone the rotating of the screen until the keyguard as well as the
857 // window manager have reported a draw complete.
858 if (mScreenOnEarly && mAwake &&
859 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700860 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800861 disable = false;
862 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700863 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800864 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700865 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800866 mOrientationSensorEnabled = true;
867 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700868 }
869 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800870 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700871 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800872 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700873 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800874 mOrientationSensorEnabled = false;
875 }
876 }
877
Jeff Brown13f00f02014-10-31 14:45:50 -0700878 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
879 // Hold a wake lock until the power key is released.
880 if (!mPowerKeyWakeLock.isHeld()) {
881 mPowerKeyWakeLock.acquire();
882 }
883
884 // Cancel multi-press detection timeout.
885 if (mPowerKeyPressCounter != 0) {
886 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
887 }
888
889 // Detect user pressing the power button in panic when an application has
890 // taken over the whole screen.
891 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800892 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700893 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700894 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700895 }
896
897 // Latch power key state to detect screenshot chord.
898 if (interactive && !mScreenshotChordPowerKeyTriggered
899 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
900 mScreenshotChordPowerKeyTriggered = true;
901 mScreenshotChordPowerKeyTime = event.getDownTime();
902 interceptScreenshotChord();
903 }
904
905 // Stop ringing or end call if configured to do so when power is pressed.
906 TelecomManager telecomManager = getTelecommService();
907 boolean hungUp = false;
908 if (telecomManager != null) {
909 if (telecomManager.isRinging()) {
910 // Pressing Power while there's a ringing incoming
911 // call should silence the ringer.
912 telecomManager.silenceRinger();
913 } else if ((mIncallPowerBehavior
914 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
915 && telecomManager.isInCall() && interactive) {
916 // Otherwise, if "Power button ends call" is enabled,
917 // the Power button will hang up any current active call.
918 hungUp = telecomManager.endCall();
919 }
920 }
921
922 // If the power key has still not yet been handled, then detect short
923 // press, long press, or multi press and decide what to do.
924 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
925 || mScreenshotChordVolumeUpKeyTriggered;
926 if (!mPowerKeyHandled) {
927 if (interactive) {
928 // When interactive, we're already awake.
929 // Wait for a long press or for the button to be released to decide what to do.
930 if (hasLongPressOnPowerBehavior()) {
931 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
932 msg.setAsynchronous(true);
933 mHandler.sendMessageDelayed(msg,
934 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
935 }
936 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800937 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800938
Bryce Leed3b28402015-03-09 15:49:13 +0000939 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
940 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
941 msg.setAsynchronous(true);
942 mHandler.sendMessageDelayed(msg,
943 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800944 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000945 } else {
946 final int maxCount = getMaxMultiPressPowerCount();
947
948 if (maxCount <= 1) {
949 mPowerKeyHandled = true;
950 } else {
951 mBeganFromNonInteractive = true;
952 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700953 }
954 }
Jeff Brown4d396052010-10-29 21:50:21 -0700955 }
956 }
957
Jeff Brown13f00f02014-10-31 14:45:50 -0700958 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
959 final boolean handled = canceled || mPowerKeyHandled;
960 mScreenshotChordPowerKeyTriggered = false;
961 cancelPendingScreenshotChordAction();
962 cancelPendingPowerKeyAction();
963
964 if (!handled) {
965 // Figure out how to handle the key now that it has been released.
966 mPowerKeyPressCounter += 1;
967
968 final int maxCount = getMaxMultiPressPowerCount();
969 final long eventTime = event.getDownTime();
970 if (mPowerKeyPressCounter < maxCount) {
971 // This could be a multi-press. Wait a little bit longer to confirm.
972 // Continue holding the wake lock.
973 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
974 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
975 msg.setAsynchronous(true);
976 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
977 return;
978 }
979
980 // No other actions. Handle it immediately.
981 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700982 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700983
984 // Done. Reset our state.
985 finishPowerKeyPress();
986 }
987
988 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800989 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700990 mPowerKeyPressCounter = 0;
991 if (mPowerKeyWakeLock.isHeld()) {
992 mPowerKeyWakeLock.release();
993 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700994 }
995
996 private void cancelPendingPowerKeyAction() {
997 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700998 mPowerKeyHandled = true;
999 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001000 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001001 }
1002
1003 private void powerPress(long eventTime, boolean interactive, int count) {
1004 if (mScreenOnEarly && !mScreenOnFully) {
1005 Slog.i(TAG, "Suppressed redundant power key press while "
1006 + "already in the process of turning the screen on.");
1007 return;
Jeff Brownff204712011-10-25 21:27:54 -07001008 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001009
1010 if (count == 2) {
1011 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1012 } else if (count == 3) {
1013 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001014 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001015 switch (mShortPressOnPowerBehavior) {
1016 case SHORT_PRESS_POWER_NOTHING:
1017 break;
1018 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1019 mPowerManager.goToSleep(eventTime,
1020 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1021 break;
1022 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1023 mPowerManager.goToSleep(eventTime,
1024 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1025 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1026 break;
1027 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1028 mPowerManager.goToSleep(eventTime,
1029 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1030 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1031 launchHomeFromHotKey();
1032 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001033 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001034 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001035 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001036 }
1037 }
1038 }
1039
1040 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1041 switch (behavior) {
1042 case MULTI_PRESS_POWER_NOTHING:
1043 break;
1044 case MULTI_PRESS_POWER_THEATER_MODE:
Bryce Lee3ae447e2015-06-30 12:31:41 -07001045 if (!isUserSetupComplete()) {
1046 Slog.i(TAG, "Ignoring toggling theater mode - device not setup.");
1047 break;
1048 }
1049
Jeff Brown13f00f02014-10-31 14:45:50 -07001050 if (isTheaterModeEnabled()) {
1051 Slog.i(TAG, "Toggling theater mode off.");
1052 Settings.Global.putInt(mContext.getContentResolver(),
1053 Settings.Global.THEATER_MODE_ON, 0);
1054 if (!interactive) {
1055 wakeUpFromPowerKey(eventTime);
1056 }
1057 } else {
1058 Slog.i(TAG, "Toggling theater mode on.");
1059 Settings.Global.putInt(mContext.getContentResolver(),
1060 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001061
1062 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001063 mPowerManager.goToSleep(eventTime,
1064 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1065 }
1066 }
1067 break;
1068 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001069 Slog.i(TAG, "Starting brightness boost.");
1070 if (!interactive) {
1071 wakeUpFromPowerKey(eventTime);
1072 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001073 mPowerManager.boostScreenBrightness(eventTime);
1074 break;
1075 }
1076 }
1077
1078 private int getMaxMultiPressPowerCount() {
1079 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1080 return 3;
1081 }
1082 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1083 return 2;
1084 }
1085 return 1;
1086 }
1087
1088 private void powerLongPress() {
1089 final int behavior = getResolvedLongPressOnPowerBehavior();
1090 switch (behavior) {
1091 case LONG_PRESS_POWER_NOTHING:
1092 break;
1093 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1094 mPowerKeyHandled = true;
1095 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1096 performAuditoryFeedbackForAccessibilityIfNeed();
1097 }
1098 showGlobalActionsInternal();
1099 break;
1100 case LONG_PRESS_POWER_SHUT_OFF:
1101 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1102 mPowerKeyHandled = true;
1103 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1104 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1105 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1106 break;
1107 }
1108 }
1109
Nick Vaccarob593a812015-05-15 11:23:05 -07001110 private void sleepPress(long eventTime) {
1111 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1112 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1113 }
1114 }
1115
1116 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001117 switch (mShortPressOnSleepBehavior) {
1118 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001119 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001120 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1121 mPowerManager.goToSleep(eventTime,
1122 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001123 break;
1124 }
1125 }
1126
Jeff Brown13f00f02014-10-31 14:45:50 -07001127 private int getResolvedLongPressOnPowerBehavior() {
1128 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1129 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1130 }
1131 return mLongPressOnPowerBehavior;
1132 }
1133
1134 private boolean hasLongPressOnPowerBehavior() {
1135 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001136 }
1137
1138 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001139 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001140 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1141 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001142 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001143 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1144 && now <= mScreenshotChordPowerKeyTime
1145 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1146 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001147 cancelPendingPowerKeyAction();
1148
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001149 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001150 }
1151 }
1152 }
1153
Winson Chung1cea2f32012-10-08 20:42:01 -07001154 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001155 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001156 // Double the time it takes to take a screenshot from the keyguard
1157 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001158 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001159 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001160 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001161 }
1162
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001163 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001164 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001165 }
1166
Jeff Brown13f00f02014-10-31 14:45:50 -07001167 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001168 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001169 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001170 mEndCallKeyHandled = true;
1171 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1172 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001173 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001174 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001175 }
1176 };
1177
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001178 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001179 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001180 public void run() {
1181 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001182 }
1183 };
1184
Alan Viverettee34560b22014-07-10 14:50:06 -07001185 @Override
1186 public void showGlobalActions() {
1187 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1188 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1189 }
1190
1191 void showGlobalActionsInternal() {
1192 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001193 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001194 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001195 }
Jim Millerab954542014-10-10 18:21:49 -07001196 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001197 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1198 if (keyguardShowing) {
1199 // since it took two seconds of long press to bring this up,
1200 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001201 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001202 }
1203 }
1204
1205 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001206 return Settings.Global.getInt(
1207 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001208 }
1209
Maurice Lam99c6e072014-04-28 18:24:28 -07001210 boolean isUserSetupComplete() {
1211 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1212 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1213 }
1214
Jeff Brown13f00f02014-10-31 14:45:50 -07001215 private void handleShortPressOnHome() {
1216 // If there's a dream running then use home to escape the dream
1217 // but don't actually go home.
1218 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1219 mDreamManagerInternal.stopDream(false /*immediate*/);
1220 return;
1221 }
1222
1223 // Go home!
1224 launchHomeFromHotKey();
1225 }
1226
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001227 private void handleLongPressOnHome(int deviceId) {
Joe Onorato46b0d682010-11-22 17:37:27 -08001228 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001229 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001230 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001231
Jeff Browncaca8812013-05-09 13:34:33 -07001232 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1233 toggleRecentApps();
1234 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001235 launchAssistAction(null, deviceId);
Jim Millere6ad1a82010-08-20 19:25:39 -07001236 }
1237 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001238 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001239
Jeff Browncaca8812013-05-09 13:34:33 -07001240 private void handleDoubleTapOnHome() {
1241 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1242 mHomeConsumed = true;
1243 toggleRecentApps();
1244 }
1245 }
1246
1247 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1248 @Override
1249 public void run() {
1250 if (mHomeDoubleTapPending) {
1251 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001252 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001253 }
1254 }
1255 };
1256
Mark Renoufc1256912015-03-11 14:38:23 -04001257 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001258 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001259 }
1260
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001261 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001262 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001263 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001264 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001265 mContext = context;
1266 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001267 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001268 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001269 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001270 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001271 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Mark Renoufc1256912015-03-11 14:38:23 -04001272
1273 // Init display burn-in protection
1274 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1275 com.android.internal.R.bool.config_enableBurnInProtection);
1276 // Allow a system property to override this. Used by developer settings.
1277 boolean burnInProtectionDevMode =
1278 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1279 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1280 final int minHorizontal;
1281 final int maxHorizontal;
1282 final int minVertical;
1283 final int maxVertical;
1284 final int maxRadius;
1285 if (burnInProtectionDevMode) {
1286 minHorizontal = -8;
1287 maxHorizontal = 8;
1288 minVertical = -8;
1289 maxVertical = -4;
1290 maxRadius = (isRoundWindow()) ? 6 : -1;
1291 } else {
1292 Resources resources = context.getResources();
1293 minHorizontal = resources.getInteger(
1294 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1295 maxHorizontal = resources.getInteger(
1296 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1297 minVertical = resources.getInteger(
1298 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1299 maxVertical = resources.getInteger(
1300 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1301 maxRadius = resources.getInteger(
1302 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1303 }
1304 mBurnInProtectionHelper = new BurnInProtectionHelper(
1305 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001306 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001307
Jeff Brown70825162012-03-28 17:27:48 -07001308 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001309 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001310 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001311 try {
1312 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1313 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001314 mSettingsObserver = new SettingsObserver(mHandler);
1315 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001316 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001317 mUiMode = context.getResources().getInteger(
1318 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001319 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1320 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1321 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1322 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001323 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1324 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1325 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1326 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1327 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1328 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1329 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1330 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001331
Jeff Brown96307042012-07-27 15:51:34 -07001332 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1333 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001334 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001335 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1336 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001337 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001338 mSupportAutoRotation = mContext.getResources().getBoolean(
1339 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001340 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001341 com.android.internal.R.integer.config_lidOpenRotation);
1342 mCarDockRotation = readRotation(
1343 com.android.internal.R.integer.config_carDockRotation);
1344 mDeskDockRotation = readRotation(
1345 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001346 mUndockedHdmiRotation = readRotation(
1347 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001348 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1349 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1350 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1351 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001352 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1353 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1354 mLidNavigationAccessibility = mContext.getResources().getInteger(
1355 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001356 mLidControlsSleep = mContext.getResources().getBoolean(
1357 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001358 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1359 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001360
1361 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1362 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1363 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1364 || mContext.getResources().getBoolean(
1365 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1366 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1367 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001368 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1369 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001370 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1371 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1372 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1373 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1374 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1375 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1376
Bryce Lee55e846d2014-11-04 12:43:44 -08001377 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1378 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1379
Bryce Leed3b28402015-03-09 15:49:13 +00001380 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1381 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1382
Jeff Brown13f00f02014-10-31 14:45:50 -07001383 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1384 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1385 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1386 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1387 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1388 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1389 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1390 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001391 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1392 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001393
John Spurlock61560172015-02-06 19:46:04 -05001394 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001395
Jeff Brownf71343d2013-05-31 17:59:11 -07001396 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001397
Svetoslav8e3feb12014-02-24 13:46:47 -08001398 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1399 Context.ACCESSIBILITY_SERVICE);
1400
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001401 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001402 IntentFilter filter = new IntentFilter();
1403 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1404 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1405 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1406 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001407 filter.addAction(Intent.ACTION_DOCK_EVENT);
1408 Intent intent = context.registerReceiver(mDockReceiver, filter);
1409 if (intent != null) {
1410 // Retrieve current sticky dock event broadcast.
1411 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1412 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1413 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001414
Jeff Brown6aaf2952012-10-05 16:01:08 -07001415 // register for dream-related broadcasts
1416 filter = new IntentFilter();
1417 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1418 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1419 context.registerReceiver(mDreamReceiver, filter);
1420
Christopher Tate5e08af02012-09-21 17:17:22 -07001421 // register for multiuser-relevant broadcasts
1422 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1423 context.registerReceiver(mMultiuserReceiver, filter);
1424
John Spurlock57306e62013-04-22 09:48:49 -04001425 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001426 mSystemGestures = new SystemGesturesPointerEventListener(context,
1427 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001428 @Override
1429 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001430 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001431 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001432 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001433 }
1434 @Override
1435 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001436 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001437 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001438 }
1439 }
1440 @Override
1441 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001442 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001443 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001444 }
1445 }
1446 @Override
1447 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001448 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001449 }
Adrian Roos3595be42015-03-05 16:31:15 +01001450 @Override
1451 public void onDown() {
1452 mOrientationListener.onTouchStart();
1453 }
1454 @Override
1455 public void onUpOrCancel() {
1456 mOrientationListener.onTouchEnd();
1457 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001458 });
John Spurlockf1a36642013-10-12 17:50:42 -04001459 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001460 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001461
Jeff Brownc2346132012-04-13 01:55:38 -07001462 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001463 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1464 com.android.internal.R.array.config_longPressVibePattern);
1465 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1466 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001467 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1468 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001469 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1470 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001471 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1472 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001473 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1474 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1475 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1476 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001477 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1478 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001479
Christopher Tatee90585f2012-03-05 18:56:25 -08001480 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1481 com.android.internal.R.bool.config_enableScreenshotChord);
1482
Justin Kohd378ad72013-04-01 12:18:26 -07001483 mGlobalKeyManager = new GlobalKeyManager(mContext);
1484
Joe Onoratoea495d42011-04-06 11:41:11 -07001485 // Controls rotation and the like.
1486 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001487
1488 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001489 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001490 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1491 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001492 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001493
1494 mWindowManagerInternal.registerAppTransitionListener(
1495 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001496 }
1497
Jeff Brownf71343d2013-05-31 17:59:11 -07001498 /**
1499 * Read values from config.xml that may be overridden depending on
1500 * the configuration of the device.
1501 * eg. Disable long press on home goes to recents on sw600dp.
1502 */
1503 private void readConfigurationDependentBehaviors() {
1504 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1505 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1506 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1507 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1508 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1509 }
1510
1511 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1512 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1513 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1514 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1515 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1516 }
1517 }
1518
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001519 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001520 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001521 // This method might be called before the policy has been fully initialized
1522 // or for other displays we don't care about.
1523 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1524 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001525 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001526 mDisplay = display;
1527
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001528 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001529 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001530 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001531 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001532 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001533 mLandscapeRotation = Surface.ROTATION_0;
1534 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001535 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001536 mPortraitRotation = Surface.ROTATION_90;
1537 mUpsideDownRotation = Surface.ROTATION_270;
1538 } else {
1539 mPortraitRotation = Surface.ROTATION_270;
1540 mUpsideDownRotation = Surface.ROTATION_90;
1541 }
1542 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001543 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001544 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001545 mPortraitRotation = Surface.ROTATION_0;
1546 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001547 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001548 mLandscapeRotation = Surface.ROTATION_270;
1549 mSeascapeRotation = Surface.ROTATION_90;
1550 } else {
1551 mLandscapeRotation = Surface.ROTATION_90;
1552 mSeascapeRotation = Surface.ROTATION_270;
1553 }
1554 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001555
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001556 mStatusBarHeight =
1557 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001558
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001559 // Height of the navigation bar when presented horizontally at bottom
1560 mNavigationBarHeightForRotation[mPortraitRotation] =
1561 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001562 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001563 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001564 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1565 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001566
1567 // Width of the navigation bar when presented vertically along one side
1568 mNavigationBarWidthForRotation[mPortraitRotation] =
1569 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1570 mNavigationBarWidthForRotation[mLandscapeRotation] =
1571 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001572 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001573
1574 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001575 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001576 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001577
Devin Kimd7b12b42014-05-05 14:34:58 -07001578 // Allow the navigation bar to move on non-square small devices (phones).
1579 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001580
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001581 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001582 // Allow a system property to override this. Used by the emulator.
1583 // See also hasNavigationBar().
1584 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1585 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001586 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001587 } else if ("0".equals(navBarOverride)) {
1588 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001589 }
1590
Jeff Brown27f1d672012-10-17 18:32:34 -07001591 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1592 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001593 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001594 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001595 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001596 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001597 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001598 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001599
Chong Zhangae6119ff2014-11-11 18:54:39 -08001600 // For demo purposes, allow the rotation of the remote display to be controlled.
1601 // By default, remote display locks rotation to landscape.
1602 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1603 mDemoRotation = mPortraitRotation;
1604 } else {
1605 mDemoRotation = mLandscapeRotation;
1606 }
1607 mDemoRotationLock = SystemProperties.getBoolean(
1608 "persist.demo.rotationlock", false);
1609
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001610 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1611 // http://developer.android.com/guide/practices/screens_support.html#range
1612 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1613 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1614 // For debug purposes the next line turns this feature off with:
1615 // $ adb shell setprop config.override_forced_orient true
1616 // $ adb shell wm size reset
1617 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1618 }
1619
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001620 /**
1621 * @return whether the navigation bar can be hidden, e.g. the device has a
1622 * navigation bar and touch exploration is not enabled
1623 */
1624 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001625 return mHasNavigationBar
1626 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001627 }
1628
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001629 @Override
1630 public boolean isDefaultOrientationForced() {
1631 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001632 }
1633
Dianne Hackbornc652de82013-02-15 16:32:56 -08001634 @Override
1635 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1636 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1637 mOverscanLeft = left;
1638 mOverscanTop = top;
1639 mOverscanRight = right;
1640 mOverscanBottom = bottom;
1641 }
1642 }
1643
Dianne Hackbornc777e072010-02-12 13:07:59 -08001644 public void updateSettings() {
1645 ContentResolver resolver = mContext.getContentResolver();
1646 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001647 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001648 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001649 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001650 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1651 UserHandle.USER_CURRENT);
1652 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001653 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001654 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1655 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001656
Jeff Browna20dda42014-05-27 20:57:24 -07001657 // Configure wake gesture.
1658 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1659 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1660 UserHandle.USER_CURRENT) != 0;
1661 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1662 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1663 updateWakeGestureListenerLp();
1664 }
1665
Jeff Brown207673cd2012-06-05 17:47:11 -07001666 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001667 int userRotation = Settings.System.getIntForUser(resolver,
1668 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1669 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001670 if (mUserRotation != userRotation) {
1671 mUserRotation = userRotation;
1672 updateRotation = true;
1673 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001674 int userRotationMode = Settings.System.getIntForUser(resolver,
1675 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001676 WindowManagerPolicy.USER_ROTATION_FREE :
1677 WindowManagerPolicy.USER_ROTATION_LOCKED;
1678 if (mUserRotationMode != userRotationMode) {
1679 mUserRotationMode = userRotationMode;
1680 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001681 updateOrientationListenerLp();
1682 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001683
Dianne Hackbornc777e072010-02-12 13:07:59 -08001684 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001685 int pointerLocation = Settings.System.getIntForUser(resolver,
1686 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001687 if (mPointerLocationMode != pointerLocation) {
1688 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001689 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1690 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001691 }
1692 }
1693 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001694 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1695 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1696 String imId = Settings.Secure.getStringForUser(resolver,
1697 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001698 boolean hasSoftInput = imId != null && imId.length() > 0;
1699 if (mHasSoftInput != hasSoftInput) {
1700 mHasSoftInput = hasSoftInput;
1701 updateRotation = true;
1702 }
John Spurlockf1a36642013-10-12 17:50:42 -04001703 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001704 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001705 }
tiger_huangcc6366d2015-06-29 17:17:30 +08001706 }
1707 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05001708 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001709 }
1710 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001711 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001712 }
Jeff Brown70825162012-03-28 17:27:48 -07001713 }
1714
Jeff Browna20dda42014-05-27 20:57:24 -07001715 private void updateWakeGestureListenerLp() {
1716 if (shouldEnableWakeGestureLp()) {
1717 mWakeGestureListener.requestWakeUpTrigger();
1718 } else {
1719 mWakeGestureListener.cancelWakeUpTrigger();
1720 }
1721 }
1722
1723 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001724 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001725 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1726 && mWakeGestureListener.isSupported();
1727 }
1728
Jeff Brown70825162012-03-28 17:27:48 -07001729 private void enablePointerLocation() {
1730 if (mPointerLocationView == null) {
1731 mPointerLocationView = new PointerLocationView(mContext);
1732 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001733 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1734 WindowManager.LayoutParams.MATCH_PARENT,
1735 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001736 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001737 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1738 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1739 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1740 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001741 if (ActivityManager.isHighEndGfx()) {
1742 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1743 lp.privateFlags |=
1744 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1745 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001746 lp.format = PixelFormat.TRANSLUCENT;
1747 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001748 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001749 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001750 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001751 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001752 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001753 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001754 }
Jeff Brown70825162012-03-28 17:27:48 -07001755
1756 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001757 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001758 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1759 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001760 wm.removeView(mPointerLocationView);
1761 mPointerLocationView = null;
1762 }
1763 }
1764
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001765 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001766 try {
1767 int rotation = mContext.getResources().getInteger(resID);
1768 switch (rotation) {
1769 case 0:
1770 return Surface.ROTATION_0;
1771 case 90:
1772 return Surface.ROTATION_90;
1773 case 180:
1774 return Surface.ROTATION_180;
1775 case 270:
1776 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001777 }
1778 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001779 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001780 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001781 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001782 }
1783
1784 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001785 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001786 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001787 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001788
1789 outAppOp[0] = AppOpsManager.OP_NONE;
1790
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001791 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1792 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1793 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1794 return WindowManagerGlobal.ADD_INVALID_TYPE;
1795 }
1796
1797 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1798 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001799 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001800 }
1801 String permission = null;
1802 switch (type) {
1803 case TYPE_TOAST:
1804 // XXX right now the app process has complete control over
1805 // this... should introduce a token to let the system
1806 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001807 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001808 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001809 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001810 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001811 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001812 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001813 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001814 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001815 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001816 break;
1817 case TYPE_PHONE:
1818 case TYPE_PRIORITY_PHONE:
1819 case TYPE_SYSTEM_ALERT:
1820 case TYPE_SYSTEM_ERROR:
1821 case TYPE_SYSTEM_OVERLAY:
1822 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001823 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001824 break;
1825 default:
1826 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1827 }
1828 if (permission != null) {
Billy Laucbe540f2015-06-25 01:51:44 +01001829 if (permission == android.Manifest.permission.SYSTEM_ALERT_WINDOW) {
1830 final int callingUid = Binder.getCallingUid();
Billy Lau060275f2015-07-15 22:29:19 +01001831 // system processes will be automatically allowed privilege to draw
Billy Laucbe540f2015-06-25 01:51:44 +01001832 if (callingUid == Process.SYSTEM_UID) {
1833 return WindowManagerGlobal.ADD_OKAY;
1834 }
1835
Billy Lau060275f2015-07-15 22:29:19 +01001836 // check if user has enabled this operation. SecurityException will be thrown if
1837 // this app has not been allowed by the user
Billy Laucbe540f2015-06-25 01:51:44 +01001838 final int mode = mAppOpsManager.checkOp(outAppOp[0], callingUid,
1839 attrs.packageName);
Billy Lau060275f2015-07-15 22:29:19 +01001840 switch (mode) {
1841 case AppOpsManager.MODE_ALLOWED:
1842 case AppOpsManager.MODE_IGNORED:
1843 // although we return ADD_OKAY for MODE_IGNORED, the added window will
1844 // actually be hidden in WindowManagerService
1845 return WindowManagerGlobal.ADD_OKAY;
1846 case AppOpsManager.MODE_ERRORED:
Billy Laucbe540f2015-06-25 01:51:44 +01001847 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
Billy Lau060275f2015-07-15 22:29:19 +01001848 default:
1849 // in the default mode, we will make a decision here based on
1850 // checkCallingPermission()
1851 if (mContext.checkCallingPermission(permission) !=
1852 PackageManager.PERMISSION_GRANTED) {
1853 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
1854 } else {
1855 return WindowManagerGlobal.ADD_OKAY;
1856 }
Billy Laucbe540f2015-06-25 01:51:44 +01001857 }
Billy Laucbe540f2015-06-25 01:51:44 +01001858 }
1859
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001860 if (mContext.checkCallingOrSelfPermission(permission)
1861 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001862 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001863 }
1864 }
Jeff Brown98365d72012-08-19 20:30:52 -07001865 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001866 }
Craig Mautner88400d32012-09-30 12:35:45 -07001867
1868 @Override
1869 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1870
1871 // If this switch statement is modified, modify the comment in the declarations of
1872 // the type in {@link WindowManager.LayoutParams} as well.
1873 switch (attrs.type) {
1874 default:
1875 // These are the windows that by default are shown only to the user that created
1876 // them. If this needs to be overridden, set
1877 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1878 // {@link WindowManager.LayoutParams}. Note that permission
1879 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1880 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1881 return true;
1882 }
1883 break;
1884
1885 // These are the windows that by default are shown to all users. However, to
1886 // protect against spoofing, check permissions below.
1887 case TYPE_APPLICATION_STARTING:
1888 case TYPE_BOOT_PROGRESS:
1889 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07001890 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001891 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001892 case TYPE_KEYGUARD_DIALOG:
1893 case TYPE_MAGNIFICATION_OVERLAY:
1894 case TYPE_NAVIGATION_BAR:
1895 case TYPE_NAVIGATION_BAR_PANEL:
1896 case TYPE_PHONE:
1897 case TYPE_POINTER:
1898 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001899 case TYPE_SEARCH_BAR:
1900 case TYPE_STATUS_BAR:
1901 case TYPE_STATUS_BAR_PANEL:
1902 case TYPE_STATUS_BAR_SUB_PANEL:
1903 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001904 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001905 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001906 break;
1907 }
1908
1909 // Check if third party app has set window to system window type.
1910 return mContext.checkCallingOrSelfPermission(
1911 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1912 != PackageManager.PERMISSION_GRANTED;
1913 }
1914
Craig Mautner967212c2013-04-13 21:10:58 -07001915 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001916 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1917 switch (attrs.type) {
1918 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001919 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001920 // These types of windows can't receive input events.
1921 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1922 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001923 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001924 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001925 case TYPE_STATUS_BAR:
1926
1927 // If the Keyguard is in a hidden state (occluded by another window), we force to
1928 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1929 // the keyguard as occluded wouldn't set these flags again.
1930 // See {@link #processKeyguardSetHiddenResultLw}.
1931 if (mKeyguardHidden) {
1932 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1933 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1934 }
1935 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001936 }
Adrian Roos38502112014-04-09 21:04:11 +02001937
1938 if (attrs.type != TYPE_STATUS_BAR) {
1939 // The status bar is the only window allowed to exhibit keyguard behavior.
1940 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1941 }
Adrian Roosea562512014-05-05 13:33:03 +02001942
1943 if (ActivityManager.isHighEndGfx()
1944 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001945 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001946 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1947 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001948 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001949
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001950 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001951 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001952 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001953
Michael Wright3818c922014-09-02 13:59:07 -07001954 private void readCameraLensCoverState() {
1955 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1956 }
1957
Jeff Browndaa37532012-05-01 15:54:03 -07001958 private boolean isHidden(int accessibilityMode) {
1959 switch (accessibilityMode) {
1960 case 1:
1961 return mLidState == LID_CLOSED;
1962 case 2:
1963 return mLidState == LID_OPEN;
1964 default:
1965 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001966 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001967 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001968
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001969 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001970 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001971 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1972 int navigationPresence) {
1973 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1974
Jeff Brownf71343d2013-05-31 17:59:11 -07001975 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001976 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001977 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001978
Jeff Browndaa37532012-05-01 15:54:03 -07001979 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1980 || (keyboardPresence == PRESENCE_INTERNAL
1981 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001982 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001983 if (!mHasSoftInput) {
1984 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1985 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001986 }
1987
Jeff Browndaa37532012-05-01 15:54:03 -07001988 if (config.navigation == Configuration.NAVIGATION_NONAV
1989 || (navigationPresence == PRESENCE_INTERNAL
1990 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001991 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001992 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001993 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001994
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001995 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001996 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001997 public int windowTypeToLayerLw(int type) {
1998 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001999 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002000 }
2001 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07002002 case TYPE_PRIVATE_PRESENTATION:
2003 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002004 case TYPE_WALLPAPER:
2005 // wallpaper is at the bottom, though the window manager may move it.
2006 return 2;
2007 case TYPE_PHONE:
2008 return 3;
2009 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002010 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002011 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002012 case TYPE_VOICE_INTERACTION:
2013 // voice interaction layer is almost immediately above apps.
2014 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07002015 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002016 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07002017 case TYPE_SYSTEM_DIALOG:
2018 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002019 case TYPE_TOAST:
2020 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07002021 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002022 case TYPE_PRIORITY_PHONE:
2023 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07002024 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002025 case TYPE_DREAM:
2026 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07002027 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002028 case TYPE_SYSTEM_ALERT:
2029 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002030 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002031 case TYPE_INPUT_METHOD:
2032 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002033 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002034 case TYPE_INPUT_METHOD_DIALOG:
2035 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002036 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08002037 case TYPE_KEYGUARD_SCRIM:
2038 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002039 return 14;
Selim Cinekf83e8242015-05-19 18:08:14 -07002040 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002041 return 15;
Selim Cinekf83e8242015-05-19 18:08:14 -07002042 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002043 return 16;
Selim Cinekf83e8242015-05-19 18:08:14 -07002044 case TYPE_STATUS_BAR_PANEL:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002045 return 17;
Selim Cinekf83e8242015-05-19 18:08:14 -07002046 case TYPE_KEYGUARD_DIALOG:
2047 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002048 case TYPE_VOLUME_OVERLAY:
2049 // the on-screen volume indicator and controller shown when the user
2050 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07002051 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002052 case TYPE_SYSTEM_OVERLAY:
2053 // the on-screen volume indicator and controller shown when the user
2054 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07002055 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002056 case TYPE_NAVIGATION_BAR:
2057 // the navigation bar, if available, shows atop most things
Selim Cinekf83e8242015-05-19 18:08:14 -07002058 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002059 case TYPE_NAVIGATION_BAR_PANEL:
2060 // some panels (e.g. search) need to show on top of the navigation bar
Selim Cinekf83e8242015-05-19 18:08:14 -07002061 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002062 case TYPE_SYSTEM_ERROR:
2063 // system-level error dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002064 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002065 case TYPE_MAGNIFICATION_OVERLAY:
2066 // used to highlight the magnified portion of a display
Selim Cinekf83e8242015-05-19 18:08:14 -07002067 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002068 case TYPE_DISPLAY_OVERLAY:
2069 // used to simulate secondary display devices
Selim Cinekf83e8242015-05-19 18:08:14 -07002070 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002071 case TYPE_DRAG:
2072 // the drag layer: input for drag-and-drop is associated with this window,
2073 // which sits above all other focusable windows
Selim Cinekf83e8242015-05-19 18:08:14 -07002074 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002075 case TYPE_ACCESSIBILITY_OVERLAY:
2076 // overlay put by accessibility services to intercept user interaction
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002077 return 27;
Selim Cinekf83e8242015-05-19 18:08:14 -07002078 case TYPE_SECURE_SYSTEM_OVERLAY:
Svetoslav3a5c7212014-10-14 09:54:26 -07002079 return 28;
Selim Cinekf83e8242015-05-19 18:08:14 -07002080 case TYPE_BOOT_PROGRESS:
2081 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002082 case TYPE_POINTER:
2083 // the (mouse) pointer layer
Svetoslav3a5c7212014-10-14 09:54:26 -07002084 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002085 }
2086 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002087 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002088 }
2089
2090 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002091 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002092 public int subWindowTypeToLayerLw(int type) {
2093 switch (type) {
2094 case TYPE_APPLICATION_PANEL:
2095 case TYPE_APPLICATION_ATTACHED_DIALOG:
2096 return APPLICATION_PANEL_SUBLAYER;
2097 case TYPE_APPLICATION_MEDIA:
2098 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002099 case TYPE_APPLICATION_MEDIA_OVERLAY:
2100 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002101 case TYPE_APPLICATION_SUB_PANEL:
2102 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002103 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2104 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002105 }
2106 Log.e(TAG, "Unknown sub-window type: " + type);
2107 return 0;
2108 }
2109
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002110 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002111 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002112 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002113 }
2114
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002115 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002116 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002117 if (mHasNavigationBar) {
2118 // For a basic navigation bar, when we are in landscape mode we place
2119 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002120 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2121 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002122 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002123 }
2124 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002125 }
2126
Jose Lima9546b202014-07-02 17:21:51 -07002127 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002128 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002129 if (mHasNavigationBar) {
2130 // For a basic navigation bar, when we are in portrait mode we place
2131 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002132 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2133 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002134 }
2135 }
2136 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002137 }
2138
Jose Lima9546b202014-07-02 17:21:51 -07002139 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002140 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2141 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002142 }
2143
Jose Lima9546b202014-07-02 17:21:51 -07002144 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002145 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002146 // There is a separate status bar at the top of the display. We don't count that as part
2147 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002148 // we do want to exclude it since applications can't generally use that part
2149 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002150 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002151 }
2152
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002153 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002154 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2155 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002156 (isKeyguardHostWindow(attrs) &&
2157 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002158 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002159 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002160
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002161 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002162 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2163 return attrs.type == TYPE_STATUS_BAR;
2164 }
2165
2166 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002167 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002168 switch (attrs.type) {
2169 case TYPE_STATUS_BAR:
2170 case TYPE_NAVIGATION_BAR:
2171 case TYPE_WALLPAPER:
2172 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002173 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002174 return false;
2175 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002176 // Hide only windows below the keyguard host window.
2177 return windowTypeToLayerLw(win.getBaseType())
2178 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002179 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002180 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002181
Craig Mautner7d7808f2014-09-11 18:02:38 -07002182 @Override
2183 public WindowState getWinShowWhenLockedLw() {
2184 return mWinShowWhenLocked;
2185 }
2186
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002187 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002188 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002189 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2190 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002191 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002192 if (!SHOW_STARTING_ANIMATIONS) {
2193 return null;
2194 }
2195 if (packageName == null) {
2196 return null;
2197 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002198
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002199 WindowManager wm = null;
2200 View view = null;
2201
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002202 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002203 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002204 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2205 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2206 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002207 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002208 try {
2209 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002210 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002211 } catch (PackageManager.NameNotFoundException e) {
2212 // Ignore
2213 }
2214 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002215
Jorim Jaggia16cc152015-06-01 16:55:05 -07002216 PhoneWindow win = new PhoneWindow(context);
2217 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002218 final TypedArray ta = win.getWindowStyle();
2219 if (ta.getBoolean(
2220 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2221 || ta.getBoolean(
2222 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002223 return null;
2224 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002225
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002226 Resources r = context.getResources();
2227 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002228
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002229 win.setType(
2230 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002231
2232 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2233 // Assumes it's safe to show starting windows of launched apps while
2234 // the keyguard is being hidden. This is okay because starting windows never show
2235 // secret information.
2236 if (mKeyguardHidden) {
2237 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2238 }
2239 }
2240
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002241 // Force the window flags: this is a fake window, so it is not really
2242 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2243 // flag because we do know that the next window will take input
2244 // focus, so we want to get the IME window up on top of us right away.
2245 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002246 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002247 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2248 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2249 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002250 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002251 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2252 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2253 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002254
Adam Powell04fe6eb2013-05-31 14:39:48 -07002255 win.setDefaultIcon(icon);
2256 win.setDefaultLogo(logo);
2257
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002258 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002259 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002260
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002261 final WindowManager.LayoutParams params = win.getAttributes();
2262 params.token = appToken;
2263 params.packageName = packageName;
2264 params.windowAnimations = win.getWindowStyle().getResourceId(
2265 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002266 params.privateFlags |=
2267 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002268 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002269
2270 if (!compatInfo.supportsScreen()) {
2271 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2272 }
2273
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002274 params.setTitle("Starting " + packageName);
2275
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002276 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2277 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002278
2279 if (win.isFloating()) {
2280 // Whoops, there is no way to display an animation/preview
2281 // of such a thing! After all that work... let's skip it.
2282 // (Note that we must do this here because it is in
2283 // getDecorView() where the theme is evaluated... maybe
2284 // we should peek the floating attribute from the theme
2285 // earlier.)
2286 return null;
2287 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002288
Craig Mautner6fbda632012-07-03 09:26:39 -07002289 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002290 TAG, "Adding starting window for " + packageName
2291 + " / " + appToken + ": "
2292 + (view.getParent() != null ? view : null));
2293
2294 wm.addView(view, params);
2295
2296 // Only return the view if it was successfully added to the
2297 // window manager... which we can tell by it having a parent.
2298 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002299 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002300 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002301 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2302 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002303 } catch (RuntimeException e) {
2304 // don't crash if something else bad happens, for example a
2305 // failure loading resources because we are loading from an app
2306 // on external storage that has been unmounted.
2307 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002308 } finally {
2309 if (view != null && view.getParent() == null) {
2310 Log.w(TAG, "view not successfully added to wm, removing view");
2311 wm.removeViewImmediate(view);
2312 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002313 }
2314
2315 return null;
2316 }
2317
2318 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002319 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002320 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002321 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2322 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002323
2324 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002325 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002326 wm.removeView(window);
2327 }
2328 }
2329
2330 /**
2331 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002332 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002333 * Currently enforces that three window types are singletons:
2334 * <ul>
2335 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002336 * <li>KEYGUARD_TYPE</li>
2337 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002338 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002339 * @param win The window to be added
2340 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002341 *
Jeff Brown98365d72012-08-19 20:30:52 -07002342 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2343 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002344 */
Jose Lima9546b202014-07-02 17:21:51 -07002345 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002346 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2347 switch (attrs.type) {
2348 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002349 mContext.enforceCallingOrSelfPermission(
2350 android.Manifest.permission.STATUS_BAR_SERVICE,
2351 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002352 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002353 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002354 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002355 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002356 }
2357 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002358 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002359 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002360 case TYPE_NAVIGATION_BAR:
2361 mContext.enforceCallingOrSelfPermission(
2362 android.Manifest.permission.STATUS_BAR_SERVICE,
2363 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002364 if (mNavigationBar != null) {
2365 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002366 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002367 }
2368 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002369 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002370 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002371 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002372 break;
Jim Millere898ac52012-04-06 17:10:57 -07002373 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002374 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002375 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002376 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002377 mContext.enforceCallingOrSelfPermission(
2378 android.Manifest.permission.STATUS_BAR_SERVICE,
2379 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002380 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002381 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002382 if (mKeyguardScrim != null) {
2383 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2384 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002385 mKeyguardScrim = win;
2386 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002387 }
Jeff Brown98365d72012-08-19 20:30:52 -07002388 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002389 }
2390
2391 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002392 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002393 public void removeWindowLw(WindowState win) {
2394 if (mStatusBar == win) {
2395 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002396 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002397 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002398 } else if (mKeyguardScrim == win) {
2399 Log.v(TAG, "Removing keyguard scrim");
2400 mKeyguardScrim = null;
2401 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002402 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002403 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002404 }
2405 }
2406
2407 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002408
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002409 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002410 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002411 public int selectAnimationLw(WindowState win, int transit) {
2412 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2413 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002414 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002415 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002416 if (transit == TRANSIT_EXIT
2417 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002418 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002419 } else if (transit == TRANSIT_ENTER
2420 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002421 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002422 }
2423 } else if (win == mNavigationBar) {
2424 // This can be on either the bottom or the right.
2425 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002426 if (transit == TRANSIT_EXIT
2427 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002428 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002429 } else if (transit == TRANSIT_ENTER
2430 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002431 return R.anim.dock_bottom_enter;
2432 }
2433 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002434 if (transit == TRANSIT_EXIT
2435 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002436 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002437 } else if (transit == TRANSIT_ENTER
2438 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002439 return R.anim.dock_right_enter;
2440 }
2441 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002442 }
2443
2444 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002445 if (win.hasAppShownWindows()) {
2446 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2447 return com.android.internal.R.anim.app_starting_exit;
2448 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002449 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002450 && transit == TRANSIT_ENTER) {
2451 // Special case: we are animating in a dream, while the keyguard
2452 // is shown. We don't want an animation on the dream, because
2453 // we need it shown immediately with the keyguard animating away
2454 // to reveal it.
2455 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002456 }
2457
2458 return 0;
2459 }
2460
Craig Mautner3c174372013-02-21 17:54:37 -08002461 @Override
2462 public void selectRotationAnimationLw(int anim[]) {
2463 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2464 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2465 + (mTopFullscreenOpaqueWindowState == null ?
2466 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2467 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2468 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2469 case ROTATION_ANIMATION_CROSSFADE:
2470 anim[0] = R.anim.rotation_animation_xfade_exit;
2471 anim[1] = R.anim.rotation_animation_enter;
2472 break;
2473 case ROTATION_ANIMATION_JUMPCUT:
2474 anim[0] = R.anim.rotation_animation_jump_exit;
2475 anim[1] = R.anim.rotation_animation_enter;
2476 break;
2477 case ROTATION_ANIMATION_ROTATE:
2478 default:
2479 anim[0] = anim[1] = 0;
2480 break;
2481 }
2482 } else {
2483 anim[0] = anim[1] = 0;
2484 }
2485 }
2486
2487 @Override
2488 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2489 boolean forceDefault) {
2490 switch (exitAnimId) {
2491 case R.anim.rotation_animation_xfade_exit:
2492 case R.anim.rotation_animation_jump_exit:
2493 // These are the only cases that matter.
2494 if (forceDefault) {
2495 return false;
2496 }
2497 int anim[] = new int[2];
2498 selectRotationAnimationLw(anim);
2499 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2500 default:
2501 return true;
2502 }
2503 }
2504
2505 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002506 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2507 boolean goingToNotificationShade) {
2508 if (goingToNotificationShade) {
2509 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002510 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002511
2512 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2513 R.anim.lock_screen_behind_enter_wallpaper :
2514 R.anim.lock_screen_behind_enter);
2515
2516 // TODO: Use XML interpolators when we have log interpolators available in XML.
2517 final List<Animation> animations = set.getAnimations();
2518 for (int i = animations.size() - 1; i >= 0; --i) {
2519 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2520 }
2521
2522 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002523 }
2524
2525
2526 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002527 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2528 if (goingToNotificationShade) {
2529 return null;
2530 } else {
2531 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2532 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002533 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002534
2535 private static void awakenDreams() {
2536 IDreamManager dreamManager = getDreamManager();
2537 if (dreamManager != null) {
2538 try {
2539 dreamManager.awaken();
2540 } catch (RemoteException e) {
2541 // fine, stay asleep then
2542 }
2543 }
2544 }
2545
2546 static IDreamManager getDreamManager() {
2547 return IDreamManager.Stub.asInterface(
2548 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2549 }
2550
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002551 TelecomManager getTelecommService() {
2552 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002553 }
2554
Jeff Brown4d396052010-10-29 21:50:21 -07002555 static IAudioService getAudioService() {
2556 IAudioService audioService = IAudioService.Stub.asInterface(
2557 ServiceManager.checkService(Context.AUDIO_SERVICE));
2558 if (audioService == null) {
2559 Log.w(TAG, "Unable to find IAudioService interface.");
2560 }
2561 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002562 }
2563
2564 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002565 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002566 }
2567
2568 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2569 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2570 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2571 };
2572
2573 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002574 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002575 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002576 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002577 final int keyCode = event.getKeyCode();
2578 final int repeatCount = event.getRepeatCount();
2579 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002580 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002581 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2582 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002583
Jeff Brown40013652012-05-16 21:22:36 -07002584 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002585 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002586 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2587 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002588 }
2589
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002590 // If we think we might have a volume down & power key chord on the way
2591 // but we're not sure, then tell the dispatcher to wait a little while and
2592 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002593 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002594 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002595 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002596 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2597 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002598 if (now < timeoutTime) {
2599 return timeoutTime - now;
2600 }
2601 }
2602 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002603 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002604 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002605 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002606 }
2607 return -1;
2608 }
2609 }
2610
Michael Wright6a62e552014-06-03 19:19:48 -07002611 // Cancel any pending meta actions if we see any other keys being pressed between the down
2612 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002613 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002614 mPendingMetaAction = false;
2615 }
2616
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002617 // First we always handle the home key here, so applications
2618 // can never break it, although if keyguard is on, we do let
2619 // it handle it, because that gives us the correct 5 second
2620 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002621 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002622
Jeff Brown49ed71d2010-12-06 17:13:33 -08002623 // If we have released the home key, and didn't do anything else
2624 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002625 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002626 cancelPreloadRecentApps();
2627
Jeff Brown49ed71d2010-12-06 17:13:33 -08002628 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002629 if (mHomeConsumed) {
2630 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002631 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002632 }
Jeff Browncaca8812013-05-09 13:34:33 -07002633
2634 if (canceled) {
2635 Log.i(TAG, "Ignoring HOME; event canceled.");
2636 return -1;
2637 }
2638
Yorke Lee4f803242014-12-15 23:22:06 +00002639 // If an incoming call is ringing, HOME is totally disabled.
2640 // (The user is already on the InCallUI at this point,
2641 // and his ONLY options are to answer or reject the call.)
2642 TelecomManager telecomManager = getTelecommService();
2643 if (telecomManager != null && telecomManager.isRinging()) {
2644 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2645 return -1;
2646 }
2647
Jeff Browncaca8812013-05-09 13:34:33 -07002648 // Delay handling home if a double-tap is possible.
2649 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2650 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2651 mHomeDoubleTapPending = true;
2652 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2653 ViewConfiguration.getDoubleTapTimeout());
2654 return -1;
2655 }
2656
Jeff Brown13f00f02014-10-31 14:45:50 -07002657 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002658 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002659 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002660
2661 // If a system window has focus, then it doesn't make sense
2662 // right now to interact with applications.
2663 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2664 if (attrs != null) {
2665 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002666 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2667 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2668 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002669 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002670 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002671 }
2672 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2673 for (int i=0; i<typeCount; i++) {
2674 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2675 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002676 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002677 }
2678 }
2679 }
Jeff Browncaca8812013-05-09 13:34:33 -07002680
2681 // Remember that home is pressed and handle special actions.
2682 if (repeatCount == 0) {
2683 mHomePressed = true;
2684 if (mHomeDoubleTapPending) {
2685 mHomeDoubleTapPending = false;
2686 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2687 handleDoubleTapOnHome();
2688 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2689 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2690 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002691 }
Jeff Browncaca8812013-05-09 13:34:33 -07002692 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2693 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002694 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002695 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002696 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002697 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002698 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002699 // Hijack modified menu keys for debugging features
2700 final int chordBug = KeyEvent.META_SHIFT_ON;
2701
2702 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002703 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002704 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002705 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2706 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002707 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002708 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002709 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002710 Intent service = new Intent();
2711 service.setClassName(mContext, "com.android.server.LoadAverageService");
2712 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002713 boolean shown = Settings.Global.getInt(
2714 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002715 if (!shown) {
2716 mContext.startService(service);
2717 } else {
2718 mContext.stopService(service);
2719 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002720 Settings.Global.putInt(
2721 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002722 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002723 }
2724 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002725 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002726 if (down) {
2727 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002728 mSearchKeyShortcutPending = true;
2729 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002730 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002731 } else {
2732 mSearchKeyShortcutPending = false;
2733 if (mConsumeSearchKeyUp) {
2734 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002735 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002736 }
2737 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002738 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002739 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002740 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002741 if (down && repeatCount == 0) {
2742 preloadRecentApps();
2743 } else if (!down) {
2744 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002745 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002746 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002747 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002748 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2749 if (down) {
2750 IStatusBarService service = getStatusBarService();
2751 if (service != null) {
2752 try {
2753 service.expandNotificationsPanel();
2754 } catch (RemoteException e) {
2755 // do nothing.
2756 }
2757 }
2758 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002759 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2760 if (down) {
2761 if (repeatCount == 0) {
2762 mAssistKeyLongPressed = false;
2763 } else if (repeatCount == 1) {
2764 mAssistKeyLongPressed = true;
2765 if (!keyguardOn) {
2766 launchAssistLongPressAction();
2767 }
2768 }
2769 } else {
2770 if (mAssistKeyLongPressed) {
2771 mAssistKeyLongPressed = false;
2772 } else {
2773 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002774 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002775 }
2776 }
2777 }
2778 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002779 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2780 if (!down) {
2781 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002782 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002783 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2784 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07002785 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
2786 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
2787 if (dic != null) {
2788 try {
2789 dic.exitIdle("voice-search");
2790 } catch (RemoteException e) {
2791 }
2792 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002793 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002794 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002795 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002796 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002797 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002798 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2799 if (down && repeatCount == 0) {
2800 mHandler.post(mScreenshotRunnable);
2801 }
2802 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002803 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2804 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2805 if (down) {
2806 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2807
2808 // Disable autobrightness if it's on
2809 int auto = Settings.System.getIntForUser(
2810 mContext.getContentResolver(),
2811 Settings.System.SCREEN_BRIGHTNESS_MODE,
2812 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2813 UserHandle.USER_CURRENT_OR_SELF);
2814 if (auto != 0) {
2815 Settings.System.putIntForUser(mContext.getContentResolver(),
2816 Settings.System.SCREEN_BRIGHTNESS_MODE,
2817 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2818 UserHandle.USER_CURRENT_OR_SELF);
2819 }
2820
2821 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2822 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2823 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2824 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2825 Settings.System.SCREEN_BRIGHTNESS,
2826 mPowerManager.getDefaultScreenBrightnessSetting(),
2827 UserHandle.USER_CURRENT_OR_SELF);
2828 brightness += step;
2829 // Make sure we don't go beyond the limits.
2830 brightness = Math.min(max, brightness);
2831 brightness = Math.max(min, brightness);
2832
2833 Settings.System.putIntForUser(mContext.getContentResolver(),
2834 Settings.System.SCREEN_BRIGHTNESS, brightness,
2835 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002836 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002837 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002838 }
2839 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002840 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002841 if (down) {
2842 mPendingMetaAction = true;
2843 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002844 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07002845 }
2846 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002847 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002848
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002849 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002850 // Any printing key that is chorded with Search should be consumed
2851 // even if no shortcut was invoked. This prevents text from being
2852 // inadvertently inserted when using a keyboard that has built-in macro
2853 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002854 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002855 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2856 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002857 mConsumeSearchKeyUp = true;
2858 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002859 if (down && repeatCount == 0 && !keyguardOn) {
2860 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2861 if (shortcutIntent != null) {
2862 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002863 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002864 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002865 } catch (ActivityNotFoundException ex) {
2866 Slog.w(TAG, "Dropping shortcut key combination because "
2867 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002868 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002869 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002870 } else {
2871 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002872 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002873 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002874 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002875 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002876 }
2877 }
2878
Jeff Brown68b909d2011-12-07 16:36:01 -08002879 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002880 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002881 && (metaState & KeyEvent.META_META_ON) != 0) {
2882 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002883 if (kcm.isPrintingKey(keyCode)) {
2884 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2885 metaState & ~(KeyEvent.META_META_ON
2886 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2887 if (shortcutIntent != null) {
2888 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2889 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002890 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002891 } catch (ActivityNotFoundException ex) {
2892 Slog.w(TAG, "Dropping shortcut key combination because "
2893 + "the activity to which it is registered was not found: "
2894 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2895 }
2896 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002897 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002898 }
2899 }
2900
Jeff Brown6651a632011-11-28 12:59:11 -08002901 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002902 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002903 String category = sApplicationLaunchKeyCategories.get(keyCode);
2904 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002905 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002906 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2907 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002908 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002909 } catch (ActivityNotFoundException ex) {
2910 Slog.w(TAG, "Dropping application launch key because "
2911 + "the activity to which it is registered was not found: "
2912 + "keyCode=" + keyCode + ", category=" + category, ex);
2913 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002914 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002915 }
2916 }
2917
Michael Wright61c46752014-08-21 16:57:33 -07002918 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002919 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002920 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002921 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002922 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002923 mRecentAppsHeldModifiers = shiftlessModifiers;
2924 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002925 return -1;
2926 }
2927 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002928 } else if (!down && mRecentAppsHeldModifiers != 0
2929 && (metaState & mRecentAppsHeldModifiers) == 0) {
2930 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002931 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002932 }
2933
Jeff Browncf39bdf2012-05-18 14:41:19 -07002934 // Handle keyboard language switching.
2935 if (down && repeatCount == 0
2936 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2937 || (keyCode == KeyEvent.KEYCODE_SPACE
2938 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2939 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2940 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2941 return -1;
2942 }
2943 if (mLanguageSwitchKeyPressed && !down
2944 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2945 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2946 mLanguageSwitchKeyPressed = false;
2947 return -1;
2948 }
2949
Jeff Brown13f00f02014-10-31 14:45:50 -07002950 if (isValidGlobalKey(keyCode)
2951 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002952 return -1;
2953 }
2954
Michael Wright6a62e552014-06-03 19:19:48 -07002955 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002956 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002957 return -1;
2958 }
2959
Jeff Brown68b909d2011-12-07 16:36:01 -08002960 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002961 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002962 }
2963
Jeff Brown3915bb82010-11-05 15:02:16 -07002964 /** {@inheritDoc} */
2965 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002966 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002967 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002968 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002969 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2970 + ", flags=" + event.getFlags()
2971 + ", keyCode=" + event.getKeyCode()
2972 + ", scanCode=" + event.getScanCode()
2973 + ", metaState=" + event.getMetaState()
2974 + ", repeatCount=" + event.getRepeatCount()
2975 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002976 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002977
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002978 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002979 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2980 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002981 final int keyCode = event.getKeyCode();
2982 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002983 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2984 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002985
Jeff Brown54875002011-04-06 15:33:01 -07002986 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002987 final FallbackAction fallbackAction;
2988 if (initialDown) {
2989 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2990 } else {
2991 fallbackAction = mFallbackActions.get(keyCode);
2992 }
2993
2994 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002995 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002996 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2997 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002998 }
2999
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003000 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
3001 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08003002 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003003 event.getAction(), fallbackAction.keyCode,
3004 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08003005 event.getDeviceId(), event.getScanCode(),
3006 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003007
3008 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
3009 fallbackEvent.recycle();
3010 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003011 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003012
3013 if (initialDown) {
3014 mFallbackActions.put(keyCode, fallbackAction);
3015 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3016 mFallbackActions.remove(keyCode);
3017 fallbackAction.recycle();
3018 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003019 }
3020 }
3021
Jeff Brown40013652012-05-16 21:22:36 -07003022 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003023 if (fallbackEvent == null) {
3024 Slog.d(TAG, "No fallback.");
3025 } else {
3026 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3027 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003028 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003029 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003030 }
3031
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003032 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003033 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003034 if ((actions & ACTION_PASS_TO_USER) != 0) {
3035 long delayMillis = interceptKeyBeforeDispatching(
3036 win, fallbackEvent, policyFlags);
3037 if (delayMillis == 0) {
3038 return true;
3039 }
3040 }
3041 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003042 }
3043
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003044 private void launchAssistLongPressAction() {
3045 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3046 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3047
3048 // launch the search activity
3049 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3050 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3051 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003052 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003053 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003054 SearchManager searchManager = getSearchManager();
3055 if (searchManager != null) {
3056 searchManager.stopSearch();
3057 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003058 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003059 } catch (ActivityNotFoundException e) {
3060 Slog.w(TAG, "No activity to handle assist long press action.", e);
3061 }
3062 }
3063
3064 private void launchAssistAction() {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003065 launchAssistAction(null, Integer.MIN_VALUE);
Michael Wright8ab940a2014-09-01 11:01:27 -07003066 }
3067
3068 private void launchAssistAction(String hint) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003069 launchAssistAction(hint, Integer.MIN_VALUE);
3070 }
3071
3072 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003073 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003074 Bundle args = null;
3075 if (deviceId > Integer.MIN_VALUE) {
3076 args = new Bundle();
3077 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003078 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003079 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3080 .launchAssistAction(hint, UserHandle.myUserId(), args);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003081 }
3082
Bart Sears8b1c27c2015-03-18 23:51:02 +00003083 private void startActivityAsUser(Intent intent, UserHandle handle) {
3084 if (isUserSetupComplete()) {
3085 mContext.startActivityAsUser(intent, handle);
3086 } else {
3087 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3088 }
3089 }
3090
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003091 private SearchManager getSearchManager() {
3092 if (mSearchManager == null) {
3093 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3094 }
3095 return mSearchManager;
3096 }
3097
Jeff Browncaca8812013-05-09 13:34:33 -07003098 private void preloadRecentApps() {
3099 mPreloadedRecentApps = true;
3100 try {
3101 IStatusBarService statusbar = getStatusBarService();
3102 if (statusbar != null) {
3103 statusbar.preloadRecentApps();
3104 }
3105 } catch (RemoteException e) {
3106 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3107 // re-acquire status bar service next time it is needed.
3108 mStatusBarService = null;
3109 }
3110 }
3111
3112 private void cancelPreloadRecentApps() {
3113 if (mPreloadedRecentApps) {
3114 mPreloadedRecentApps = false;
3115 try {
3116 IStatusBarService statusbar = getStatusBarService();
3117 if (statusbar != null) {
3118 statusbar.cancelPreloadRecentApps();
3119 }
3120 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003121 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003122 // re-acquire status bar service next time it is needed.
3123 mStatusBarService = null;
3124 }
3125 }
3126 }
3127
3128 private void toggleRecentApps() {
3129 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003130 try {
3131 IStatusBarService statusbar = getStatusBarService();
3132 if (statusbar != null) {
3133 statusbar.toggleRecentApps();
3134 }
3135 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003136 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3137 // re-acquire status bar service next time it is needed.
3138 mStatusBarService = null;
3139 }
3140 }
3141
Craig Mautner84984fa2014-06-19 11:19:20 -07003142 @Override
3143 public void showRecentApps() {
3144 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3145 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3146 }
3147
Winson Chung1e8d71b2014-05-16 17:05:22 -07003148 private void showRecentApps(boolean triggeredFromAltTab) {
3149 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3150 try {
3151 IStatusBarService statusbar = getStatusBarService();
3152 if (statusbar != null) {
3153 statusbar.showRecentApps(triggeredFromAltTab);
3154 }
3155 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003156 Slog.e(TAG, "RemoteException when showing recent apps", e);
3157 // re-acquire status bar service next time it is needed.
3158 mStatusBarService = null;
3159 }
3160 }
3161
Winson Chungcdcd4872014-08-05 18:00:13 -07003162 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003163 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3164 try {
3165 IStatusBarService statusbar = getStatusBarService();
3166 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003167 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003168 }
3169 } catch (RemoteException e) {
3170 Slog.e(TAG, "RemoteException when closing recent apps", e);
3171 // re-acquire status bar service next time it is needed.
3172 mStatusBarService = null;
3173 }
3174 }
3175
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003176 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003177 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003178 }
3179
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003180 /**
3181 * A home key -> launch home action was detected. Take the appropriate action
3182 * given the situation with the keyguard.
3183 */
Bryce Lee662ed802015-04-10 20:11:39 +00003184 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3185 if (respectKeyguard) {
3186 if (isKeyguardShowingAndNotOccluded()) {
3187 // don't launch home if keyguard showing
3188 return;
3189 }
3190
3191 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3192 // when in keyguard restricted mode, must first verify unlock
3193 // before launching home
3194 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3195 @Override
3196 public void onKeyguardExitResult(boolean success) {
3197 if (success) {
3198 try {
3199 ActivityManagerNative.getDefault().stopAppSwitches();
3200 } catch (RemoteException e) {
3201 }
3202 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3203 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003204 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003205 }
Bryce Lee662ed802015-04-10 20:11:39 +00003206 });
3207 return;
3208 }
3209 }
3210
3211 // no keyguard stuff to worry about, just launch home!
3212 try {
3213 ActivityManagerNative.getDefault().stopAppSwitches();
3214 } catch (RemoteException e) {
3215 }
3216 if (mRecentsVisible) {
3217 // Hide Recents and notify it to launch Home
3218 if (awakenFromDreams) {
3219 awakenDreams();
3220 }
3221 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3222 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003223 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003224 // Otherwise, just launch Home
3225 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3226 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003227 }
3228 }
3229
John Spurlock04db1762013-05-13 12:46:41 -04003230 private final Runnable mClearHideNavigationFlag = new Runnable() {
3231 @Override
3232 public void run() {
3233 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3234 // Clear flags.
3235 mForceClearedSystemUiFlags &=
3236 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3237 }
3238 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003239 }
3240 };
3241
3242 /**
3243 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3244 * to determine when the nav bar should be shown and prevent applications from
3245 * receiving those touches.
3246 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003247 final class HideNavInputEventReceiver extends InputEventReceiver {
3248 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3249 super(inputChannel, looper);
3250 }
3251
Dianne Hackborndf89e652011-10-06 22:35:11 -07003252 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003253 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003254 boolean handled = false;
3255 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003256 if (event instanceof MotionEvent
3257 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3258 final MotionEvent motionEvent = (MotionEvent)event;
3259 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003260 // When the user taps down, we re-show the nav bar.
3261 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003262 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003263 // Any user activity always causes us to show the
3264 // navigation controls, if they had been hidden.
3265 // We also clear the low profile and only content
3266 // flags so that tapping on the screen will atomically
3267 // restore all currently hidden screen decorations.
3268 int newVal = mResettingSystemUiFlags |
3269 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3270 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3271 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003272 if (mResettingSystemUiFlags != newVal) {
3273 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003274 changed = true;
3275 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003276 // We don't allow the system's nav bar to be hidden
3277 // again for 1 second, to prevent applications from
3278 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003279 newVal = mForceClearedSystemUiFlags |
3280 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003281 if (mForceClearedSystemUiFlags != newVal) {
3282 mForceClearedSystemUiFlags = newVal;
3283 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003284 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003285 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003286 }
3287 if (changed) {
3288 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3289 }
3290 }
3291 }
3292 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003293 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003294 }
3295 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003296 }
3297 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3298 new InputEventReceiver.Factory() {
3299 @Override
3300 public InputEventReceiver createInputEventReceiver(
3301 InputChannel inputChannel, Looper looper) {
3302 return new HideNavInputEventReceiver(inputChannel, looper);
3303 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003304 };
3305
3306 @Override
3307 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003308 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3309 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003310 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003311
Dianne Hackborndf89e652011-10-06 22:35:11 -07003312 // Reset any bits in mForceClearingStatusBarVisibility that
3313 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003314 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003315 // Clear any bits in the new visibility that are currently being
3316 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003317 return visibility & ~mResettingSystemUiFlags
3318 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003319 }
3320
Craig Mautner69b08182012-09-05 13:07:13 -07003321 @Override
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003322 public void getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation,
3323 Rect outContentInsets, Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003324 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003325 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3326 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003327
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003328 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
3329 if (useOutsets) {
3330 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
3331 if (outset > 0) {
3332 if (displayRotation == Surface.ROTATION_0) {
3333 outOutsets.bottom += outset;
3334 } else if (displayRotation == Surface.ROTATION_90) {
3335 outOutsets.right += outset;
3336 } else if (displayRotation == Surface.ROTATION_180) {
3337 outOutsets.top += outset;
3338 } else if (displayRotation == Surface.ROTATION_270) {
3339 outOutsets.left += outset;
3340 }
3341 }
3342 }
3343
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003344 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003345 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003346 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003347 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003348 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003349 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3350 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3351 } else {
3352 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3353 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3354 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003355 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3356 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003357 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003358 availRight - mStableFullscreenRight,
3359 availBottom - mStableFullscreenBottom);
3360 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003361 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003362 availRight - mStableRight, availBottom - mStableBottom);
3363 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003364 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003365 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003366 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003367 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003368 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003369 availRight - mCurRight, availBottom - mCurBottom);
3370 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003371 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003372 availRight - mCurRight, availBottom - mCurBottom);
3373 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003374
3375 outStableInsets.set(mStableLeft, mStableTop,
3376 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003377 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003378 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003379 outContentInsets.setEmpty();
3380 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003381 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003382
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003383 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
3384 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
3385 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
3386 }
3387
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003388 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003389 @Override
3390 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3391 int displayRotation) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003392 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003393 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3394 if (isDefaultDisplay) {
3395 switch (displayRotation) {
3396 case Surface.ROTATION_90:
3397 overscanLeft = mOverscanTop;
3398 overscanTop = mOverscanRight;
3399 overscanRight = mOverscanBottom;
3400 overscanBottom = mOverscanLeft;
3401 break;
3402 case Surface.ROTATION_180:
3403 overscanLeft = mOverscanRight;
3404 overscanTop = mOverscanBottom;
3405 overscanRight = mOverscanLeft;
3406 overscanBottom = mOverscanTop;
3407 break;
3408 case Surface.ROTATION_270:
3409 overscanLeft = mOverscanBottom;
3410 overscanTop = mOverscanLeft;
3411 overscanRight = mOverscanTop;
3412 overscanBottom = mOverscanRight;
3413 break;
3414 default:
3415 overscanLeft = mOverscanLeft;
3416 overscanTop = mOverscanTop;
3417 overscanRight = mOverscanRight;
3418 overscanBottom = mOverscanBottom;
3419 break;
3420 }
3421 } else {
3422 overscanLeft = 0;
3423 overscanTop = 0;
3424 overscanRight = 0;
3425 overscanBottom = 0;
3426 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003427 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3428 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3429 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3430 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003431 mSystemLeft = 0;
3432 mSystemTop = 0;
3433 mSystemRight = displayWidth;
3434 mSystemBottom = displayHeight;
3435 mUnrestrictedScreenLeft = overscanLeft;
3436 mUnrestrictedScreenTop = overscanTop;
3437 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3438 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3439 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3440 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003441 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3442 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003443 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003444 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003445 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003446 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003447 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003448 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003449 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003450 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003451 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003452 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003453
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003454 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3455 final Rect pf = mTmpParentFrame;
3456 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003457 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003458 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003459 final Rect dcf = mTmpDecorFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003460 final Rect osf = mTmpOutsetFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003461 pf.left = df.left = of.left = vf.left = mDockLeft;
3462 pf.top = df.top = of.top = vf.top = mDockTop;
3463 pf.right = df.right = of.right = vf.right = mDockRight;
3464 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003465 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003466
Craig Mautner69b08182012-09-05 13:07:13 -07003467 if (isDefaultDisplay) {
3468 // For purposes of putting out fake window up to steal focus, we will
3469 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003470 final int sysui = mLastSystemUiFlags;
3471 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003472 boolean navTranslucent = (sysui
3473 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003474 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3475 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3476 boolean navAllowedHidden = immersive || immersiveSticky;
3477 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003478 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3479 if (!isKeyguardShowing) {
3480 navTranslucent &= areTranslucentBarsAllowed();
3481 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003482
Craig Mautner69b08182012-09-05 13:07:13 -07003483 // When the navigation bar isn't visible, we put up a fake
3484 // input window to catch all touch events. This way we can
3485 // detect when the user presses anywhere to bring back the nav
3486 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003487 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003488 if (mInputConsumer != null) {
3489 mInputConsumer.dismiss();
3490 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003491 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003492 } else if (mInputConsumer == null) {
3493 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3494 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003495 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003496
Craig Mautner69b08182012-09-05 13:07:13 -07003497 // For purposes of positioning and showing the nav bar, if we have
3498 // decided that it can't be hidden (because of the screen aspect ratio),
3499 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003500 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003501
John Spurlockad3e6cb2013-04-30 08:47:43 -04003502 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003503 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003504 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003505 // Force the navigation bar to its appropriate place and
3506 // size. We need to do this directly, instead of relying on
3507 // it to bubble up from the nav bar, because this needs to
3508 // change atomically with screen rotations.
3509 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3510 if (mNavigationBarOnBottom) {
3511 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003512 int top = displayHeight - overscanBottom
3513 - mNavigationBarHeightForRotation[displayRotation];
3514 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003515 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003516 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003517 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003518 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003519 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003520 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003521 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3522 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003523 } else {
3524 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003525 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003526 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003527 if (navVisible && !navTranslucent && !navAllowedHidden
3528 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003529 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003530 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003531 // and not in the process of animating on or off, then
3532 // we can tell the app that it is covered by it.
3533 mSystemBottom = mTmpNavigationFrame.top;
3534 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003535 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003536 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003537 int left = displayWidth - overscanRight
3538 - mNavigationBarWidthForRotation[displayRotation];
3539 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003540 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003541 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003542 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003543 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003544 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003545 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003546 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3547 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003548 } else {
3549 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003550 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003551 }
John Spurlockbd957402013-10-03 11:38:39 -04003552 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3553 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003554 // If the nav bar is currently requested to be visible,
3555 // and not in the process of animating on or off, then
3556 // we can tell the app that it is covered by it.
3557 mSystemRight = mTmpNavigationFrame.left;
3558 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003559 }
Craig Mautner69b08182012-09-05 13:07:13 -07003560 // Make sure the content and current rectangles are updated to
3561 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003562 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3563 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3564 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3565 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003566 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3567 // And compute the final frame.
3568 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003569 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003570 mTmpNavigationFrame, mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003571 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003572 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003573 updateSysUiVisibility = true;
3574 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003575 }
Craig Mautnereda67292013-04-28 13:50:14 -07003576 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003577 mDockLeft, mDockTop, mDockRight, mDockBottom));
3578
3579 // decide where the status bar goes ahead of time
3580 if (mStatusBar != null) {
3581 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003582 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3583 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3584 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3585 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3586 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003587 vf.left = mStableLeft;
3588 vf.top = mStableTop;
3589 vf.right = mStableRight;
3590 vf.bottom = mStableBottom;
3591
3592 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3593
3594 // Let the status bar determine its size.
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003595 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3596 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3597 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
Craig Mautner69b08182012-09-05 13:07:13 -07003598
3599 // For layout, the status bar is always at the top with our fixed height.
3600 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3601
John Spurlocke1f366f2013-08-05 12:22:40 -04003602 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003603 boolean statusBarTranslucent = (sysui
3604 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003605 if (!isKeyguardShowing) {
3606 statusBarTranslucent &= areTranslucentBarsAllowed();
3607 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003608
Craig Mautner69b08182012-09-05 13:07:13 -07003609 // If the status bar is hidden, we don't want to cause
3610 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003611 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003612 // Status bar may go away, so the screen area it occupies
3613 // is available to apps but just covering them when the
3614 // status bar is visible.
3615 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3616
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003617 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3618 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3619 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3620 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003621
Craig Mautnereda67292013-04-28 13:50:14 -07003622 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003623 String.format(
3624 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3625 mDockLeft, mDockTop, mDockRight, mDockBottom,
3626 mContentLeft, mContentTop, mContentRight, mContentBottom,
3627 mCurLeft, mCurTop, mCurRight, mCurBottom));
3628 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003629 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003630 && !statusBarTransient && !statusBarTranslucent
3631 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003632 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003633 // and not in the process of animating on or off, then
3634 // we can tell the app that it is covered by it.
3635 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3636 }
John Spurlock27735a42013-08-14 17:57:38 -04003637 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003638 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003639 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003640 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003641 if (updateSysUiVisibility) {
3642 updateSystemUiVisibilityLw();
3643 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003644 }
3645 }
3646
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003647 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003648 @Override
John Spurlock46646232013-09-30 22:32:42 -04003649 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003650 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3651 return mStatusBar.getSurfaceLayer();
3652 }
3653
3654 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3655 return mNavigationBar.getSurfaceLayer();
3656 }
3657
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003658 return 0;
3659 }
3660
Craig Mautner967212c2013-04-13 21:10:58 -07003661 @Override
3662 public void getContentRectLw(Rect r) {
3663 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3664 }
3665
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003666 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3667 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003668 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3669 // Here's a special case: if this attached window is a panel that is
3670 // above the dock window, and the window it is attached to is below
3671 // the dock window, then the frames we computed for the window it is
3672 // attached to can not be used because the dock is effectively part
3673 // of the underlying window and the attached window is floating on top
3674 // of the whole thing. So, we ignore the attached window and explicitly
3675 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003676 df.left = of.left = cf.left = vf.left = mDockLeft;
3677 df.top = of.top = cf.top = vf.top = mDockTop;
3678 df.right = of.right = cf.right = vf.right = mDockRight;
3679 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003680 } else {
3681 // The effective display frame of the attached window depends on
3682 // whether it is taking care of insetting its content. If not,
3683 // we need to use the parent's content frame so that the entire
3684 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003685 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003686 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003687 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003688 // Set the content frame of the attached window to the parent's decor frame
3689 // (same as content frame when IME isn't present) if specifically requested by
3690 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3691 // Otherwise, use the overscan frame.
3692 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3693 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003694 } else {
3695 // If the window is resizing, then we want to base the content
3696 // frame on our attached content frame to resize... however,
3697 // things can be tricky if the attached window is NOT in resize
3698 // mode, in which case its content frame will be larger.
3699 // Ungh. So to deal with that, make sure the content frame
3700 // we end up using is not covering the IM dock.
3701 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003702 if (attached.isVoiceInteraction()) {
3703 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3704 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3705 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3706 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3707 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003708 if (cf.left < mContentLeft) cf.left = mContentLeft;
3709 if (cf.top < mContentTop) cf.top = mContentTop;
3710 if (cf.right > mContentRight) cf.right = mContentRight;
3711 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3712 }
3713 }
3714 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003715 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003716 vf.set(attached.getVisibleFrameLw());
3717 }
3718 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3719 // window should be positioned relative to its parent or the entire
3720 // screen.
3721 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3722 ? attached.getFrameLw() : df);
3723 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003724
3725 private void applyStableConstraints(int sysui, int fl, Rect r) {
3726 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3727 // If app is requesting a stable layout, don't let the
3728 // content insets go below the stable values.
3729 if ((fl & FLAG_FULLSCREEN) != 0) {
3730 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3731 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3732 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3733 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3734 } else {
3735 if (r.left < mStableLeft) r.left = mStableLeft;
3736 if (r.top < mStableTop) r.top = mStableTop;
3737 if (r.right > mStableRight) r.right = mStableRight;
3738 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3739 }
3740 }
3741 }
3742
Jorim Jaggiaa806142015-05-20 18:04:16 -07003743 private boolean canReceiveInput(WindowState win) {
3744 boolean notFocusable =
3745 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
3746 boolean altFocusableIm =
3747 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
3748 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
3749 return !notFocusableForIm;
3750 }
3751
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003752 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003753 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003754 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07003755 // We've already done the navigation bar and status bar. If the status bar can receive
3756 // input, we need to layout it again to accomodate for the IME window.
3757 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003758 return;
3759 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07003760 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07003761 final boolean isDefaultDisplay = win.isDefaultDisplay();
3762 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003763 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3764 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003765 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003766 offsetInputMethodWindowLw(mLastInputMethodWindow);
3767 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003768
John Spurlockc6d1c602014-01-17 15:22:06 -05003769 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003770 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003771 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003772
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003773 final Rect pf = mTmpParentFrame;
3774 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003775 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003776 final Rect cf = mTmpContentFrame;
3777 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003778 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003779 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003780 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04003781 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003782
3783 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003784 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003785
Craig Mautnerf683b562012-10-02 11:10:57 -07003786 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3787
Adrian Roosfa104232014-06-20 16:10:14 -07003788 if (isDefaultDisplay) {
3789 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3790 } else {
3791 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3792 }
3793
Craig Mautner69b08182012-09-05 13:07:13 -07003794 if (!isDefaultDisplay) {
3795 if (attached != null) {
3796 // If this window is attached to another, our display
3797 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003798 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003799 } else {
3800 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003801 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3802 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3803 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003804 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003805 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003806 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003807 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003808 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003809 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3810 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3811 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003812 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003813 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003814 // ...with content insets above the nav bar
3815 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003816 // IM dock windows always go to the bottom of the screen.
3817 attrs.gravity = Gravity.BOTTOM;
3818 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003819 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003820 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003821 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003822 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3823 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003824 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003825 // Note: In Phone landscape mode, the button bar should also be excluded.
3826 cf.right = vf.right = mStableRight;
3827 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003828 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07003829 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02003830 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3831 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3832 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3833 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3834 cf.left = vf.left = mStableLeft;
3835 cf.top = vf.top = mStableTop;
3836 cf.right = vf.right = mStableRight;
3837 vf.bottom = mStableBottom;
3838 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003839 } else {
John Spurlock46646232013-09-30 22:32:42 -04003840
3841 // Default policy decor for the default display
3842 dcf.left = mSystemLeft;
3843 dcf.top = mSystemTop;
3844 dcf.right = mSystemRight;
3845 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003846 final boolean inheritTranslucentDecor = (attrs.privateFlags
3847 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003848 final boolean isAppWindow =
3849 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3850 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3851 final boolean topAtRest =
3852 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3853 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003854 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3855 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003856 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3857 && (fl & WindowManager.LayoutParams.
3858 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003859 // Ensure policy decor includes status bar
3860 dcf.top = mStableTop;
3861 }
John Spurlockbd957402013-10-03 11:38:39 -04003862 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003863 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3864 && (fl & WindowManager.LayoutParams.
3865 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003866 // Ensure policy decor includes navigation bar
3867 dcf.bottom = mStableBottom;
3868 dcf.right = mStableRight;
3869 }
3870 }
3871
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003872 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3873 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003874 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003875 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003876 // This is the case for a normal activity window: we want it
3877 // to cover all of the screen space, and it can take care of
3878 // moving its contents to account for screen decorations that
3879 // intrude into that space.
3880 if (attached != null) {
3881 // If this window is attached to another, our display
3882 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003883 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003884 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003885 if (attrs.type == TYPE_STATUS_BAR_PANEL
3886 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003887 // Status bar panels are the only windows who can go on top of
3888 // the status bar. They are protected by the STATUS_BAR_SERVICE
3889 // permission, so they have the same privileges as the status
3890 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003891 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003892 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003893
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003894 pf.left = df.left = of.left = hasNavBar
3895 ? mDockLeft : mUnrestrictedScreenLeft;
3896 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3897 pf.right = df.right = of.right = hasNavBar
3898 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3899 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3900 pf.bottom = df.bottom = of.bottom = hasNavBar
3901 ? mRestrictedScreenTop+mRestrictedScreenHeight
3902 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003903
Craig Mautnereda67292013-04-28 13:50:14 -07003904 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003905 "Laying out status bar window: (%d,%d - %d,%d)",
3906 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003907 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003908 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3909 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3910 // Asking to layout into the overscan region, so give it that pure
3911 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003912 pf.left = df.left = of.left = mOverscanScreenLeft;
3913 pf.top = df.top = of.top = mOverscanScreenTop;
3914 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3915 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3916 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003917 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003918 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003919 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3920 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003921 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003922 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003923 // only do this for application windows to ensure no window that
3924 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003925 pf.left = df.left = mOverscanScreenLeft;
3926 pf.top = df.top = mOverscanScreenTop;
3927 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3928 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003929 // We need to tell the app about where the frame inside the overscan
3930 // is, so it can inset its content by that amount -- it didn't ask
3931 // to actually extend itself into the overscan region.
3932 of.left = mUnrestrictedScreenLeft;
3933 of.top = mUnrestrictedScreenTop;
3934 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3935 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003936 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003937 pf.left = df.left = mRestrictedOverscanScreenLeft;
3938 pf.top = df.top = mRestrictedOverscanScreenTop;
3939 pf.right = df.right = mRestrictedOverscanScreenLeft
3940 + mRestrictedOverscanScreenWidth;
3941 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3942 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003943 // We need to tell the app about where the frame inside the overscan
3944 // is, so it can inset its content by that amount -- it didn't ask
3945 // to actually extend itself into the overscan region.
3946 of.left = mUnrestrictedScreenLeft;
3947 of.top = mUnrestrictedScreenTop;
3948 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3949 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003950 }
Craig Mautner69b08182012-09-05 13:07:13 -07003951
John Spurlock46646232013-09-30 22:32:42 -04003952 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003953 if (win.isVoiceInteraction()) {
3954 cf.left = mVoiceContentLeft;
3955 cf.top = mVoiceContentTop;
3956 cf.right = mVoiceContentRight;
3957 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003958 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003959 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3960 cf.left = mDockLeft;
3961 cf.top = mDockTop;
3962 cf.right = mDockRight;
3963 cf.bottom = mDockBottom;
3964 } else {
3965 cf.left = mContentLeft;
3966 cf.top = mContentTop;
3967 cf.right = mContentRight;
3968 cf.bottom = mContentBottom;
3969 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003970 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003971 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003972 // Full screen windows are always given a layout that is as if the
3973 // status bar and other transient decors are gone. This is to avoid
3974 // bad states when moving from a window that is not hding the
3975 // status bar to one that is.
3976 cf.left = mRestrictedScreenLeft;
3977 cf.top = mRestrictedScreenTop;
3978 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3979 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003980 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003981 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003982 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3983 vf.left = mCurLeft;
3984 vf.top = mCurTop;
3985 vf.right = mCurRight;
3986 vf.bottom = mCurBottom;
3987 } else {
3988 vf.set(cf);
3989 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003990 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003991 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3992 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3993 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003994 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3995 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003996 // A window that has requested to fill the entire screen just
3997 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003998 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04003999 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
4000 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004001 pf.left = df.left = of.left = cf.left = hasNavBar
4002 ? mDockLeft : mUnrestrictedScreenLeft;
4003 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4004 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004005 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08004006 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004007 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004008 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004009 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004010 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04004011 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
4012 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07004013 } else if (attrs.type == TYPE_NAVIGATION_BAR
4014 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004015 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004016 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4017 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4018 pf.right = df.right = of.right = mUnrestrictedScreenLeft
4019 + mUnrestrictedScreenWidth;
4020 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
4021 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004022 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004023 "Laying out navigation bar window: (%d,%d - %d,%d)",
4024 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08004025 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
4026 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07004027 && ((fl & FLAG_FULLSCREEN) != 0)) {
4028 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004029 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4030 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4031 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4032 + mOverscanScreenWidth;
4033 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4034 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08004035 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08004036 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004037 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4038 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4039 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4040 + mOverscanScreenWidth;
4041 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4042 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04004043 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004044 // The wallpaper also has Real Ultimate Power, but we want to tell
4045 // it about the overscan area.
4046 pf.left = df.left = mOverscanScreenLeft;
4047 pf.top = df.top = mOverscanScreenTop;
4048 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4049 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4050 of.left = cf.left = mUnrestrictedScreenLeft;
4051 of.top = cf.top = mUnrestrictedScreenTop;
4052 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4053 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004054 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004055 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4056 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4057 // Asking to layout into the overscan region, so give it that pure
4058 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004059 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4060 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4061 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004062 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004063 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004064 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004065 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004066 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004067 && (attrs.type == TYPE_STATUS_BAR
4068 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004069 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004070 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4071 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004072 // Asking for layout as if the nav bar is hidden, lets the
4073 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004074 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004075 // can be above the nav bar can do this.
4076 // XXX This assumes that an app asking for this will also
4077 // ask for layout in only content. We can't currently figure out
4078 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004079 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4080 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4081 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4082 + mUnrestrictedScreenWidth;
4083 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4084 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004085 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004086 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4087 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4088 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4089 + mRestrictedScreenWidth;
4090 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4091 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004092 }
Craig Mautner69b08182012-09-05 13:07:13 -07004093
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004094 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004095
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004096 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4097 vf.left = mCurLeft;
4098 vf.top = mCurTop;
4099 vf.right = mCurRight;
4100 vf.bottom = mCurBottom;
4101 } else {
4102 vf.set(cf);
4103 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004104 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004105 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4106 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004107 // A child window should be placed inside of the same visible
4108 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004109 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004110 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004111 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4112 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004113 // Otherwise, a normal window must be placed inside the content
4114 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004115 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4116 // Status bar panels and the volume dialog are the only windows who can go on
4117 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004118 // permission, so they have the same privileges as the status
4119 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004120 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4121 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4122 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4123 + mRestrictedScreenWidth;
4124 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4125 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004126 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004127 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004128 pf.left = df.left = of.left = cf.left = mStableLeft;
4129 pf.top = df.top = of.top = cf.top = mStableTop;
4130 pf.right = df.right = of.right = cf.right = mStableRight;
4131 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004132 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004133 pf.left = mContentLeft;
4134 pf.top = mContentTop;
4135 pf.right = mContentRight;
4136 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004137 if (win.isVoiceInteraction()) {
4138 df.left = of.left = cf.left = mVoiceContentLeft;
4139 df.top = of.top = cf.top = mVoiceContentTop;
4140 df.right = of.right = cf.right = mVoiceContentRight;
4141 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4142 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004143 df.left = of.left = cf.left = mDockLeft;
4144 df.top = of.top = cf.top = mDockTop;
4145 df.right = of.right = cf.right = mDockRight;
4146 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004147 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004148 df.left = of.left = cf.left = mContentLeft;
4149 df.top = of.top = cf.top = mContentTop;
4150 df.right = of.right = cf.right = mContentRight;
4151 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004152 }
4153 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4154 vf.left = mCurLeft;
4155 vf.top = mCurTop;
4156 vf.right = mCurRight;
4157 vf.bottom = mCurBottom;
4158 } else {
4159 vf.set(cf);
4160 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004161 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004162 }
4163 }
Craig Mautner69b08182012-09-05 13:07:13 -07004164
Craig Mautnerb816bed2013-07-23 10:26:17 -07004165 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4166 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004167 df.left = df.top = -10000;
4168 df.right = df.bottom = 10000;
4169 if (attrs.type != TYPE_WALLPAPER) {
4170 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4171 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4172 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004173 }
4174
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004175 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4176 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004177 // We only want to apply outsets to certain types of windows. For example, we never want to
4178 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004179 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004180 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004181 osf = mTmpOutsetFrame;
4182 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4183 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4184 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004185 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004186 if (rotation == Surface.ROTATION_0) {
4187 osf.bottom += outset;
4188 } else if (rotation == Surface.ROTATION_90) {
4189 osf.right += outset;
4190 } else if (rotation == Surface.ROTATION_180) {
4191 osf.top -= outset;
4192 } else if (rotation == Surface.ROTATION_270) {
4193 osf.left -= outset;
4194 }
4195 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4196 + " with rotation " + rotation + ", result: " + osf);
4197 }
4198 }
4199
Craig Mautnereda67292013-04-28 13:50:14 -07004200 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004201 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004202 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004203 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004204 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004205 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004206 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004207 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004208 + " sf=" + sf.toShortString()
4209 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004210
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004211 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004212
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004213 // Dock windows carve out the bottom of the screen, so normal windows
4214 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004215 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4216 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004217 setLastInputMethodWindowLw(null, null);
4218 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004219 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004220 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4221 && !win.getGivenInsetsPendingLw()) {
4222 offsetVoiceInputWindowLw(win);
4223 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004224 }
4225
satok1bc0a492012-04-25 22:47:12 +09004226 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004227 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004228 top += win.getGivenContentInsetsLw().top;
4229 if (mContentBottom > top) {
4230 mContentBottom = top;
4231 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004232 if (mVoiceContentBottom > top) {
4233 mVoiceContentBottom = top;
4234 }
satok1bc0a492012-04-25 22:47:12 +09004235 top = win.getVisibleFrameLw().top;
4236 top += win.getGivenVisibleInsetsLw().top;
4237 if (mCurBottom > top) {
4238 mCurBottom = top;
4239 }
Craig Mautnereda67292013-04-28 13:50:14 -07004240 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004241 + mDockBottom + " mContentBottom="
4242 + mContentBottom + " mCurBottom=" + mCurBottom);
4243 }
4244
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004245 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004246 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004247 top += win.getGivenContentInsetsLw().top;
4248 if (mVoiceContentBottom > top) {
4249 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004250 }
4251 }
4252
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004253 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004254 @Override
4255 public void finishLayoutLw() {
4256 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004257 }
4258
4259 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004260 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004261 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004262 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004263 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004264 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004265 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004266 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004267 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004268 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004269 mForcingShowNavBar = false;
4270 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004271
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004272 mHideLockScreen = false;
4273 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004274 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004275 mShowingLockscreen = false;
4276 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004277 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004278 mKeyguardSecure = isKeyguardSecure();
4279 mKeyguardSecureIncludingHidden = mKeyguardSecure
4280 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004281 }
4282
4283 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004284 @Override
Yohei Yukawad1a09222015-06-30 16:22:05 -07004285 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,
4286 WindowState attached) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004287 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4288 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004289 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004290 if (mTopFullscreenOpaqueWindowState == null
4291 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4292 mForcingShowNavBar = true;
4293 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004294 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004295 if (attrs.type == TYPE_STATUS_BAR) {
4296 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4297 mForceStatusBarFromKeyguard = true;
4298 }
4299 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4300 mForceStatusBarTransparent = true;
4301 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004302 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004303
4304 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4305 && attrs.type < FIRST_SYSTEM_WINDOW;
4306 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4307 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4308
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004309 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004310 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004311 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004312 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004313 mForceStatusBarFromKeyguard = true;
4314 } else {
4315 mForceStatusBar = true;
4316 }
4317 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004318 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004319 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004320 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004321 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004322 // If the lockscreen was showing when the dream started then wait
4323 // for the dream to draw before hiding the lockscreen.
4324 if (!mDreamingLockscreen
4325 || (win.isVisibleLw() && win.hasDrawnLw())) {
4326 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004327 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004328 }
4329 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004330
Yohei Yukawad1a09222015-06-30 16:22:05 -07004331 final IApplicationToken appToken = win.getAppToken();
4332
4333 // For app windows that are not attached, we decide if all windows in the app they
4334 // represent should be hidden or if we should hide the lockscreen. For attached app
4335 // windows we defer the decision to the window it is attached to.
4336 if (appWindow && attached == null) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004337 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004338 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004339 mAppsToBeHidden.remove(appToken);
4340 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004341 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004342 if (dismissKeyguard && !mKeyguardSecure) {
4343 mAppsThatDismissKeyguard.add(appToken);
4344 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004345 mWinShowWhenLocked = win;
4346 mHideLockScreen = true;
4347 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004348 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004349 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004350 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004351 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004352 mAppsToBeHidden.add(appToken);
4353 } else {
4354 mAppsToBeHidden.remove(appToken);
4355 }
4356 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004357 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004358 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004359 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004360 if (attrs.x == 0 && attrs.y == 0
4361 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4362 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4363 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4364 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004365 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4366 mTopFullscreenOpaqueOrDimmingWindowState = win;
4367 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004368 if (!mAppsThatDismissKeyguard.isEmpty() &&
4369 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4370 if (DEBUG_LAYOUT) Slog.v(TAG,
4371 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004372 mDismissKeyguard = (mWinDismissingKeyguard == win
4373 && mSecureDismissingKeyguard == mKeyguardSecure)
4374 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004375 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004376 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004377 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004378 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4379 if (DEBUG_LAYOUT) Slog.v(TAG,
4380 "Setting mHideLockScreen to true by win " + win);
4381 mHideLockScreen = true;
4382 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004383 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004384 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004385 mAllowLockscreenWhenOn = true;
4386 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004387 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004388
4389 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004390 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4391 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004392 win.hideLw(false);
4393 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004394 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004395 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4396 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4397 // that is being hidden in an animation - keep the
4398 // keyguard hidden until the new window shows up and
4399 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004400 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004401 mHideLockScreen = true;
4402 mWinShowWhenLocked = win;
4403 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004404 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004405 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4406 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4407 && win.isDimming()) {
4408 mTopFullscreenOpaqueOrDimmingWindowState = win;
4409 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004410 }
4411
4412 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004413 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004414 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004415 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4416 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4417 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004418 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4419 // fullscreen window.
4420 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4421 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4422 mTopFullscreenOpaqueWindowState.hideLw(false);
4423 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4424 }
4425
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004426 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004427 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004428
4429 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4430 ? mTopFullscreenOpaqueWindowState.getAttrs()
4431 : null;
4432
Jeff Brownc8018eb2012-10-29 21:33:27 -07004433 // If we are not currently showing a dream then remember the current
4434 // lockscreen state. We will use this to determine whether the dream
4435 // started while the lockscreen was showing and remember this state
4436 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004437 if (!mShowingDream) {
4438 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004439 if (mDreamingSleepTokenNeeded) {
4440 mDreamingSleepTokenNeeded = false;
4441 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4442 }
4443 } else {
4444 if (!mDreamingSleepTokenNeeded) {
4445 mDreamingSleepTokenNeeded = true;
4446 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4447 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004448 }
4449
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004450 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004451 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004452 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004453 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004454 boolean shouldBeTransparent = mForceStatusBarTransparent
4455 && !mForceStatusBar
4456 && !mForceStatusBarFromKeyguard;
4457 if (!shouldBeTransparent) {
4458 mStatusBarController.setShowTransparent(false /* transparent */);
4459 } else if (!mStatusBar.isVisibleLw()) {
4460 mStatusBarController.setShowTransparent(true /* transparent */);
4461 }
4462 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004463 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004464 if (mStatusBarController.setBarShowingLw(true)) {
4465 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4466 }
Craig Mautner81defc72013-10-29 11:10:42 -07004467 // Maintain fullscreen layout until incoming animation is complete.
4468 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004469 // Transient status bar on the lockscreen is not allowed
4470 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4471 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4472 mLastSystemUiFlags, mLastSystemUiFlags);
4473 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004474 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004475 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004476 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004477 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004478 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004479 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004480 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004481 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004482 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004483 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004484 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004485 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004486 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4487 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004488 if (mStatusBarController.isTransientShowing()) {
4489 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004490 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4491 }
4492 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004493 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004494 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004495 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004496 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004497 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004498 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004499 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004500 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004501 if (mStatusBarController.setBarShowingLw(true)) {
4502 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4503 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004504 }
4505 }
4506 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004507
Craig Mautner81defc72013-10-29 11:10:42 -07004508 if (mTopIsFullscreen != topIsFullscreen) {
4509 if (!topIsFullscreen) {
4510 // Force another layout when status bar becomes fully shown.
4511 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4512 }
4513 mTopIsFullscreen = topIsFullscreen;
4514 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004515
Craig Mautner39834192012-09-02 07:47:24 -07004516 // Hide the key guard if a visible window explicitly specifies that it wants to be
4517 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004518 if (mKeyguardDelegate != null && mStatusBar != null) {
4519 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4520 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004521 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004522 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004523 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004524 changes |= FINISH_LAYOUT_REDO_LAYOUT
4525 | FINISH_LAYOUT_REDO_CONFIG
4526 | FINISH_LAYOUT_REDO_WALLPAPER;
4527 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004528 if (mKeyguardDelegate.isShowing()) {
4529 mHandler.post(new Runnable() {
4530 @Override
4531 public void run() {
4532 mKeyguardDelegate.keyguardDone(false, false);
4533 }
4534 });
4535 }
4536 } else if (mHideLockScreen) {
4537 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004538 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004539 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004540 changes |= FINISH_LAYOUT_REDO_LAYOUT
4541 | FINISH_LAYOUT_REDO_CONFIG
4542 | FINISH_LAYOUT_REDO_WALLPAPER;
4543 }
4544 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004545 mKeyguardHidden = false;
4546 if (setKeyguardOccludedLw(false)) {
4547 changes |= FINISH_LAYOUT_REDO_LAYOUT
4548 | FINISH_LAYOUT_REDO_CONFIG
4549 | FINISH_LAYOUT_REDO_WALLPAPER;
4550 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004551 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4552 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004553 mHandler.post(new Runnable() {
4554 @Override
4555 public void run() {
4556 mKeyguardDelegate.dismiss();
4557 }
4558 });
4559 }
4560 } else {
4561 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004562 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004563 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004564 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004565 changes |= FINISH_LAYOUT_REDO_LAYOUT
4566 | FINISH_LAYOUT_REDO_CONFIG
4567 | FINISH_LAYOUT_REDO_WALLPAPER;
4568 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004569 }
4570 }
Joe Onorato664644d2011-01-23 17:53:23 -08004571
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004572 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004573 // If the navigation bar has been hidden or shown, we need to do another
4574 // layout pass to update that window.
4575 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4576 }
Joe Onorato664644d2011-01-23 17:53:23 -08004577
Mike Lockwood28569302010-01-28 11:54:40 -05004578 // update since mAllowLockscreenWhenOn might have changed
4579 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004580 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004581 }
4582
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004583 /**
Jim Millerab954542014-10-10 18:21:49 -07004584 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004585 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004586 * @return Whether the flags have changed and we have to redo the layout.
4587 */
Jim Millerab954542014-10-10 18:21:49 -07004588 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4589 boolean wasOccluded = mKeyguardOccluded;
4590 boolean showing = mKeyguardDelegate.isShowing();
4591 if (wasOccluded && !isOccluded && showing) {
4592 mKeyguardOccluded = false;
4593 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004594 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4595 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4596 return true;
Jim Millerab954542014-10-10 18:21:49 -07004597 } else if (!wasOccluded && isOccluded && showing) {
4598 mKeyguardOccluded = true;
4599 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004600 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4601 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4602 return true;
4603 } else {
4604 return false;
4605 }
4606 }
4607
4608 private boolean isStatusBarKeyguard() {
4609 return mStatusBar != null
4610 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4611 }
4612
Jose Lima9546b202014-07-02 17:21:51 -07004613 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004614 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004615 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004616 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004617 return false;
4618 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004619 return true;
4620 }
4621
Jose Lima9546b202014-07-02 17:21:51 -07004622 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004623 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004624 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004625 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004626 // If the navigation bar has been hidden or shown, we need to do another
4627 // layout pass to update that window.
4628 return FINISH_LAYOUT_REDO_LAYOUT;
4629 }
4630 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004631 }
4632
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004633 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004634 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004635 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4636 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004637 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4638 if (newLidState == mLidState) {
4639 return;
4640 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004641
Jeff Brownc458ce92012-04-30 14:58:40 -07004642 mLidState = newLidState;
4643 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004644 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004645
4646 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004647 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004648 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004649 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004650 }
4651 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004652
Michael Wright3818c922014-09-02 13:59:07 -07004653 @Override
4654 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4655 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4656 if (mCameraLensCoverState == lensCoverState) {
4657 return;
4658 }
4659 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4660 lensCoverState == CAMERA_LENS_UNCOVERED) {
4661 Intent intent;
4662 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4663 mKeyguardDelegate.isShowing();
4664 if (keyguardActive) {
4665 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4666 } else {
4667 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4668 }
Bryce Lee584a4452014-10-21 15:55:55 -07004669 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004670 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004671 }
4672 mCameraLensCoverState = lensCoverState;
4673 }
4674
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004675 void setHdmiPlugged(boolean plugged) {
4676 if (mHdmiPlugged != plugged) {
4677 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004678 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004679 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004680 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004681 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004682 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004683 }
4684 }
4685
Joe Onoratoea495d42011-04-06 11:41:11 -07004686 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004687 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004688 // watch for HDMI plug messages if the hdmi switch exists
4689 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4690 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4691
Joe Onoratoea495d42011-04-06 11:41:11 -07004692 final String filename = "/sys/class/switch/hdmi/state";
4693 FileReader reader = null;
4694 try {
4695 reader = new FileReader(filename);
4696 char[] buf = new char[15];
4697 int n = reader.read(buf);
4698 if (n > 1) {
4699 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4700 }
4701 } catch (IOException ex) {
4702 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4703 } catch (NumberFormatException ex) {
4704 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4705 } finally {
4706 if (reader != null) {
4707 try {
4708 reader.close();
4709 } catch (IOException ex) {
4710 }
Joe Onoratodc100302011-01-11 17:07:41 -08004711 }
4712 }
4713 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004714 // This dance forces the code in setHdmiPlugged to run.
4715 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4716 mHdmiPlugged = !plugged;
4717 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004718 }
4719
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004720 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004721 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004722
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004723 final Runnable mScreenshotTimeout = new Runnable() {
4724 @Override public void run() {
4725 synchronized (mScreenshotLock) {
4726 if (mScreenshotConnection != null) {
4727 mContext.unbindService(mScreenshotConnection);
4728 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004729 }
Winson Chung9112ec32011-06-27 13:15:32 -07004730 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004731 }
4732 };
4733
4734 // Assume this is called from the Handler thread.
4735 private void takeScreenshot() {
4736 synchronized (mScreenshotLock) {
4737 if (mScreenshotConnection != null) {
4738 return;
4739 }
4740 ComponentName cn = new ComponentName("com.android.systemui",
4741 "com.android.systemui.screenshot.TakeScreenshotService");
4742 Intent intent = new Intent();
4743 intent.setComponent(cn);
4744 ServiceConnection conn = new ServiceConnection() {
4745 @Override
4746 public void onServiceConnected(ComponentName name, IBinder service) {
4747 synchronized (mScreenshotLock) {
4748 if (mScreenshotConnection != this) {
4749 return;
4750 }
4751 Messenger messenger = new Messenger(service);
4752 Message msg = Message.obtain(null, 1);
4753 final ServiceConnection myConn = this;
4754 Handler h = new Handler(mHandler.getLooper()) {
4755 @Override
4756 public void handleMessage(Message msg) {
4757 synchronized (mScreenshotLock) {
4758 if (mScreenshotConnection == myConn) {
4759 mContext.unbindService(mScreenshotConnection);
4760 mScreenshotConnection = null;
4761 mHandler.removeCallbacks(mScreenshotTimeout);
4762 }
4763 }
4764 }
4765 };
4766 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004767 msg.arg1 = msg.arg2 = 0;
4768 if (mStatusBar != null && mStatusBar.isVisibleLw())
4769 msg.arg1 = 1;
4770 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4771 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004772 try {
4773 messenger.send(msg);
4774 } catch (RemoteException e) {
4775 }
4776 }
4777 }
4778 @Override
4779 public void onServiceDisconnected(ComponentName name) {}
4780 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004781 if (mContext.bindServiceAsUser(
4782 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004783 mScreenshotConnection = conn;
4784 mHandler.postDelayed(mScreenshotTimeout, 10000);
4785 }
4786 }
Winson Chung9112ec32011-06-27 13:15:32 -07004787 }
4788
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004789 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004790 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004791 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004792 if (!mSystemBooted) {
4793 // If we have not yet booted, don't let key events do anything.
4794 return 0;
4795 }
4796
Jeff Brown037c33e2014-04-09 00:31:55 -07004797 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004798 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4799 final boolean canceled = event.isCanceled();
4800 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004801
Jeff Brown3122e442010-10-11 23:32:49 -07004802 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004803
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004804 // If screen is off then we treat the case where the keyguard is open but hidden
4805 // the same as if it were open and in front.
4806 // This will prevent any keys other than the power button from waking the screen
4807 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004808 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004809 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004810 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004811 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004812
Jeff Brown40013652012-05-16 21:22:36 -07004813 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004814 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004815 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004816 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004817 }
4818
Jeff Brown037c33e2014-04-09 00:31:55 -07004819 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004820 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004821 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4822 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004823 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004824 // When the device is interactive or the key is injected pass the
4825 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004826 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004827 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004828 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4829 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4830 // to the application but preserve its wake key status to make sure we still move
4831 // from dozing to fully interactive if we would normally go from off to fully
4832 // interactive.
4833 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004834 } else {
4835 // When the screen is off and the key is not injected, determine whether
4836 // to wake the device but don't pass the key to the application.
4837 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004838 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4839 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004840 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004841 }
4842
Justin Kohd378ad72013-04-01 12:18:26 -07004843 // If the key would be handled globally, just return the result, don't worry about special
4844 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004845 if (isValidGlobalKey(keyCode)
4846 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004847 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004848 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004849 }
Justin Kohd378ad72013-04-01 12:18:26 -07004850 return result;
4851 }
4852
Jeff Brownbae8e772014-06-12 19:59:45 -07004853 boolean useHapticFeedback = down
4854 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4855 && event.getRepeatCount() == 0;
4856
Jeff Brown4d396052010-10-29 21:50:21 -07004857 // Handle special keys.
4858 switch (keyCode) {
4859 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004860 case KeyEvent.KEYCODE_VOLUME_UP:
4861 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004862 if (mUseTvRouting) {
4863 // On TVs volume keys never go to the foreground app
4864 result &= ~ACTION_PASS_TO_USER;
4865 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004866 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4867 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004868 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004869 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004870 mScreenshotChordVolumeDownKeyTriggered = true;
4871 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4872 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004873 cancelPendingPowerKeyAction();
4874 interceptScreenshotChord();
4875 }
4876 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004877 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004878 cancelPendingScreenshotChordAction();
4879 }
4880 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4881 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004882 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004883 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004884 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004885 cancelPendingPowerKeyAction();
4886 cancelPendingScreenshotChordAction();
4887 }
4888 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004889 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004890 cancelPendingScreenshotChordAction();
4891 }
4892 }
Jeff Brown4d396052010-10-29 21:50:21 -07004893 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004894 TelecomManager telecomManager = getTelecommService();
4895 if (telecomManager != null) {
4896 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004897 // If an incoming call is ringing, either VOLUME key means
4898 // "silence ringer". We handle these keys here, rather than
4899 // in the InCallScreen, to make sure we'll respond to them
4900 // even if the InCallScreen hasn't come to the foreground yet.
4901 // Look for the DOWN event here, to agree with the "fallback"
4902 // behavior in the InCallScreen.
4903 Log.i(TAG, "interceptKeyBeforeQueueing:"
4904 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004905
Santos Cordon6848f722014-05-21 15:22:12 -07004906 // Silence the ringer. (It's safe to call this
4907 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004908 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004909
Santos Cordon6848f722014-05-21 15:22:12 -07004910 // And *don't* pass this key thru to the current activity
4911 // (which is probably the InCallScreen.)
4912 result &= ~ACTION_PASS_TO_USER;
4913 break;
4914 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004915 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004916 && (result & ACTION_PASS_TO_USER) == 0) {
4917 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004918 // the application, just pass it to the session service.
4919
4920 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004921 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004922 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004923 }
4924 }
4925
RoboErik430fc482014-06-12 15:49:20 -07004926 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004927 if (mUseTvRouting) {
4928 dispatchDirectAudioEvent(event);
4929 } else {
4930 // If we aren't passing to the user and no one else
4931 // handled it send it to the session manager to
4932 // figure out.
4933 MediaSessionLegacyHelper.getHelper(mContext)
4934 .sendVolumeKeyEvent(event, true);
4935 }
Jeff Brown4d396052010-10-29 21:50:21 -07004936 break;
4937 }
4938 }
4939 break;
4940 }
4941
4942 case KeyEvent.KEYCODE_ENDCALL: {
4943 result &= ~ACTION_PASS_TO_USER;
4944 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004945 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004946 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004947 if (telecomManager != null) {
4948 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004949 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004950 if (interactive && !hungUp) {
4951 mEndCallKeyHandled = false;
4952 mHandler.postDelayed(mEndCallLongPress,
4953 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4954 } else {
4955 mEndCallKeyHandled = true;
4956 }
Jeff Brown4d396052010-10-29 21:50:21 -07004957 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004958 if (!mEndCallKeyHandled) {
4959 mHandler.removeCallbacks(mEndCallLongPress);
4960 if (!canceled) {
4961 if ((mEndcallBehavior
4962 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4963 if (goHome()) {
4964 break;
4965 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004966 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004967 if ((mEndcallBehavior
4968 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4969 mPowerManager.goToSleep(event.getEventTime(),
4970 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4971 isWakeKey = false;
4972 }
Jeff Brown4d396052010-10-29 21:50:21 -07004973 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004974 }
Jeff Brown4d396052010-10-29 21:50:21 -07004975 }
4976 break;
4977 }
4978
4979 case KeyEvent.KEYCODE_POWER: {
4980 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004981 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004982 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004983 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004984 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004985 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004986 }
4987 break;
4988 }
4989
Jeff Brown6212a492014-03-07 13:58:47 -08004990 case KeyEvent.KEYCODE_SLEEP: {
4991 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004992 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004993 if (!mPowerManager.isInteractive()) {
4994 useHapticFeedback = false; // suppress feedback if already non-interactive
4995 }
Nick Vaccarob593a812015-05-15 11:23:05 -07004996 if (down) {
4997 sleepPress(event.getEventTime());
4998 } else {
4999 sleepRelease(event.getEventTime());
5000 }
Jeff Brown6212a492014-03-07 13:58:47 -08005001 break;
5002 }
5003
5004 case KeyEvent.KEYCODE_WAKEUP: {
5005 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005006 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08005007 break;
5008 }
5009
Jeff Brown4d396052010-10-29 21:50:21 -07005010 case KeyEvent.KEYCODE_MEDIA_PLAY:
5011 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5012 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07005013 case KeyEvent.KEYCODE_HEADSETHOOK:
5014 case KeyEvent.KEYCODE_MUTE:
5015 case KeyEvent.KEYCODE_MEDIA_STOP:
5016 case KeyEvent.KEYCODE_MEDIA_NEXT:
5017 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5018 case KeyEvent.KEYCODE_MEDIA_REWIND:
5019 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005020 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
5021 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07005022 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
5023 // If the global session is active pass all media keys to it
5024 // instead of the active window.
5025 result &= ~ACTION_PASS_TO_USER;
5026 }
Jeff Brown4d396052010-10-29 21:50:21 -07005027 if ((result & ACTION_PASS_TO_USER) == 0) {
5028 // Only do this if we would otherwise not pass it to the user. In that
5029 // case, the PhoneWindow class will do the same thing, except it will
5030 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07005031 // Note that we need to make a copy of the key event here because the
5032 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07005033 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07005034 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
5035 new KeyEvent(event));
5036 msg.setAsynchronous(true);
5037 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005038 }
5039 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005040 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005041
Jeff Brown4d396052010-10-29 21:50:21 -07005042 case KeyEvent.KEYCODE_CALL: {
5043 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005044 TelecomManager telecomManager = getTelecommService();
5045 if (telecomManager != null) {
5046 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005047 Log.i(TAG, "interceptKeyBeforeQueueing:"
5048 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005049 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005050
Santos Cordon6848f722014-05-21 15:22:12 -07005051 // And *don't* pass this key thru to the current activity
5052 // (which is presumably the InCallScreen.)
5053 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005054 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005055 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005056 }
Jeff Brown4d396052010-10-29 21:50:21 -07005057 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005058 }
Michael Wright869a67c2014-08-26 19:33:06 -07005059 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5060 // Only do this if we would otherwise not pass it to the user. In that case,
5061 // interceptKeyBeforeDispatching would apply a similar but different policy in
5062 // order to invoke voice assist actions. Note that we need to make a copy of the
5063 // key event here because the original key event will be recycled when we return.
5064 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5065 mBroadcastWakeLock.acquire();
5066 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5067 keyguardActive ? 1 : 0, 0);
5068 msg.setAsynchronous(true);
5069 msg.sendToTarget();
5070 }
5071 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005072 }
Jeff Brown26875502014-01-30 21:47:47 -08005073
Jeff Brownbae8e772014-06-12 19:59:45 -07005074 if (useHapticFeedback) {
5075 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5076 }
5077
Jeff Brown26875502014-01-30 21:47:47 -08005078 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005079 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08005080 }
Bryce Lee584a4452014-10-21 15:55:55 -07005081
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005082 return result;
5083 }
5084
Jeff Brown1c2e4942012-11-06 16:32:01 -08005085 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005086 * Returns true if the key can have global actions attached to it.
5087 * We reserve all power management keys for the system since they require
5088 * very careful handling.
5089 */
5090 private static boolean isValidGlobalKey(int keyCode) {
5091 switch (keyCode) {
5092 case KeyEvent.KEYCODE_POWER:
5093 case KeyEvent.KEYCODE_WAKEUP:
5094 case KeyEvent.KEYCODE_SLEEP:
5095 return false;
5096 default:
5097 return true;
5098 }
5099 }
5100
5101 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005102 * When the screen is off we ignore some keys that might otherwise typically
5103 * be considered wake keys. We filter them out here.
5104 *
5105 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5106 * is always considered a wake key.
5107 */
5108 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5109 switch (keyCode) {
5110 // ignore volume keys unless docked
5111 case KeyEvent.KEYCODE_VOLUME_UP:
5112 case KeyEvent.KEYCODE_VOLUME_DOWN:
5113 case KeyEvent.KEYCODE_VOLUME_MUTE:
5114 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5115
5116 // ignore media and camera keys
5117 case KeyEvent.KEYCODE_MUTE:
5118 case KeyEvent.KEYCODE_HEADSETHOOK:
5119 case KeyEvent.KEYCODE_MEDIA_PLAY:
5120 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5121 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5122 case KeyEvent.KEYCODE_MEDIA_STOP:
5123 case KeyEvent.KEYCODE_MEDIA_NEXT:
5124 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5125 case KeyEvent.KEYCODE_MEDIA_REWIND:
5126 case KeyEvent.KEYCODE_MEDIA_RECORD:
5127 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005128 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005129 case KeyEvent.KEYCODE_CAMERA:
5130 return false;
5131 }
5132 return true;
5133 }
5134
5135
Jeff Brown56194eb2011-03-02 19:23:13 -08005136 /** {@inheritDoc} */
5137 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005138 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5139 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08005140 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
5141 return 0;
5142 }
Michael Wright70af00a2014-09-03 19:30:20 -07005143 }
Bryce Lee5c138322014-11-03 08:26:09 -08005144
Michael Wright70af00a2014-09-03 19:30:20 -07005145 if (shouldDispatchInputWhenNonInteractive()) {
5146 return ACTION_PASS_TO_USER;
5147 }
Bryce Lee5c138322014-11-03 08:26:09 -08005148
Bryce Lee812d7022014-11-10 13:33:28 -08005149 // If we have not passed the action up and we are in theater mode without dreaming,
5150 // there will be no dream to intercept the touch and wake into ambient. The device should
5151 // wake up in this case.
5152 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
5153 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
5154 }
5155
Jeff Brown037c33e2014-04-09 00:31:55 -07005156 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005157 }
5158
Michael Wright70af00a2014-09-03 19:30:20 -07005159 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08005160 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07005161 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5162 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005163 return true;
5164 }
5165
5166 // Send events to a dozing dream even if the screen is off since the dream
5167 // is in control of the state of the screen.
5168 IDreamManager dreamManager = getDreamManager();
5169
5170 try {
5171 if (dreamManager != null && dreamManager.isDreaming()) {
5172 return true;
5173 }
5174 } catch (RemoteException e) {
5175 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5176 }
5177
5178 // Otherwise, consume events since the user can't see what is being
5179 // interacted with.
5180 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005181 }
5182
RoboErik001c59c2015-01-26 15:53:51 -08005183 private void dispatchDirectAudioEvent(KeyEvent event) {
5184 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5185 return;
5186 }
5187 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005188 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5189 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005190 String pkgName = mContext.getOpPackageName();
5191 switch (keyCode) {
5192 case KeyEvent.KEYCODE_VOLUME_UP:
5193 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005194 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005195 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005196 } catch (RemoteException e) {
5197 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5198 }
5199 break;
5200 case KeyEvent.KEYCODE_VOLUME_DOWN:
5201 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005202 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005203 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005204 } catch (RemoteException e) {
5205 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5206 }
5207 break;
5208 case KeyEvent.KEYCODE_VOLUME_MUTE:
5209 try {
5210 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005211 getAudioService().adjustSuggestedStreamVolume(
5212 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005213 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005214 }
5215 } catch (RemoteException e) {
5216 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5217 }
5218 break;
5219 }
5220 }
5221
Jeff Brown40013652012-05-16 21:22:36 -07005222 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5223 if (DEBUG_INPUT) {
5224 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005225 }
5226
Jeff Brown40013652012-05-16 21:22:36 -07005227 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5228 if (DEBUG_INPUT) {
5229 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5230 }
5231
5232 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5233 mHavePendingMediaKeyRepeatWithWakeLock = false;
5234 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5235 }
5236
5237 dispatchMediaKeyWithWakeLockToAudioService(event);
5238
5239 if (event.getAction() == KeyEvent.ACTION_DOWN
5240 && event.getRepeatCount() == 0) {
5241 mHavePendingMediaKeyRepeatWithWakeLock = true;
5242
5243 Message msg = mHandler.obtainMessage(
5244 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5245 msg.setAsynchronous(true);
5246 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5247 } else {
5248 mBroadcastWakeLock.release();
5249 }
5250 }
5251
5252 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5253 mHavePendingMediaKeyRepeatWithWakeLock = false;
5254
5255 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5256 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5257 if (DEBUG_INPUT) {
5258 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5259 }
5260
5261 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5262 mBroadcastWakeLock.release();
5263 }
5264
5265 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5266 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005267 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005268 }
5269 }
5270
Michael Wright869a67c2014-08-26 19:33:06 -07005271 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005272 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5273 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5274 if (dic != null) {
5275 try {
5276 dic.exitIdle("voice-search");
5277 } catch (RemoteException e) {
5278 }
5279 }
Michael Wright869a67c2014-08-26 19:33:06 -07005280 Intent voiceIntent =
5281 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5282 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005283 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005284 mBroadcastWakeLock.release();
5285 }
5286
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005287 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005288 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005289 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005290 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5291 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5292 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005293 } else {
5294 try {
5295 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5296 ServiceManager.getService(Context.UI_MODE_SERVICE));
5297 mUiMode = uiModeService.getCurrentModeType();
5298 } catch (RemoteException e) {
5299 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005300 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005301 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005302 synchronized (mLock) {
5303 updateOrientationListenerLp();
5304 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005305 }
5306 };
5307
Jeff Brown6aaf2952012-10-05 16:01:08 -07005308 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5309 @Override
5310 public void onReceive(Context context, Intent intent) {
5311 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005312 if (mKeyguardDelegate != null) {
5313 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005314 }
5315 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005316 if (mKeyguardDelegate != null) {
5317 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005318 }
5319 }
5320 }
5321 };
5322
Christopher Tate5e08af02012-09-21 17:17:22 -07005323 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5324 @Override
5325 public void onReceive(Context context, Intent intent) {
5326 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5327 // tickle the settings observer: this first ensures that we're
5328 // observing the relevant settings for the newly-active user,
5329 // and then updates our own bookkeeping based on the now-
5330 // current user.
5331 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005332
5333 // force a re-application of focused window sysui visibility.
5334 // the window may never have been shown for this user
5335 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005336 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005337 mLastSystemUiFlags = 0;
5338 updateSystemUiVisibilityLw();
5339 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005340 }
5341 }
5342 };
5343
Adrian Roosddc8b272015-05-21 16:28:27 -07005344 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005345 @Override
5346 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005347 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5348 if (!isUserSetupComplete()) {
5349 // Swipe-up for navigation bar is disabled during setup
5350 return;
5351 }
5352 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5353 mNavigationBarController.showTransient();
5354 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005355 }
5356 };
5357
John Spurlocke1f366f2013-08-05 12:22:40 -04005358 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005359 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005360 if (!isUserSetupComplete()) {
5361 // Swipe-up for navigation bar is disabled during setup
5362 return;
5363 }
John Spurlock27735a42013-08-14 17:57:38 -04005364 boolean sb = mStatusBarController.checkShowTransientBarLw();
5365 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005366 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005367 // Don't show status bar when swiping on already visible navigation bar
5368 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005369 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005370 return;
5371 }
John Spurlock27735a42013-08-14 17:57:38 -04005372 if (sb) mStatusBarController.showTransient();
5373 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005374 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005375 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005376 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005377 }
5378 }
5379
Jeff Brown3ee549c2014-09-22 20:14:39 -07005380 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005381 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005382 public void startedGoingToSleep(int why) {
5383 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005384 if (mKeyguardDelegate != null) {
5385 mKeyguardDelegate.onStartedGoingToSleep(why);
5386 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005387 }
5388
5389 // Called on the PowerManager's Notifier thread.
5390 @Override
5391 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005392 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005393 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04005394 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005395
5396 // We must get this work done here because the power manager will drop
5397 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005398 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005399 mAwake = false;
5400 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005401 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005402 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005403 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005404 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005405 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005406 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005407 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005408 }
5409
Jeff Brown3ee549c2014-09-22 20:14:39 -07005410 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005411 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005412 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005413 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005414 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005415
Jeff Brown3ee549c2014-09-22 20:14:39 -07005416 // Since goToSleep performs these functions synchronously, we must
5417 // do the same here. We cannot post this work to a handler because
5418 // that might cause it to become reordered with respect to what
5419 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005420 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005421 mAwake = true;
5422 mKeyguardDrawComplete = false;
5423 if (mKeyguardDelegate != null) {
5424 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5425 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5426 }
5427
Jeff Browna20dda42014-05-27 20:57:24 -07005428 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005429 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005430 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005431 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005432
Jim Miller5ecd8112013-01-09 18:50:26 -08005433 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005434 mKeyguardDelegate.onStartedWakingUp(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005435 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005436 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005437 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005438 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005439 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005440 }
5441
Jeff Brown416c49c2015-05-26 19:50:18 -07005442 // Called on the PowerManager's Notifier thread.
5443 @Override
5444 public void finishedWakingUp() {
5445 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5446 }
5447
5448 private void wakeUpFromPowerKey(long eventTime) {
5449 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5450 }
5451
5452 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Leed3896842015-06-23 17:06:51 -07005453 final boolean theaterModeEnabled = isTheaterModeEnabled();
5454 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07005455 return false;
5456 }
5457
Bryce Leed3896842015-06-23 17:06:51 -07005458 if (theaterModeEnabled) {
5459 Settings.Global.putInt(mContext.getContentResolver(),
5460 Settings.Global.THEATER_MODE_ON, 0);
5461 }
5462
Jeff Brown416c49c2015-05-26 19:50:18 -07005463 mPowerManager.wakeUp(wakeTime);
5464 return true;
5465 }
5466
Jeff Brown36c4db82014-09-19 12:05:31 -07005467 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005468 synchronized (mLock) {
5469 if (!mAwake || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005470 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005471 }
5472
Jeff Brown36c4db82014-09-19 12:05:31 -07005473 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005474 if (mKeyguardDelegate != null) {
5475 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5476 }
5477 }
5478
5479 finishScreenTurningOn();
5480 }
5481
5482 // Called on the DisplayManager's DisplayPowerController thread.
5483 @Override
5484 public void screenTurnedOff() {
5485 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5486
Jeff Brown48d1b142015-06-10 16:36:03 -07005487 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005488 synchronized (mLock) {
5489 mScreenOnEarly = false;
5490 mScreenOnFully = false;
5491 mWindowManagerDrawComplete = false;
5492 mScreenOnListener = null;
5493 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005494 }
5495 }
5496
Jeff Brown3ee549c2014-09-22 20:14:39 -07005497 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005498 @Override
5499 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005500 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005501
Jeff Brown48d1b142015-06-10 16:36:03 -07005502 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005503 synchronized (mLock) {
5504 mScreenOnEarly = true;
5505 mScreenOnFully = false;
5506 mWindowManagerDrawComplete = false;
5507 mScreenOnListener = screenOnListener;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005508 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005509
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005510 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5511 WAITING_FOR_DRAWN_TIMEOUT);
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005512 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
5513 // as well as enabling the orientation change logic/sensor.
Jeff Brown36c4db82014-09-19 12:05:31 -07005514 }
5515
Jeff Brown36c4db82014-09-19 12:05:31 -07005516 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005517 synchronized (mLock) {
5518 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005519 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005520 }
5521
Jeff Brown36c4db82014-09-19 12:05:31 -07005522 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005523 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005524
5525 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005526 }
5527
Craig Mautner8a0da012014-05-31 15:13:37 -07005528 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005529 synchronized (mLock) {
5530 // We have just finished drawing screen content. Since the orientation listener
5531 // gets only installed when all windows are drawn, we try to install it again.
5532 updateOrientationListenerLp();
5533 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005534 final ScreenOnListener listener;
5535 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005536 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005537 if (DEBUG_WAKEUP) Slog.d(TAG,
5538 "finishScreenTurningOn: mAwake=" + mAwake
5539 + ", mScreenOnEarly=" + mScreenOnEarly
5540 + ", mScreenOnFully=" + mScreenOnFully
5541 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5542 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5543
5544 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5545 || (mAwake && !mKeyguardDrawComplete)) {
5546 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005547 }
5548
Jeff Brown3ee549c2014-09-22 20:14:39 -07005549 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5550 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005551 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005552 mScreenOnFully = true;
5553
5554 // Remember the first time we draw the keyguard so we know when we're done with
5555 // the main part of booting and can enable the screen and hide boot messages.
5556 if (!mKeyguardDrawnOnce && mAwake) {
5557 mKeyguardDrawnOnce = true;
5558 enableScreen = true;
5559 if (mBootMessageNeedsHiding) {
5560 mBootMessageNeedsHiding = false;
5561 hideBootMessages();
5562 }
5563 } else {
5564 enableScreen = false;
5565 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005566 }
5567
Jeff Brown3ee549c2014-09-22 20:14:39 -07005568 if (listener != null) {
5569 listener.onScreenOn();
5570 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005571
Jeff Brown3ee549c2014-09-22 20:14:39 -07005572 if (enableScreen) {
5573 try {
5574 mWindowManager.enableScreenIfNeeded();
5575 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005576 }
Craig Mautnera631d492014-08-05 15:16:01 -07005577 }
5578 }
5579
5580 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005581 synchronized (mLock) {
5582 if (!mKeyguardDrawnOnce) {
5583 mBootMessageNeedsHiding = true;
5584 return; // keyguard hasn't drawn the first time yet, not done booting
5585 }
Craig Mautnera631d492014-08-05 15:16:01 -07005586 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005587
5588 if (mBootMsgDialog != null) {
5589 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5590 mBootMsgDialog.dismiss();
5591 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005592 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005593 }
5594
5595 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005596 public boolean isScreenOn() {
5597 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005598 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005599
Dianne Hackborn08743722009-12-21 12:16:51 -08005600 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005601 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005602 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005603 if (mKeyguardDelegate != null) {
5604 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005605 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005606 }
5607
5608 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005609 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005610 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005611 if (mKeyguardDelegate != null) {
5612 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005613 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005614 }
5615
Jim Millerab954542014-10-10 18:21:49 -07005616 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005617 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005618 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005619 }
5620
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005621 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005622 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005623 public boolean isKeyguardLocked() {
5624 return keyguardOn();
5625 }
5626
5627 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005628 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005629 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005630 if (mKeyguardDelegate == null) return false;
5631 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005632 }
5633
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005634 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005635 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07005636 public boolean isKeyguardShowingOrOccluded() {
5637 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
5638 }
5639
5640 /** {@inheritDoc} */
5641 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005642 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005643 if (mKeyguardDelegate == null) return false;
5644 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005645 }
5646
Jose Lima9546b202014-07-02 17:21:51 -07005647 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005648 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005649 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005650 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005651 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005652 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005653 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005654 // ask the keyguard to prompt the user to authenticate if necessary
5655 mKeyguardDelegate.dismiss();
5656 }
5657 });
5658 }
5659 }
5660
5661 public void notifyActivityDrawnForKeyguardLw() {
5662 if (mKeyguardDelegate != null) {
5663 mHandler.post(new Runnable() {
5664 @Override
5665 public void run() {
5666 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005667 }
5668 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005669 }
5670 }
5671
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005672 @Override
5673 public boolean isKeyguardDrawnLw() {
5674 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005675 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005676 }
5677 }
5678
Jorim Jaggi0d674622014-05-21 01:34:15 +02005679 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005680 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005681 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005682 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005683 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005684 }
5685 }
5686
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005687 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005688 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005689 }
5690
5691 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005692 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005693 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005694
Jeff Brown01a98dd2011-09-20 15:08:29 -07005695 @Override
5696 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005697 if (false) {
5698 Slog.v(TAG, "rotationForOrientationLw(orient="
5699 + orientation + ", last=" + lastRotation
5700 + "); user=" + mUserRotation + " "
5701 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5702 ? "USER_ROTATION_LOCKED" : "")
5703 );
5704 }
5705
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005706 if (mForceDefaultOrientation) {
5707 return Surface.ROTATION_0;
5708 }
5709
The Android Open Source Project0727d222009-03-11 12:11:58 -07005710 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005711 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5712 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005713 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005714 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005715
Jeff Browndec6cf42011-11-15 14:08:20 -08005716 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005717 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005718 // Ignore sensor when lid switch is open and rotation is forced.
5719 preferredRotation = mLidOpenRotation;
5720 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005721 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005722 // Ignore sensor when in car dock unless explicitly enabled.
5723 // This case can override the behavior of NOSENSOR, and can also
5724 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005725 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005726 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005727 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5728 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5729 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005730 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005731 // Ignore sensor when in desk dock unless explicitly enabled.
5732 // This case can override the behavior of NOSENSOR, and can also
5733 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005734 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005735 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005736 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5737 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005738 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005739 preferredRotation = mDemoHdmiRotation;
5740 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5741 && mUndockedHdmiRotation >= 0) {
5742 // Ignore sensor when plugged into HDMI and an undocked orientation has
5743 // been specified in the configuration (only for legacy devices without
5744 // full multi-display support).
5745 // Note that the dock orientation overrides the HDMI orientation.
5746 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005747 } else if (mDemoRotationLock) {
5748 // Ignore sensor when demo rotation lock is enabled.
5749 // Note that the dock orientation and HDMI rotation lock override this.
5750 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005751 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5752 // Application just wants to remain locked in the last rotation.
5753 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005754 } else if (!mSupportAutoRotation) {
5755 // If we don't support auto-rotation then bail out here and ignore
5756 // the sensor and any rotation lock settings.
5757 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005758 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005759 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005760 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5761 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5762 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5763 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005764 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5765 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5766 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5767 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5768 // Otherwise, use sensor only if requested by the application or enabled
5769 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005770 if (mAllowAllRotations < 0) {
5771 // Can't read this during init() because the context doesn't
5772 // have display metrics at that time so we cannot determine
5773 // tablet vs. phone then.
5774 mAllowAllRotations = mContext.getResources().getBoolean(
5775 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5776 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005777 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005778 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005779 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5780 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005781 preferredRotation = sensorRotation;
5782 } else {
5783 preferredRotation = lastRotation;
5784 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005785 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5786 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5787 // Apply rotation lock. Does not apply to NOSENSOR.
5788 // The idea is that the user rotation expresses a weak preference for the direction
5789 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5790 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005791 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005792 } else {
5793 // No overriding preference.
5794 // We will do exactly what the application asked us to do.
5795 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005796 }
5797
Dianne Hackborne5439f22010-10-02 16:53:50 -07005798 switch (orientation) {
5799 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005800 // Return portrait unless overridden.
5801 if (isAnyPortrait(preferredRotation)) {
5802 return preferredRotation;
5803 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005804 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005805
Jeff Brown01a98dd2011-09-20 15:08:29 -07005806 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005807 // Return landscape unless overridden.
5808 if (isLandscapeOrSeascape(preferredRotation)) {
5809 return preferredRotation;
5810 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005811 return mLandscapeRotation;
5812
5813 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005814 // Return reverse portrait unless overridden.
5815 if (isAnyPortrait(preferredRotation)) {
5816 return preferredRotation;
5817 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005818 return mUpsideDownRotation;
5819
5820 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005821 // Return seascape unless overridden.
5822 if (isLandscapeOrSeascape(preferredRotation)) {
5823 return preferredRotation;
5824 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005825 return mSeascapeRotation;
5826
5827 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005828 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005829 // Return either landscape rotation.
5830 if (isLandscapeOrSeascape(preferredRotation)) {
5831 return preferredRotation;
5832 }
5833 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005834 return lastRotation;
5835 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005836 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005837
Jeff Brown01a98dd2011-09-20 15:08:29 -07005838 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005839 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005840 // Return either portrait rotation.
5841 if (isAnyPortrait(preferredRotation)) {
5842 return preferredRotation;
5843 }
5844 if (isAnyPortrait(lastRotation)) {
5845 return lastRotation;
5846 }
5847 return mPortraitRotation;
5848
5849 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005850 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5851 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005852 if (preferredRotation >= 0) {
5853 return preferredRotation;
5854 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005855 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005856 }
5857 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005858 }
5859
Jeff Brown01a98dd2011-09-20 15:08:29 -07005860 @Override
5861 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5862 switch (orientation) {
5863 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5864 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5865 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5866 return isAnyPortrait(rotation);
5867
5868 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5869 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5870 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5871 return isLandscapeOrSeascape(rotation);
5872
5873 default:
5874 return true;
5875 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005876 }
5877
Jeff Brownc0347aa2011-09-23 17:26:09 -07005878 @Override
5879 public void setRotationLw(int rotation) {
5880 mOrientationListener.setCurrentRotation(rotation);
5881 }
5882
Jeff Brown01a98dd2011-09-20 15:08:29 -07005883 private boolean isLandscapeOrSeascape(int rotation) {
5884 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005885 }
5886
Jeff Brown01a98dd2011-09-20 15:08:29 -07005887 private boolean isAnyPortrait(int rotation) {
5888 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005889 }
5890
Jose Lima9546b202014-07-02 17:21:51 -07005891 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005892 public int getUserRotationMode() {
5893 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005894 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5895 WindowManagerPolicy.USER_ROTATION_FREE :
5896 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005897 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005898
5899 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005900 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005901 public void setUserRotationMode(int mode, int rot) {
5902 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005903
5904 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005905 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005906 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005907 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005908 rot,
5909 UserHandle.USER_CURRENT);
5910 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005911 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005912 0,
5913 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005914 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005915 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005916 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005917 1,
5918 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005919 }
5920 }
5921
Jose Lima9546b202014-07-02 17:21:51 -07005922 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005923 public void setSafeMode(boolean safeMode) {
5924 mSafeMode = safeMode;
5925 performHapticFeedbackLw(null, safeMode
5926 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5927 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005928 }
Craig Mautnereda67292013-04-28 13:50:14 -07005929
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005930 static long[] getLongIntArray(Resources r, int resid) {
5931 int[] ar = r.getIntArray(resid);
5932 if (ar == null) {
5933 return null;
5934 }
5935 long[] out = new long[ar.length];
5936 for (int i=0; i<ar.length; i++) {
5937 out[i] = ar[i];
5938 }
5939 return out;
5940 }
Craig Mautnereda67292013-04-28 13:50:14 -07005941
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005942 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005943 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005944 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005945 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005946 mKeyguardDelegate.onSystemReady();
5947
Michael Wright3818c922014-09-02 13:59:07 -07005948 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005949 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005950 synchronized (mLock) {
5951 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005952 mSystemReady = true;
5953 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005954 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005955 public void run() {
5956 updateSettings();
5957 }
5958 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005959 }
5960 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005961
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005962 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005963 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005964 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005965 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005966 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005967 mKeyguardDelegate.onBootCompleted();
5968 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005969 synchronized (mLock) {
5970 mSystemBooted = true;
5971 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005972 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005973 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005974 }
5975
Dianne Hackborn661cd522011-08-22 00:26:20 -07005976 ProgressDialog mBootMsgDialog = null;
5977
5978 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005979 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005980 public void showBootMessage(final CharSequence msg, final boolean always) {
5981 mHandler.post(new Runnable() {
5982 @Override public void run() {
5983 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005984 int theme;
5985 if (mContext.getPackageManager().hasSystemFeature(
5986 PackageManager.FEATURE_WATCH)) {
5987 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5988 } else if (mContext.getPackageManager().hasSystemFeature(
5989 PackageManager.FEATURE_TELEVISION)) {
5990 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5991 } else {
5992 theme = 0;
5993 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005994
5995 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005996 // This dialog will consume all events coming in to
5997 // it, to avoid it trying to do things too early in boot.
5998 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5999 return true;
6000 }
6001 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
6002 return true;
6003 }
6004 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
6005 return true;
6006 }
6007 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
6008 return true;
6009 }
6010 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
6011 return true;
6012 }
6013 @Override public boolean dispatchPopulateAccessibilityEvent(
6014 AccessibilityEvent event) {
6015 return true;
6016 }
6017 };
Jeff Hao9f60c082014-10-28 18:51:07 -07006018 if (mContext.getPackageManager().isUpgrade()) {
6019 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
6020 } else {
6021 mBootMsgDialog.setTitle(R.string.android_start_title);
6022 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006023 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
6024 mBootMsgDialog.setIndeterminate(true);
6025 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07006026 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006027 mBootMsgDialog.getWindow().addFlags(
6028 WindowManager.LayoutParams.FLAG_DIM_BEHIND
6029 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
6030 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08006031 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
6032 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
6033 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006034 mBootMsgDialog.setCancelable(false);
6035 mBootMsgDialog.show();
6036 }
6037 mBootMsgDialog.setMessage(msg);
6038 }
6039 });
6040 }
6041
6042 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006043 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006044 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07006045 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006046 }
6047
Mike Lockwood28569302010-01-28 11:54:40 -05006048 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006049 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006050 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006051 // ***************************************
6052 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
6053 // ***************************************
6054 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
6055 // WITH ITS LOCKS HELD.
6056 //
6057 // This code must be VERY careful about the locks
6058 // it acquires.
6059 // In fact, the current code acquires way too many,
6060 // and probably has lurking deadlocks.
6061
Mike Lockwood28569302010-01-28 11:54:40 -05006062 synchronized (mScreenLockTimeout) {
6063 if (mLockScreenTimerActive) {
6064 // reset the timer
6065 mHandler.removeCallbacks(mScreenLockTimeout);
6066 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6067 }
6068 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006069 }
6070
Adam Cohenf7522022012-10-03 20:03:18 -07006071 class ScreenLockTimeout implements Runnable {
6072 Bundle options;
6073
6074 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006075 public void run() {
6076 synchronized (this) {
6077 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006078 if (mKeyguardDelegate != null) {
6079 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006080 }
Mike Lockwood28569302010-01-28 11:54:40 -05006081 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006082 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006083 }
6084 }
Mike Lockwood28569302010-01-28 11:54:40 -05006085
Adam Cohenf7522022012-10-03 20:03:18 -07006086 public void setLockOptions(Bundle options) {
6087 this.options = options;
6088 }
6089 }
6090
6091 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6092
Jose Lima9546b202014-07-02 17:21:51 -07006093 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006094 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006095 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6096 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006097 if (options != null) {
6098 // In case multiple calls are made to lockNow, we don't wipe out the options
6099 // until the runnable actually executes.
6100 mScreenLockTimeout.setLockOptions(options);
6101 }
Jim Miller93c518e2012-01-17 15:55:31 -08006102 mHandler.post(mScreenLockTimeout);
6103 }
6104
Mike Lockwood28569302010-01-28 11:54:40 -05006105 private void updateLockScreenTimeout() {
6106 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006107 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006108 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006109 if (mLockScreenTimerActive != enable) {
6110 if (enable) {
6111 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
6112 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6113 } else {
6114 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6115 mHandler.removeCallbacks(mScreenLockTimeout);
6116 }
6117 mLockScreenTimerActive = enable;
6118 }
6119 }
6120 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006121
Jeff Brown061ea992015-04-17 19:55:47 -07006122 private void updateDreamingSleepToken(boolean acquire) {
6123 if (acquire) {
6124 if (mDreamingSleepToken == null) {
6125 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6126 }
6127 } else {
6128 if (mDreamingSleepToken != null) {
6129 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006130 mDreamingSleepToken = null;
6131 }
6132 }
6133 }
6134
6135 private void updateScreenOffSleepToken(boolean acquire) {
6136 if (acquire) {
6137 if (mScreenOffSleepToken == null) {
6138 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6139 }
6140 } else {
6141 if (mScreenOffSleepToken != null) {
6142 mScreenOffSleepToken.release();
6143 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006144 }
6145 }
6146 }
6147
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006148 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006149 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006150 public void enableScreenAfterBoot() {
6151 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006152 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006153 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006154 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006155
Jeff Brownc458ce92012-04-30 14:58:40 -07006156 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006157 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006158 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006159 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006160 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07006161 }
Jeff Browna20dda42014-05-27 20:57:24 -07006162
6163 synchronized (mLock) {
6164 updateWakeGestureListenerLp();
6165 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006166 }
6167
Jeff Brown4f5fa282014-06-12 19:19:15 -07006168 void updateUiMode() {
6169 if (mUiModeManager == null) {
6170 mUiModeManager = IUiModeManager.Stub.asInterface(
6171 ServiceManager.getService(Context.UI_MODE_SERVICE));
6172 }
6173 try {
6174 mUiMode = mUiModeManager.getCurrentModeType();
6175 } catch (RemoteException e) {
6176 }
6177 }
6178
Jeff Brown01a98dd2011-09-20 15:08:29 -07006179 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006180 try {
6181 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006182 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6183 } catch (RemoteException e) {
6184 // Ignore
6185 }
6186 }
6187
6188 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6189 try {
6190 //set orientation on WindowManager
6191 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006192 } catch (RemoteException e) {
6193 // Ignore
6194 }
6195 }
6196
Daniel Sandler6396c722013-04-16 20:19:09 -04006197 /**
6198 * Return an Intent to launch the currently active dock app as home. Returns
6199 * null if the standard home should be launched, which is the case if any of the following is
6200 * true:
6201 * <ul>
6202 * <li>The device is not in either car mode or desk mode
6203 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
6204 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6205 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6206 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6207 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006208 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006209 */
6210 Intent createHomeDockIntent() {
6211 Intent intent = null;
6212
6213 // What home does is based on the mode, not the dock state. That
6214 // is, when in car mode you should be taken to car home regardless
6215 // of whether we are actually in a car dock.
6216 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6217 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
6218 intent = mCarDockIntent;
6219 }
6220 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6221 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6222 intent = mDeskDockIntent;
6223 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006224 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6225 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6226 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6227 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6228 // Always launch dock home from home when watch is docked, if it exists.
6229 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006230 }
6231
6232 if (intent == null) {
6233 return null;
6234 }
6235
6236 ActivityInfo ai = null;
6237 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6238 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006239 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006240 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006241 if (info != null) {
6242 ai = info.activityInfo;
6243 }
6244 if (ai != null
6245 && ai.metaData != null
6246 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6247 intent = new Intent(intent);
6248 intent.setClassName(ai.packageName, ai.name);
6249 return intent;
6250 }
6251
6252 return null;
6253 }
6254
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006255 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6256 if (awakenFromDreams) {
6257 awakenDreams();
6258 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006259
6260 Intent dock = createHomeDockIntent();
6261 if (dock != null) {
6262 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006263 if (fromHomeKey) {
6264 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6265 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006266 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006267 return;
6268 } catch (ActivityNotFoundException e) {
6269 }
6270 }
6271
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006272 Intent intent;
6273
6274 if (fromHomeKey) {
6275 intent = new Intent(mHomeIntent);
6276 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6277 } else {
6278 intent = mHomeIntent;
6279 }
6280
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006281 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006282 }
Craig Mautnereda67292013-04-28 13:50:14 -07006283
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006284 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006285 * goes to the home screen
6286 * @return whether it did anything
6287 */
6288 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006289 if (!isUserSetupComplete()) {
6290 Slog.i(TAG, "Not going home because user setup is in progress.");
6291 return false;
6292 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006293 if (false) {
6294 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006295 try {
6296 ActivityManagerNative.getDefault().stopAppSwitches();
6297 } catch (RemoteException e) {
6298 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006299 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006300 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006301 } else {
6302 // This code brings home to the front or, if it is already
6303 // at the front, puts the device to sleep.
6304 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006305 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6306 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6307 Log.d(TAG, "UTS-TEST-MODE");
6308 } else {
6309 ActivityManagerNative.getDefault().stopAppSwitches();
6310 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006311 Intent dock = createHomeDockIntent();
6312 if (dock != null) {
6313 int result = ActivityManagerNative.getDefault()
6314 .startActivityAsUser(null, null, dock,
6315 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6316 null, null, 0,
6317 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006318 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006319 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6320 return false;
6321 }
6322 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006323 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006324 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006325 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006326 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006327 null, null, 0,
6328 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006329 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006330 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006331 return false;
6332 }
6333 } catch (RemoteException ex) {
6334 // bummer, the activity manager, which is in this process, is dead
6335 }
6336 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006337 return true;
6338 }
Craig Mautnereda67292013-04-28 13:50:14 -07006339
6340 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006341 public void setCurrentOrientationLw(int newOrientation) {
6342 synchronized (mLock) {
6343 if (newOrientation != mCurrentAppOrientation) {
6344 mCurrentAppOrientation = newOrientation;
6345 updateOrientationListenerLp();
6346 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006347 }
6348 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006349
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006350 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6351 if (!isGlobalAccessibilityGestureEnabled()) {
6352 return;
6353 }
6354 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6355 Context.AUDIO_SERVICE);
6356 if (audioManager.isSilentMode()) {
6357 return;
6358 }
6359 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6360 Settings.System.DEFAULT_NOTIFICATION_URI);
6361 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6362 ringTone.play();
6363 }
Craig Mautnereda67292013-04-28 13:50:14 -07006364
Bryce Lee584a4452014-10-21 15:55:55 -07006365 private boolean isTheaterModeEnabled() {
6366 return Settings.Global.getInt(mContext.getContentResolver(),
6367 Settings.Global.THEATER_MODE_ON, 0) == 1;
6368 }
6369
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006370 private boolean isGlobalAccessibilityGestureEnabled() {
6371 return Settings.Global.getInt(mContext.getContentResolver(),
6372 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6373 }
6374
Craig Mautnereda67292013-04-28 13:50:14 -07006375 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006376 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006377 if (!mVibrator.hasVibrator()) {
6378 return false;
6379 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006380 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6381 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006382 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006383 return false;
6384 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006385 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006386 switch (effectId) {
6387 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006388 pattern = mLongPressVibePattern;
6389 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006390 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006391 pattern = mVirtualKeyVibePattern;
6392 break;
6393 case HapticFeedbackConstants.KEYBOARD_TAP:
6394 pattern = mKeyboardTapVibePattern;
6395 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006396 case HapticFeedbackConstants.CLOCK_TICK:
6397 pattern = mClockTickVibePattern;
6398 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006399 case HapticFeedbackConstants.CALENDAR_DATE:
6400 pattern = mCalendarDateVibePattern;
6401 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006402 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006403 pattern = mSafeModeDisabledVibePattern;
6404 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006405 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006406 pattern = mSafeModeEnabledVibePattern;
6407 break;
Mady Mellore8608912015-06-05 09:02:55 -07006408 case HapticFeedbackConstants.CONTEXT_CLICK:
6409 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006410 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006411 default:
6412 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006413 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006414 int owningUid;
6415 String owningPackage;
6416 if (win != null) {
6417 owningUid = win.getOwningUid();
6418 owningPackage = win.getOwningPackage();
6419 } else {
6420 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006421 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006422 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006423 if (pattern.length == 1) {
6424 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006425 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006426 } else {
6427 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006428 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006429 }
6430 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006431 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006432
6433 @Override
6434 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006435 }
6436
Jeff Brownc38c9be2012-10-04 13:16:19 -07006437 @Override
6438 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006439 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006440 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006441 }
6442 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006443
Dianne Hackborndf89e652011-10-06 22:35:11 -07006444 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006445 // If there is no window focused, there will be nobody to handle the events
6446 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006447 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6448 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006449 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006450 return 0;
6451 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006452 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006453 // We are updating at a point where the keyguard has gotten
6454 // focus, but we were last in a state where the top window is
6455 // hiding it. This is probably because the keyguard as been
6456 // shown while the top window was displayed, so we want to ignore
6457 // it here because this is just a very transient change and it
6458 // will quickly lose focus once it correctly gets hidden.
6459 return 0;
6460 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006461
John Spurlock1db8b682014-02-18 11:18:59 -05006462 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006463 & ~mResettingSystemUiFlags
6464 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006465 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006466 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006467 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006468 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006469 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006470 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006471 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006472 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006473 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006474 return 0;
6475 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006476 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006477 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006478 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006479 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006480 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006481 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006482 try {
6483 IStatusBarService statusbar = getStatusBarService();
6484 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006485 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006486 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006487 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006488 } catch (RemoteException e) {
6489 // re-acquire status bar service next time it is needed.
6490 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006491 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006492 }
6493 });
6494 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006495 }
6496
Adrian Rooscd3884d2015-02-18 17:25:23 +01006497 private int updateLightStatusBarLw(int vis) {
6498 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6499 ? mStatusBar
6500 : mTopFullscreenOpaqueOrDimmingWindowState;
6501
6502 if (statusColorWin != null) {
6503 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6504 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6505 // its light flag.
6506 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6507 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6508 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6509 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6510 // Otherwise if it's dimming, clear the light flag.
6511 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6512 }
6513 }
6514 return vis;
6515 }
6516
John Spurlock79da8332013-09-20 12:04:47 -04006517 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006518 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006519 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6520 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006521 : mTopFullscreenOpaqueWindowState;
6522 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6523 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6524
John Spurlock27735a42013-08-14 17:57:38 -04006525 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006526 int type = win.getAttrs().type;
6527 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006528 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006529 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6530 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006531 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006532 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6533 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006534 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006535 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6536 }
John Spurlockbd957402013-10-03 11:38:39 -04006537 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006538 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006539
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006540 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006541 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6542 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006543 }
6544
John Spurlock27735a42013-08-14 17:57:38 -04006545 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006546 boolean immersiveSticky =
6547 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006548 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006549 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006550 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006551 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6552 boolean hideStatusBarSysui =
6553 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006554 boolean hideNavBarSysui =
6555 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006556
John Spurlock27735a42013-08-14 17:57:38 -04006557 boolean transientStatusBarAllowed =
6558 mStatusBar != null && (
6559 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006560 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006561 || statusBarHasFocus);
6562
John Spurlockf1a36642013-10-12 17:50:42 -04006563 boolean transientNavBarAllowed =
6564 mNavigationBar != null &&
6565 hideNavBarSysui && immersiveSticky;
6566
Adrian Roosddc8b272015-05-21 16:28:27 -07006567 final long now = SystemClock.uptimeMillis();
6568 final boolean pendingPanic = mPendingPanicGestureUptime != 0
6569 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
6570 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
6571 // The user performed the panic gesture recently, we're about to hide the bars,
6572 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
6573 mPendingPanicGestureUptime = 0;
6574 mStatusBarController.showTransient();
6575 mNavigationBarController.showTransient();
6576 }
6577
John Spurlockf25706f2013-11-07 18:02:43 -05006578 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006579 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006580 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006581 && !transientNavBarAllowed;
6582 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006583 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006584 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006585 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006586 }
John Spurlock27735a42013-08-14 17:57:38 -04006587
Selim Cinekf98702e2015-05-20 22:48:40 -07006588 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
6589 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
6590 final boolean navAllowedHidden = immersive || immersiveSticky;
6591
Selim Cinekd6623612015-05-22 18:56:22 -07006592 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
6593 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07006594 // We can't hide the navbar from this window otherwise the input consumer would not get
6595 // the input events.
6596 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
6597 }
6598
John Spurlock27735a42013-08-14 17:57:38 -04006599 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6600
6601 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006602 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6603 boolean newImmersiveMode = isImmersiveMode(vis);
6604 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006605 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006606 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6607 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006608 }
John Spurlock27735a42013-08-14 17:57:38 -04006609
John Spurlockf1a36642013-10-12 17:50:42 -04006610 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6611
John Spurlocke1f366f2013-08-05 12:22:40 -04006612 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006613 }
6614
John Spurlockf1a36642013-10-12 17:50:42 -04006615 private void clearClearableFlagsLw() {
6616 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6617 if (newVal != mResettingSystemUiFlags) {
6618 mResettingSystemUiFlags = newVal;
6619 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6620 }
6621 }
6622
6623 private boolean isImmersiveMode(int vis) {
6624 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006625 return mNavigationBar != null
6626 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006627 && (vis & flags) != 0
6628 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006629 }
6630
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006631 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006632 * @return whether the navigation or status bar can be made translucent
6633 *
6634 * This should return true unless touch exploration is not enabled or
6635 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006636 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006637 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006638 return mTranslucentDecorEnabled
6639 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006640 }
6641
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006642 // Use this instead of checking config_showNavigationBar so that it can be consistently
6643 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006644 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006645 public boolean hasNavigationBar() {
6646 return mHasNavigationBar;
6647 }
6648
satok1bc0a492012-04-25 22:47:12 +09006649 @Override
6650 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6651 mLastInputMethodWindow = ime;
6652 mLastInputMethodTargetWindow = target;
6653 }
6654
Craig Mautnerf1b67412012-09-19 13:18:29 -07006655 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006656 public int getInputMethodWindowVisibleHeightLw() {
6657 return mDockBottom - mCurBottom;
6658 }
6659
6660 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006661 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006662 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006663 if (mKeyguardDelegate != null) {
6664 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006665 }
John Spurlock13451a22012-09-28 14:40:41 -04006666 if (mStatusBarService != null) {
6667 try {
6668 mStatusBarService.setCurrentUser(newUserId);
6669 } catch (RemoteException e) {
6670 // oh well
6671 }
6672 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006673 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006674 }
6675
6676 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006677 public boolean canMagnifyWindow(int windowType) {
6678 switch (windowType) {
6679 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6680 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6681 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6682 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6683 return false;
6684 }
6685 }
6686 return true;
6687 }
6688
6689 @Override
6690 public boolean isTopLevelWindow(int windowType) {
6691 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6692 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6693 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6694 }
6695 return true;
6696 }
6697
Jim Miller4eeb4f62012-11-08 00:04:29 -08006698 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006699 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006700 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006701 pw.print(" mSystemReady="); pw.print(mSystemReady);
6702 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006703 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006704 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006705 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006706 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006707 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6708 || mForceClearedSystemUiFlags != 0) {
6709 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6710 pw.print(Integer.toHexString(mLastSystemUiFlags));
6711 pw.print(" mResettingSystemUiFlags=0x");
6712 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6713 pw.print(" mForceClearedSystemUiFlags=0x");
6714 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006715 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006716 if (mLastFocusNeedsMenu) {
6717 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6718 pw.println(mLastFocusNeedsMenu);
6719 }
Jeff Browna20dda42014-05-27 20:57:24 -07006720 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6721 pw.println(mWakeGestureEnabledSetting);
6722
Jeff Brownbcdfc622014-03-06 19:13:04 -08006723 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006724 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6725 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006726 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6727 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6728 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6729 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006730 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006731 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006732 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6733 pw.print(mCarDockEnablesAccelerometer);
6734 pw.print(" mDeskDockEnablesAccelerometer=");
6735 pw.println(mDeskDockEnablesAccelerometer);
6736 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6737 pw.print(mLidKeyboardAccessibility);
6738 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006739 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006740 pw.print(prefix);
6741 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6742 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006743 pw.print(prefix);
6744 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6745 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006746 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006747 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6748 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6749 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6750 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6751 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6752 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6753 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006754 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6755 pw.print(","); pw.print(mOverscanScreenTop);
6756 pw.print(") "); pw.print(mOverscanScreenWidth);
6757 pw.print("x"); pw.println(mOverscanScreenHeight);
6758 if (mOverscanLeft != 0 || mOverscanTop != 0
6759 || mOverscanRight != 0 || mOverscanBottom != 0) {
6760 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6761 pw.print(" top="); pw.print(mOverscanTop);
6762 pw.print(" right="); pw.print(mOverscanRight);
6763 pw.print(" bottom="); pw.println(mOverscanBottom);
6764 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006765 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6766 pw.print(mRestrictedOverscanScreenLeft);
6767 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6768 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6769 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006770 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6771 pw.print(","); pw.print(mUnrestrictedScreenTop);
6772 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6773 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6774 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6775 pw.print(","); pw.print(mRestrictedScreenTop);
6776 pw.print(") "); pw.print(mRestrictedScreenWidth);
6777 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006778 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6779 pw.print(","); pw.print(mStableFullscreenTop);
6780 pw.print(")-("); pw.print(mStableFullscreenRight);
6781 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006782 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6783 pw.print(","); pw.print(mStableTop);
6784 pw.print(")-("); pw.print(mStableRight);
6785 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006786 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6787 pw.print(","); pw.print(mSystemTop);
6788 pw.print(")-("); pw.print(mSystemRight);
6789 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006790 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6791 pw.print(","); pw.print(mCurTop);
6792 pw.print(")-("); pw.print(mCurRight);
6793 pw.print(","); pw.print(mCurBottom); pw.println(")");
6794 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6795 pw.print(","); pw.print(mContentTop);
6796 pw.print(")-("); pw.print(mContentRight);
6797 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006798 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6799 pw.print(","); pw.print(mVoiceContentTop);
6800 pw.print(")-("); pw.print(mVoiceContentRight);
6801 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006802 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6803 pw.print(","); pw.print(mDockTop);
6804 pw.print(")-("); pw.print(mDockRight);
6805 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006806 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6807 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006808 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6809 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006810 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6811 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006812 if (mLastInputMethodWindow != null) {
6813 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6814 pw.println(mLastInputMethodWindow);
6815 }
6816 if (mLastInputMethodTargetWindow != null) {
6817 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6818 pw.println(mLastInputMethodTargetWindow);
6819 }
6820 if (mStatusBar != null) {
6821 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006822 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6823 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006824 }
6825 if (mNavigationBar != null) {
6826 pw.print(prefix); pw.print("mNavigationBar=");
6827 pw.println(mNavigationBar);
6828 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006829 if (mFocusedWindow != null) {
6830 pw.print(prefix); pw.print("mFocusedWindow=");
6831 pw.println(mFocusedWindow);
6832 }
6833 if (mFocusedApp != null) {
6834 pw.print(prefix); pw.print("mFocusedApp=");
6835 pw.println(mFocusedApp);
6836 }
6837 if (mWinDismissingKeyguard != null) {
6838 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6839 pw.println(mWinDismissingKeyguard);
6840 }
6841 if (mTopFullscreenOpaqueWindowState != null) {
6842 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6843 pw.println(mTopFullscreenOpaqueWindowState);
6844 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006845 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6846 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6847 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6848 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006849 if (mForcingShowNavBar) {
6850 pw.print(prefix); pw.print("mForcingShowNavBar=");
6851 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6852 pw.println(mForcingShowNavBarLayer);
6853 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006854 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006855 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006856 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6857 pw.print(" mForceStatusBarFromKeyguard=");
6858 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006859 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006860 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006861 pw.print(" mHomePressed="); pw.println(mHomePressed);
6862 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6863 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6864 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6865 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6866 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6867 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6868 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6869 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6870 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6871 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006872 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6873 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6874 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006875
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006876 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006877 mStatusBarController.dump(pw, prefix);
6878 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006879 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006880
Jeff Browna20dda42014-05-27 20:57:24 -07006881 if (mWakeGestureListener != null) {
6882 mWakeGestureListener.dump(pw, prefix);
6883 }
Jeff Brown600f0032014-05-22 17:06:00 -07006884 if (mOrientationListener != null) {
6885 mOrientationListener.dump(pw, prefix);
6886 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006887 if (mBurnInProtectionHelper != null) {
6888 mBurnInProtectionHelper.dump(prefix, pw);
6889 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006890 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006891}