blob: 461c9367c0092d452f7ca0e5645c2a683e777b91 [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;
Jinsuk Kime601b712015-07-07 08:01:02 +090047import android.hardware.hdmi.HdmiControlManager;
48import android.hardware.hdmi.HdmiPlaybackClient;
49import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback;
John Spurlock7b414672014-07-18 13:02:39 -040050import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080051import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050052import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080053import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070054import android.media.Ringtone;
55import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070056import android.media.session.MediaSessionLegacyHelper;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070057import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080058import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070059import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080060import android.os.Handler;
61import android.os.IBinder;
Dianne Hackbornb6683c42015-06-18 17:40:33 -070062import android.os.IDeviceIdleController;
Jeff Brown32cbc38552011-12-01 14:01:49 -080063import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070064import android.os.Message;
65import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080066import android.os.PowerManager;
67import android.os.RemoteException;
68import android.os.ServiceManager;
69import android.os.SystemClock;
70import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080071import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070072import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080073import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070074import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080075import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070076import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040077import android.service.dreams.DreamService;
78import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070079import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070080import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070081import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080082import android.util.EventLog;
83import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070084import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080085import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070086import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080087import android.view.Gravity;
88import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080089import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080090import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070091import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070092import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080093import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080094import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080095import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080096import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080097import android.view.KeyEvent;
98import android.view.MotionEvent;
Adam Powell6711f3b2015-05-06 15:57:09 -070099import com.android.internal.policy.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800100import android.view.Surface;
101import android.view.View;
102import android.view.ViewConfiguration;
103import android.view.Window;
104import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800105import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700106import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800107import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800108import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800109import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800110import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200111import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800112import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800113import com.android.internal.R;
Craig Mautnerae446592012-12-06 19:05:05 -0800114import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700115import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800116import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700117import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100118import com.android.server.policy.keyguard.KeyguardServiceDelegate;
119import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800120
121import java.io.File;
122import java.io.FileReader;
123import java.io.IOException;
124import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700125import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800126import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800127
Dianne Hackbornc652de82013-02-15 16:32:56 -0800128import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700129import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
130import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
131import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700132import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
133import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
134import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800135
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800136/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700137 * WindowManagerPolicy implementation for the Android phone UI. This
138 * introduces a new method suffix, Lp, for an internal lock of the
139 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400140 * 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 -0700141 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800142 */
143public class PhoneWindowManager implements WindowManagerPolicy {
144 static final String TAG = "WindowManager";
145 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700146 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700147 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700148 static final boolean DEBUG_KEYGUARD = false;
149 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700150 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700151 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800152 static final boolean SHOW_STARTING_ANIMATIONS = true;
153 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400154
Daniel Sandler6396c722013-04-16 20:19:09 -0400155 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
156 // No longer recommended for desk docks; still useful in car docks.
157 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
158 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
159
Jeff Brown6d8fd272014-05-20 21:24:38 -0700160 static final int SHORT_PRESS_POWER_NOTHING = 0;
161 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
162 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
163 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800164 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700165
Joe Onoratod208e702010-10-08 16:22:43 -0400166 static final int LONG_PRESS_POWER_NOTHING = 0;
167 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
168 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700169 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700170
Jeff Brown13f00f02014-10-31 14:45:50 -0700171 static final int MULTI_PRESS_POWER_NOTHING = 0;
172 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
173 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
174
Michael Jurka3b1fc472011-06-13 10:54:40 -0700175 // These need to match the documentation/constant in
176 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800177 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800178 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700179 static final int LONG_PRESS_HOME_ASSIST = 2;
180
181 static final int DOUBLE_TAP_HOME_NOTHING = 0;
182 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800183
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000184 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
185 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
186
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700187 static final int APPLICATION_MEDIA_SUBLAYER = -2;
188 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800189 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800190 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700191 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700192
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800193 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
194 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
195 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500196 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700197 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800198
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700199 /**
200 * These are the system UI flags that, when changing, can cause the layout
201 * of the screen to change.
202 */
203 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400204 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400205 | View.SYSTEM_UI_FLAG_FULLSCREEN
206 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200207 | View.NAVIGATION_BAR_TRANSLUCENT
208 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700209
John Spurlock7b414672014-07-18 13:02:39 -0400210 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
211 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
212 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
213 .build();
214
Adrian Roosddc8b272015-05-21 16:28:27 -0700215 // The panic gesture may become active only after the keyguard is dismissed and the immersive
216 // app shows again. If that doesn't happen for 30s we drop the gesture.
217 private static final long PANIC_GESTURE_EXPIRATION = 30000;
218
Jim Miller5ecd8112013-01-09 18:50:26 -0800219 /**
220 * Keyguard stuff
221 */
222 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100223 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700224 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800225
Jeff Brown6651a632011-11-28 12:59:11 -0800226 /* Table of Application Launch keys. Maps from key codes to intent categories.
227 *
228 * These are special keys that are used to launch particular kinds of applications,
229 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
230 * usage page. We don't support quite that many yet...
231 */
232 static SparseArray<String> sApplicationLaunchKeyCategories;
233 static {
234 sApplicationLaunchKeyCategories = new SparseArray<String>();
235 sApplicationLaunchKeyCategories.append(
236 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
237 sApplicationLaunchKeyCategories.append(
238 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
239 sApplicationLaunchKeyCategories.append(
240 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
241 sApplicationLaunchKeyCategories.append(
242 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
243 sApplicationLaunchKeyCategories.append(
244 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
245 sApplicationLaunchKeyCategories.append(
246 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
247 }
248
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700249 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000250 static final int WAITING_FOR_DRAWN_TIMEOUT = 500;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700251
Dianne Hackborndf89e652011-10-06 22:35:11 -0700252 /**
253 * Lock protecting internal state. Must not call out into window
254 * manager with lock held. (This lock will be acquired in places
255 * where the window manager is calling in with its own lock held.)
256 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800257 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700258
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800259 Context mContext;
260 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700261 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700262 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700263 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700264 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700265 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400266 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700267 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700268 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800269 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700270 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800271 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000272 BurnInProtectionHelper mBurnInProtectionHelper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800273
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700274 // Vibrator pattern for haptic feedback of a long press.
275 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700276
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700277 // Vibrator pattern for haptic feedback of virtual key press.
278 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700279
Amith Yamasanic33cb712010-02-10 15:21:49 -0800280 // Vibrator pattern for a short vibration.
281 long[] mKeyboardTapVibePattern;
282
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700283 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
284 long[] mClockTickVibePattern;
285
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700286 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
287 long[] mCalendarDateVibePattern;
288
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700289 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
290 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700291
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700292 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
293 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700294
Mady Mellore8608912015-06-05 09:02:55 -0700295 // Vibrator pattern for haptic feedback of a context click.
296 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700297
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800298 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
299 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400300
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800301 boolean mSafeMode;
302 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700303 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400304 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400305 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700306 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400307 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
308 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
309 int[] mNavigationBarHeightForRotation = new int[4];
310 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400311
Craig Mautnera631d492014-08-05 15:16:01 -0700312 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800313 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700314 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700315 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700316 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700317 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
318 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
319 }
320 };
321 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
322 @Override
323 public void onShown(IBinder windowToken) {
324 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
325 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
326 }
327 };
328
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800329 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800330 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900331 WindowState mLastInputMethodWindow = null;
332 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800333
Jeff Brown13f00f02014-10-31 14:45:50 -0700334 // FIXME This state is shared between the input reader and handler thread.
335 // Technically it's broken and buggy but it has been like this for many years
336 // and we have not yet seen any problems. Someday we'll rewrite this logic
337 // so that only one thread is involved in handling input policy. Unfortunately
338 // it's on a critical path for power management so we can't just post the work to the
339 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
340 // to hold wakelocks during dispatch and eliminating the critical path.
341 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800342 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700343 volatile int mPowerKeyPressCounter;
344 volatile boolean mEndCallKeyHandled;
345
Winson Chungd42a6cf2014-06-03 16:24:04 -0700346 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700347 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700348 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800349
Jeff Brown2e7760e2012-04-11 15:14:55 -0700350 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700351 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700352 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800353
Dianne Hackbornc777e072010-02-12 13:07:59 -0800354 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700355 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800356 boolean mHdmiPlugged;
Jinsuk Kime601b712015-07-07 08:01:02 +0900357 HdmiControl mHdmiControl;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700358 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400359 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700360 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700361 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400362 int mCarDockRotation;
363 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700364 int mUndockedHdmiRotation;
365 int mDemoHdmiRotation;
366 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800367 int mDemoRotation;
368 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400369
Jeff Browna20dda42014-05-27 20:57:24 -0700370 boolean mWakeGestureEnabledSetting;
371 MyWakeGestureListener mWakeGestureListener;
372
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700373 // Default display does not rotate, apps that require non-default orientation will have to
374 // have the orientation emulated.
375 private boolean mForceDefaultOrientation = false;
376
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400377 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
378 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700379 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400380
Jeff Brownbcdfc622014-03-06 19:13:04 -0800381 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700382 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400383 boolean mCarDockEnablesAccelerometer;
384 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700385 int mLidKeyboardAccessibility;
386 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700387 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700388 int mShortPressOnPowerBehavior;
389 int mLongPressOnPowerBehavior;
390 int mDoublePressOnPowerBehavior;
391 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000392 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700393 boolean mAwake;
394 boolean mScreenOnEarly;
395 boolean mScreenOnFully;
396 ScreenOnListener mScreenOnListener;
397 boolean mKeyguardDrawComplete;
398 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800399 boolean mOrientationSensorEnabled = false;
400 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800401 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400402 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800403 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700404
Jeff Brown70825162012-03-28 17:27:48 -0700405 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800406
407 // The last window we were told about in focusChanged.
408 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800409 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800410
Jeff Brown70825162012-03-28 17:27:48 -0700411 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800412
Dianne Hackbornc652de82013-02-15 16:32:56 -0800413 // The current size of the screen; really; extends into the overscan area of
414 // the screen and doesn't account for any system elements like the status bar.
415 int mOverscanScreenLeft, mOverscanScreenTop;
416 int mOverscanScreenWidth, mOverscanScreenHeight;
417 // The current visible size of the screen; really; (ir)regardless of whether the status
418 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800419 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
420 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800421 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
422 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
423 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700424 // The current size of the screen; these may be different than (0,0)-(dw,dh)
425 // if the status bar can't be hidden; in that case it effectively carves out
426 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800427 int mRestrictedScreenLeft, mRestrictedScreenTop;
428 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700429 // During layout, the current screen borders accounting for any currently
430 // visible system UI elements.
431 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700432 // For applications requesting stable content insets, these are them.
433 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700434 // For applications requesting stable content insets but have also set the
435 // fullscreen window flag, these are the stable dimensions without the status bar.
436 int mStableFullscreenLeft, mStableFullscreenTop;
437 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800438 // During layout, the current screen borders with all outer decoration
439 // (status bar, input method dock) accounted for.
440 int mCurLeft, mCurTop, mCurRight, mCurBottom;
441 // During layout, the frame in which content should be displayed
442 // to the user, accounting for all screen decoration except for any
443 // space they deem as available for other content. This is usually
444 // the same as mCur*, but may be larger if the screen decor has supplied
445 // content insets.
446 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700447 // During layout, the frame in which voice content should be displayed
448 // to the user, accounting for all screen decoration except for any
449 // space they deem as available for other content.
450 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800451 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800452 // windows are placed.
453 int mDockLeft, mDockTop, mDockRight, mDockBottom;
454 // During layout, the layer at which the doc window is placed.
455 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700456 // During layout, this is the layer of the status bar.
457 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700458 int mLastSystemUiFlags;
459 // Bits that we are in the process of clearing, so we want to prevent
460 // them from being set by applications until everything has been updated
461 // to have them clear.
462 int mResettingSystemUiFlags = 0;
463 // Bits that we are currently always keeping cleared.
464 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800465 // What we last reported to system UI about whether the compatibility
466 // menu needs to be displayed.
467 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700468 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
469 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700470
Selim Cinekf83e8242015-05-19 18:08:14 -0700471 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700472
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800473 static final Rect mTmpParentFrame = new Rect();
474 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800475 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800476 static final Rect mTmpContentFrame = new Rect();
477 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400478 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700479 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700480 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700481 static final Rect mTmpOutsetFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700482
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800483 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100484 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700485 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200486 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400487 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800488 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700489 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700490 private boolean mForceStatusBarTransparent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700491 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800492 boolean mForcingShowNavBar;
493 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700494
495 // States of keyguard dismiss.
496 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
497 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
498 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
499 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
500
501 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
502 * be done once per window. */
503 private WindowState mWinDismissingKeyguard;
504
tingna_sunge785ffa2015-05-12 13:23:15 +0800505 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
506 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
507 * lock SIM card. This variable is used to record the previous keyguard secure state for
508 * monitoring secure state change on window dismissing keyguard. */
509 private boolean mSecureDismissingKeyguard;
510
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700511 /** The window that is currently showing "over" the keyguard. If there is an app window
512 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
513 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
514 * the wallpaper. */
515 private WindowState mWinShowWhenLocked;
516
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700517 boolean mShowingLockscreen;
518 boolean mShowingDream;
519 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700520 boolean mDreamingSleepTokenNeeded;
521 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700522 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700523 boolean mKeyguardSecure;
524 boolean mKeyguardSecureIncludingHidden;
525 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800526 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700527 boolean mHomeConsumed;
528 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800529 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700530 Intent mCarDockIntent;
531 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700532 boolean mSearchKeyShortcutPending;
533 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700534 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700535 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800536
Mike Lockwood28569302010-01-28 11:54:40 -0500537 // support for activating the lock screen while the screen is on
538 boolean mAllowLockscreenWhenOn;
539 int mLockScreenTimeout;
540 boolean mLockScreenTimerActive;
541
David Brownbaf8d092010-03-08 21:52:59 -0800542 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800543 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800544
545 // Behavior of POWER button while in-call and screen on.
546 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
547 int mIncallPowerBehavior;
548
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700549 Display mDisplay;
550
Dianne Hackborn9d132642011-04-21 17:26:39 -0700551 int mLandscapeRotation = 0; // default landscape rotation
552 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
553 int mPortraitRotation = 0; // default portrait rotation
554 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700555
Dianne Hackbornc652de82013-02-15 16:32:56 -0800556 int mOverscanLeft = 0;
557 int mOverscanTop = 0;
558 int mOverscanRight = 0;
559 int mOverscanBottom = 0;
560
Joe Onorato46b0d682010-11-22 17:37:27 -0800561 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700562 private int mLongPressOnHomeBehavior;
563
564 // What we do when the user double-taps on home
565 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800566
Bryce Lee584a4452014-10-21 15:55:55 -0700567 // Allowed theater mode wake actions
568 private boolean mAllowTheaterModeWakeFromKey;
569 private boolean mAllowTheaterModeWakeFromPowerKey;
570 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800571 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700572 private boolean mAllowTheaterModeWakeFromCameraLens;
573 private boolean mAllowTheaterModeWakeFromLidSwitch;
574 private boolean mAllowTheaterModeWakeFromWakeGesture;
575
Bryce Leed3b28402015-03-09 15:49:13 +0000576 // Whether to support long press from power button in non-interactive mode
577 private boolean mSupportLongPressPowerWhenNonInteractive;
578
Bryce Lee55e846d2014-11-04 12:43:44 -0800579 // Whether to go to sleep entering theater mode from power button
580 private boolean mGoToSleepOnButtonPressTheaterMode;
581
Winson Chung9112ec32011-06-27 13:15:32 -0700582 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700583 // Time to volume and power must be pressed within this interval of each other.
584 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700585 // Increase the chord delay when taking a screenshot from the keyguard
586 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800587 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700588 private boolean mScreenshotChordVolumeDownKeyTriggered;
589 private long mScreenshotChordVolumeDownKeyTime;
590 private boolean mScreenshotChordVolumeDownKeyConsumed;
591 private boolean mScreenshotChordVolumeUpKeyTriggered;
592 private boolean mScreenshotChordPowerKeyTriggered;
593 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700594
Michael Wrightb854e242013-02-05 17:54:02 -0800595 /* The number of steps between min and max brightness */
596 private static final int BRIGHTNESS_STEPS = 10;
597
Christopher Tate5e08af02012-09-21 17:17:22 -0700598 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800599 ShortcutManager mShortcutManager;
600 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700601 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700602 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800603
Craig Mautnerd625ab22013-09-06 13:40:31 -0700604 private int mCurrentUserId;
605
Justin Kohd378ad72013-04-01 12:18:26 -0700606 // Maps global key codes to the components that will handle them.
607 private GlobalKeyManager mGlobalKeyManager;
608
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700609 // Fallback actions by key code.
610 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
611 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800612
Jorim Jaggi76a16232014-08-08 17:00:47 +0200613 private final LogDecelerateInterpolator mLogDecelerateInterpolator
614 = new LogDecelerateInterpolator(100, 0);
615
Jeff Brown70825162012-03-28 17:27:48 -0700616 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
617 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700618 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
619 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700620 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
621 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
622 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700623 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700624 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700625 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700626 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700627 private static final int MSG_POWER_DELAYED_PRESS = 13;
628 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700629 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jeff Brown70825162012-03-28 17:27:48 -0700630
631 private class PolicyHandler extends Handler {
632 @Override
633 public void handleMessage(Message msg) {
634 switch (msg.what) {
635 case MSG_ENABLE_POINTER_LOCATION:
636 enablePointerLocation();
637 break;
638 case MSG_DISABLE_POINTER_LOCATION:
639 disablePointerLocation();
640 break;
Jeff Brown40013652012-05-16 21:22:36 -0700641 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
642 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
643 break;
644 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
645 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
646 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700647 case MSG_DISPATCH_SHOW_RECENTS:
648 showRecentApps(false);
649 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700650 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
651 showGlobalActionsInternal();
652 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700653 case MSG_KEYGUARD_DRAWN_COMPLETE:
654 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700655 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700656 break;
657 case MSG_KEYGUARD_DRAWN_TIMEOUT:
658 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700659 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700660 break;
661 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
662 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700663 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700664 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700665 case MSG_HIDE_BOOT_MESSAGE:
666 handleHideBootMessage();
667 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700668 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
669 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
670 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700671 case MSG_POWER_DELAYED_PRESS:
672 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
673 finishPowerKeyPress();
674 break;
675 case MSG_POWER_LONG_PRESS:
676 powerLongPress();
677 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700678 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
679 updateDreamingSleepToken(msg.arg1 != 0);
680 break;
Jeff Brown70825162012-03-28 17:27:48 -0700681 }
682 }
683 }
684
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800685 private UEventObserver mHDMIObserver = new UEventObserver() {
686 @Override
687 public void onUEvent(UEventObserver.UEvent event) {
688 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
689 }
690 };
691
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800692 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800693 SettingsObserver(Handler handler) {
694 super(handler);
695 }
David Brownbaf8d092010-03-08 21:52:59 -0800696
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800697 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700698 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800699 ContentResolver resolver = mContext.getContentResolver();
700 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700701 Settings.System.END_BUTTON_BEHAVIOR), false, this,
702 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800703 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700704 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
705 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700706 resolver.registerContentObserver(Settings.Secure.getUriFor(
707 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
708 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800709 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700710 Settings.System.ACCELEROMETER_ROTATION), false, this,
711 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500712 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700713 Settings.System.USER_ROTATION), false, this,
714 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400715 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700716 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
717 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800718 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700719 Settings.System.POINTER_LOCATION), false, this,
720 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800721 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700722 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
723 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500724 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400725 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700726 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500727 resolver.registerContentObserver(Settings.Global.getUriFor(
728 Settings.Global.POLICY_CONTROL), false, this,
729 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800730 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800731 }
732
733 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800734 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700735 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800736 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800737 }
Craig Mautner967212c2013-04-13 21:10:58 -0700738
Jeff Browna20dda42014-05-27 20:57:24 -0700739 class MyWakeGestureListener extends WakeGestureListener {
740 MyWakeGestureListener(Context context, Handler handler) {
741 super(context, handler);
742 }
743
744 @Override
745 public void onWakeUp() {
746 synchronized (mLock) {
747 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700748 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700749 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700750 }
751 }
752 }
753 }
754
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800755 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800756 MyOrientationListener(Context context, Handler handler) {
757 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800758 }
Craig Mautner967212c2013-04-13 21:10:58 -0700759
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800760 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700761 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700762 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700763 updateRotation(false);
764 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800765 }
766 MyOrientationListener mOrientationListener;
767
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100768 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400769
John Spurlock27735a42013-08-14 17:57:38 -0400770 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400771 View.NAVIGATION_BAR_TRANSIENT,
772 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400773 View.NAVIGATION_BAR_TRANSLUCENT,
774 StatusBarManager.WINDOW_NAVIGATION_BAR,
775 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400776
John Spurlockf1a36642013-10-12 17:50:42 -0400777 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400778
Craig Mautner037aa8d2013-06-07 10:35:44 -0700779 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400780
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700781 IStatusBarService getStatusBarService() {
782 synchronized (mServiceAquireLock) {
783 if (mStatusBarService == null) {
784 mStatusBarService = IStatusBarService.Stub.asInterface(
785 ServiceManager.getService("statusbar"));
786 }
787 return mStatusBarService;
788 }
789 }
790
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700791 /*
792 * We always let the sensor be switched on by default except when
793 * the user has explicitly disabled sensor based rotation or when the
794 * screen is switched off.
795 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700796 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800797 if (mSupportAutoRotation) {
798 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
799 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
800 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
801 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
802 // If the application has explicitly requested to follow the
803 // orientation, then we need to turn the sensor on.
804 return true;
805 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800806 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700807 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800808 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
809 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
810 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400811 // enable accelerometer if we are docked in a dock that enables accelerometer
812 // orientation management,
813 return true;
814 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700815 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800816 // If the setting for using the sensor by default is enabled, then
817 // we will always leave it on. Note that the user could go to
818 // a window that forces an orientation that does not use the
819 // sensor and in theory we could turn it off... however, when next
820 // turning it on we won't have a good value for the current
821 // orientation for a little bit, which can cause orientation
822 // changes to lag, so we'd like to keep it always on. (It will
823 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700824 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800825 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800826 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800827 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700828
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800829 /*
830 * Various use cases for invoking this function
831 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700832 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800833 * if not already enabled
834 * screen turned on and current app does not have sensor orientation, disable listeners if
835 * already enabled
836 * screen turning on and current app has sensor based orientation, enable listeners if needed
837 * screen turning on and current app has nosensor based orientation, do nothing
838 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700839 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800840 if (!mOrientationListener.canDetectOrientation()) {
841 // If sensor is turned off or nonexistent for some reason
842 return;
843 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000844 // Could have been invoked due to screen turning on or off or
845 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -0700846 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
847 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000848 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
849 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
850 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800851 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000852 // Note: We postpone the rotating of the screen until the keyguard as well as the
853 // window manager have reported a draw complete.
854 if (mScreenOnEarly && mAwake &&
855 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700856 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800857 disable = false;
858 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700859 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800860 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700861 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800862 mOrientationSensorEnabled = true;
863 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700864 }
865 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800866 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700867 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800868 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700869 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800870 mOrientationSensorEnabled = false;
871 }
872 }
873
Jeff Brown13f00f02014-10-31 14:45:50 -0700874 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
875 // Hold a wake lock until the power key is released.
876 if (!mPowerKeyWakeLock.isHeld()) {
877 mPowerKeyWakeLock.acquire();
878 }
879
880 // Cancel multi-press detection timeout.
881 if (mPowerKeyPressCounter != 0) {
882 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
883 }
884
885 // Detect user pressing the power button in panic when an application has
886 // taken over the whole screen.
887 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800888 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700889 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700890 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700891 }
892
893 // Latch power key state to detect screenshot chord.
894 if (interactive && !mScreenshotChordPowerKeyTriggered
895 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
896 mScreenshotChordPowerKeyTriggered = true;
897 mScreenshotChordPowerKeyTime = event.getDownTime();
898 interceptScreenshotChord();
899 }
900
901 // Stop ringing or end call if configured to do so when power is pressed.
902 TelecomManager telecomManager = getTelecommService();
903 boolean hungUp = false;
904 if (telecomManager != null) {
905 if (telecomManager.isRinging()) {
906 // Pressing Power while there's a ringing incoming
907 // call should silence the ringer.
908 telecomManager.silenceRinger();
909 } else if ((mIncallPowerBehavior
910 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
911 && telecomManager.isInCall() && interactive) {
912 // Otherwise, if "Power button ends call" is enabled,
913 // the Power button will hang up any current active call.
914 hungUp = telecomManager.endCall();
915 }
916 }
917
918 // If the power key has still not yet been handled, then detect short
919 // press, long press, or multi press and decide what to do.
920 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
921 || mScreenshotChordVolumeUpKeyTriggered;
922 if (!mPowerKeyHandled) {
923 if (interactive) {
924 // When interactive, we're already awake.
925 // Wait for a long press or for the button to be released to decide what to do.
926 if (hasLongPressOnPowerBehavior()) {
927 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
928 msg.setAsynchronous(true);
929 mHandler.sendMessageDelayed(msg,
930 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
931 }
932 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800933 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800934
Bryce Leed3b28402015-03-09 15:49:13 +0000935 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
936 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
937 msg.setAsynchronous(true);
938 mHandler.sendMessageDelayed(msg,
939 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800940 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000941 } else {
942 final int maxCount = getMaxMultiPressPowerCount();
943
944 if (maxCount <= 1) {
945 mPowerKeyHandled = true;
946 } else {
947 mBeganFromNonInteractive = true;
948 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700949 }
950 }
Jeff Brown4d396052010-10-29 21:50:21 -0700951 }
952 }
953
Jeff Brown13f00f02014-10-31 14:45:50 -0700954 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
955 final boolean handled = canceled || mPowerKeyHandled;
956 mScreenshotChordPowerKeyTriggered = false;
957 cancelPendingScreenshotChordAction();
958 cancelPendingPowerKeyAction();
959
960 if (!handled) {
961 // Figure out how to handle the key now that it has been released.
962 mPowerKeyPressCounter += 1;
963
964 final int maxCount = getMaxMultiPressPowerCount();
965 final long eventTime = event.getDownTime();
966 if (mPowerKeyPressCounter < maxCount) {
967 // This could be a multi-press. Wait a little bit longer to confirm.
968 // Continue holding the wake lock.
969 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
970 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
971 msg.setAsynchronous(true);
972 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
973 return;
974 }
975
976 // No other actions. Handle it immediately.
977 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700978 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700979
980 // Done. Reset our state.
981 finishPowerKeyPress();
982 }
983
984 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800985 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700986 mPowerKeyPressCounter = 0;
987 if (mPowerKeyWakeLock.isHeld()) {
988 mPowerKeyWakeLock.release();
989 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700990 }
991
992 private void cancelPendingPowerKeyAction() {
993 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700994 mPowerKeyHandled = true;
995 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700996 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700997 }
998
999 private void powerPress(long eventTime, boolean interactive, int count) {
1000 if (mScreenOnEarly && !mScreenOnFully) {
1001 Slog.i(TAG, "Suppressed redundant power key press while "
1002 + "already in the process of turning the screen on.");
1003 return;
Jeff Brownff204712011-10-25 21:27:54 -07001004 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001005
1006 if (count == 2) {
1007 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1008 } else if (count == 3) {
1009 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001010 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001011 switch (mShortPressOnPowerBehavior) {
1012 case SHORT_PRESS_POWER_NOTHING:
1013 break;
1014 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1015 mPowerManager.goToSleep(eventTime,
1016 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1017 break;
1018 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1019 mPowerManager.goToSleep(eventTime,
1020 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1021 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1022 break;
1023 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1024 mPowerManager.goToSleep(eventTime,
1025 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1026 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1027 launchHomeFromHotKey();
1028 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001029 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001030 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001031 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001032 }
1033 }
1034 }
1035
1036 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1037 switch (behavior) {
1038 case MULTI_PRESS_POWER_NOTHING:
1039 break;
1040 case MULTI_PRESS_POWER_THEATER_MODE:
1041 if (isTheaterModeEnabled()) {
1042 Slog.i(TAG, "Toggling theater mode off.");
1043 Settings.Global.putInt(mContext.getContentResolver(),
1044 Settings.Global.THEATER_MODE_ON, 0);
1045 if (!interactive) {
1046 wakeUpFromPowerKey(eventTime);
1047 }
1048 } else {
1049 Slog.i(TAG, "Toggling theater mode on.");
1050 Settings.Global.putInt(mContext.getContentResolver(),
1051 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001052
1053 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001054 mPowerManager.goToSleep(eventTime,
1055 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1056 }
1057 }
1058 break;
1059 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001060 Slog.i(TAG, "Starting brightness boost.");
1061 if (!interactive) {
1062 wakeUpFromPowerKey(eventTime);
1063 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001064 mPowerManager.boostScreenBrightness(eventTime);
1065 break;
1066 }
1067 }
1068
1069 private int getMaxMultiPressPowerCount() {
1070 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1071 return 3;
1072 }
1073 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1074 return 2;
1075 }
1076 return 1;
1077 }
1078
1079 private void powerLongPress() {
1080 final int behavior = getResolvedLongPressOnPowerBehavior();
1081 switch (behavior) {
1082 case LONG_PRESS_POWER_NOTHING:
1083 break;
1084 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1085 mPowerKeyHandled = true;
1086 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1087 performAuditoryFeedbackForAccessibilityIfNeed();
1088 }
1089 showGlobalActionsInternal();
1090 break;
1091 case LONG_PRESS_POWER_SHUT_OFF:
1092 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1093 mPowerKeyHandled = true;
1094 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1095 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1096 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1097 break;
1098 }
1099 }
1100
Nick Vaccarob593a812015-05-15 11:23:05 -07001101 private void sleepPress(long eventTime) {
1102 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1103 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1104 }
1105 }
1106
1107 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001108 switch (mShortPressOnSleepBehavior) {
1109 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001110 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001111 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1112 mPowerManager.goToSleep(eventTime,
1113 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001114 break;
1115 }
1116 }
1117
Jeff Brown13f00f02014-10-31 14:45:50 -07001118 private int getResolvedLongPressOnPowerBehavior() {
1119 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1120 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1121 }
1122 return mLongPressOnPowerBehavior;
1123 }
1124
1125 private boolean hasLongPressOnPowerBehavior() {
1126 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001127 }
1128
1129 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001130 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001131 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1132 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001133 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001134 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1135 && now <= mScreenshotChordPowerKeyTime
1136 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1137 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001138 cancelPendingPowerKeyAction();
1139
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001140 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001141 }
1142 }
1143 }
1144
Winson Chung1cea2f32012-10-08 20:42:01 -07001145 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001146 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001147 // Double the time it takes to take a screenshot from the keyguard
1148 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001149 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001150 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001151 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001152 }
1153
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001154 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001155 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001156 }
1157
Jeff Brown13f00f02014-10-31 14:45:50 -07001158 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001159 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001160 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001161 mEndCallKeyHandled = true;
1162 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1163 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001164 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001165 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001166 }
1167 };
1168
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001169 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001170 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001171 public void run() {
1172 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001173 }
1174 };
1175
Alan Viverettee34560b22014-07-10 14:50:06 -07001176 @Override
1177 public void showGlobalActions() {
1178 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1179 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1180 }
1181
1182 void showGlobalActionsInternal() {
1183 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001184 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001185 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001186 }
Jim Millerab954542014-10-10 18:21:49 -07001187 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001188 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1189 if (keyguardShowing) {
1190 // since it took two seconds of long press to bring this up,
1191 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001192 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001193 }
1194 }
1195
1196 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001197 return Settings.Global.getInt(
1198 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001199 }
1200
Maurice Lam99c6e072014-04-28 18:24:28 -07001201 boolean isUserSetupComplete() {
1202 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1203 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1204 }
1205
Jeff Brown13f00f02014-10-31 14:45:50 -07001206 private void handleShortPressOnHome() {
Jinsuk Kime601b712015-07-07 08:01:02 +09001207 // Turn on the connected TV and switch HDMI input if we're a HDMI playback device.
1208 getHdmiControl().turnOnTv();
1209
Jeff Brown13f00f02014-10-31 14:45:50 -07001210 // If there's a dream running then use home to escape the dream
1211 // but don't actually go home.
1212 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1213 mDreamManagerInternal.stopDream(false /*immediate*/);
1214 return;
1215 }
1216
1217 // Go home!
1218 launchHomeFromHotKey();
1219 }
1220
Jinsuk Kime601b712015-07-07 08:01:02 +09001221 /**
1222 * Creates an accessor to HDMI control service that performs the operation of
1223 * turning on TV (optional) and switching input to us. If HDMI control service
1224 * is not available or we're not a HDMI playback device, the operation is no-op.
1225 */
1226 private HdmiControl getHdmiControl() {
1227 if (null == mHdmiControl) {
1228 HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService(
1229 Context.HDMI_CONTROL_SERVICE);
1230 HdmiPlaybackClient client = null;
1231 if (manager != null) {
1232 client = manager.getPlaybackClient();
1233 }
1234 mHdmiControl = new HdmiControl(client);
1235 }
1236 return mHdmiControl;
1237 }
1238
1239 private static class HdmiControl {
1240 private final HdmiPlaybackClient mClient;
1241
1242 private HdmiControl(HdmiPlaybackClient client) {
1243 mClient = client;
1244 }
1245
1246 public void turnOnTv() {
1247 if (mClient == null) {
1248 return;
1249 }
1250 mClient.oneTouchPlay(new OneTouchPlayCallback() {
1251 @Override
1252 public void onComplete(int result) {
1253 if (result != HdmiControlManager.RESULT_SUCCESS) {
1254 Log.w(TAG, "One touch play failed: " + result);
1255 }
1256 }
1257 });
1258 }
1259 }
1260
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001261 private void handleLongPressOnHome(int deviceId) {
Joe Onorato46b0d682010-11-22 17:37:27 -08001262 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001263 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001264 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001265
Jeff Browncaca8812013-05-09 13:34:33 -07001266 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1267 toggleRecentApps();
1268 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001269 launchAssistAction(null, deviceId);
Jim Millere6ad1a82010-08-20 19:25:39 -07001270 }
1271 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001272 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001273
Jeff Browncaca8812013-05-09 13:34:33 -07001274 private void handleDoubleTapOnHome() {
1275 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1276 mHomeConsumed = true;
1277 toggleRecentApps();
1278 }
1279 }
1280
1281 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1282 @Override
1283 public void run() {
1284 if (mHomeDoubleTapPending) {
1285 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001286 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001287 }
1288 }
1289 };
1290
Mark Renoufc1256912015-03-11 14:38:23 -04001291 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001292 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001293 }
1294
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001295 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001296 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001297 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001298 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001299 mContext = context;
1300 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001301 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001302 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001303 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001304 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Mark Renoufc1256912015-03-11 14:38:23 -04001305
1306 // Init display burn-in protection
1307 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1308 com.android.internal.R.bool.config_enableBurnInProtection);
1309 // Allow a system property to override this. Used by developer settings.
1310 boolean burnInProtectionDevMode =
1311 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1312 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1313 final int minHorizontal;
1314 final int maxHorizontal;
1315 final int minVertical;
1316 final int maxVertical;
1317 final int maxRadius;
1318 if (burnInProtectionDevMode) {
1319 minHorizontal = -8;
1320 maxHorizontal = 8;
1321 minVertical = -8;
1322 maxVertical = -4;
1323 maxRadius = (isRoundWindow()) ? 6 : -1;
1324 } else {
1325 Resources resources = context.getResources();
1326 minHorizontal = resources.getInteger(
1327 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1328 maxHorizontal = resources.getInteger(
1329 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1330 minVertical = resources.getInteger(
1331 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1332 maxVertical = resources.getInteger(
1333 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1334 maxRadius = resources.getInteger(
1335 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1336 }
1337 mBurnInProtectionHelper = new BurnInProtectionHelper(
1338 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001339 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001340
Jeff Brown70825162012-03-28 17:27:48 -07001341 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001342 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001343 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001344 try {
1345 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1346 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001347 mSettingsObserver = new SettingsObserver(mHandler);
1348 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001349 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001350 mUiMode = context.getResources().getInteger(
1351 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001352 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1353 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1354 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1355 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001356 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1357 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1358 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1359 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1360 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1361 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1362 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1363 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001364
Jeff Brown96307042012-07-27 15:51:34 -07001365 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1366 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001367 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001368 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1369 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001370 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001371 mSupportAutoRotation = mContext.getResources().getBoolean(
1372 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001373 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001374 com.android.internal.R.integer.config_lidOpenRotation);
1375 mCarDockRotation = readRotation(
1376 com.android.internal.R.integer.config_carDockRotation);
1377 mDeskDockRotation = readRotation(
1378 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001379 mUndockedHdmiRotation = readRotation(
1380 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001381 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1382 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1383 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1384 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001385 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1386 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1387 mLidNavigationAccessibility = mContext.getResources().getInteger(
1388 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001389 mLidControlsSleep = mContext.getResources().getBoolean(
1390 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001391 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1392 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001393
1394 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1395 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1396 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1397 || mContext.getResources().getBoolean(
1398 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1399 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1400 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001401 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1402 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001403 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1404 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1405 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1406 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1407 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1408 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1409
Bryce Lee55e846d2014-11-04 12:43:44 -08001410 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1411 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1412
Bryce Leed3b28402015-03-09 15:49:13 +00001413 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1414 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1415
Jeff Brown13f00f02014-10-31 14:45:50 -07001416 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1417 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1418 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1419 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1420 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1421 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1422 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1423 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001424 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1425 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001426
John Spurlock61560172015-02-06 19:46:04 -05001427 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001428
Jeff Brownf71343d2013-05-31 17:59:11 -07001429 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001430
Svetoslav8e3feb12014-02-24 13:46:47 -08001431 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1432 Context.ACCESSIBILITY_SERVICE);
1433
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001434 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001435 IntentFilter filter = new IntentFilter();
1436 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1437 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1438 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1439 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001440 filter.addAction(Intent.ACTION_DOCK_EVENT);
1441 Intent intent = context.registerReceiver(mDockReceiver, filter);
1442 if (intent != null) {
1443 // Retrieve current sticky dock event broadcast.
1444 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1445 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1446 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001447
Jeff Brown6aaf2952012-10-05 16:01:08 -07001448 // register for dream-related broadcasts
1449 filter = new IntentFilter();
1450 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1451 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1452 context.registerReceiver(mDreamReceiver, filter);
1453
Christopher Tate5e08af02012-09-21 17:17:22 -07001454 // register for multiuser-relevant broadcasts
1455 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1456 context.registerReceiver(mMultiuserReceiver, filter);
1457
John Spurlock57306e62013-04-22 09:48:49 -04001458 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001459 mSystemGestures = new SystemGesturesPointerEventListener(context,
1460 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001461 @Override
1462 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001463 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001464 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001465 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001466 }
1467 @Override
1468 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001469 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001470 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001471 }
1472 }
1473 @Override
1474 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001475 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001476 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001477 }
1478 }
1479 @Override
1480 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001481 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001482 }
Adrian Roos3595be42015-03-05 16:31:15 +01001483 @Override
1484 public void onDown() {
1485 mOrientationListener.onTouchStart();
1486 }
1487 @Override
1488 public void onUpOrCancel() {
1489 mOrientationListener.onTouchEnd();
1490 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001491 });
John Spurlockf1a36642013-10-12 17:50:42 -04001492 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001493 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001494
Jeff Brownc2346132012-04-13 01:55:38 -07001495 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001496 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1497 com.android.internal.R.array.config_longPressVibePattern);
1498 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1499 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001500 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1501 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001502 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1503 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001504 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1505 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001506 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1507 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1508 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1509 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001510 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1511 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001512
Christopher Tatee90585f2012-03-05 18:56:25 -08001513 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1514 com.android.internal.R.bool.config_enableScreenshotChord);
1515
Justin Kohd378ad72013-04-01 12:18:26 -07001516 mGlobalKeyManager = new GlobalKeyManager(mContext);
1517
Joe Onoratoea495d42011-04-06 11:41:11 -07001518 // Controls rotation and the like.
1519 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001520
1521 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001522 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001523 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1524 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001525 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001526
1527 mWindowManagerInternal.registerAppTransitionListener(
1528 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001529 }
1530
Jeff Brownf71343d2013-05-31 17:59:11 -07001531 /**
1532 * Read values from config.xml that may be overridden depending on
1533 * the configuration of the device.
1534 * eg. Disable long press on home goes to recents on sw600dp.
1535 */
1536 private void readConfigurationDependentBehaviors() {
1537 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1538 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1539 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1540 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1541 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1542 }
1543
1544 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1545 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1546 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1547 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1548 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1549 }
1550 }
1551
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001552 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001553 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001554 // This method might be called before the policy has been fully initialized
1555 // or for other displays we don't care about.
1556 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1557 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001558 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001559 mDisplay = display;
1560
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001561 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001562 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001563 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001564 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001565 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001566 mLandscapeRotation = Surface.ROTATION_0;
1567 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001568 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001569 mPortraitRotation = Surface.ROTATION_90;
1570 mUpsideDownRotation = Surface.ROTATION_270;
1571 } else {
1572 mPortraitRotation = Surface.ROTATION_270;
1573 mUpsideDownRotation = Surface.ROTATION_90;
1574 }
1575 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001576 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001577 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001578 mPortraitRotation = Surface.ROTATION_0;
1579 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001580 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001581 mLandscapeRotation = Surface.ROTATION_270;
1582 mSeascapeRotation = Surface.ROTATION_90;
1583 } else {
1584 mLandscapeRotation = Surface.ROTATION_90;
1585 mSeascapeRotation = Surface.ROTATION_270;
1586 }
1587 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001588
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001589 mStatusBarHeight =
1590 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001591
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001592 // Height of the navigation bar when presented horizontally at bottom
1593 mNavigationBarHeightForRotation[mPortraitRotation] =
1594 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001595 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001596 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001597 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1598 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001599
1600 // Width of the navigation bar when presented vertically along one side
1601 mNavigationBarWidthForRotation[mPortraitRotation] =
1602 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1603 mNavigationBarWidthForRotation[mLandscapeRotation] =
1604 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001605 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001606
1607 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001608 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001609 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001610
Devin Kimd7b12b42014-05-05 14:34:58 -07001611 // Allow the navigation bar to move on non-square small devices (phones).
1612 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001613
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001614 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001615 // Allow a system property to override this. Used by the emulator.
1616 // See also hasNavigationBar().
1617 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1618 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001619 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001620 } else if ("0".equals(navBarOverride)) {
1621 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001622 }
1623
Jeff Brown27f1d672012-10-17 18:32:34 -07001624 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1625 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001626 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001627 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001628 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001629 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001630 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001631 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001632
Chong Zhangae6119ff2014-11-11 18:54:39 -08001633 // For demo purposes, allow the rotation of the remote display to be controlled.
1634 // By default, remote display locks rotation to landscape.
1635 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1636 mDemoRotation = mPortraitRotation;
1637 } else {
1638 mDemoRotation = mLandscapeRotation;
1639 }
1640 mDemoRotationLock = SystemProperties.getBoolean(
1641 "persist.demo.rotationlock", false);
1642
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001643 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1644 // http://developer.android.com/guide/practices/screens_support.html#range
1645 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1646 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1647 // For debug purposes the next line turns this feature off with:
1648 // $ adb shell setprop config.override_forced_orient true
1649 // $ adb shell wm size reset
1650 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1651 }
1652
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001653 /**
1654 * @return whether the navigation bar can be hidden, e.g. the device has a
1655 * navigation bar and touch exploration is not enabled
1656 */
1657 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001658 return mHasNavigationBar
1659 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001660 }
1661
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001662 @Override
1663 public boolean isDefaultOrientationForced() {
1664 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001665 }
1666
Dianne Hackbornc652de82013-02-15 16:32:56 -08001667 @Override
1668 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1669 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1670 mOverscanLeft = left;
1671 mOverscanTop = top;
1672 mOverscanRight = right;
1673 mOverscanBottom = bottom;
1674 }
1675 }
1676
Dianne Hackbornc777e072010-02-12 13:07:59 -08001677 public void updateSettings() {
1678 ContentResolver resolver = mContext.getContentResolver();
1679 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001680 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001681 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001682 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001683 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1684 UserHandle.USER_CURRENT);
1685 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001686 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001687 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1688 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001689
Jeff Browna20dda42014-05-27 20:57:24 -07001690 // Configure wake gesture.
1691 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1692 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1693 UserHandle.USER_CURRENT) != 0;
1694 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1695 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1696 updateWakeGestureListenerLp();
1697 }
1698
Jeff Brown207673cd2012-06-05 17:47:11 -07001699 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001700 int userRotation = Settings.System.getIntForUser(resolver,
1701 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1702 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001703 if (mUserRotation != userRotation) {
1704 mUserRotation = userRotation;
1705 updateRotation = true;
1706 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001707 int userRotationMode = Settings.System.getIntForUser(resolver,
1708 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001709 WindowManagerPolicy.USER_ROTATION_FREE :
1710 WindowManagerPolicy.USER_ROTATION_LOCKED;
1711 if (mUserRotationMode != userRotationMode) {
1712 mUserRotationMode = userRotationMode;
1713 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001714 updateOrientationListenerLp();
1715 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001716
Dianne Hackbornc777e072010-02-12 13:07:59 -08001717 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001718 int pointerLocation = Settings.System.getIntForUser(resolver,
1719 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001720 if (mPointerLocationMode != pointerLocation) {
1721 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001722 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1723 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001724 }
1725 }
1726 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001727 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1728 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1729 String imId = Settings.Secure.getStringForUser(resolver,
1730 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001731 boolean hasSoftInput = imId != null && imId.length() > 0;
1732 if (mHasSoftInput != hasSoftInput) {
1733 mHasSoftInput = hasSoftInput;
1734 updateRotation = true;
1735 }
John Spurlockf1a36642013-10-12 17:50:42 -04001736 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001737 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001738 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001739 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001740 }
1741 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001742 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001743 }
Jeff Brown70825162012-03-28 17:27:48 -07001744 }
1745
Jeff Browna20dda42014-05-27 20:57:24 -07001746 private void updateWakeGestureListenerLp() {
1747 if (shouldEnableWakeGestureLp()) {
1748 mWakeGestureListener.requestWakeUpTrigger();
1749 } else {
1750 mWakeGestureListener.cancelWakeUpTrigger();
1751 }
1752 }
1753
1754 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001755 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001756 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1757 && mWakeGestureListener.isSupported();
1758 }
1759
Jeff Brown70825162012-03-28 17:27:48 -07001760 private void enablePointerLocation() {
1761 if (mPointerLocationView == null) {
1762 mPointerLocationView = new PointerLocationView(mContext);
1763 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001764 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1765 WindowManager.LayoutParams.MATCH_PARENT,
1766 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001767 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001768 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1769 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1770 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1771 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001772 if (ActivityManager.isHighEndGfx()) {
1773 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1774 lp.privateFlags |=
1775 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1776 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001777 lp.format = PixelFormat.TRANSLUCENT;
1778 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001779 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001780 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001781 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001782 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001783 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001784 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001785 }
Jeff Brown70825162012-03-28 17:27:48 -07001786
1787 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001788 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001789 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1790 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001791 wm.removeView(mPointerLocationView);
1792 mPointerLocationView = null;
1793 }
1794 }
1795
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001796 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001797 try {
1798 int rotation = mContext.getResources().getInteger(resID);
1799 switch (rotation) {
1800 case 0:
1801 return Surface.ROTATION_0;
1802 case 90:
1803 return Surface.ROTATION_90;
1804 case 180:
1805 return Surface.ROTATION_180;
1806 case 270:
1807 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001808 }
1809 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001810 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001811 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001812 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001813 }
1814
1815 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001816 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001817 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001818 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001819
1820 outAppOp[0] = AppOpsManager.OP_NONE;
1821
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001822 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1823 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1824 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1825 return WindowManagerGlobal.ADD_INVALID_TYPE;
1826 }
1827
1828 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1829 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001830 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001831 }
1832 String permission = null;
1833 switch (type) {
1834 case TYPE_TOAST:
1835 // XXX right now the app process has complete control over
1836 // this... should introduce a token to let the system
1837 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001838 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001839 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001840 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001841 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001842 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001843 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001844 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001845 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001846 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001847 break;
1848 case TYPE_PHONE:
1849 case TYPE_PRIORITY_PHONE:
1850 case TYPE_SYSTEM_ALERT:
1851 case TYPE_SYSTEM_ERROR:
1852 case TYPE_SYSTEM_OVERLAY:
1853 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001854 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001855 break;
1856 default:
1857 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1858 }
1859 if (permission != null) {
1860 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
Adrian Roos37d7a682014-11-06 18:15:16 +01003322 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3323 Rect outStableInsets) {
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
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003328 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003329 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003330 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003331 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003332 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003333 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3334 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3335 } else {
3336 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3337 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3338 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003339 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3340 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003341 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003342 availRight - mStableFullscreenRight,
3343 availBottom - mStableFullscreenBottom);
3344 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003345 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003346 availRight - mStableRight, availBottom - mStableBottom);
3347 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003348 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003349 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003350 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003351 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003352 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003353 availRight - mCurRight, availBottom - mCurBottom);
3354 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003355 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003356 availRight - mCurRight, availBottom - mCurBottom);
3357 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003358
3359 outStableInsets.set(mStableLeft, mStableTop,
3360 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003361 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003362 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003363 outContentInsets.setEmpty();
3364 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003365 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003366
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003367 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003368 @Override
3369 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3370 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003371 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3372 if (isDefaultDisplay) {
3373 switch (displayRotation) {
3374 case Surface.ROTATION_90:
3375 overscanLeft = mOverscanTop;
3376 overscanTop = mOverscanRight;
3377 overscanRight = mOverscanBottom;
3378 overscanBottom = mOverscanLeft;
3379 break;
3380 case Surface.ROTATION_180:
3381 overscanLeft = mOverscanRight;
3382 overscanTop = mOverscanBottom;
3383 overscanRight = mOverscanLeft;
3384 overscanBottom = mOverscanTop;
3385 break;
3386 case Surface.ROTATION_270:
3387 overscanLeft = mOverscanBottom;
3388 overscanTop = mOverscanLeft;
3389 overscanRight = mOverscanTop;
3390 overscanBottom = mOverscanRight;
3391 break;
3392 default:
3393 overscanLeft = mOverscanLeft;
3394 overscanTop = mOverscanTop;
3395 overscanRight = mOverscanRight;
3396 overscanBottom = mOverscanBottom;
3397 break;
3398 }
3399 } else {
3400 overscanLeft = 0;
3401 overscanTop = 0;
3402 overscanRight = 0;
3403 overscanBottom = 0;
3404 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003405 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3406 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3407 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3408 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003409 mSystemLeft = 0;
3410 mSystemTop = 0;
3411 mSystemRight = displayWidth;
3412 mSystemBottom = displayHeight;
3413 mUnrestrictedScreenLeft = overscanLeft;
3414 mUnrestrictedScreenTop = overscanTop;
3415 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3416 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3417 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3418 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003419 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3420 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003421 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003422 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003423 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003424 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003425 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003426 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003427 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003428 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003429 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003430 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003431
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003432 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3433 final Rect pf = mTmpParentFrame;
3434 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003435 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003436 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003437 final Rect dcf = mTmpDecorFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003438 final Rect osf = mTmpOutsetFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003439 pf.left = df.left = of.left = vf.left = mDockLeft;
3440 pf.top = df.top = of.top = vf.top = mDockTop;
3441 pf.right = df.right = of.right = vf.right = mDockRight;
3442 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003443 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003444
Craig Mautner69b08182012-09-05 13:07:13 -07003445 if (isDefaultDisplay) {
3446 // For purposes of putting out fake window up to steal focus, we will
3447 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003448 final int sysui = mLastSystemUiFlags;
3449 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003450 boolean navTranslucent = (sysui
3451 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003452 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3453 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3454 boolean navAllowedHidden = immersive || immersiveSticky;
3455 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003456 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3457 if (!isKeyguardShowing) {
3458 navTranslucent &= areTranslucentBarsAllowed();
3459 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003460
Craig Mautner69b08182012-09-05 13:07:13 -07003461 // When the navigation bar isn't visible, we put up a fake
3462 // input window to catch all touch events. This way we can
3463 // detect when the user presses anywhere to bring back the nav
3464 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003465 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003466 if (mInputConsumer != null) {
3467 mInputConsumer.dismiss();
3468 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003469 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003470 } else if (mInputConsumer == null) {
3471 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3472 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003473 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003474
Craig Mautner69b08182012-09-05 13:07:13 -07003475 // For purposes of positioning and showing the nav bar, if we have
3476 // decided that it can't be hidden (because of the screen aspect ratio),
3477 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003478 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003479
John Spurlockad3e6cb2013-04-30 08:47:43 -04003480 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003481 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003482 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003483 // Force the navigation bar to its appropriate place and
3484 // size. We need to do this directly, instead of relying on
3485 // it to bubble up from the nav bar, because this needs to
3486 // change atomically with screen rotations.
3487 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3488 if (mNavigationBarOnBottom) {
3489 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003490 int top = displayHeight - overscanBottom
3491 - mNavigationBarHeightForRotation[displayRotation];
3492 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003493 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003494 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003495 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003496 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003497 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003498 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003499 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3500 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003501 } else {
3502 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003503 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003504 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003505 if (navVisible && !navTranslucent && !navAllowedHidden
3506 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003507 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003508 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003509 // and not in the process of animating on or off, then
3510 // we can tell the app that it is covered by it.
3511 mSystemBottom = mTmpNavigationFrame.top;
3512 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003513 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003514 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003515 int left = displayWidth - overscanRight
3516 - mNavigationBarWidthForRotation[displayRotation];
3517 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003518 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003519 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003520 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003521 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003522 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003523 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003524 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3525 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003526 } else {
3527 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003528 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003529 }
John Spurlockbd957402013-10-03 11:38:39 -04003530 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3531 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003532 // If the nav bar is currently requested to be visible,
3533 // and not in the process of animating on or off, then
3534 // we can tell the app that it is covered by it.
3535 mSystemRight = mTmpNavigationFrame.left;
3536 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003537 }
Craig Mautner69b08182012-09-05 13:07:13 -07003538 // Make sure the content and current rectangles are updated to
3539 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003540 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3541 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3542 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3543 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003544 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3545 // And compute the final frame.
3546 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003547 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003548 mTmpNavigationFrame, mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003549 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003550 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003551 updateSysUiVisibility = true;
3552 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003553 }
Craig Mautnereda67292013-04-28 13:50:14 -07003554 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003555 mDockLeft, mDockTop, mDockRight, mDockBottom));
3556
3557 // decide where the status bar goes ahead of time
3558 if (mStatusBar != null) {
3559 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003560 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3561 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3562 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3563 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3564 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003565 vf.left = mStableLeft;
3566 vf.top = mStableTop;
3567 vf.right = mStableRight;
3568 vf.bottom = mStableBottom;
3569
3570 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3571
3572 // Let the status bar determine its size.
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003573 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3574 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3575 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
Craig Mautner69b08182012-09-05 13:07:13 -07003576
3577 // For layout, the status bar is always at the top with our fixed height.
3578 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3579
John Spurlocke1f366f2013-08-05 12:22:40 -04003580 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003581 boolean statusBarTranslucent = (sysui
3582 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003583 if (!isKeyguardShowing) {
3584 statusBarTranslucent &= areTranslucentBarsAllowed();
3585 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003586
Craig Mautner69b08182012-09-05 13:07:13 -07003587 // If the status bar is hidden, we don't want to cause
3588 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003589 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003590 // Status bar may go away, so the screen area it occupies
3591 // is available to apps but just covering them when the
3592 // status bar is visible.
3593 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3594
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003595 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3596 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3597 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3598 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003599
Craig Mautnereda67292013-04-28 13:50:14 -07003600 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003601 String.format(
3602 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3603 mDockLeft, mDockTop, mDockRight, mDockBottom,
3604 mContentLeft, mContentTop, mContentRight, mContentBottom,
3605 mCurLeft, mCurTop, mCurRight, mCurBottom));
3606 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003607 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003608 && !statusBarTransient && !statusBarTranslucent
3609 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003610 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003611 // and not in the process of animating on or off, then
3612 // we can tell the app that it is covered by it.
3613 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3614 }
John Spurlock27735a42013-08-14 17:57:38 -04003615 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003616 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003617 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003618 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003619 if (updateSysUiVisibility) {
3620 updateSystemUiVisibilityLw();
3621 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003622 }
3623 }
3624
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003625 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003626 @Override
John Spurlock46646232013-09-30 22:32:42 -04003627 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003628 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3629 return mStatusBar.getSurfaceLayer();
3630 }
3631
3632 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3633 return mNavigationBar.getSurfaceLayer();
3634 }
3635
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003636 return 0;
3637 }
3638
Craig Mautner967212c2013-04-13 21:10:58 -07003639 @Override
3640 public void getContentRectLw(Rect r) {
3641 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3642 }
3643
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003644 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3645 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003646 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3647 // Here's a special case: if this attached window is a panel that is
3648 // above the dock window, and the window it is attached to is below
3649 // the dock window, then the frames we computed for the window it is
3650 // attached to can not be used because the dock is effectively part
3651 // of the underlying window and the attached window is floating on top
3652 // of the whole thing. So, we ignore the attached window and explicitly
3653 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003654 df.left = of.left = cf.left = vf.left = mDockLeft;
3655 df.top = of.top = cf.top = vf.top = mDockTop;
3656 df.right = of.right = cf.right = vf.right = mDockRight;
3657 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003658 } else {
3659 // The effective display frame of the attached window depends on
3660 // whether it is taking care of insetting its content. If not,
3661 // we need to use the parent's content frame so that the entire
3662 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003663 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003664 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003665 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003666 // Set the content frame of the attached window to the parent's decor frame
3667 // (same as content frame when IME isn't present) if specifically requested by
3668 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3669 // Otherwise, use the overscan frame.
3670 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3671 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003672 } else {
3673 // If the window is resizing, then we want to base the content
3674 // frame on our attached content frame to resize... however,
3675 // things can be tricky if the attached window is NOT in resize
3676 // mode, in which case its content frame will be larger.
3677 // Ungh. So to deal with that, make sure the content frame
3678 // we end up using is not covering the IM dock.
3679 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003680 if (attached.isVoiceInteraction()) {
3681 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3682 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3683 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3684 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3685 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003686 if (cf.left < mContentLeft) cf.left = mContentLeft;
3687 if (cf.top < mContentTop) cf.top = mContentTop;
3688 if (cf.right > mContentRight) cf.right = mContentRight;
3689 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3690 }
3691 }
3692 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003693 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003694 vf.set(attached.getVisibleFrameLw());
3695 }
3696 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3697 // window should be positioned relative to its parent or the entire
3698 // screen.
3699 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3700 ? attached.getFrameLw() : df);
3701 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003702
3703 private void applyStableConstraints(int sysui, int fl, Rect r) {
3704 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3705 // If app is requesting a stable layout, don't let the
3706 // content insets go below the stable values.
3707 if ((fl & FLAG_FULLSCREEN) != 0) {
3708 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3709 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3710 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3711 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3712 } else {
3713 if (r.left < mStableLeft) r.left = mStableLeft;
3714 if (r.top < mStableTop) r.top = mStableTop;
3715 if (r.right > mStableRight) r.right = mStableRight;
3716 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3717 }
3718 }
3719 }
3720
Jorim Jaggiaa806142015-05-20 18:04:16 -07003721 private boolean canReceiveInput(WindowState win) {
3722 boolean notFocusable =
3723 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
3724 boolean altFocusableIm =
3725 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
3726 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
3727 return !notFocusableForIm;
3728 }
3729
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003730 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003731 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003732 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07003733 // We've already done the navigation bar and status bar. If the status bar can receive
3734 // input, we need to layout it again to accomodate for the IME window.
3735 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003736 return;
3737 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07003738 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07003739 final boolean isDefaultDisplay = win.isDefaultDisplay();
3740 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003741 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3742 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003743 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003744 offsetInputMethodWindowLw(mLastInputMethodWindow);
3745 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003746
John Spurlockc6d1c602014-01-17 15:22:06 -05003747 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003748 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003749 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003750
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003751 final Rect pf = mTmpParentFrame;
3752 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003753 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003754 final Rect cf = mTmpContentFrame;
3755 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003756 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003757 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003758 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04003759 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003760
3761 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003762 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003763
Craig Mautnerf683b562012-10-02 11:10:57 -07003764 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3765
Adrian Roosfa104232014-06-20 16:10:14 -07003766 if (isDefaultDisplay) {
3767 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3768 } else {
3769 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3770 }
3771
Craig Mautner69b08182012-09-05 13:07:13 -07003772 if (!isDefaultDisplay) {
3773 if (attached != null) {
3774 // If this window is attached to another, our display
3775 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003776 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003777 } else {
3778 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003779 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3780 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3781 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003782 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003783 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003784 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003785 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003786 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003787 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3788 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3789 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003790 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003791 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003792 // ...with content insets above the nav bar
3793 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003794 // IM dock windows always go to the bottom of the screen.
3795 attrs.gravity = Gravity.BOTTOM;
3796 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003797 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003798 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003799 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003800 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3801 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003802 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003803 // Note: In Phone landscape mode, the button bar should also be excluded.
3804 cf.right = vf.right = mStableRight;
3805 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003806 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07003807 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02003808 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3809 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3810 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3811 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3812 cf.left = vf.left = mStableLeft;
3813 cf.top = vf.top = mStableTop;
3814 cf.right = vf.right = mStableRight;
3815 vf.bottom = mStableBottom;
3816 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003817 } else {
John Spurlock46646232013-09-30 22:32:42 -04003818
3819 // Default policy decor for the default display
3820 dcf.left = mSystemLeft;
3821 dcf.top = mSystemTop;
3822 dcf.right = mSystemRight;
3823 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003824 final boolean inheritTranslucentDecor = (attrs.privateFlags
3825 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003826 final boolean isAppWindow =
3827 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3828 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3829 final boolean topAtRest =
3830 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3831 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003832 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3833 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003834 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3835 && (fl & WindowManager.LayoutParams.
3836 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003837 // Ensure policy decor includes status bar
3838 dcf.top = mStableTop;
3839 }
John Spurlockbd957402013-10-03 11:38:39 -04003840 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003841 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3842 && (fl & WindowManager.LayoutParams.
3843 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003844 // Ensure policy decor includes navigation bar
3845 dcf.bottom = mStableBottom;
3846 dcf.right = mStableRight;
3847 }
3848 }
3849
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003850 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3851 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003852 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003853 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003854 // This is the case for a normal activity window: we want it
3855 // to cover all of the screen space, and it can take care of
3856 // moving its contents to account for screen decorations that
3857 // intrude into that space.
3858 if (attached != null) {
3859 // If this window is attached to another, our display
3860 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003861 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003862 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003863 if (attrs.type == TYPE_STATUS_BAR_PANEL
3864 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003865 // Status bar panels are the only windows who can go on top of
3866 // the status bar. They are protected by the STATUS_BAR_SERVICE
3867 // permission, so they have the same privileges as the status
3868 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003869 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003870 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003871
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003872 pf.left = df.left = of.left = hasNavBar
3873 ? mDockLeft : mUnrestrictedScreenLeft;
3874 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3875 pf.right = df.right = of.right = hasNavBar
3876 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3877 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3878 pf.bottom = df.bottom = of.bottom = hasNavBar
3879 ? mRestrictedScreenTop+mRestrictedScreenHeight
3880 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003881
Craig Mautnereda67292013-04-28 13:50:14 -07003882 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003883 "Laying out status bar window: (%d,%d - %d,%d)",
3884 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003885 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003886 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3887 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3888 // Asking to layout into the overscan region, so give it that pure
3889 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003890 pf.left = df.left = of.left = mOverscanScreenLeft;
3891 pf.top = df.top = of.top = mOverscanScreenTop;
3892 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3893 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3894 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003895 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003896 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003897 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3898 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003899 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003900 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003901 // only do this for application windows to ensure no window that
3902 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003903 pf.left = df.left = mOverscanScreenLeft;
3904 pf.top = df.top = mOverscanScreenTop;
3905 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3906 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003907 // We need to tell the app about where the frame inside the overscan
3908 // is, so it can inset its content by that amount -- it didn't ask
3909 // to actually extend itself into the overscan region.
3910 of.left = mUnrestrictedScreenLeft;
3911 of.top = mUnrestrictedScreenTop;
3912 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3913 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003914 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003915 pf.left = df.left = mRestrictedOverscanScreenLeft;
3916 pf.top = df.top = mRestrictedOverscanScreenTop;
3917 pf.right = df.right = mRestrictedOverscanScreenLeft
3918 + mRestrictedOverscanScreenWidth;
3919 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3920 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003921 // We need to tell the app about where the frame inside the overscan
3922 // is, so it can inset its content by that amount -- it didn't ask
3923 // to actually extend itself into the overscan region.
3924 of.left = mUnrestrictedScreenLeft;
3925 of.top = mUnrestrictedScreenTop;
3926 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3927 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003928 }
Craig Mautner69b08182012-09-05 13:07:13 -07003929
John Spurlock46646232013-09-30 22:32:42 -04003930 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003931 if (win.isVoiceInteraction()) {
3932 cf.left = mVoiceContentLeft;
3933 cf.top = mVoiceContentTop;
3934 cf.right = mVoiceContentRight;
3935 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003936 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003937 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3938 cf.left = mDockLeft;
3939 cf.top = mDockTop;
3940 cf.right = mDockRight;
3941 cf.bottom = mDockBottom;
3942 } else {
3943 cf.left = mContentLeft;
3944 cf.top = mContentTop;
3945 cf.right = mContentRight;
3946 cf.bottom = mContentBottom;
3947 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003948 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003949 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003950 // Full screen windows are always given a layout that is as if the
3951 // status bar and other transient decors are gone. This is to avoid
3952 // bad states when moving from a window that is not hding the
3953 // status bar to one that is.
3954 cf.left = mRestrictedScreenLeft;
3955 cf.top = mRestrictedScreenTop;
3956 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3957 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003958 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003959 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003960 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3961 vf.left = mCurLeft;
3962 vf.top = mCurTop;
3963 vf.right = mCurRight;
3964 vf.bottom = mCurBottom;
3965 } else {
3966 vf.set(cf);
3967 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003968 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003969 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3970 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3971 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003972 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3973 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003974 // A window that has requested to fill the entire screen just
3975 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003976 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04003977 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
3978 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003979 pf.left = df.left = of.left = cf.left = hasNavBar
3980 ? mDockLeft : mUnrestrictedScreenLeft;
3981 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3982 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003983 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003984 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003985 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003986 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003987 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003988 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003989 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3990 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003991 } else if (attrs.type == TYPE_NAVIGATION_BAR
3992 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003993 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003994 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3995 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3996 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3997 + mUnrestrictedScreenWidth;
3998 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3999 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004000 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004001 "Laying out navigation bar window: (%d,%d - %d,%d)",
4002 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08004003 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
4004 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07004005 && ((fl & FLAG_FULLSCREEN) != 0)) {
4006 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004007 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4008 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4009 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4010 + mOverscanScreenWidth;
4011 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4012 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08004013 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08004014 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004015 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4016 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4017 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4018 + mOverscanScreenWidth;
4019 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4020 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04004021 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004022 // The wallpaper also has Real Ultimate Power, but we want to tell
4023 // it about the overscan area.
4024 pf.left = df.left = mOverscanScreenLeft;
4025 pf.top = df.top = mOverscanScreenTop;
4026 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4027 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4028 of.left = cf.left = mUnrestrictedScreenLeft;
4029 of.top = cf.top = mUnrestrictedScreenTop;
4030 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4031 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004032 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004033 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4034 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4035 // Asking to layout into the overscan region, so give it that pure
4036 // unrestricted area.
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
Dianne Hackbornc652de82013-02-15 16:32:56 -08004040 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004041 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004042 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004043 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004044 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004045 && (attrs.type == TYPE_STATUS_BAR
4046 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004047 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004048 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4049 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004050 // Asking for layout as if the nav bar is hidden, lets the
4051 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004052 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004053 // can be above the nav bar can do this.
4054 // XXX This assumes that an app asking for this will also
4055 // ask for layout in only content. We can't currently figure out
4056 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004057 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4058 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4059 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4060 + mUnrestrictedScreenWidth;
4061 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4062 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004063 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004064 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4065 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4066 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4067 + mRestrictedScreenWidth;
4068 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4069 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004070 }
Craig Mautner69b08182012-09-05 13:07:13 -07004071
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004072 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004073
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004074 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4075 vf.left = mCurLeft;
4076 vf.top = mCurTop;
4077 vf.right = mCurRight;
4078 vf.bottom = mCurBottom;
4079 } else {
4080 vf.set(cf);
4081 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004082 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004083 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4084 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004085 // A child window should be placed inside of the same visible
4086 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004087 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004088 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004089 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4090 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004091 // Otherwise, a normal window must be placed inside the content
4092 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004093 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4094 // Status bar panels and the volume dialog are the only windows who can go on
4095 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004096 // permission, so they have the same privileges as the status
4097 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004098 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4099 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4100 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4101 + mRestrictedScreenWidth;
4102 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4103 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004104 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004105 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004106 pf.left = df.left = of.left = cf.left = mStableLeft;
4107 pf.top = df.top = of.top = cf.top = mStableTop;
4108 pf.right = df.right = of.right = cf.right = mStableRight;
4109 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004110 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004111 pf.left = mContentLeft;
4112 pf.top = mContentTop;
4113 pf.right = mContentRight;
4114 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004115 if (win.isVoiceInteraction()) {
4116 df.left = of.left = cf.left = mVoiceContentLeft;
4117 df.top = of.top = cf.top = mVoiceContentTop;
4118 df.right = of.right = cf.right = mVoiceContentRight;
4119 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4120 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004121 df.left = of.left = cf.left = mDockLeft;
4122 df.top = of.top = cf.top = mDockTop;
4123 df.right = of.right = cf.right = mDockRight;
4124 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004125 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004126 df.left = of.left = cf.left = mContentLeft;
4127 df.top = of.top = cf.top = mContentTop;
4128 df.right = of.right = cf.right = mContentRight;
4129 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004130 }
4131 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4132 vf.left = mCurLeft;
4133 vf.top = mCurTop;
4134 vf.right = mCurRight;
4135 vf.bottom = mCurBottom;
4136 } else {
4137 vf.set(cf);
4138 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004139 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004140 }
4141 }
Craig Mautner69b08182012-09-05 13:07:13 -07004142
Craig Mautnerb816bed2013-07-23 10:26:17 -07004143 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4144 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004145 df.left = df.top = -10000;
4146 df.right = df.bottom = 10000;
4147 if (attrs.type != TYPE_WALLPAPER) {
4148 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4149 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4150 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004151 }
4152
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004153 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4154 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004155 // We only want to apply outsets to certain types of windows. For example, we never want to
4156 // apply the outsets to floating dialogs, because they wouldn't make sense there.
4157 final boolean useOutsets = attrs.type == TYPE_WALLPAPER
4158 || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
4159 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
4160 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004161 osf = mTmpOutsetFrame;
4162 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4163 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4164 if (outset > 0) {
4165 int rotation = Surface.ROTATION_0;
4166 try {
4167 rotation = mWindowManager.getRotation();
4168 } catch (RemoteException e) {
4169 }
4170 if (rotation == Surface.ROTATION_0) {
4171 osf.bottom += outset;
4172 } else if (rotation == Surface.ROTATION_90) {
4173 osf.right += outset;
4174 } else if (rotation == Surface.ROTATION_180) {
4175 osf.top -= outset;
4176 } else if (rotation == Surface.ROTATION_270) {
4177 osf.left -= outset;
4178 }
4179 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4180 + " with rotation " + rotation + ", result: " + osf);
4181 }
4182 }
4183
Craig Mautnereda67292013-04-28 13:50:14 -07004184 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004185 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004186 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004187 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004188 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004189 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004190 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004191 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004192 + " sf=" + sf.toShortString()
4193 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004194
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004195 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004196
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004197 // Dock windows carve out the bottom of the screen, so normal windows
4198 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004199 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4200 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004201 setLastInputMethodWindowLw(null, null);
4202 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004203 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004204 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4205 && !win.getGivenInsetsPendingLw()) {
4206 offsetVoiceInputWindowLw(win);
4207 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004208 }
4209
satok1bc0a492012-04-25 22:47:12 +09004210 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004211 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004212 top += win.getGivenContentInsetsLw().top;
4213 if (mContentBottom > top) {
4214 mContentBottom = top;
4215 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004216 if (mVoiceContentBottom > top) {
4217 mVoiceContentBottom = top;
4218 }
satok1bc0a492012-04-25 22:47:12 +09004219 top = win.getVisibleFrameLw().top;
4220 top += win.getGivenVisibleInsetsLw().top;
4221 if (mCurBottom > top) {
4222 mCurBottom = top;
4223 }
Craig Mautnereda67292013-04-28 13:50:14 -07004224 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004225 + mDockBottom + " mContentBottom="
4226 + mContentBottom + " mCurBottom=" + mCurBottom);
4227 }
4228
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004229 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004230 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004231 top += win.getGivenContentInsetsLw().top;
4232 if (mVoiceContentBottom > top) {
4233 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004234 }
4235 }
4236
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004237 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004238 @Override
4239 public void finishLayoutLw() {
4240 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004241 }
4242
4243 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004244 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004245 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004246 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004247 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004248 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004249 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004250 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004251 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004252 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004253 mForcingShowNavBar = false;
4254 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004255
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004256 mHideLockScreen = false;
4257 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004258 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004259 mShowingLockscreen = false;
4260 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004261 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004262 mKeyguardSecure = isKeyguardSecure();
4263 mKeyguardSecureIncludingHidden = mKeyguardSecure
4264 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004265 }
4266
4267 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004268 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004269 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004270 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4271 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004272 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004273 if (mTopFullscreenOpaqueWindowState == null
4274 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4275 mForcingShowNavBar = true;
4276 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004277 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004278 if (attrs.type == TYPE_STATUS_BAR) {
4279 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4280 mForceStatusBarFromKeyguard = true;
4281 }
4282 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4283 mForceStatusBarTransparent = true;
4284 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004285 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004286
4287 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4288 && attrs.type < FIRST_SYSTEM_WINDOW;
4289 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4290 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4291
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004292 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004293 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004294 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004295 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004296 mForceStatusBarFromKeyguard = true;
4297 } else {
4298 mForceStatusBar = true;
4299 }
4300 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004301 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004302 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004303 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004304 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004305 // If the lockscreen was showing when the dream started then wait
4306 // for the dream to draw before hiding the lockscreen.
4307 if (!mDreamingLockscreen
4308 || (win.isVisibleLw() && win.hasDrawnLw())) {
4309 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004310 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004311 }
4312 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004313
Craig Mautnerab55e522014-03-03 13:26:03 -08004314 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004315 final IApplicationToken appToken = win.getAppToken();
4316 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004317 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004318 mAppsToBeHidden.remove(appToken);
4319 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004320 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004321 if (dismissKeyguard && !mKeyguardSecure) {
4322 mAppsThatDismissKeyguard.add(appToken);
4323 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004324 mWinShowWhenLocked = win;
4325 mHideLockScreen = true;
4326 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004327 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004328 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004329 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004330 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004331 mAppsToBeHidden.add(appToken);
4332 } else {
4333 mAppsToBeHidden.remove(appToken);
4334 }
4335 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004336 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004337 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004338 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004339 if (attrs.x == 0 && attrs.y == 0
4340 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4341 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4342 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4343 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004344 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4345 mTopFullscreenOpaqueOrDimmingWindowState = win;
4346 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004347 if (!mAppsThatDismissKeyguard.isEmpty() &&
4348 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4349 if (DEBUG_LAYOUT) Slog.v(TAG,
4350 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004351 mDismissKeyguard = (mWinDismissingKeyguard == win
4352 && mSecureDismissingKeyguard == mKeyguardSecure)
4353 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004354 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004355 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004356 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004357 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4358 if (DEBUG_LAYOUT) Slog.v(TAG,
4359 "Setting mHideLockScreen to true by win " + win);
4360 mHideLockScreen = true;
4361 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004362 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004363 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004364 mAllowLockscreenWhenOn = true;
4365 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004366 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004367
4368 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004369 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4370 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004371 win.hideLw(false);
4372 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004373 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004374 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4375 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4376 // that is being hidden in an animation - keep the
4377 // keyguard hidden until the new window shows up and
4378 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004379 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004380 mHideLockScreen = true;
4381 mWinShowWhenLocked = win;
4382 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004383 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004384 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4385 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4386 && win.isDimming()) {
4387 mTopFullscreenOpaqueOrDimmingWindowState = win;
4388 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004389 }
4390
4391 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004392 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004393 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004394 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4395 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4396 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004397 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4398 // fullscreen window.
4399 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4400 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4401 mTopFullscreenOpaqueWindowState.hideLw(false);
4402 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4403 }
4404
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004405 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004406 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004407
4408 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4409 ? mTopFullscreenOpaqueWindowState.getAttrs()
4410 : null;
4411
Jeff Brownc8018eb2012-10-29 21:33:27 -07004412 // If we are not currently showing a dream then remember the current
4413 // lockscreen state. We will use this to determine whether the dream
4414 // started while the lockscreen was showing and remember this state
4415 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004416 if (!mShowingDream) {
4417 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004418 if (mDreamingSleepTokenNeeded) {
4419 mDreamingSleepTokenNeeded = false;
4420 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4421 }
4422 } else {
4423 if (!mDreamingSleepTokenNeeded) {
4424 mDreamingSleepTokenNeeded = true;
4425 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4426 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004427 }
4428
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004429 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004430 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004431 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004432 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004433 boolean shouldBeTransparent = mForceStatusBarTransparent
4434 && !mForceStatusBar
4435 && !mForceStatusBarFromKeyguard;
4436 if (!shouldBeTransparent) {
4437 mStatusBarController.setShowTransparent(false /* transparent */);
4438 } else if (!mStatusBar.isVisibleLw()) {
4439 mStatusBarController.setShowTransparent(true /* transparent */);
4440 }
4441 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004442 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004443 if (mStatusBarController.setBarShowingLw(true)) {
4444 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4445 }
Craig Mautner81defc72013-10-29 11:10:42 -07004446 // Maintain fullscreen layout until incoming animation is complete.
4447 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004448 // Transient status bar on the lockscreen is not allowed
4449 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4450 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4451 mLastSystemUiFlags, mLastSystemUiFlags);
4452 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004453 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004454 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004455 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004456 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004457 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004458 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004459 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004460 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004461 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004462 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004463 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004464 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004465 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4466 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004467 if (mStatusBarController.isTransientShowing()) {
4468 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004469 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4470 }
4471 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004472 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004473 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004474 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004475 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004476 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004477 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004478 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004479 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004480 if (mStatusBarController.setBarShowingLw(true)) {
4481 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4482 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004483 }
4484 }
4485 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004486
Craig Mautner81defc72013-10-29 11:10:42 -07004487 if (mTopIsFullscreen != topIsFullscreen) {
4488 if (!topIsFullscreen) {
4489 // Force another layout when status bar becomes fully shown.
4490 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4491 }
4492 mTopIsFullscreen = topIsFullscreen;
4493 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004494
Craig Mautner39834192012-09-02 07:47:24 -07004495 // Hide the key guard if a visible window explicitly specifies that it wants to be
4496 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004497 if (mKeyguardDelegate != null && mStatusBar != null) {
4498 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4499 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004500 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004501 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004502 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004503 changes |= FINISH_LAYOUT_REDO_LAYOUT
4504 | FINISH_LAYOUT_REDO_CONFIG
4505 | FINISH_LAYOUT_REDO_WALLPAPER;
4506 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004507 if (mKeyguardDelegate.isShowing()) {
4508 mHandler.post(new Runnable() {
4509 @Override
4510 public void run() {
4511 mKeyguardDelegate.keyguardDone(false, false);
4512 }
4513 });
4514 }
4515 } else if (mHideLockScreen) {
4516 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004517 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004518 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004519 changes |= FINISH_LAYOUT_REDO_LAYOUT
4520 | FINISH_LAYOUT_REDO_CONFIG
4521 | FINISH_LAYOUT_REDO_WALLPAPER;
4522 }
4523 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004524 mKeyguardHidden = false;
4525 if (setKeyguardOccludedLw(false)) {
4526 changes |= FINISH_LAYOUT_REDO_LAYOUT
4527 | FINISH_LAYOUT_REDO_CONFIG
4528 | FINISH_LAYOUT_REDO_WALLPAPER;
4529 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004530 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4531 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004532 mHandler.post(new Runnable() {
4533 @Override
4534 public void run() {
4535 mKeyguardDelegate.dismiss();
4536 }
4537 });
4538 }
4539 } else {
4540 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004541 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004542 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004543 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004544 changes |= FINISH_LAYOUT_REDO_LAYOUT
4545 | FINISH_LAYOUT_REDO_CONFIG
4546 | FINISH_LAYOUT_REDO_WALLPAPER;
4547 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004548 }
4549 }
Joe Onorato664644d2011-01-23 17:53:23 -08004550
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004551 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004552 // If the navigation bar has been hidden or shown, we need to do another
4553 // layout pass to update that window.
4554 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4555 }
Joe Onorato664644d2011-01-23 17:53:23 -08004556
Mike Lockwood28569302010-01-28 11:54:40 -05004557 // update since mAllowLockscreenWhenOn might have changed
4558 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004559 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004560 }
4561
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004562 /**
Jim Millerab954542014-10-10 18:21:49 -07004563 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004564 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004565 * @return Whether the flags have changed and we have to redo the layout.
4566 */
Jim Millerab954542014-10-10 18:21:49 -07004567 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4568 boolean wasOccluded = mKeyguardOccluded;
4569 boolean showing = mKeyguardDelegate.isShowing();
4570 if (wasOccluded && !isOccluded && showing) {
4571 mKeyguardOccluded = false;
4572 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004573 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4574 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4575 return true;
Jim Millerab954542014-10-10 18:21:49 -07004576 } else if (!wasOccluded && isOccluded && showing) {
4577 mKeyguardOccluded = true;
4578 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004579 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4580 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4581 return true;
4582 } else {
4583 return false;
4584 }
4585 }
4586
4587 private boolean isStatusBarKeyguard() {
4588 return mStatusBar != null
4589 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4590 }
4591
Jose Lima9546b202014-07-02 17:21:51 -07004592 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004593 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004594 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004595 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004596 return false;
4597 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004598 return true;
4599 }
4600
Jose Lima9546b202014-07-02 17:21:51 -07004601 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004602 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004603 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004604 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004605 // If the navigation bar has been hidden or shown, we need to do another
4606 // layout pass to update that window.
4607 return FINISH_LAYOUT_REDO_LAYOUT;
4608 }
4609 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004610 }
4611
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004612 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004613 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004614 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4615 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004616 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4617 if (newLidState == mLidState) {
4618 return;
4619 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004620
Jeff Brownc458ce92012-04-30 14:58:40 -07004621 mLidState = newLidState;
4622 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004623 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004624
4625 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004626 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004627 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004628 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004629 }
4630 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004631
Michael Wright3818c922014-09-02 13:59:07 -07004632 @Override
4633 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4634 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4635 if (mCameraLensCoverState == lensCoverState) {
4636 return;
4637 }
4638 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4639 lensCoverState == CAMERA_LENS_UNCOVERED) {
4640 Intent intent;
4641 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4642 mKeyguardDelegate.isShowing();
4643 if (keyguardActive) {
4644 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4645 } else {
4646 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4647 }
Bryce Lee584a4452014-10-21 15:55:55 -07004648 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004649 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004650 }
4651 mCameraLensCoverState = lensCoverState;
4652 }
4653
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004654 void setHdmiPlugged(boolean plugged) {
4655 if (mHdmiPlugged != plugged) {
4656 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004657 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004658 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004659 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004660 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004661 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004662 }
4663 }
4664
Joe Onoratoea495d42011-04-06 11:41:11 -07004665 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004666 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004667 // watch for HDMI plug messages if the hdmi switch exists
4668 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4669 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4670
Joe Onoratoea495d42011-04-06 11:41:11 -07004671 final String filename = "/sys/class/switch/hdmi/state";
4672 FileReader reader = null;
4673 try {
4674 reader = new FileReader(filename);
4675 char[] buf = new char[15];
4676 int n = reader.read(buf);
4677 if (n > 1) {
4678 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4679 }
4680 } catch (IOException ex) {
4681 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4682 } catch (NumberFormatException ex) {
4683 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4684 } finally {
4685 if (reader != null) {
4686 try {
4687 reader.close();
4688 } catch (IOException ex) {
4689 }
Joe Onoratodc100302011-01-11 17:07:41 -08004690 }
4691 }
4692 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004693 // This dance forces the code in setHdmiPlugged to run.
4694 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4695 mHdmiPlugged = !plugged;
4696 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004697 }
4698
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004699 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004700 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004701
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004702 final Runnable mScreenshotTimeout = new Runnable() {
4703 @Override public void run() {
4704 synchronized (mScreenshotLock) {
4705 if (mScreenshotConnection != null) {
4706 mContext.unbindService(mScreenshotConnection);
4707 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004708 }
Winson Chung9112ec32011-06-27 13:15:32 -07004709 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004710 }
4711 };
4712
4713 // Assume this is called from the Handler thread.
4714 private void takeScreenshot() {
4715 synchronized (mScreenshotLock) {
4716 if (mScreenshotConnection != null) {
4717 return;
4718 }
4719 ComponentName cn = new ComponentName("com.android.systemui",
4720 "com.android.systemui.screenshot.TakeScreenshotService");
4721 Intent intent = new Intent();
4722 intent.setComponent(cn);
4723 ServiceConnection conn = new ServiceConnection() {
4724 @Override
4725 public void onServiceConnected(ComponentName name, IBinder service) {
4726 synchronized (mScreenshotLock) {
4727 if (mScreenshotConnection != this) {
4728 return;
4729 }
4730 Messenger messenger = new Messenger(service);
4731 Message msg = Message.obtain(null, 1);
4732 final ServiceConnection myConn = this;
4733 Handler h = new Handler(mHandler.getLooper()) {
4734 @Override
4735 public void handleMessage(Message msg) {
4736 synchronized (mScreenshotLock) {
4737 if (mScreenshotConnection == myConn) {
4738 mContext.unbindService(mScreenshotConnection);
4739 mScreenshotConnection = null;
4740 mHandler.removeCallbacks(mScreenshotTimeout);
4741 }
4742 }
4743 }
4744 };
4745 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004746 msg.arg1 = msg.arg2 = 0;
4747 if (mStatusBar != null && mStatusBar.isVisibleLw())
4748 msg.arg1 = 1;
4749 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4750 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004751 try {
4752 messenger.send(msg);
4753 } catch (RemoteException e) {
4754 }
4755 }
4756 }
4757 @Override
4758 public void onServiceDisconnected(ComponentName name) {}
4759 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004760 if (mContext.bindServiceAsUser(
4761 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004762 mScreenshotConnection = conn;
4763 mHandler.postDelayed(mScreenshotTimeout, 10000);
4764 }
4765 }
Winson Chung9112ec32011-06-27 13:15:32 -07004766 }
4767
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004768 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004769 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004770 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004771 if (!mSystemBooted) {
4772 // If we have not yet booted, don't let key events do anything.
4773 return 0;
4774 }
4775
Jeff Brown037c33e2014-04-09 00:31:55 -07004776 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004777 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4778 final boolean canceled = event.isCanceled();
4779 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004780
Jeff Brown3122e442010-10-11 23:32:49 -07004781 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004782
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004783 // If screen is off then we treat the case where the keyguard is open but hidden
4784 // the same as if it were open and in front.
4785 // This will prevent any keys other than the power button from waking the screen
4786 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004787 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004788 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004789 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004790 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004791
Jeff Brown40013652012-05-16 21:22:36 -07004792 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004793 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004794 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004795 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004796 }
4797
Jeff Brown037c33e2014-04-09 00:31:55 -07004798 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004799 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004800 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4801 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004802 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004803 // When the device is interactive or the key is injected pass the
4804 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004805 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004806 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004807 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4808 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4809 // to the application but preserve its wake key status to make sure we still move
4810 // from dozing to fully interactive if we would normally go from off to fully
4811 // interactive.
4812 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004813 } else {
4814 // When the screen is off and the key is not injected, determine whether
4815 // to wake the device but don't pass the key to the application.
4816 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004817 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4818 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004819 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004820 }
4821
Justin Kohd378ad72013-04-01 12:18:26 -07004822 // If the key would be handled globally, just return the result, don't worry about special
4823 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004824 if (isValidGlobalKey(keyCode)
4825 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004826 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004827 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004828 }
Justin Kohd378ad72013-04-01 12:18:26 -07004829 return result;
4830 }
4831
Jeff Brownbae8e772014-06-12 19:59:45 -07004832 boolean useHapticFeedback = down
4833 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4834 && event.getRepeatCount() == 0;
4835
Jeff Brown4d396052010-10-29 21:50:21 -07004836 // Handle special keys.
4837 switch (keyCode) {
4838 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004839 case KeyEvent.KEYCODE_VOLUME_UP:
4840 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004841 if (mUseTvRouting) {
4842 // On TVs volume keys never go to the foreground app
4843 result &= ~ACTION_PASS_TO_USER;
4844 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004845 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4846 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004847 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004848 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004849 mScreenshotChordVolumeDownKeyTriggered = true;
4850 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4851 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004852 cancelPendingPowerKeyAction();
4853 interceptScreenshotChord();
4854 }
4855 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004856 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004857 cancelPendingScreenshotChordAction();
4858 }
4859 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4860 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004861 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004862 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004863 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004864 cancelPendingPowerKeyAction();
4865 cancelPendingScreenshotChordAction();
4866 }
4867 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004868 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004869 cancelPendingScreenshotChordAction();
4870 }
4871 }
Jeff Brown4d396052010-10-29 21:50:21 -07004872 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004873 TelecomManager telecomManager = getTelecommService();
4874 if (telecomManager != null) {
4875 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004876 // If an incoming call is ringing, either VOLUME key means
4877 // "silence ringer". We handle these keys here, rather than
4878 // in the InCallScreen, to make sure we'll respond to them
4879 // even if the InCallScreen hasn't come to the foreground yet.
4880 // Look for the DOWN event here, to agree with the "fallback"
4881 // behavior in the InCallScreen.
4882 Log.i(TAG, "interceptKeyBeforeQueueing:"
4883 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004884
Santos Cordon6848f722014-05-21 15:22:12 -07004885 // Silence the ringer. (It's safe to call this
4886 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004887 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004888
Santos Cordon6848f722014-05-21 15:22:12 -07004889 // And *don't* pass this key thru to the current activity
4890 // (which is probably the InCallScreen.)
4891 result &= ~ACTION_PASS_TO_USER;
4892 break;
4893 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004894 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004895 && (result & ACTION_PASS_TO_USER) == 0) {
4896 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004897 // the application, just pass it to the session service.
4898
4899 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004900 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004901 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004902 }
4903 }
4904
RoboErik430fc482014-06-12 15:49:20 -07004905 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004906 if (mUseTvRouting) {
4907 dispatchDirectAudioEvent(event);
4908 } else {
4909 // If we aren't passing to the user and no one else
4910 // handled it send it to the session manager to
4911 // figure out.
4912 MediaSessionLegacyHelper.getHelper(mContext)
4913 .sendVolumeKeyEvent(event, true);
4914 }
Jeff Brown4d396052010-10-29 21:50:21 -07004915 break;
4916 }
4917 }
4918 break;
4919 }
4920
4921 case KeyEvent.KEYCODE_ENDCALL: {
4922 result &= ~ACTION_PASS_TO_USER;
4923 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004924 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004925 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004926 if (telecomManager != null) {
4927 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004928 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004929 if (interactive && !hungUp) {
4930 mEndCallKeyHandled = false;
4931 mHandler.postDelayed(mEndCallLongPress,
4932 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4933 } else {
4934 mEndCallKeyHandled = true;
4935 }
Jeff Brown4d396052010-10-29 21:50:21 -07004936 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004937 if (!mEndCallKeyHandled) {
4938 mHandler.removeCallbacks(mEndCallLongPress);
4939 if (!canceled) {
4940 if ((mEndcallBehavior
4941 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4942 if (goHome()) {
4943 break;
4944 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004945 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004946 if ((mEndcallBehavior
4947 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4948 mPowerManager.goToSleep(event.getEventTime(),
4949 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4950 isWakeKey = false;
4951 }
Jeff Brown4d396052010-10-29 21:50:21 -07004952 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004953 }
Jeff Brown4d396052010-10-29 21:50:21 -07004954 }
4955 break;
4956 }
4957
4958 case KeyEvent.KEYCODE_POWER: {
4959 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004960 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004961 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004962 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004963 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004964 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004965 }
4966 break;
4967 }
4968
Jeff Brown6212a492014-03-07 13:58:47 -08004969 case KeyEvent.KEYCODE_SLEEP: {
4970 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004971 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004972 if (!mPowerManager.isInteractive()) {
4973 useHapticFeedback = false; // suppress feedback if already non-interactive
4974 }
Nick Vaccarob593a812015-05-15 11:23:05 -07004975 if (down) {
4976 sleepPress(event.getEventTime());
4977 } else {
4978 sleepRelease(event.getEventTime());
4979 }
Jeff Brown6212a492014-03-07 13:58:47 -08004980 break;
4981 }
4982
4983 case KeyEvent.KEYCODE_WAKEUP: {
4984 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004985 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004986 break;
4987 }
4988
Jeff Brown4d396052010-10-29 21:50:21 -07004989 case KeyEvent.KEYCODE_MEDIA_PLAY:
4990 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4991 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004992 case KeyEvent.KEYCODE_HEADSETHOOK:
4993 case KeyEvent.KEYCODE_MUTE:
4994 case KeyEvent.KEYCODE_MEDIA_STOP:
4995 case KeyEvent.KEYCODE_MEDIA_NEXT:
4996 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4997 case KeyEvent.KEYCODE_MEDIA_REWIND:
4998 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004999 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
5000 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07005001 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
5002 // If the global session is active pass all media keys to it
5003 // instead of the active window.
5004 result &= ~ACTION_PASS_TO_USER;
5005 }
Jeff Brown4d396052010-10-29 21:50:21 -07005006 if ((result & ACTION_PASS_TO_USER) == 0) {
5007 // Only do this if we would otherwise not pass it to the user. In that
5008 // case, the PhoneWindow class will do the same thing, except it will
5009 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07005010 // Note that we need to make a copy of the key event here because the
5011 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07005012 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07005013 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
5014 new KeyEvent(event));
5015 msg.setAsynchronous(true);
5016 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005017 }
5018 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005019 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005020
Jeff Brown4d396052010-10-29 21:50:21 -07005021 case KeyEvent.KEYCODE_CALL: {
5022 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005023 TelecomManager telecomManager = getTelecommService();
5024 if (telecomManager != null) {
5025 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005026 Log.i(TAG, "interceptKeyBeforeQueueing:"
5027 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005028 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005029
Santos Cordon6848f722014-05-21 15:22:12 -07005030 // And *don't* pass this key thru to the current activity
5031 // (which is presumably the InCallScreen.)
5032 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005033 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005034 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005035 }
Jeff Brown4d396052010-10-29 21:50:21 -07005036 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005037 }
Michael Wright869a67c2014-08-26 19:33:06 -07005038 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5039 // Only do this if we would otherwise not pass it to the user. In that case,
5040 // interceptKeyBeforeDispatching would apply a similar but different policy in
5041 // order to invoke voice assist actions. Note that we need to make a copy of the
5042 // key event here because the original key event will be recycled when we return.
5043 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5044 mBroadcastWakeLock.acquire();
5045 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5046 keyguardActive ? 1 : 0, 0);
5047 msg.setAsynchronous(true);
5048 msg.sendToTarget();
5049 }
5050 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005051 }
Jeff Brown26875502014-01-30 21:47:47 -08005052
Jeff Brownbae8e772014-06-12 19:59:45 -07005053 if (useHapticFeedback) {
5054 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5055 }
5056
Jeff Brown26875502014-01-30 21:47:47 -08005057 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005058 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08005059 }
Bryce Lee584a4452014-10-21 15:55:55 -07005060
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005061 return result;
5062 }
5063
Jeff Brown1c2e4942012-11-06 16:32:01 -08005064 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005065 * Returns true if the key can have global actions attached to it.
5066 * We reserve all power management keys for the system since they require
5067 * very careful handling.
5068 */
5069 private static boolean isValidGlobalKey(int keyCode) {
5070 switch (keyCode) {
5071 case KeyEvent.KEYCODE_POWER:
5072 case KeyEvent.KEYCODE_WAKEUP:
5073 case KeyEvent.KEYCODE_SLEEP:
5074 return false;
5075 default:
5076 return true;
5077 }
5078 }
5079
5080 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005081 * When the screen is off we ignore some keys that might otherwise typically
5082 * be considered wake keys. We filter them out here.
5083 *
5084 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5085 * is always considered a wake key.
5086 */
5087 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5088 switch (keyCode) {
5089 // ignore volume keys unless docked
5090 case KeyEvent.KEYCODE_VOLUME_UP:
5091 case KeyEvent.KEYCODE_VOLUME_DOWN:
5092 case KeyEvent.KEYCODE_VOLUME_MUTE:
5093 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5094
5095 // ignore media and camera keys
5096 case KeyEvent.KEYCODE_MUTE:
5097 case KeyEvent.KEYCODE_HEADSETHOOK:
5098 case KeyEvent.KEYCODE_MEDIA_PLAY:
5099 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5100 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5101 case KeyEvent.KEYCODE_MEDIA_STOP:
5102 case KeyEvent.KEYCODE_MEDIA_NEXT:
5103 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5104 case KeyEvent.KEYCODE_MEDIA_REWIND:
5105 case KeyEvent.KEYCODE_MEDIA_RECORD:
5106 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005107 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005108 case KeyEvent.KEYCODE_CAMERA:
5109 return false;
5110 }
5111 return true;
5112 }
5113
5114
Jeff Brown56194eb2011-03-02 19:23:13 -08005115 /** {@inheritDoc} */
5116 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005117 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5118 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08005119 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
5120 return 0;
5121 }
Michael Wright70af00a2014-09-03 19:30:20 -07005122 }
Bryce Lee5c138322014-11-03 08:26:09 -08005123
Michael Wright70af00a2014-09-03 19:30:20 -07005124 if (shouldDispatchInputWhenNonInteractive()) {
5125 return ACTION_PASS_TO_USER;
5126 }
Bryce Lee5c138322014-11-03 08:26:09 -08005127
Bryce Lee812d7022014-11-10 13:33:28 -08005128 // If we have not passed the action up and we are in theater mode without dreaming,
5129 // there will be no dream to intercept the touch and wake into ambient. The device should
5130 // wake up in this case.
5131 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
5132 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
5133 }
5134
Jeff Brown037c33e2014-04-09 00:31:55 -07005135 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005136 }
5137
Michael Wright70af00a2014-09-03 19:30:20 -07005138 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08005139 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07005140 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5141 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005142 return true;
5143 }
5144
5145 // Send events to a dozing dream even if the screen is off since the dream
5146 // is in control of the state of the screen.
5147 IDreamManager dreamManager = getDreamManager();
5148
5149 try {
5150 if (dreamManager != null && dreamManager.isDreaming()) {
5151 return true;
5152 }
5153 } catch (RemoteException e) {
5154 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5155 }
5156
5157 // Otherwise, consume events since the user can't see what is being
5158 // interacted with.
5159 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005160 }
5161
RoboErik001c59c2015-01-26 15:53:51 -08005162 private void dispatchDirectAudioEvent(KeyEvent event) {
5163 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5164 return;
5165 }
5166 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005167 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5168 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005169 String pkgName = mContext.getOpPackageName();
5170 switch (keyCode) {
5171 case KeyEvent.KEYCODE_VOLUME_UP:
5172 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005173 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005174 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005175 } catch (RemoteException e) {
5176 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5177 }
5178 break;
5179 case KeyEvent.KEYCODE_VOLUME_DOWN:
5180 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005181 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005182 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005183 } catch (RemoteException e) {
5184 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5185 }
5186 break;
5187 case KeyEvent.KEYCODE_VOLUME_MUTE:
5188 try {
5189 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005190 getAudioService().adjustSuggestedStreamVolume(
5191 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005192 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005193 }
5194 } catch (RemoteException e) {
5195 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5196 }
5197 break;
5198 }
5199 }
5200
Jeff Brown40013652012-05-16 21:22:36 -07005201 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5202 if (DEBUG_INPUT) {
5203 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005204 }
5205
Jeff Brown40013652012-05-16 21:22:36 -07005206 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5207 if (DEBUG_INPUT) {
5208 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5209 }
5210
5211 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5212 mHavePendingMediaKeyRepeatWithWakeLock = false;
5213 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5214 }
5215
5216 dispatchMediaKeyWithWakeLockToAudioService(event);
5217
5218 if (event.getAction() == KeyEvent.ACTION_DOWN
5219 && event.getRepeatCount() == 0) {
5220 mHavePendingMediaKeyRepeatWithWakeLock = true;
5221
5222 Message msg = mHandler.obtainMessage(
5223 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5224 msg.setAsynchronous(true);
5225 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5226 } else {
5227 mBroadcastWakeLock.release();
5228 }
5229 }
5230
5231 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5232 mHavePendingMediaKeyRepeatWithWakeLock = false;
5233
5234 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5235 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5236 if (DEBUG_INPUT) {
5237 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5238 }
5239
5240 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5241 mBroadcastWakeLock.release();
5242 }
5243
5244 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5245 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005246 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005247 }
5248 }
5249
Michael Wright869a67c2014-08-26 19:33:06 -07005250 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005251 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5252 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5253 if (dic != null) {
5254 try {
5255 dic.exitIdle("voice-search");
5256 } catch (RemoteException e) {
5257 }
5258 }
Michael Wright869a67c2014-08-26 19:33:06 -07005259 Intent voiceIntent =
5260 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5261 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005262 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005263 mBroadcastWakeLock.release();
5264 }
5265
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005266 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005267 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005268 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005269 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5270 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5271 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005272 } else {
5273 try {
5274 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5275 ServiceManager.getService(Context.UI_MODE_SERVICE));
5276 mUiMode = uiModeService.getCurrentModeType();
5277 } catch (RemoteException e) {
5278 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005279 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005280 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005281 synchronized (mLock) {
5282 updateOrientationListenerLp();
5283 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005284 }
5285 };
5286
Jeff Brown6aaf2952012-10-05 16:01:08 -07005287 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5288 @Override
5289 public void onReceive(Context context, Intent intent) {
5290 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005291 if (mKeyguardDelegate != null) {
5292 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005293 }
5294 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005295 if (mKeyguardDelegate != null) {
5296 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005297 }
5298 }
5299 }
5300 };
5301
Christopher Tate5e08af02012-09-21 17:17:22 -07005302 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5303 @Override
5304 public void onReceive(Context context, Intent intent) {
5305 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5306 // tickle the settings observer: this first ensures that we're
5307 // observing the relevant settings for the newly-active user,
5308 // and then updates our own bookkeeping based on the now-
5309 // current user.
5310 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005311
5312 // force a re-application of focused window sysui visibility.
5313 // the window may never have been shown for this user
5314 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005315 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005316 mLastSystemUiFlags = 0;
5317 updateSystemUiVisibilityLw();
5318 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005319 }
5320 }
5321 };
5322
Adrian Roosddc8b272015-05-21 16:28:27 -07005323 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005324 @Override
5325 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005326 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5327 if (!isUserSetupComplete()) {
5328 // Swipe-up for navigation bar is disabled during setup
5329 return;
5330 }
5331 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5332 mNavigationBarController.showTransient();
5333 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005334 }
5335 };
5336
John Spurlocke1f366f2013-08-05 12:22:40 -04005337 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005338 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005339 if (!isUserSetupComplete()) {
5340 // Swipe-up for navigation bar is disabled during setup
5341 return;
5342 }
John Spurlock27735a42013-08-14 17:57:38 -04005343 boolean sb = mStatusBarController.checkShowTransientBarLw();
5344 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005345 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005346 // Don't show status bar when swiping on already visible navigation bar
5347 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005348 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005349 return;
5350 }
John Spurlock27735a42013-08-14 17:57:38 -04005351 if (sb) mStatusBarController.showTransient();
5352 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005353 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005354 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005355 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005356 }
5357 }
5358
Jeff Brown3ee549c2014-09-22 20:14:39 -07005359 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005360 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005361 public void startedGoingToSleep(int why) {
5362 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005363 if (mKeyguardDelegate != null) {
5364 mKeyguardDelegate.onStartedGoingToSleep(why);
5365 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005366 }
5367
5368 // Called on the PowerManager's Notifier thread.
5369 @Override
5370 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005371 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005372 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005373
5374 // We must get this work done here because the power manager will drop
5375 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005376 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005377 mAwake = false;
5378 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005379 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005380 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005381 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005382 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005383 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005384 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005385 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005386 }
5387
Jeff Brown3ee549c2014-09-22 20:14:39 -07005388 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005389 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005390 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005391 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005392 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005393
Jeff Brown3ee549c2014-09-22 20:14:39 -07005394 // Since goToSleep performs these functions synchronously, we must
5395 // do the same here. We cannot post this work to a handler because
5396 // that might cause it to become reordered with respect to what
5397 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005398 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005399 mAwake = true;
5400 mKeyguardDrawComplete = false;
5401 if (mKeyguardDelegate != null) {
5402 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5403 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5404 }
5405
Jeff Browna20dda42014-05-27 20:57:24 -07005406 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005407 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005408 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005409 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005410
Jim Miller5ecd8112013-01-09 18:50:26 -08005411 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005412 mKeyguardDelegate.onStartedWakingUp(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005413 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005414 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005415 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005416 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005417 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005418 }
5419
Jeff Brown416c49c2015-05-26 19:50:18 -07005420 // Called on the PowerManager's Notifier thread.
5421 @Override
5422 public void finishedWakingUp() {
5423 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5424 }
5425
5426 private void wakeUpFromPowerKey(long eventTime) {
5427 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5428 }
5429
5430 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Leed3896842015-06-23 17:06:51 -07005431 final boolean theaterModeEnabled = isTheaterModeEnabled();
5432 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07005433 return false;
5434 }
5435
Bryce Leed3896842015-06-23 17:06:51 -07005436 if (theaterModeEnabled) {
5437 Settings.Global.putInt(mContext.getContentResolver(),
5438 Settings.Global.THEATER_MODE_ON, 0);
5439 }
5440
Jeff Brown416c49c2015-05-26 19:50:18 -07005441 mPowerManager.wakeUp(wakeTime);
5442 return true;
5443 }
5444
Jeff Brown36c4db82014-09-19 12:05:31 -07005445 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005446 synchronized (mLock) {
5447 if (!mAwake || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005448 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005449 }
5450
Jeff Brown36c4db82014-09-19 12:05:31 -07005451 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005452 if (mKeyguardDelegate != null) {
5453 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5454 }
5455 }
5456
5457 finishScreenTurningOn();
5458 }
5459
5460 // Called on the DisplayManager's DisplayPowerController thread.
5461 @Override
5462 public void screenTurnedOff() {
5463 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5464
Jeff Brown48d1b142015-06-10 16:36:03 -07005465 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005466 synchronized (mLock) {
5467 mScreenOnEarly = false;
5468 mScreenOnFully = false;
5469 mWindowManagerDrawComplete = false;
5470 mScreenOnListener = null;
5471 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005472 }
5473 }
5474
Jeff Brown3ee549c2014-09-22 20:14:39 -07005475 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005476 @Override
5477 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005478 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005479
Jeff Brown48d1b142015-06-10 16:36:03 -07005480 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005481 synchronized (mLock) {
5482 mScreenOnEarly = true;
5483 mScreenOnFully = false;
5484 mWindowManagerDrawComplete = false;
5485 mScreenOnListener = screenOnListener;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005486 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005487
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005488 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5489 WAITING_FOR_DRAWN_TIMEOUT);
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005490 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
5491 // as well as enabling the orientation change logic/sensor.
Jeff Brown36c4db82014-09-19 12:05:31 -07005492 }
5493
Jeff Brown36c4db82014-09-19 12:05:31 -07005494 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005495 synchronized (mLock) {
5496 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005497 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005498 }
5499
Jeff Brown36c4db82014-09-19 12:05:31 -07005500 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005501 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005502
5503 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005504 }
5505
Craig Mautner8a0da012014-05-31 15:13:37 -07005506 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005507 synchronized (mLock) {
5508 // We have just finished drawing screen content. Since the orientation listener
5509 // gets only installed when all windows are drawn, we try to install it again.
5510 updateOrientationListenerLp();
5511 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005512 final ScreenOnListener listener;
5513 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005514 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005515 if (DEBUG_WAKEUP) Slog.d(TAG,
5516 "finishScreenTurningOn: mAwake=" + mAwake
5517 + ", mScreenOnEarly=" + mScreenOnEarly
5518 + ", mScreenOnFully=" + mScreenOnFully
5519 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5520 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5521
5522 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5523 || (mAwake && !mKeyguardDrawComplete)) {
5524 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005525 }
5526
Jeff Brown3ee549c2014-09-22 20:14:39 -07005527 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5528 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005529 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005530 mScreenOnFully = true;
5531
5532 // Remember the first time we draw the keyguard so we know when we're done with
5533 // the main part of booting and can enable the screen and hide boot messages.
5534 if (!mKeyguardDrawnOnce && mAwake) {
5535 mKeyguardDrawnOnce = true;
5536 enableScreen = true;
5537 if (mBootMessageNeedsHiding) {
5538 mBootMessageNeedsHiding = false;
5539 hideBootMessages();
5540 }
5541 } else {
5542 enableScreen = false;
5543 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005544 }
5545
Jeff Brown3ee549c2014-09-22 20:14:39 -07005546 if (listener != null) {
5547 listener.onScreenOn();
5548 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005549
Jeff Brown3ee549c2014-09-22 20:14:39 -07005550 if (enableScreen) {
5551 try {
5552 mWindowManager.enableScreenIfNeeded();
5553 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005554 }
Craig Mautnera631d492014-08-05 15:16:01 -07005555 }
5556 }
5557
5558 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005559 synchronized (mLock) {
5560 if (!mKeyguardDrawnOnce) {
5561 mBootMessageNeedsHiding = true;
5562 return; // keyguard hasn't drawn the first time yet, not done booting
5563 }
Craig Mautnera631d492014-08-05 15:16:01 -07005564 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005565
5566 if (mBootMsgDialog != null) {
5567 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5568 mBootMsgDialog.dismiss();
5569 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005570 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005571 }
5572
5573 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005574 public boolean isScreenOn() {
5575 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005576 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005577
Dianne Hackborn08743722009-12-21 12:16:51 -08005578 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005579 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005580 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005581 if (mKeyguardDelegate != null) {
5582 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005583 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005584 }
5585
5586 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005587 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005588 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005589 if (mKeyguardDelegate != null) {
5590 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005591 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005592 }
5593
Jim Millerab954542014-10-10 18:21:49 -07005594 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005595 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005596 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005597 }
5598
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005599 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005600 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005601 public boolean isKeyguardLocked() {
5602 return keyguardOn();
5603 }
5604
5605 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005606 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005607 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005608 if (mKeyguardDelegate == null) return false;
5609 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005610 }
5611
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005612 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005613 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07005614 public boolean isKeyguardShowingOrOccluded() {
5615 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
5616 }
5617
5618 /** {@inheritDoc} */
5619 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005620 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005621 if (mKeyguardDelegate == null) return false;
5622 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005623 }
5624
Jose Lima9546b202014-07-02 17:21:51 -07005625 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005626 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005627 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005628 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005629 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005630 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005631 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005632 // ask the keyguard to prompt the user to authenticate if necessary
5633 mKeyguardDelegate.dismiss();
5634 }
5635 });
5636 }
5637 }
5638
5639 public void notifyActivityDrawnForKeyguardLw() {
5640 if (mKeyguardDelegate != null) {
5641 mHandler.post(new Runnable() {
5642 @Override
5643 public void run() {
5644 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005645 }
5646 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005647 }
5648 }
5649
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005650 @Override
5651 public boolean isKeyguardDrawnLw() {
5652 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005653 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005654 }
5655 }
5656
Jorim Jaggi0d674622014-05-21 01:34:15 +02005657 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005658 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005659 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005660 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005661 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005662 }
5663 }
5664
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005665 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005666 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005667 }
5668
5669 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005670 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005671 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005672
Jeff Brown01a98dd2011-09-20 15:08:29 -07005673 @Override
5674 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005675 if (false) {
5676 Slog.v(TAG, "rotationForOrientationLw(orient="
5677 + orientation + ", last=" + lastRotation
5678 + "); user=" + mUserRotation + " "
5679 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5680 ? "USER_ROTATION_LOCKED" : "")
5681 );
5682 }
5683
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005684 if (mForceDefaultOrientation) {
5685 return Surface.ROTATION_0;
5686 }
5687
The Android Open Source Project0727d222009-03-11 12:11:58 -07005688 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005689 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5690 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005691 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005692 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005693
Jeff Browndec6cf42011-11-15 14:08:20 -08005694 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005695 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005696 // Ignore sensor when lid switch is open and rotation is forced.
5697 preferredRotation = mLidOpenRotation;
5698 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005699 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005700 // Ignore sensor when in car dock unless explicitly enabled.
5701 // This case can override the behavior of NOSENSOR, and can also
5702 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005703 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005704 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005705 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5706 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5707 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005708 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005709 // Ignore sensor when in desk dock unless explicitly enabled.
5710 // This case can override the behavior of NOSENSOR, and can also
5711 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005712 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005713 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005714 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5715 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005716 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005717 preferredRotation = mDemoHdmiRotation;
5718 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5719 && mUndockedHdmiRotation >= 0) {
5720 // Ignore sensor when plugged into HDMI and an undocked orientation has
5721 // been specified in the configuration (only for legacy devices without
5722 // full multi-display support).
5723 // Note that the dock orientation overrides the HDMI orientation.
5724 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005725 } else if (mDemoRotationLock) {
5726 // Ignore sensor when demo rotation lock is enabled.
5727 // Note that the dock orientation and HDMI rotation lock override this.
5728 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005729 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5730 // Application just wants to remain locked in the last rotation.
5731 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005732 } else if (!mSupportAutoRotation) {
5733 // If we don't support auto-rotation then bail out here and ignore
5734 // the sensor and any rotation lock settings.
5735 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005736 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005737 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005738 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5739 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5740 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5741 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005742 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5743 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5744 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5745 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5746 // Otherwise, use sensor only if requested by the application or enabled
5747 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005748 if (mAllowAllRotations < 0) {
5749 // Can't read this during init() because the context doesn't
5750 // have display metrics at that time so we cannot determine
5751 // tablet vs. phone then.
5752 mAllowAllRotations = mContext.getResources().getBoolean(
5753 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5754 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005755 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005756 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005757 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5758 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005759 preferredRotation = sensorRotation;
5760 } else {
5761 preferredRotation = lastRotation;
5762 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005763 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5764 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5765 // Apply rotation lock. Does not apply to NOSENSOR.
5766 // The idea is that the user rotation expresses a weak preference for the direction
5767 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5768 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005769 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005770 } else {
5771 // No overriding preference.
5772 // We will do exactly what the application asked us to do.
5773 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005774 }
5775
Dianne Hackborne5439f22010-10-02 16:53:50 -07005776 switch (orientation) {
5777 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005778 // Return portrait unless overridden.
5779 if (isAnyPortrait(preferredRotation)) {
5780 return preferredRotation;
5781 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005782 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005783
Jeff Brown01a98dd2011-09-20 15:08:29 -07005784 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005785 // Return landscape unless overridden.
5786 if (isLandscapeOrSeascape(preferredRotation)) {
5787 return preferredRotation;
5788 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005789 return mLandscapeRotation;
5790
5791 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005792 // Return reverse portrait unless overridden.
5793 if (isAnyPortrait(preferredRotation)) {
5794 return preferredRotation;
5795 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005796 return mUpsideDownRotation;
5797
5798 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005799 // Return seascape unless overridden.
5800 if (isLandscapeOrSeascape(preferredRotation)) {
5801 return preferredRotation;
5802 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005803 return mSeascapeRotation;
5804
5805 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005806 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005807 // Return either landscape rotation.
5808 if (isLandscapeOrSeascape(preferredRotation)) {
5809 return preferredRotation;
5810 }
5811 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005812 return lastRotation;
5813 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005814 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005815
Jeff Brown01a98dd2011-09-20 15:08:29 -07005816 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005817 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005818 // Return either portrait rotation.
5819 if (isAnyPortrait(preferredRotation)) {
5820 return preferredRotation;
5821 }
5822 if (isAnyPortrait(lastRotation)) {
5823 return lastRotation;
5824 }
5825 return mPortraitRotation;
5826
5827 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005828 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5829 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005830 if (preferredRotation >= 0) {
5831 return preferredRotation;
5832 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005833 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005834 }
5835 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005836 }
5837
Jeff Brown01a98dd2011-09-20 15:08:29 -07005838 @Override
5839 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5840 switch (orientation) {
5841 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5842 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5843 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5844 return isAnyPortrait(rotation);
5845
5846 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5847 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5848 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5849 return isLandscapeOrSeascape(rotation);
5850
5851 default:
5852 return true;
5853 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005854 }
5855
Jeff Brownc0347aa2011-09-23 17:26:09 -07005856 @Override
5857 public void setRotationLw(int rotation) {
5858 mOrientationListener.setCurrentRotation(rotation);
5859 }
5860
Jeff Brown01a98dd2011-09-20 15:08:29 -07005861 private boolean isLandscapeOrSeascape(int rotation) {
5862 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005863 }
5864
Jeff Brown01a98dd2011-09-20 15:08:29 -07005865 private boolean isAnyPortrait(int rotation) {
5866 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005867 }
5868
Jose Lima9546b202014-07-02 17:21:51 -07005869 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005870 public int getUserRotationMode() {
5871 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005872 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5873 WindowManagerPolicy.USER_ROTATION_FREE :
5874 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005875 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005876
5877 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005878 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005879 public void setUserRotationMode(int mode, int rot) {
5880 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005881
5882 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005883 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005884 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005885 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005886 rot,
5887 UserHandle.USER_CURRENT);
5888 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005889 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005890 0,
5891 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005892 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005893 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005894 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005895 1,
5896 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005897 }
5898 }
5899
Jose Lima9546b202014-07-02 17:21:51 -07005900 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005901 public void setSafeMode(boolean safeMode) {
5902 mSafeMode = safeMode;
5903 performHapticFeedbackLw(null, safeMode
5904 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5905 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005906 }
Craig Mautnereda67292013-04-28 13:50:14 -07005907
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005908 static long[] getLongIntArray(Resources r, int resid) {
5909 int[] ar = r.getIntArray(resid);
5910 if (ar == null) {
5911 return null;
5912 }
5913 long[] out = new long[ar.length];
5914 for (int i=0; i<ar.length; i++) {
5915 out[i] = ar[i];
5916 }
5917 return out;
5918 }
Craig Mautnereda67292013-04-28 13:50:14 -07005919
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005920 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005921 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005922 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005923 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005924 mKeyguardDelegate.onSystemReady();
5925
Michael Wright3818c922014-09-02 13:59:07 -07005926 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005927 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005928 synchronized (mLock) {
5929 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005930 mSystemReady = true;
5931 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005932 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005933 public void run() {
5934 updateSettings();
5935 }
5936 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005937 }
5938 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005939
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005940 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005941 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005942 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005943 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005944 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005945 mKeyguardDelegate.onBootCompleted();
5946 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005947 synchronized (mLock) {
5948 mSystemBooted = true;
5949 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005950 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005951 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005952 }
5953
Dianne Hackborn661cd522011-08-22 00:26:20 -07005954 ProgressDialog mBootMsgDialog = null;
5955
5956 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005957 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005958 public void showBootMessage(final CharSequence msg, final boolean always) {
5959 mHandler.post(new Runnable() {
5960 @Override public void run() {
5961 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005962 int theme;
5963 if (mContext.getPackageManager().hasSystemFeature(
5964 PackageManager.FEATURE_WATCH)) {
5965 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5966 } else if (mContext.getPackageManager().hasSystemFeature(
5967 PackageManager.FEATURE_TELEVISION)) {
5968 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5969 } else {
5970 theme = 0;
5971 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005972
5973 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005974 // This dialog will consume all events coming in to
5975 // it, to avoid it trying to do things too early in boot.
5976 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5977 return true;
5978 }
5979 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5980 return true;
5981 }
5982 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5983 return true;
5984 }
5985 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5986 return true;
5987 }
5988 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5989 return true;
5990 }
5991 @Override public boolean dispatchPopulateAccessibilityEvent(
5992 AccessibilityEvent event) {
5993 return true;
5994 }
5995 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005996 if (mContext.getPackageManager().isUpgrade()) {
5997 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5998 } else {
5999 mBootMsgDialog.setTitle(R.string.android_start_title);
6000 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006001 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
6002 mBootMsgDialog.setIndeterminate(true);
6003 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07006004 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006005 mBootMsgDialog.getWindow().addFlags(
6006 WindowManager.LayoutParams.FLAG_DIM_BEHIND
6007 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
6008 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08006009 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
6010 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
6011 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006012 mBootMsgDialog.setCancelable(false);
6013 mBootMsgDialog.show();
6014 }
6015 mBootMsgDialog.setMessage(msg);
6016 }
6017 });
6018 }
6019
6020 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006021 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006022 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07006023 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006024 }
6025
Mike Lockwood28569302010-01-28 11:54:40 -05006026 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006027 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006028 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006029 // ***************************************
6030 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
6031 // ***************************************
6032 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
6033 // WITH ITS LOCKS HELD.
6034 //
6035 // This code must be VERY careful about the locks
6036 // it acquires.
6037 // In fact, the current code acquires way too many,
6038 // and probably has lurking deadlocks.
6039
Mike Lockwood28569302010-01-28 11:54:40 -05006040 synchronized (mScreenLockTimeout) {
6041 if (mLockScreenTimerActive) {
6042 // reset the timer
6043 mHandler.removeCallbacks(mScreenLockTimeout);
6044 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6045 }
6046 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006047 }
6048
Adam Cohenf7522022012-10-03 20:03:18 -07006049 class ScreenLockTimeout implements Runnable {
6050 Bundle options;
6051
6052 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006053 public void run() {
6054 synchronized (this) {
6055 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006056 if (mKeyguardDelegate != null) {
6057 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006058 }
Mike Lockwood28569302010-01-28 11:54:40 -05006059 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006060 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006061 }
6062 }
Mike Lockwood28569302010-01-28 11:54:40 -05006063
Adam Cohenf7522022012-10-03 20:03:18 -07006064 public void setLockOptions(Bundle options) {
6065 this.options = options;
6066 }
6067 }
6068
6069 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6070
Jose Lima9546b202014-07-02 17:21:51 -07006071 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006072 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006073 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6074 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006075 if (options != null) {
6076 // In case multiple calls are made to lockNow, we don't wipe out the options
6077 // until the runnable actually executes.
6078 mScreenLockTimeout.setLockOptions(options);
6079 }
Jim Miller93c518e2012-01-17 15:55:31 -08006080 mHandler.post(mScreenLockTimeout);
6081 }
6082
Mike Lockwood28569302010-01-28 11:54:40 -05006083 private void updateLockScreenTimeout() {
6084 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006085 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006086 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006087 if (mLockScreenTimerActive != enable) {
6088 if (enable) {
6089 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
6090 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6091 } else {
6092 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6093 mHandler.removeCallbacks(mScreenLockTimeout);
6094 }
6095 mLockScreenTimerActive = enable;
6096 }
6097 }
6098 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006099
Jeff Brown061ea992015-04-17 19:55:47 -07006100 private void updateDreamingSleepToken(boolean acquire) {
6101 if (acquire) {
6102 if (mDreamingSleepToken == null) {
6103 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6104 }
6105 } else {
6106 if (mDreamingSleepToken != null) {
6107 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006108 mDreamingSleepToken = null;
6109 }
6110 }
6111 }
6112
6113 private void updateScreenOffSleepToken(boolean acquire) {
6114 if (acquire) {
6115 if (mScreenOffSleepToken == null) {
6116 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6117 }
6118 } else {
6119 if (mScreenOffSleepToken != null) {
6120 mScreenOffSleepToken.release();
6121 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006122 }
6123 }
6124 }
6125
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006126 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006127 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006128 public void enableScreenAfterBoot() {
6129 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006130 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006131 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006132 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006133
Jeff Brownc458ce92012-04-30 14:58:40 -07006134 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006135 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006136 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006137 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006138 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07006139 }
Jeff Browna20dda42014-05-27 20:57:24 -07006140
6141 synchronized (mLock) {
6142 updateWakeGestureListenerLp();
6143 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006144 }
6145
Jeff Brown4f5fa282014-06-12 19:19:15 -07006146 void updateUiMode() {
6147 if (mUiModeManager == null) {
6148 mUiModeManager = IUiModeManager.Stub.asInterface(
6149 ServiceManager.getService(Context.UI_MODE_SERVICE));
6150 }
6151 try {
6152 mUiMode = mUiModeManager.getCurrentModeType();
6153 } catch (RemoteException e) {
6154 }
6155 }
6156
Jeff Brown01a98dd2011-09-20 15:08:29 -07006157 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006158 try {
6159 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006160 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6161 } catch (RemoteException e) {
6162 // Ignore
6163 }
6164 }
6165
6166 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6167 try {
6168 //set orientation on WindowManager
6169 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006170 } catch (RemoteException e) {
6171 // Ignore
6172 }
6173 }
6174
Daniel Sandler6396c722013-04-16 20:19:09 -04006175 /**
6176 * Return an Intent to launch the currently active dock app as home. Returns
6177 * null if the standard home should be launched, which is the case if any of the following is
6178 * true:
6179 * <ul>
6180 * <li>The device is not in either car mode or desk mode
6181 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
6182 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6183 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6184 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6185 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006186 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006187 */
6188 Intent createHomeDockIntent() {
6189 Intent intent = null;
6190
6191 // What home does is based on the mode, not the dock state. That
6192 // is, when in car mode you should be taken to car home regardless
6193 // of whether we are actually in a car dock.
6194 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6195 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
6196 intent = mCarDockIntent;
6197 }
6198 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6199 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6200 intent = mDeskDockIntent;
6201 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006202 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6203 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6204 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6205 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6206 // Always launch dock home from home when watch is docked, if it exists.
6207 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006208 }
6209
6210 if (intent == null) {
6211 return null;
6212 }
6213
6214 ActivityInfo ai = null;
6215 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6216 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006217 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006218 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006219 if (info != null) {
6220 ai = info.activityInfo;
6221 }
6222 if (ai != null
6223 && ai.metaData != null
6224 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6225 intent = new Intent(intent);
6226 intent.setClassName(ai.packageName, ai.name);
6227 return intent;
6228 }
6229
6230 return null;
6231 }
6232
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006233 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6234 if (awakenFromDreams) {
6235 awakenDreams();
6236 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006237
6238 Intent dock = createHomeDockIntent();
6239 if (dock != null) {
6240 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006241 if (fromHomeKey) {
6242 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6243 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006244 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006245 return;
6246 } catch (ActivityNotFoundException e) {
6247 }
6248 }
6249
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006250 Intent intent;
6251
6252 if (fromHomeKey) {
6253 intent = new Intent(mHomeIntent);
6254 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6255 } else {
6256 intent = mHomeIntent;
6257 }
6258
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006259 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006260 }
Craig Mautnereda67292013-04-28 13:50:14 -07006261
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006262 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006263 * goes to the home screen
6264 * @return whether it did anything
6265 */
6266 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006267 if (!isUserSetupComplete()) {
6268 Slog.i(TAG, "Not going home because user setup is in progress.");
6269 return false;
6270 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006271 if (false) {
6272 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006273 try {
6274 ActivityManagerNative.getDefault().stopAppSwitches();
6275 } catch (RemoteException e) {
6276 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006277 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006278 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006279 } else {
6280 // This code brings home to the front or, if it is already
6281 // at the front, puts the device to sleep.
6282 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006283 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6284 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6285 Log.d(TAG, "UTS-TEST-MODE");
6286 } else {
6287 ActivityManagerNative.getDefault().stopAppSwitches();
6288 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006289 Intent dock = createHomeDockIntent();
6290 if (dock != null) {
6291 int result = ActivityManagerNative.getDefault()
6292 .startActivityAsUser(null, null, dock,
6293 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6294 null, null, 0,
6295 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006296 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006297 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6298 return false;
6299 }
6300 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006301 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006302 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006303 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006304 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006305 null, null, 0,
6306 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006307 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006308 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006309 return false;
6310 }
6311 } catch (RemoteException ex) {
6312 // bummer, the activity manager, which is in this process, is dead
6313 }
6314 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006315 return true;
6316 }
Craig Mautnereda67292013-04-28 13:50:14 -07006317
6318 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006319 public void setCurrentOrientationLw(int newOrientation) {
6320 synchronized (mLock) {
6321 if (newOrientation != mCurrentAppOrientation) {
6322 mCurrentAppOrientation = newOrientation;
6323 updateOrientationListenerLp();
6324 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006325 }
6326 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006327
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006328 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6329 if (!isGlobalAccessibilityGestureEnabled()) {
6330 return;
6331 }
6332 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6333 Context.AUDIO_SERVICE);
6334 if (audioManager.isSilentMode()) {
6335 return;
6336 }
6337 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6338 Settings.System.DEFAULT_NOTIFICATION_URI);
6339 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6340 ringTone.play();
6341 }
Craig Mautnereda67292013-04-28 13:50:14 -07006342
Bryce Lee584a4452014-10-21 15:55:55 -07006343 private boolean isTheaterModeEnabled() {
6344 return Settings.Global.getInt(mContext.getContentResolver(),
6345 Settings.Global.THEATER_MODE_ON, 0) == 1;
6346 }
6347
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006348 private boolean isGlobalAccessibilityGestureEnabled() {
6349 return Settings.Global.getInt(mContext.getContentResolver(),
6350 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6351 }
6352
Craig Mautnereda67292013-04-28 13:50:14 -07006353 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006354 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006355 if (!mVibrator.hasVibrator()) {
6356 return false;
6357 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006358 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6359 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006360 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006361 return false;
6362 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006363 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006364 switch (effectId) {
6365 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006366 pattern = mLongPressVibePattern;
6367 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006368 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006369 pattern = mVirtualKeyVibePattern;
6370 break;
6371 case HapticFeedbackConstants.KEYBOARD_TAP:
6372 pattern = mKeyboardTapVibePattern;
6373 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006374 case HapticFeedbackConstants.CLOCK_TICK:
6375 pattern = mClockTickVibePattern;
6376 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006377 case HapticFeedbackConstants.CALENDAR_DATE:
6378 pattern = mCalendarDateVibePattern;
6379 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006380 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006381 pattern = mSafeModeDisabledVibePattern;
6382 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006383 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006384 pattern = mSafeModeEnabledVibePattern;
6385 break;
Mady Mellore8608912015-06-05 09:02:55 -07006386 case HapticFeedbackConstants.CONTEXT_CLICK:
6387 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006388 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006389 default:
6390 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006391 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006392 int owningUid;
6393 String owningPackage;
6394 if (win != null) {
6395 owningUid = win.getOwningUid();
6396 owningPackage = win.getOwningPackage();
6397 } else {
6398 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006399 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006400 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006401 if (pattern.length == 1) {
6402 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006403 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006404 } else {
6405 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006406 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006407 }
6408 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006409 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006410
6411 @Override
6412 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006413 }
6414
Jeff Brownc38c9be2012-10-04 13:16:19 -07006415 @Override
6416 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006417 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006418 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006419 }
6420 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006421
Dianne Hackborndf89e652011-10-06 22:35:11 -07006422 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006423 // If there is no window focused, there will be nobody to handle the events
6424 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006425 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6426 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006427 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006428 return 0;
6429 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006430 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006431 // We are updating at a point where the keyguard has gotten
6432 // focus, but we were last in a state where the top window is
6433 // hiding it. This is probably because the keyguard as been
6434 // shown while the top window was displayed, so we want to ignore
6435 // it here because this is just a very transient change and it
6436 // will quickly lose focus once it correctly gets hidden.
6437 return 0;
6438 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006439
John Spurlock1db8b682014-02-18 11:18:59 -05006440 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006441 & ~mResettingSystemUiFlags
6442 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006443 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006444 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006445 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006446 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006447 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006448 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006449 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006450 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006451 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006452 return 0;
6453 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006454 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006455 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006456 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006457 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006458 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006459 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006460 try {
6461 IStatusBarService statusbar = getStatusBarService();
6462 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006463 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006464 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006465 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006466 } catch (RemoteException e) {
6467 // re-acquire status bar service next time it is needed.
6468 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006469 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006470 }
6471 });
6472 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006473 }
6474
Adrian Rooscd3884d2015-02-18 17:25:23 +01006475 private int updateLightStatusBarLw(int vis) {
6476 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6477 ? mStatusBar
6478 : mTopFullscreenOpaqueOrDimmingWindowState;
6479
6480 if (statusColorWin != null) {
6481 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6482 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6483 // its light flag.
6484 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6485 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6486 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6487 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6488 // Otherwise if it's dimming, clear the light flag.
6489 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6490 }
6491 }
6492 return vis;
6493 }
6494
John Spurlock79da8332013-09-20 12:04:47 -04006495 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006496 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006497 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6498 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006499 : mTopFullscreenOpaqueWindowState;
6500 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6501 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6502
John Spurlock27735a42013-08-14 17:57:38 -04006503 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006504 int type = win.getAttrs().type;
6505 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006506 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006507 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6508 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006509 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006510 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6511 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006512 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006513 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6514 }
John Spurlockbd957402013-10-03 11:38:39 -04006515 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006516 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006517
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006518 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006519 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6520 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006521 }
6522
John Spurlock27735a42013-08-14 17:57:38 -04006523 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006524 boolean immersiveSticky =
6525 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006526 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006527 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006528 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006529 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6530 boolean hideStatusBarSysui =
6531 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006532 boolean hideNavBarSysui =
6533 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006534
John Spurlock27735a42013-08-14 17:57:38 -04006535 boolean transientStatusBarAllowed =
6536 mStatusBar != null && (
6537 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006538 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006539 || statusBarHasFocus);
6540
John Spurlockf1a36642013-10-12 17:50:42 -04006541 boolean transientNavBarAllowed =
6542 mNavigationBar != null &&
6543 hideNavBarSysui && immersiveSticky;
6544
Adrian Roosddc8b272015-05-21 16:28:27 -07006545 final long now = SystemClock.uptimeMillis();
6546 final boolean pendingPanic = mPendingPanicGestureUptime != 0
6547 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
6548 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
6549 // The user performed the panic gesture recently, we're about to hide the bars,
6550 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
6551 mPendingPanicGestureUptime = 0;
6552 mStatusBarController.showTransient();
6553 mNavigationBarController.showTransient();
6554 }
6555
John Spurlockf25706f2013-11-07 18:02:43 -05006556 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006557 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006558 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006559 && !transientNavBarAllowed;
6560 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006561 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006562 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006563 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006564 }
John Spurlock27735a42013-08-14 17:57:38 -04006565
Selim Cinekf98702e2015-05-20 22:48:40 -07006566 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
6567 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
6568 final boolean navAllowedHidden = immersive || immersiveSticky;
6569
Selim Cinekd6623612015-05-22 18:56:22 -07006570 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
6571 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07006572 // We can't hide the navbar from this window otherwise the input consumer would not get
6573 // the input events.
6574 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
6575 }
6576
John Spurlock27735a42013-08-14 17:57:38 -04006577 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6578
6579 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006580 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6581 boolean newImmersiveMode = isImmersiveMode(vis);
6582 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006583 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006584 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6585 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006586 }
John Spurlock27735a42013-08-14 17:57:38 -04006587
John Spurlockf1a36642013-10-12 17:50:42 -04006588 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6589
John Spurlocke1f366f2013-08-05 12:22:40 -04006590 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006591 }
6592
John Spurlockf1a36642013-10-12 17:50:42 -04006593 private void clearClearableFlagsLw() {
6594 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6595 if (newVal != mResettingSystemUiFlags) {
6596 mResettingSystemUiFlags = newVal;
6597 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6598 }
6599 }
6600
6601 private boolean isImmersiveMode(int vis) {
6602 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006603 return mNavigationBar != null
6604 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006605 && (vis & flags) != 0
6606 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006607 }
6608
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006609 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006610 * @return whether the navigation or status bar can be made translucent
6611 *
6612 * This should return true unless touch exploration is not enabled or
6613 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006614 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006615 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006616 return mTranslucentDecorEnabled
6617 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006618 }
6619
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006620 // Use this instead of checking config_showNavigationBar so that it can be consistently
6621 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006622 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006623 public boolean hasNavigationBar() {
6624 return mHasNavigationBar;
6625 }
6626
satok1bc0a492012-04-25 22:47:12 +09006627 @Override
6628 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6629 mLastInputMethodWindow = ime;
6630 mLastInputMethodTargetWindow = target;
6631 }
6632
Craig Mautnerf1b67412012-09-19 13:18:29 -07006633 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006634 public int getInputMethodWindowVisibleHeightLw() {
6635 return mDockBottom - mCurBottom;
6636 }
6637
6638 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006639 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006640 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006641 if (mKeyguardDelegate != null) {
6642 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006643 }
John Spurlock13451a22012-09-28 14:40:41 -04006644 if (mStatusBarService != null) {
6645 try {
6646 mStatusBarService.setCurrentUser(newUserId);
6647 } catch (RemoteException e) {
6648 // oh well
6649 }
6650 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006651 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006652 }
6653
6654 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006655 public boolean canMagnifyWindow(int windowType) {
6656 switch (windowType) {
6657 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6658 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6659 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6660 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6661 return false;
6662 }
6663 }
6664 return true;
6665 }
6666
6667 @Override
6668 public boolean isTopLevelWindow(int windowType) {
6669 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6670 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6671 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6672 }
6673 return true;
6674 }
6675
Jim Miller4eeb4f62012-11-08 00:04:29 -08006676 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006677 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006678 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006679 pw.print(" mSystemReady="); pw.print(mSystemReady);
6680 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006681 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006682 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006683 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006684 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006685 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6686 || mForceClearedSystemUiFlags != 0) {
6687 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6688 pw.print(Integer.toHexString(mLastSystemUiFlags));
6689 pw.print(" mResettingSystemUiFlags=0x");
6690 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6691 pw.print(" mForceClearedSystemUiFlags=0x");
6692 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006693 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006694 if (mLastFocusNeedsMenu) {
6695 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6696 pw.println(mLastFocusNeedsMenu);
6697 }
Jeff Browna20dda42014-05-27 20:57:24 -07006698 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6699 pw.println(mWakeGestureEnabledSetting);
6700
Jeff Brownbcdfc622014-03-06 19:13:04 -08006701 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006702 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6703 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006704 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6705 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6706 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6707 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006708 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006709 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006710 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6711 pw.print(mCarDockEnablesAccelerometer);
6712 pw.print(" mDeskDockEnablesAccelerometer=");
6713 pw.println(mDeskDockEnablesAccelerometer);
6714 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6715 pw.print(mLidKeyboardAccessibility);
6716 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006717 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006718 pw.print(prefix);
6719 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6720 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006721 pw.print(prefix);
6722 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6723 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006724 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006725 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6726 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6727 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6728 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6729 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6730 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6731 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006732 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6733 pw.print(","); pw.print(mOverscanScreenTop);
6734 pw.print(") "); pw.print(mOverscanScreenWidth);
6735 pw.print("x"); pw.println(mOverscanScreenHeight);
6736 if (mOverscanLeft != 0 || mOverscanTop != 0
6737 || mOverscanRight != 0 || mOverscanBottom != 0) {
6738 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6739 pw.print(" top="); pw.print(mOverscanTop);
6740 pw.print(" right="); pw.print(mOverscanRight);
6741 pw.print(" bottom="); pw.println(mOverscanBottom);
6742 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006743 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6744 pw.print(mRestrictedOverscanScreenLeft);
6745 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6746 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6747 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006748 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6749 pw.print(","); pw.print(mUnrestrictedScreenTop);
6750 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6751 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6752 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6753 pw.print(","); pw.print(mRestrictedScreenTop);
6754 pw.print(") "); pw.print(mRestrictedScreenWidth);
6755 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006756 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6757 pw.print(","); pw.print(mStableFullscreenTop);
6758 pw.print(")-("); pw.print(mStableFullscreenRight);
6759 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006760 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6761 pw.print(","); pw.print(mStableTop);
6762 pw.print(")-("); pw.print(mStableRight);
6763 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006764 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6765 pw.print(","); pw.print(mSystemTop);
6766 pw.print(")-("); pw.print(mSystemRight);
6767 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006768 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6769 pw.print(","); pw.print(mCurTop);
6770 pw.print(")-("); pw.print(mCurRight);
6771 pw.print(","); pw.print(mCurBottom); pw.println(")");
6772 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6773 pw.print(","); pw.print(mContentTop);
6774 pw.print(")-("); pw.print(mContentRight);
6775 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006776 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6777 pw.print(","); pw.print(mVoiceContentTop);
6778 pw.print(")-("); pw.print(mVoiceContentRight);
6779 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006780 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6781 pw.print(","); pw.print(mDockTop);
6782 pw.print(")-("); pw.print(mDockRight);
6783 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006784 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6785 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006786 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6787 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006788 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6789 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006790 if (mLastInputMethodWindow != null) {
6791 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6792 pw.println(mLastInputMethodWindow);
6793 }
6794 if (mLastInputMethodTargetWindow != null) {
6795 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6796 pw.println(mLastInputMethodTargetWindow);
6797 }
6798 if (mStatusBar != null) {
6799 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006800 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6801 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006802 }
6803 if (mNavigationBar != null) {
6804 pw.print(prefix); pw.print("mNavigationBar=");
6805 pw.println(mNavigationBar);
6806 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006807 if (mFocusedWindow != null) {
6808 pw.print(prefix); pw.print("mFocusedWindow=");
6809 pw.println(mFocusedWindow);
6810 }
6811 if (mFocusedApp != null) {
6812 pw.print(prefix); pw.print("mFocusedApp=");
6813 pw.println(mFocusedApp);
6814 }
6815 if (mWinDismissingKeyguard != null) {
6816 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6817 pw.println(mWinDismissingKeyguard);
6818 }
6819 if (mTopFullscreenOpaqueWindowState != null) {
6820 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6821 pw.println(mTopFullscreenOpaqueWindowState);
6822 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006823 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6824 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6825 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6826 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006827 if (mForcingShowNavBar) {
6828 pw.print(prefix); pw.print("mForcingShowNavBar=");
6829 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6830 pw.println(mForcingShowNavBarLayer);
6831 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006832 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006833 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006834 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6835 pw.print(" mForceStatusBarFromKeyguard=");
6836 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006837 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006838 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006839 pw.print(" mHomePressed="); pw.println(mHomePressed);
6840 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6841 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6842 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6843 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6844 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6845 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6846 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6847 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6848 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6849 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006850 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6851 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6852 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006853
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006854 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006855 mStatusBarController.dump(pw, prefix);
6856 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006857 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006858
Jeff Browna20dda42014-05-27 20:57:24 -07006859 if (mWakeGestureListener != null) {
6860 mWakeGestureListener.dump(pw, prefix);
6861 }
Jeff Brown600f0032014-05-22 17:06:00 -07006862 if (mOrientationListener != null) {
6863 mOrientationListener.dump(pw, prefix);
6864 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006865 if (mBurnInProtectionHelper != null) {
6866 mBurnInProtectionHelper.dump(prefix, pw);
6867 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006868 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006869}