blob: 121ef21812a19ed253bbb61da055d7a6423b86b2 [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
Wale Ogunwale3797c222015-10-27 14:21:58 -070019import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
20import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070021import static android.view.WindowManager.LayoutParams.*;
22import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
23import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
24import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
25import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
26import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
27import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
28
Dianne Hackborna4972e92012-03-14 10:38:05 -070029import android.app.ActivityManager;
Jeff Brown061ea992015-04-17 19:55:47 -070030import android.app.ActivityManagerInternal;
31import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080032import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080033import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040034import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070035import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070036import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040037import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080038import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070039import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080040import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040041import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080042import android.content.ContentResolver;
43import android.content.Context;
44import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070045import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070046import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080047import android.content.pm.ActivityInfo;
48import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040049import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070050import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080051import android.content.res.Configuration;
52import android.content.res.Resources;
53import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080054import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080055import android.graphics.Rect;
Jinsuk Kime601b712015-07-07 08:01:02 +090056import android.hardware.hdmi.HdmiControlManager;
57import android.hardware.hdmi.HdmiPlaybackClient;
58import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback;
John Spurlock7b414672014-07-18 13:02:39 -040059import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080060import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050061import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080062import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070063import android.media.Ringtone;
64import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070065import android.media.session.MediaSessionLegacyHelper;
Billy Laucbe540f2015-06-25 01:51:44 +010066import android.os.Binder;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070067import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080068import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070069import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080070import android.os.Handler;
71import android.os.IBinder;
Dianne Hackbornb6683c42015-06-18 17:40:33 -070072import android.os.IDeviceIdleController;
Jeff Brown32cbc38552011-12-01 14:01:49 -080073import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070074import android.os.Message;
75import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080076import android.os.PowerManager;
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -070077import android.os.PowerManagerInternal;
Billy Laucbe540f2015-06-25 01:51:44 +010078import android.os.Process;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080079import android.os.RemoteException;
80import android.os.ServiceManager;
81import android.os.SystemClock;
82import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080083import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070084import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080085import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070086import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080087import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070088import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040089import android.service.dreams.DreamService;
90import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070091import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070092import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070093import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080094import android.util.EventLog;
95import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070096import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080097import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070098import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080099import android.view.Gravity;
100import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800101import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800102import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -0700103import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -0700104import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -0800105import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800106import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -0800107import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -0800108import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800109import android.view.KeyEvent;
110import android.view.MotionEvent;
Chris Wren9bb290b2015-06-29 12:02:13 -0400111
112import com.android.internal.logging.MetricsLogger;
Adam Powell6711f3b2015-05-06 15:57:09 -0700113import com.android.internal.policy.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800114import android.view.Surface;
115import android.view.View;
116import android.view.ViewConfiguration;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800117import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800118import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700119import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800120import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800121import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800122import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800123import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200124import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800125import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800126import com.android.internal.R;
Craig Mautnerae446592012-12-06 19:05:05 -0800127import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700128import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800129import com.android.internal.widget.PointerLocationView;
Adrian Roos5941c982015-09-03 15:59:49 -0700130import com.android.server.GestureLauncherService;
Craig Mautner8a0da012014-05-31 15:13:37 -0700131import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100132import com.android.server.policy.keyguard.KeyguardServiceDelegate;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700133import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800134
135import java.io.File;
136import java.io.FileReader;
137import java.io.IOException;
138import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700139import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800140import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800141
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800142/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700143 * WindowManagerPolicy implementation for the Android phone UI. This
144 * introduces a new method suffix, Lp, for an internal lock of the
145 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400146 * 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 -0700147 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800148 */
149public class PhoneWindowManager implements WindowManagerPolicy {
150 static final String TAG = "WindowManager";
151 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700152 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700153 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700154 static final boolean DEBUG_KEYGUARD = false;
155 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700156 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700157 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800158 static final boolean SHOW_STARTING_ANIMATIONS = true;
159 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400160
Daniel Sandler6396c722013-04-16 20:19:09 -0400161 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
162 // No longer recommended for desk docks; still useful in car docks.
163 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
164 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
165
Jeff Brown6d8fd272014-05-20 21:24:38 -0700166 static final int SHORT_PRESS_POWER_NOTHING = 0;
167 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
168 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
169 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800170 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700171
Joe Onoratod208e702010-10-08 16:22:43 -0400172 static final int LONG_PRESS_POWER_NOTHING = 0;
173 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
174 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700175 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700176
Jeff Brown13f00f02014-10-31 14:45:50 -0700177 static final int MULTI_PRESS_POWER_NOTHING = 0;
178 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
179 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
180
Michael Jurka3b1fc472011-06-13 10:54:40 -0700181 // These need to match the documentation/constant in
182 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800183 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800184 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700185 static final int LONG_PRESS_HOME_ASSIST = 2;
186
187 static final int DOUBLE_TAP_HOME_NOTHING = 0;
188 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800189
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000190 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
191 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
192
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700193 static final int APPLICATION_MEDIA_SUBLAYER = -2;
194 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800195 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800196 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700197 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700198
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800199 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
200 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
201 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500202 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700203 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800204
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700205 /**
206 * These are the system UI flags that, when changing, can cause the layout
207 * of the screen to change.
208 */
209 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400210 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400211 | View.SYSTEM_UI_FLAG_FULLSCREEN
212 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200213 | View.NAVIGATION_BAR_TRANSLUCENT
214 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700215
John Spurlock7b414672014-07-18 13:02:39 -0400216 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
217 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
218 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
219 .build();
220
Adrian Roosddc8b272015-05-21 16:28:27 -0700221 // The panic gesture may become active only after the keyguard is dismissed and the immersive
222 // app shows again. If that doesn't happen for 30s we drop the gesture.
223 private static final long PANIC_GESTURE_EXPIRATION = 30000;
224
Jim Miller5ecd8112013-01-09 18:50:26 -0800225 /**
226 * Keyguard stuff
227 */
228 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100229 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700230 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800231
Jeff Brown6651a632011-11-28 12:59:11 -0800232 /* Table of Application Launch keys. Maps from key codes to intent categories.
233 *
234 * These are special keys that are used to launch particular kinds of applications,
235 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
236 * usage page. We don't support quite that many yet...
237 */
238 static SparseArray<String> sApplicationLaunchKeyCategories;
239 static {
240 sApplicationLaunchKeyCategories = new SparseArray<String>();
241 sApplicationLaunchKeyCategories.append(
242 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
243 sApplicationLaunchKeyCategories.append(
244 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
245 sApplicationLaunchKeyCategories.append(
246 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
247 sApplicationLaunchKeyCategories.append(
248 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
249 sApplicationLaunchKeyCategories.append(
250 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
251 sApplicationLaunchKeyCategories.append(
252 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
253 }
254
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700255 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700256 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700257
Dianne Hackborndf89e652011-10-06 22:35:11 -0700258 /**
259 * Lock protecting internal state. Must not call out into window
260 * manager with lock held. (This lock will be acquired in places
261 * where the window manager is calling in with its own lock held.)
262 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800263 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700264
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800265 Context mContext;
266 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700267 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700268 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700269 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700270 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700271 DreamManagerInternal mDreamManagerInternal;
Michael Wrighta4d22d72015-09-16 23:19:26 +0100272 PowerManagerInternal mPowerManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400273 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700274 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700275 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800276 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700277 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800278 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000279 BurnInProtectionHelper mBurnInProtectionHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100280 AppOpsManager mAppOpsManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800281
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700282 // Vibrator pattern for haptic feedback of a long press.
283 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700284
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700285 // Vibrator pattern for haptic feedback of virtual key press.
286 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700287
Amith Yamasanic33cb712010-02-10 15:21:49 -0800288 // Vibrator pattern for a short vibration.
289 long[] mKeyboardTapVibePattern;
290
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700291 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
292 long[] mClockTickVibePattern;
293
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700294 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
295 long[] mCalendarDateVibePattern;
296
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700297 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
298 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700299
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700300 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
301 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700302
Mady Mellore8608912015-06-05 09:02:55 -0700303 // Vibrator pattern for haptic feedback of a context click.
304 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700305
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800306 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
307 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400308
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800309 boolean mSafeMode;
310 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700311 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400312 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400313 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700314 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400315 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
316 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
317 int[] mNavigationBarHeightForRotation = new int[4];
318 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400319
Craig Mautnera631d492014-08-05 15:16:01 -0700320 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800321 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700322 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700323 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700324 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700325 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
326 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
327 }
328 };
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700329 final DrawnListener mKeyguardDrawnCallback = new DrawnListener() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700330 @Override
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700331 public void onDrawn() {
332 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn.");
Craig Mautner8a0da012014-05-31 15:13:37 -0700333 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
334 }
335 };
336
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800337 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800338 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900339 WindowState mLastInputMethodWindow = null;
340 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800341
Jeff Brown13f00f02014-10-31 14:45:50 -0700342 // FIXME This state is shared between the input reader and handler thread.
343 // Technically it's broken and buggy but it has been like this for many years
344 // and we have not yet seen any problems. Someday we'll rewrite this logic
345 // so that only one thread is involved in handling input policy. Unfortunately
346 // it's on a critical path for power management so we can't just post the work to the
347 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
348 // to hold wakelocks during dispatch and eliminating the critical path.
349 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800350 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700351 volatile int mPowerKeyPressCounter;
352 volatile boolean mEndCallKeyHandled;
353
Winson Chungd42a6cf2014-06-03 16:24:04 -0700354 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700355 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700356 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800357
Jeff Brown2e7760e2012-04-11 15:14:55 -0700358 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700359 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700360 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800361
Dianne Hackbornc777e072010-02-12 13:07:59 -0800362 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700363 boolean mSystemBooted;
Adrian Roos3542f7d2015-07-13 15:57:53 -0700364 private boolean mDeferBindKeyguard;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800365 boolean mHdmiPlugged;
Jinsuk Kime601b712015-07-07 08:01:02 +0900366 HdmiControl mHdmiControl;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700367 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400368 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700369 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700370 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400371 int mCarDockRotation;
372 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700373 int mUndockedHdmiRotation;
374 int mDemoHdmiRotation;
375 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800376 int mDemoRotation;
377 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400378
Jeff Browna20dda42014-05-27 20:57:24 -0700379 boolean mWakeGestureEnabledSetting;
380 MyWakeGestureListener mWakeGestureListener;
381
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700382 // Default display does not rotate, apps that require non-default orientation will have to
383 // have the orientation emulated.
384 private boolean mForceDefaultOrientation = false;
385
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400386 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
387 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700388 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400389
Jeff Brownbcdfc622014-03-06 19:13:04 -0800390 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700391 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400392 boolean mCarDockEnablesAccelerometer;
393 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700394 int mLidKeyboardAccessibility;
395 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700396 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700397 int mShortPressOnPowerBehavior;
398 int mLongPressOnPowerBehavior;
399 int mDoublePressOnPowerBehavior;
400 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000401 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700402 boolean mAwake;
403 boolean mScreenOnEarly;
404 boolean mScreenOnFully;
405 ScreenOnListener mScreenOnListener;
406 boolean mKeyguardDrawComplete;
407 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800408 boolean mOrientationSensorEnabled = false;
409 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800410 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400411 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800412 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700413
Jeff Brown70825162012-03-28 17:27:48 -0700414 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800415
416 // The last window we were told about in focusChanged.
417 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800418 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800419
Jeff Brown70825162012-03-28 17:27:48 -0700420 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800421
Dianne Hackbornc652de82013-02-15 16:32:56 -0800422 // The current size of the screen; really; extends into the overscan area of
423 // the screen and doesn't account for any system elements like the status bar.
424 int mOverscanScreenLeft, mOverscanScreenTop;
425 int mOverscanScreenWidth, mOverscanScreenHeight;
426 // The current visible size of the screen; really; (ir)regardless of whether the status
427 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800428 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
429 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800430 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
431 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
432 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700433 // The current size of the screen; these may be different than (0,0)-(dw,dh)
434 // if the status bar can't be hidden; in that case it effectively carves out
435 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800436 int mRestrictedScreenLeft, mRestrictedScreenTop;
437 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700438 // During layout, the current screen borders accounting for any currently
439 // visible system UI elements.
440 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700441 // For applications requesting stable content insets, these are them.
442 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700443 // For applications requesting stable content insets but have also set the
444 // fullscreen window flag, these are the stable dimensions without the status bar.
445 int mStableFullscreenLeft, mStableFullscreenTop;
446 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800447 // During layout, the current screen borders with all outer decoration
448 // (status bar, input method dock) accounted for.
449 int mCurLeft, mCurTop, mCurRight, mCurBottom;
450 // During layout, the frame in which content should be displayed
451 // to the user, accounting for all screen decoration except for any
452 // space they deem as available for other content. This is usually
453 // the same as mCur*, but may be larger if the screen decor has supplied
454 // content insets.
455 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700456 // During layout, the frame in which voice content should be displayed
457 // to the user, accounting for all screen decoration except for any
458 // space they deem as available for other content.
459 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800460 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800461 // windows are placed.
462 int mDockLeft, mDockTop, mDockRight, mDockBottom;
463 // During layout, the layer at which the doc window is placed.
464 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700465 // During layout, this is the layer of the status bar.
466 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700467 int mLastSystemUiFlags;
468 // Bits that we are in the process of clearing, so we want to prevent
469 // them from being set by applications until everything has been updated
470 // to have them clear.
471 int mResettingSystemUiFlags = 0;
472 // Bits that we are currently always keeping cleared.
473 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800474 // What we last reported to system UI about whether the compatibility
475 // menu needs to be displayed.
476 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700477 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
478 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700479
Selim Cinekf83e8242015-05-19 18:08:14 -0700480 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700481
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800482 static final Rect mTmpParentFrame = new Rect();
483 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800484 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800485 static final Rect mTmpContentFrame = new Rect();
486 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400487 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700488 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700489 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700490 static final Rect mTmpOutsetFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700491
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800492 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100493 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700494 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200495 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400496 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800497 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700498 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700499 private boolean mForceStatusBarTransparent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700500 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800501 boolean mForcingShowNavBar;
502 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700503
504 // States of keyguard dismiss.
505 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
506 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
507 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
508 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
509
510 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
511 * be done once per window. */
512 private WindowState mWinDismissingKeyguard;
513
tingna_sunge785ffa2015-05-12 13:23:15 +0800514 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
515 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
516 * lock SIM card. This variable is used to record the previous keyguard secure state for
517 * monitoring secure state change on window dismissing keyguard. */
518 private boolean mSecureDismissingKeyguard;
519
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700520 /** The window that is currently showing "over" the keyguard. If there is an app window
521 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
522 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
523 * the wallpaper. */
524 private WindowState mWinShowWhenLocked;
525
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700526 boolean mShowingLockscreen;
527 boolean mShowingDream;
528 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700529 boolean mDreamingSleepTokenNeeded;
530 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700531 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700532 boolean mKeyguardSecure;
533 boolean mKeyguardSecureIncludingHidden;
534 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800535 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700536 boolean mHomeConsumed;
537 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800538 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700539 Intent mCarDockIntent;
540 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700541 boolean mSearchKeyShortcutPending;
542 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700543 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700544 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800545
Mike Lockwood28569302010-01-28 11:54:40 -0500546 // support for activating the lock screen while the screen is on
547 boolean mAllowLockscreenWhenOn;
548 int mLockScreenTimeout;
549 boolean mLockScreenTimerActive;
550
David Brownbaf8d092010-03-08 21:52:59 -0800551 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800552 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800553
554 // Behavior of POWER button while in-call and screen on.
555 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
556 int mIncallPowerBehavior;
557
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700558 Display mDisplay;
559
Filip Gruszczynski2987f612015-06-30 15:03:30 -0700560 private int mDisplayRotation;
561
Dianne Hackborn9d132642011-04-21 17:26:39 -0700562 int mLandscapeRotation = 0; // default landscape rotation
563 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
564 int mPortraitRotation = 0; // default portrait rotation
565 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700566
Dianne Hackbornc652de82013-02-15 16:32:56 -0800567 int mOverscanLeft = 0;
568 int mOverscanTop = 0;
569 int mOverscanRight = 0;
570 int mOverscanBottom = 0;
571
Joe Onorato46b0d682010-11-22 17:37:27 -0800572 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700573 private int mLongPressOnHomeBehavior;
574
575 // What we do when the user double-taps on home
576 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800577
Bryce Lee584a4452014-10-21 15:55:55 -0700578 // Allowed theater mode wake actions
579 private boolean mAllowTheaterModeWakeFromKey;
580 private boolean mAllowTheaterModeWakeFromPowerKey;
581 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800582 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700583 private boolean mAllowTheaterModeWakeFromCameraLens;
584 private boolean mAllowTheaterModeWakeFromLidSwitch;
585 private boolean mAllowTheaterModeWakeFromWakeGesture;
586
Bryce Leed3b28402015-03-09 15:49:13 +0000587 // Whether to support long press from power button in non-interactive mode
588 private boolean mSupportLongPressPowerWhenNonInteractive;
589
Bryce Lee55e846d2014-11-04 12:43:44 -0800590 // Whether to go to sleep entering theater mode from power button
591 private boolean mGoToSleepOnButtonPressTheaterMode;
592
Winson Chung9112ec32011-06-27 13:15:32 -0700593 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700594 // Time to volume and power must be pressed within this interval of each other.
595 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700596 // Increase the chord delay when taking a screenshot from the keyguard
597 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800598 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700599 private boolean mScreenshotChordVolumeDownKeyTriggered;
600 private long mScreenshotChordVolumeDownKeyTime;
601 private boolean mScreenshotChordVolumeDownKeyConsumed;
602 private boolean mScreenshotChordVolumeUpKeyTriggered;
603 private boolean mScreenshotChordPowerKeyTriggered;
604 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700605
Michael Wrightb854e242013-02-05 17:54:02 -0800606 /* The number of steps between min and max brightness */
607 private static final int BRIGHTNESS_STEPS = 10;
608
Christopher Tate5e08af02012-09-21 17:17:22 -0700609 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800610 ShortcutManager mShortcutManager;
611 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700612 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700613 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800614
Craig Mautnerd625ab22013-09-06 13:40:31 -0700615 private int mCurrentUserId;
616
Justin Kohd378ad72013-04-01 12:18:26 -0700617 // Maps global key codes to the components that will handle them.
618 private GlobalKeyManager mGlobalKeyManager;
619
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700620 // Fallback actions by key code.
621 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
622 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800623
Jorim Jaggi76a16232014-08-08 17:00:47 +0200624 private final LogDecelerateInterpolator mLogDecelerateInterpolator
625 = new LogDecelerateInterpolator(100, 0);
626
Jeff Brown70825162012-03-28 17:27:48 -0700627 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
628 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700629 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
630 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700631 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
632 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
633 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700634 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700635 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700636 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700637 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700638 private static final int MSG_POWER_DELAYED_PRESS = 13;
639 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700640 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700641 private static final int MSG_REQUEST_TRANSIENT_BARS = 16;
642
643 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
644 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
Jeff Brown70825162012-03-28 17:27:48 -0700645
646 private class PolicyHandler extends Handler {
647 @Override
648 public void handleMessage(Message msg) {
649 switch (msg.what) {
650 case MSG_ENABLE_POINTER_LOCATION:
651 enablePointerLocation();
652 break;
653 case MSG_DISABLE_POINTER_LOCATION:
654 disablePointerLocation();
655 break;
Jeff Brown40013652012-05-16 21:22:36 -0700656 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
657 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
658 break;
659 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
660 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
661 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700662 case MSG_DISPATCH_SHOW_RECENTS:
663 showRecentApps(false);
664 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700665 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
666 showGlobalActionsInternal();
667 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700668 case MSG_KEYGUARD_DRAWN_COMPLETE:
669 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700670 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700671 break;
672 case MSG_KEYGUARD_DRAWN_TIMEOUT:
673 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700674 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700675 break;
676 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
677 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700678 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700679 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700680 case MSG_HIDE_BOOT_MESSAGE:
681 handleHideBootMessage();
682 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700683 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
684 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
685 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700686 case MSG_POWER_DELAYED_PRESS:
687 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
688 finishPowerKeyPress();
689 break;
690 case MSG_POWER_LONG_PRESS:
691 powerLongPress();
692 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700693 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
694 updateDreamingSleepToken(msg.arg1 != 0);
695 break;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700696 case MSG_REQUEST_TRANSIENT_BARS:
697 WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ?
698 mStatusBar : mNavigationBar;
699 if (targetBar != null) {
700 requestTransientBars(targetBar);
701 }
702 break;
Jeff Brown70825162012-03-28 17:27:48 -0700703 }
704 }
705 }
706
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800707 private UEventObserver mHDMIObserver = new UEventObserver() {
708 @Override
709 public void onUEvent(UEventObserver.UEvent event) {
710 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
711 }
712 };
713
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800714 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800715 SettingsObserver(Handler handler) {
716 super(handler);
717 }
David Brownbaf8d092010-03-08 21:52:59 -0800718
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800719 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700720 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800721 ContentResolver resolver = mContext.getContentResolver();
722 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700723 Settings.System.END_BUTTON_BEHAVIOR), false, this,
724 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800725 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700726 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
727 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700728 resolver.registerContentObserver(Settings.Secure.getUriFor(
729 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
730 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800731 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700732 Settings.System.ACCELEROMETER_ROTATION), false, this,
733 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500734 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700735 Settings.System.USER_ROTATION), false, this,
736 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400737 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700738 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
739 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800740 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700741 Settings.System.POINTER_LOCATION), false, this,
742 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800743 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700744 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
745 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500746 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400747 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700748 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500749 resolver.registerContentObserver(Settings.Global.getUriFor(
750 Settings.Global.POLICY_CONTROL), false, this,
751 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800752 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800753 }
754
755 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800756 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700757 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800758 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800759 }
Craig Mautner967212c2013-04-13 21:10:58 -0700760
Jeff Browna20dda42014-05-27 20:57:24 -0700761 class MyWakeGestureListener extends WakeGestureListener {
762 MyWakeGestureListener(Context context, Handler handler) {
763 super(context, handler);
764 }
765
766 @Override
767 public void onWakeUp() {
768 synchronized (mLock) {
769 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700770 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700771 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture,
772 "android.policy:GESTURE");
Jeff Browna20dda42014-05-27 20:57:24 -0700773 }
774 }
775 }
776 }
777
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800778 class MyOrientationListener extends WindowOrientationListener {
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700779 private final Runnable mUpdateRotationRunnable = new Runnable() {
780 @Override
781 public void run() {
Tim Murray1f407642015-10-01 17:07:12 -0700782 // send interaction hint to improve redraw performance
783 mPowerManagerInternal.powerHint(PowerManagerInternal.POWER_HINT_INTERACTION, 0);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700784 updateRotation(false);
785 }
786 };
787
Craig Mautnereee29c42013-01-17 14:44:34 -0800788 MyOrientationListener(Context context, Handler handler) {
789 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800790 }
Craig Mautner967212c2013-04-13 21:10:58 -0700791
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800792 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700793 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700794 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700795 mHandler.post(mUpdateRotationRunnable);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700796 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800797 }
798 MyOrientationListener mOrientationListener;
799
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100800 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400801
John Spurlock27735a42013-08-14 17:57:38 -0400802 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400803 View.NAVIGATION_BAR_TRANSIENT,
804 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400805 View.NAVIGATION_BAR_TRANSLUCENT,
806 StatusBarManager.WINDOW_NAVIGATION_BAR,
807 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400808
John Spurlockf1a36642013-10-12 17:50:42 -0400809 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400810
Craig Mautner037aa8d2013-06-07 10:35:44 -0700811 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400812
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700813 IStatusBarService getStatusBarService() {
814 synchronized (mServiceAquireLock) {
815 if (mStatusBarService == null) {
816 mStatusBarService = IStatusBarService.Stub.asInterface(
817 ServiceManager.getService("statusbar"));
818 }
819 return mStatusBarService;
820 }
821 }
822
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700823 /*
824 * We always let the sensor be switched on by default except when
825 * the user has explicitly disabled sensor based rotation or when the
826 * screen is switched off.
827 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700828 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800829 if (mSupportAutoRotation) {
830 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
831 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
832 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
833 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
834 // If the application has explicitly requested to follow the
835 // orientation, then we need to turn the sensor on.
836 return true;
837 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800838 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700839 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800840 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
841 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
842 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400843 // enable accelerometer if we are docked in a dock that enables accelerometer
844 // orientation management,
845 return true;
846 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700847 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800848 // If the setting for using the sensor by default is enabled, then
849 // we will always leave it on. Note that the user could go to
850 // a window that forces an orientation that does not use the
851 // sensor and in theory we could turn it off... however, when next
852 // turning it on we won't have a good value for the current
853 // orientation for a little bit, which can cause orientation
854 // changes to lag, so we'd like to keep it always on. (It will
855 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700856 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800857 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800858 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800859 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700860
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800861 /*
862 * Various use cases for invoking this function
863 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700864 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800865 * if not already enabled
866 * screen turned on and current app does not have sensor orientation, disable listeners if
867 * already enabled
868 * screen turning on and current app has sensor based orientation, enable listeners if needed
869 * screen turning on and current app has nosensor based orientation, do nothing
870 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700871 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800872 if (!mOrientationListener.canDetectOrientation()) {
873 // If sensor is turned off or nonexistent for some reason
874 return;
875 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000876 // Could have been invoked due to screen turning on or off or
877 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -0700878 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
879 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000880 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
881 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
882 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800883 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000884 // Note: We postpone the rotating of the screen until the keyguard as well as the
885 // window manager have reported a draw complete.
886 if (mScreenOnEarly && mAwake &&
887 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700888 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800889 disable = false;
890 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700891 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800892 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700893 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800894 mOrientationSensorEnabled = true;
895 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700896 }
897 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800898 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700899 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800900 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700901 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800902 mOrientationSensorEnabled = false;
903 }
904 }
905
Jeff Brown13f00f02014-10-31 14:45:50 -0700906 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
907 // Hold a wake lock until the power key is released.
908 if (!mPowerKeyWakeLock.isHeld()) {
909 mPowerKeyWakeLock.acquire();
910 }
911
912 // Cancel multi-press detection timeout.
913 if (mPowerKeyPressCounter != 0) {
914 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
915 }
916
917 // Detect user pressing the power button in panic when an application has
918 // taken over the whole screen.
919 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800920 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700921 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700922 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700923 }
924
925 // Latch power key state to detect screenshot chord.
926 if (interactive && !mScreenshotChordPowerKeyTriggered
927 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
928 mScreenshotChordPowerKeyTriggered = true;
929 mScreenshotChordPowerKeyTime = event.getDownTime();
930 interceptScreenshotChord();
931 }
932
933 // Stop ringing or end call if configured to do so when power is pressed.
934 TelecomManager telecomManager = getTelecommService();
935 boolean hungUp = false;
936 if (telecomManager != null) {
937 if (telecomManager.isRinging()) {
938 // Pressing Power while there's a ringing incoming
939 // call should silence the ringer.
940 telecomManager.silenceRinger();
941 } else if ((mIncallPowerBehavior
942 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
943 && telecomManager.isInCall() && interactive) {
944 // Otherwise, if "Power button ends call" is enabled,
945 // the Power button will hang up any current active call.
946 hungUp = telecomManager.endCall();
947 }
948 }
949
Adrian Roos5941c982015-09-03 15:59:49 -0700950 GestureLauncherService gestureService = LocalServices.getService(
951 GestureLauncherService.class);
952 boolean gesturedServiceIntercepted = false;
953 if (gestureService != null) {
954 gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive);
955 }
956
Jeff Brown13f00f02014-10-31 14:45:50 -0700957 // If the power key has still not yet been handled, then detect short
958 // press, long press, or multi press and decide what to do.
959 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
Adrian Roos5941c982015-09-03 15:59:49 -0700960 || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted;
Jeff Brown13f00f02014-10-31 14:45:50 -0700961 if (!mPowerKeyHandled) {
962 if (interactive) {
963 // When interactive, we're already awake.
964 // Wait for a long press or for the button to be released to decide what to do.
965 if (hasLongPressOnPowerBehavior()) {
966 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
967 msg.setAsynchronous(true);
968 mHandler.sendMessageDelayed(msg,
969 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
970 }
971 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800972 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800973
Bryce Leed3b28402015-03-09 15:49:13 +0000974 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
975 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
976 msg.setAsynchronous(true);
977 mHandler.sendMessageDelayed(msg,
978 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800979 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000980 } else {
981 final int maxCount = getMaxMultiPressPowerCount();
982
983 if (maxCount <= 1) {
984 mPowerKeyHandled = true;
985 } else {
986 mBeganFromNonInteractive = true;
987 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700988 }
989 }
Jeff Brown4d396052010-10-29 21:50:21 -0700990 }
991 }
992
Jeff Brown13f00f02014-10-31 14:45:50 -0700993 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
994 final boolean handled = canceled || mPowerKeyHandled;
995 mScreenshotChordPowerKeyTriggered = false;
996 cancelPendingScreenshotChordAction();
997 cancelPendingPowerKeyAction();
998
999 if (!handled) {
1000 // Figure out how to handle the key now that it has been released.
1001 mPowerKeyPressCounter += 1;
1002
1003 final int maxCount = getMaxMultiPressPowerCount();
1004 final long eventTime = event.getDownTime();
1005 if (mPowerKeyPressCounter < maxCount) {
1006 // This could be a multi-press. Wait a little bit longer to confirm.
1007 // Continue holding the wake lock.
1008 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
1009 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
1010 msg.setAsynchronous(true);
1011 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
1012 return;
1013 }
1014
1015 // No other actions. Handle it immediately.
1016 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -07001017 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001018
1019 // Done. Reset our state.
1020 finishPowerKeyPress();
1021 }
1022
1023 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -08001024 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001025 mPowerKeyPressCounter = 0;
1026 if (mPowerKeyWakeLock.isHeld()) {
1027 mPowerKeyWakeLock.release();
1028 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001029 }
1030
1031 private void cancelPendingPowerKeyAction() {
1032 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001033 mPowerKeyHandled = true;
1034 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001035 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001036 }
1037
1038 private void powerPress(long eventTime, boolean interactive, int count) {
1039 if (mScreenOnEarly && !mScreenOnFully) {
1040 Slog.i(TAG, "Suppressed redundant power key press while "
1041 + "already in the process of turning the screen on.");
1042 return;
Jeff Brownff204712011-10-25 21:27:54 -07001043 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001044
1045 if (count == 2) {
1046 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1047 } else if (count == 3) {
1048 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001049 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001050 switch (mShortPressOnPowerBehavior) {
1051 case SHORT_PRESS_POWER_NOTHING:
1052 break;
1053 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1054 mPowerManager.goToSleep(eventTime,
1055 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1056 break;
1057 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1058 mPowerManager.goToSleep(eventTime,
1059 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1060 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1061 break;
1062 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1063 mPowerManager.goToSleep(eventTime,
1064 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1065 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1066 launchHomeFromHotKey();
1067 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001068 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001069 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001070 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001071 }
1072 }
1073 }
1074
1075 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1076 switch (behavior) {
1077 case MULTI_PRESS_POWER_NOTHING:
1078 break;
1079 case MULTI_PRESS_POWER_THEATER_MODE:
Bryce Lee3ae447e2015-06-30 12:31:41 -07001080 if (!isUserSetupComplete()) {
1081 Slog.i(TAG, "Ignoring toggling theater mode - device not setup.");
1082 break;
1083 }
1084
Jeff Brown13f00f02014-10-31 14:45:50 -07001085 if (isTheaterModeEnabled()) {
1086 Slog.i(TAG, "Toggling theater mode off.");
1087 Settings.Global.putInt(mContext.getContentResolver(),
1088 Settings.Global.THEATER_MODE_ON, 0);
1089 if (!interactive) {
1090 wakeUpFromPowerKey(eventTime);
1091 }
1092 } else {
1093 Slog.i(TAG, "Toggling theater mode on.");
1094 Settings.Global.putInt(mContext.getContentResolver(),
1095 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001096
1097 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001098 mPowerManager.goToSleep(eventTime,
1099 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1100 }
1101 }
1102 break;
1103 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001104 Slog.i(TAG, "Starting brightness boost.");
1105 if (!interactive) {
1106 wakeUpFromPowerKey(eventTime);
1107 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001108 mPowerManager.boostScreenBrightness(eventTime);
1109 break;
1110 }
1111 }
1112
1113 private int getMaxMultiPressPowerCount() {
1114 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1115 return 3;
1116 }
1117 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1118 return 2;
1119 }
1120 return 1;
1121 }
1122
1123 private void powerLongPress() {
1124 final int behavior = getResolvedLongPressOnPowerBehavior();
1125 switch (behavior) {
1126 case LONG_PRESS_POWER_NOTHING:
1127 break;
1128 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1129 mPowerKeyHandled = true;
1130 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1131 performAuditoryFeedbackForAccessibilityIfNeed();
1132 }
1133 showGlobalActionsInternal();
1134 break;
1135 case LONG_PRESS_POWER_SHUT_OFF:
1136 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1137 mPowerKeyHandled = true;
1138 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1139 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1140 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1141 break;
1142 }
1143 }
1144
Nick Vaccarob593a812015-05-15 11:23:05 -07001145 private void sleepPress(long eventTime) {
1146 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1147 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1148 }
1149 }
1150
1151 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001152 switch (mShortPressOnSleepBehavior) {
1153 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001154 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001155 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1156 mPowerManager.goToSleep(eventTime,
1157 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001158 break;
1159 }
1160 }
1161
Jeff Brown13f00f02014-10-31 14:45:50 -07001162 private int getResolvedLongPressOnPowerBehavior() {
1163 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1164 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1165 }
1166 return mLongPressOnPowerBehavior;
1167 }
1168
1169 private boolean hasLongPressOnPowerBehavior() {
1170 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001171 }
1172
1173 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001174 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001175 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1176 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001177 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001178 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1179 && now <= mScreenshotChordPowerKeyTime
1180 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1181 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001182 cancelPendingPowerKeyAction();
1183
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001184 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001185 }
1186 }
1187 }
1188
Winson Chung1cea2f32012-10-08 20:42:01 -07001189 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001190 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001191 // Double the time it takes to take a screenshot from the keyguard
1192 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001193 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001194 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001195 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001196 }
1197
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001198 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001199 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001200 }
1201
Jeff Brown13f00f02014-10-31 14:45:50 -07001202 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001203 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001204 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001205 mEndCallKeyHandled = true;
1206 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1207 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001208 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001209 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001210 }
1211 };
1212
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001213 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001214 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001215 public void run() {
1216 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001217 }
1218 };
1219
Alan Viverettee34560b22014-07-10 14:50:06 -07001220 @Override
1221 public void showGlobalActions() {
1222 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1223 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1224 }
1225
1226 void showGlobalActionsInternal() {
1227 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001228 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001229 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001230 }
Jim Millerab954542014-10-10 18:21:49 -07001231 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001232 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1233 if (keyguardShowing) {
1234 // since it took two seconds of long press to bring this up,
1235 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001236 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001237 }
1238 }
1239
1240 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001241 return Settings.Global.getInt(
1242 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001243 }
1244
Maurice Lam99c6e072014-04-28 18:24:28 -07001245 boolean isUserSetupComplete() {
1246 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1247 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1248 }
1249
Jeff Brown13f00f02014-10-31 14:45:50 -07001250 private void handleShortPressOnHome() {
Jinsuk Kime601b712015-07-07 08:01:02 +09001251 // Turn on the connected TV and switch HDMI input if we're a HDMI playback device.
1252 getHdmiControl().turnOnTv();
1253
Jeff Brown13f00f02014-10-31 14:45:50 -07001254 // If there's a dream running then use home to escape the dream
1255 // but don't actually go home.
1256 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1257 mDreamManagerInternal.stopDream(false /*immediate*/);
1258 return;
1259 }
1260
1261 // Go home!
1262 launchHomeFromHotKey();
1263 }
1264
Jinsuk Kime601b712015-07-07 08:01:02 +09001265 /**
1266 * Creates an accessor to HDMI control service that performs the operation of
1267 * turning on TV (optional) and switching input to us. If HDMI control service
1268 * is not available or we're not a HDMI playback device, the operation is no-op.
1269 */
1270 private HdmiControl getHdmiControl() {
1271 if (null == mHdmiControl) {
1272 HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService(
1273 Context.HDMI_CONTROL_SERVICE);
1274 HdmiPlaybackClient client = null;
1275 if (manager != null) {
1276 client = manager.getPlaybackClient();
1277 }
1278 mHdmiControl = new HdmiControl(client);
1279 }
1280 return mHdmiControl;
1281 }
1282
1283 private static class HdmiControl {
1284 private final HdmiPlaybackClient mClient;
1285
1286 private HdmiControl(HdmiPlaybackClient client) {
1287 mClient = client;
1288 }
1289
1290 public void turnOnTv() {
1291 if (mClient == null) {
1292 return;
1293 }
1294 mClient.oneTouchPlay(new OneTouchPlayCallback() {
1295 @Override
1296 public void onComplete(int result) {
1297 if (result != HdmiControlManager.RESULT_SUCCESS) {
1298 Log.w(TAG, "One touch play failed: " + result);
1299 }
1300 }
1301 });
1302 }
1303 }
1304
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001305 private void handleLongPressOnHome(int deviceId) {
Joe Onorato46b0d682010-11-22 17:37:27 -08001306 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001307 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001308 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001309
Jeff Browncaca8812013-05-09 13:34:33 -07001310 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1311 toggleRecentApps();
1312 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001313 launchAssistAction(null, deviceId);
Jim Millere6ad1a82010-08-20 19:25:39 -07001314 }
1315 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001316 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001317
Jeff Browncaca8812013-05-09 13:34:33 -07001318 private void handleDoubleTapOnHome() {
1319 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1320 mHomeConsumed = true;
1321 toggleRecentApps();
1322 }
1323 }
1324
1325 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1326 @Override
1327 public void run() {
1328 if (mHomeDoubleTapPending) {
1329 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001330 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001331 }
1332 }
1333 };
1334
Mark Renoufc1256912015-03-11 14:38:23 -04001335 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001336 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001337 }
1338
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001339 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001340 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001341 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001342 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001343 mContext = context;
1344 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001345 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001346 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001347 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001348 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Michael Wrighta4d22d72015-09-16 23:19:26 +01001349 mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001350 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Mark Renoufc1256912015-03-11 14:38:23 -04001351
1352 // Init display burn-in protection
1353 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1354 com.android.internal.R.bool.config_enableBurnInProtection);
1355 // Allow a system property to override this. Used by developer settings.
1356 boolean burnInProtectionDevMode =
1357 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1358 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1359 final int minHorizontal;
1360 final int maxHorizontal;
1361 final int minVertical;
1362 final int maxVertical;
1363 final int maxRadius;
1364 if (burnInProtectionDevMode) {
1365 minHorizontal = -8;
1366 maxHorizontal = 8;
1367 minVertical = -8;
1368 maxVertical = -4;
1369 maxRadius = (isRoundWindow()) ? 6 : -1;
1370 } else {
1371 Resources resources = context.getResources();
1372 minHorizontal = resources.getInteger(
1373 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1374 maxHorizontal = resources.getInteger(
1375 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1376 minVertical = resources.getInteger(
1377 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1378 maxVertical = resources.getInteger(
1379 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1380 maxRadius = resources.getInteger(
1381 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1382 }
1383 mBurnInProtectionHelper = new BurnInProtectionHelper(
1384 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001385 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001386
Jeff Brown70825162012-03-28 17:27:48 -07001387 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001388 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001389 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001390 try {
1391 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1392 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001393 mSettingsObserver = new SettingsObserver(mHandler);
1394 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001395 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001396 mUiMode = context.getResources().getInteger(
1397 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001398 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1399 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1400 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1401 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001402 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1403 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1404 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1405 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1406 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1407 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1408 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1409 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001410
Jeff Brown96307042012-07-27 15:51:34 -07001411 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1412 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001413 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001414 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1415 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001416 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001417 mSupportAutoRotation = mContext.getResources().getBoolean(
1418 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001419 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001420 com.android.internal.R.integer.config_lidOpenRotation);
1421 mCarDockRotation = readRotation(
1422 com.android.internal.R.integer.config_carDockRotation);
1423 mDeskDockRotation = readRotation(
1424 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001425 mUndockedHdmiRotation = readRotation(
1426 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001427 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1428 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1429 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1430 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001431 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1432 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1433 mLidNavigationAccessibility = mContext.getResources().getInteger(
1434 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001435 mLidControlsSleep = mContext.getResources().getBoolean(
1436 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001437 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1438 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001439
1440 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1441 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1442 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1443 || mContext.getResources().getBoolean(
1444 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1445 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1446 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001447 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1448 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001449 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1450 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1451 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1452 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1453 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1454 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1455
Bryce Lee55e846d2014-11-04 12:43:44 -08001456 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1457 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1458
Bryce Leed3b28402015-03-09 15:49:13 +00001459 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1460 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1461
Jeff Brown13f00f02014-10-31 14:45:50 -07001462 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1463 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1464 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1465 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1466 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1467 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1468 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1469 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001470 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1471 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001472
John Spurlock61560172015-02-06 19:46:04 -05001473 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001474
Jeff Brownf71343d2013-05-31 17:59:11 -07001475 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001476
Svetoslav8e3feb12014-02-24 13:46:47 -08001477 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1478 Context.ACCESSIBILITY_SERVICE);
1479
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001480 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001481 IntentFilter filter = new IntentFilter();
1482 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1483 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1484 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1485 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001486 filter.addAction(Intent.ACTION_DOCK_EVENT);
1487 Intent intent = context.registerReceiver(mDockReceiver, filter);
1488 if (intent != null) {
1489 // Retrieve current sticky dock event broadcast.
1490 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1491 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1492 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001493
Jeff Brown6aaf2952012-10-05 16:01:08 -07001494 // register for dream-related broadcasts
1495 filter = new IntentFilter();
1496 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1497 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1498 context.registerReceiver(mDreamReceiver, filter);
1499
Christopher Tate5e08af02012-09-21 17:17:22 -07001500 // register for multiuser-relevant broadcasts
1501 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1502 context.registerReceiver(mMultiuserReceiver, filter);
1503
John Spurlock57306e62013-04-22 09:48:49 -04001504 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001505 mSystemGestures = new SystemGesturesPointerEventListener(context,
1506 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001507 @Override
1508 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001509 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001510 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001511 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001512 }
1513 @Override
1514 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001515 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001516 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001517 }
1518 }
1519 @Override
1520 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001521 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001522 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001523 }
1524 }
1525 @Override
Michael Wrighta4d22d72015-09-16 23:19:26 +01001526 public void onFling(int duration) {
1527 if (mPowerManagerInternal != null) {
1528 mPowerManagerInternal.powerHint(
1529 PowerManagerInternal.POWER_HINT_INTERACTION, duration);
1530 }
1531 }
1532 @Override
John Spurlockad3e6cb2013-04-30 08:47:43 -04001533 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001534 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001535 }
Adrian Roos3595be42015-03-05 16:31:15 +01001536 @Override
1537 public void onDown() {
1538 mOrientationListener.onTouchStart();
1539 }
1540 @Override
1541 public void onUpOrCancel() {
1542 mOrientationListener.onTouchEnd();
1543 }
Jun Mukaid2e7e352015-07-22 17:14:02 -07001544 @Override
1545 public void onMouseHoverAtTop() {
1546 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1547 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1548 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS;
1549 mHandler.sendMessageDelayed(msg, 500);
1550 }
1551 @Override
1552 public void onMouseHoverAtBottom() {
1553 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1554 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1555 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION;
1556 mHandler.sendMessageDelayed(msg, 500);
1557 }
1558 @Override
1559 public void onMouseLeaveFromEdge() {
1560 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1561 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001562 });
John Spurlockf1a36642013-10-12 17:50:42 -04001563 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001564 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001565
Jeff Brownc2346132012-04-13 01:55:38 -07001566 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001567 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1568 com.android.internal.R.array.config_longPressVibePattern);
1569 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1570 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001571 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1572 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001573 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1574 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001575 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1576 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001577 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1578 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1579 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1580 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001581 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1582 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001583
Christopher Tatee90585f2012-03-05 18:56:25 -08001584 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1585 com.android.internal.R.bool.config_enableScreenshotChord);
1586
Justin Kohd378ad72013-04-01 12:18:26 -07001587 mGlobalKeyManager = new GlobalKeyManager(mContext);
1588
Joe Onoratoea495d42011-04-06 11:41:11 -07001589 // Controls rotation and the like.
1590 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001591
1592 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001593 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001594 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1595 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001596 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001597
1598 mWindowManagerInternal.registerAppTransitionListener(
1599 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001600 }
1601
Jeff Brownf71343d2013-05-31 17:59:11 -07001602 /**
1603 * Read values from config.xml that may be overridden depending on
1604 * the configuration of the device.
1605 * eg. Disable long press on home goes to recents on sw600dp.
1606 */
1607 private void readConfigurationDependentBehaviors() {
1608 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1609 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1610 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1611 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1612 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1613 }
1614
1615 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1616 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1617 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1618 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1619 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1620 }
1621 }
1622
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001623 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001624 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001625 // This method might be called before the policy has been fully initialized
1626 // or for other displays we don't care about.
1627 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1628 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001629 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001630 mDisplay = display;
1631
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001632 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001633 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001634 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001635 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001636 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001637 mLandscapeRotation = Surface.ROTATION_0;
1638 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001639 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001640 mPortraitRotation = Surface.ROTATION_90;
1641 mUpsideDownRotation = Surface.ROTATION_270;
1642 } else {
1643 mPortraitRotation = Surface.ROTATION_270;
1644 mUpsideDownRotation = Surface.ROTATION_90;
1645 }
1646 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001647 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001648 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001649 mPortraitRotation = Surface.ROTATION_0;
1650 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001651 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001652 mLandscapeRotation = Surface.ROTATION_270;
1653 mSeascapeRotation = Surface.ROTATION_90;
1654 } else {
1655 mLandscapeRotation = Surface.ROTATION_90;
1656 mSeascapeRotation = Surface.ROTATION_270;
1657 }
1658 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001659
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001660 mStatusBarHeight =
1661 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001662
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001663 // Height of the navigation bar when presented horizontally at bottom
1664 mNavigationBarHeightForRotation[mPortraitRotation] =
1665 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001666 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001667 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001668 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1669 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001670
1671 // Width of the navigation bar when presented vertically along one side
1672 mNavigationBarWidthForRotation[mPortraitRotation] =
1673 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1674 mNavigationBarWidthForRotation[mLandscapeRotation] =
1675 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001676 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001677
1678 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001679 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001680 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001681
Devin Kimd7b12b42014-05-05 14:34:58 -07001682 // Allow the navigation bar to move on non-square small devices (phones).
1683 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001684
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001685 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001686 // Allow a system property to override this. Used by the emulator.
1687 // See also hasNavigationBar().
1688 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1689 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001690 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001691 } else if ("0".equals(navBarOverride)) {
1692 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001693 }
1694
Jeff Brown27f1d672012-10-17 18:32:34 -07001695 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1696 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001697 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001698 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001699 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001700 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001701 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001702 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001703
Chong Zhangae6119ff2014-11-11 18:54:39 -08001704 // For demo purposes, allow the rotation of the remote display to be controlled.
1705 // By default, remote display locks rotation to landscape.
1706 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1707 mDemoRotation = mPortraitRotation;
1708 } else {
1709 mDemoRotation = mLandscapeRotation;
1710 }
1711 mDemoRotationLock = SystemProperties.getBoolean(
1712 "persist.demo.rotationlock", false);
1713
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001714 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1715 // http://developer.android.com/guide/practices/screens_support.html#range
1716 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1717 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1718 // For debug purposes the next line turns this feature off with:
1719 // $ adb shell setprop config.override_forced_orient true
1720 // $ adb shell wm size reset
1721 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1722 }
1723
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001724 /**
1725 * @return whether the navigation bar can be hidden, e.g. the device has a
1726 * navigation bar and touch exploration is not enabled
1727 */
1728 private boolean canHideNavigationBar() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04001729 return mHasNavigationBar;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001730 }
1731
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001732 @Override
1733 public boolean isDefaultOrientationForced() {
1734 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001735 }
1736
Dianne Hackbornc652de82013-02-15 16:32:56 -08001737 @Override
1738 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1739 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1740 mOverscanLeft = left;
1741 mOverscanTop = top;
1742 mOverscanRight = right;
1743 mOverscanBottom = bottom;
1744 }
1745 }
1746
Dianne Hackbornc777e072010-02-12 13:07:59 -08001747 public void updateSettings() {
1748 ContentResolver resolver = mContext.getContentResolver();
1749 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001750 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001751 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001752 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001753 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1754 UserHandle.USER_CURRENT);
1755 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001756 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001757 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1758 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001759
Jeff Browna20dda42014-05-27 20:57:24 -07001760 // Configure wake gesture.
1761 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1762 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1763 UserHandle.USER_CURRENT) != 0;
1764 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1765 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1766 updateWakeGestureListenerLp();
1767 }
1768
Jeff Brown207673cd2012-06-05 17:47:11 -07001769 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001770 int userRotation = Settings.System.getIntForUser(resolver,
1771 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1772 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001773 if (mUserRotation != userRotation) {
1774 mUserRotation = userRotation;
1775 updateRotation = true;
1776 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001777 int userRotationMode = Settings.System.getIntForUser(resolver,
1778 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001779 WindowManagerPolicy.USER_ROTATION_FREE :
1780 WindowManagerPolicy.USER_ROTATION_LOCKED;
1781 if (mUserRotationMode != userRotationMode) {
1782 mUserRotationMode = userRotationMode;
1783 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001784 updateOrientationListenerLp();
1785 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001786
Dianne Hackbornc777e072010-02-12 13:07:59 -08001787 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001788 int pointerLocation = Settings.System.getIntForUser(resolver,
1789 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001790 if (mPointerLocationMode != pointerLocation) {
1791 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001792 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1793 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001794 }
1795 }
1796 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001797 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1798 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1799 String imId = Settings.Secure.getStringForUser(resolver,
1800 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001801 boolean hasSoftInput = imId != null && imId.length() > 0;
1802 if (mHasSoftInput != hasSoftInput) {
1803 mHasSoftInput = hasSoftInput;
1804 updateRotation = true;
1805 }
John Spurlockf1a36642013-10-12 17:50:42 -04001806 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001807 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001808 }
tiger_huangcc6366d2015-06-29 17:17:30 +08001809 }
1810 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05001811 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001812 }
1813 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001814 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001815 }
Jeff Brown70825162012-03-28 17:27:48 -07001816 }
1817
Jeff Browna20dda42014-05-27 20:57:24 -07001818 private void updateWakeGestureListenerLp() {
1819 if (shouldEnableWakeGestureLp()) {
1820 mWakeGestureListener.requestWakeUpTrigger();
1821 } else {
1822 mWakeGestureListener.cancelWakeUpTrigger();
1823 }
1824 }
1825
1826 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001827 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001828 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1829 && mWakeGestureListener.isSupported();
1830 }
1831
Jeff Brown70825162012-03-28 17:27:48 -07001832 private void enablePointerLocation() {
1833 if (mPointerLocationView == null) {
1834 mPointerLocationView = new PointerLocationView(mContext);
1835 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001836 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1837 WindowManager.LayoutParams.MATCH_PARENT,
1838 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001839 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001840 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1841 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1842 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1843 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001844 if (ActivityManager.isHighEndGfx()) {
1845 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1846 lp.privateFlags |=
1847 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1848 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001849 lp.format = PixelFormat.TRANSLUCENT;
1850 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001851 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001852 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001853 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001854 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001855 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001856 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001857 }
Jeff Brown70825162012-03-28 17:27:48 -07001858
1859 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001860 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001861 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1862 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001863 wm.removeView(mPointerLocationView);
1864 mPointerLocationView = null;
1865 }
1866 }
1867
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001868 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001869 try {
1870 int rotation = mContext.getResources().getInteger(resID);
1871 switch (rotation) {
1872 case 0:
1873 return Surface.ROTATION_0;
1874 case 90:
1875 return Surface.ROTATION_90;
1876 case 180:
1877 return Surface.ROTATION_180;
1878 case 270:
1879 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001880 }
1881 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001882 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001883 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001884 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001885 }
1886
1887 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001888 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001889 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001890 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001891
1892 outAppOp[0] = AppOpsManager.OP_NONE;
1893
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001894 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1895 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1896 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1897 return WindowManagerGlobal.ADD_INVALID_TYPE;
1898 }
1899
1900 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1901 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001902 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001903 }
1904 String permission = null;
1905 switch (type) {
1906 case TYPE_TOAST:
1907 // XXX right now the app process has complete control over
1908 // this... should introduce a token to let the system
1909 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001910 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001911 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001912 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001913 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001914 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001915 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001916 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001917 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001918 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001919 break;
1920 case TYPE_PHONE:
1921 case TYPE_PRIORITY_PHONE:
1922 case TYPE_SYSTEM_ALERT:
1923 case TYPE_SYSTEM_ERROR:
1924 case TYPE_SYSTEM_OVERLAY:
1925 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001926 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001927 break;
1928 default:
1929 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1930 }
1931 if (permission != null) {
Billy Laucbe540f2015-06-25 01:51:44 +01001932 if (permission == android.Manifest.permission.SYSTEM_ALERT_WINDOW) {
1933 final int callingUid = Binder.getCallingUid();
Billy Lau060275f2015-07-15 22:29:19 +01001934 // system processes will be automatically allowed privilege to draw
Billy Laucbe540f2015-06-25 01:51:44 +01001935 if (callingUid == Process.SYSTEM_UID) {
1936 return WindowManagerGlobal.ADD_OKAY;
1937 }
1938
Billy Lau060275f2015-07-15 22:29:19 +01001939 // check if user has enabled this operation. SecurityException will be thrown if
1940 // this app has not been allowed by the user
Billy Laucbe540f2015-06-25 01:51:44 +01001941 final int mode = mAppOpsManager.checkOp(outAppOp[0], callingUid,
1942 attrs.packageName);
Billy Lau060275f2015-07-15 22:29:19 +01001943 switch (mode) {
1944 case AppOpsManager.MODE_ALLOWED:
1945 case AppOpsManager.MODE_IGNORED:
1946 // although we return ADD_OKAY for MODE_IGNORED, the added window will
1947 // actually be hidden in WindowManagerService
1948 return WindowManagerGlobal.ADD_OKAY;
1949 case AppOpsManager.MODE_ERRORED:
Billy Laucbe540f2015-06-25 01:51:44 +01001950 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
Billy Lau060275f2015-07-15 22:29:19 +01001951 default:
1952 // in the default mode, we will make a decision here based on
1953 // checkCallingPermission()
1954 if (mContext.checkCallingPermission(permission) !=
1955 PackageManager.PERMISSION_GRANTED) {
1956 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
1957 } else {
1958 return WindowManagerGlobal.ADD_OKAY;
1959 }
Billy Laucbe540f2015-06-25 01:51:44 +01001960 }
Billy Laucbe540f2015-06-25 01:51:44 +01001961 }
1962
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001963 if (mContext.checkCallingOrSelfPermission(permission)
1964 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001965 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001966 }
1967 }
Jeff Brown98365d72012-08-19 20:30:52 -07001968 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001969 }
Craig Mautner88400d32012-09-30 12:35:45 -07001970
1971 @Override
1972 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1973
1974 // If this switch statement is modified, modify the comment in the declarations of
1975 // the type in {@link WindowManager.LayoutParams} as well.
1976 switch (attrs.type) {
1977 default:
1978 // These are the windows that by default are shown only to the user that created
1979 // them. If this needs to be overridden, set
1980 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1981 // {@link WindowManager.LayoutParams}. Note that permission
1982 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1983 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1984 return true;
1985 }
1986 break;
1987
1988 // These are the windows that by default are shown to all users. However, to
1989 // protect against spoofing, check permissions below.
1990 case TYPE_APPLICATION_STARTING:
1991 case TYPE_BOOT_PROGRESS:
1992 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07001993 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001994 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001995 case TYPE_KEYGUARD_DIALOG:
1996 case TYPE_MAGNIFICATION_OVERLAY:
1997 case TYPE_NAVIGATION_BAR:
1998 case TYPE_NAVIGATION_BAR_PANEL:
1999 case TYPE_PHONE:
2000 case TYPE_POINTER:
2001 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07002002 case TYPE_SEARCH_BAR:
2003 case TYPE_STATUS_BAR:
2004 case TYPE_STATUS_BAR_PANEL:
2005 case TYPE_STATUS_BAR_SUB_PANEL:
2006 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07002007 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07002008 case TYPE_PRIVATE_PRESENTATION:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002009 case TYPE_DOCK_DIVIDER:
Craig Mautner88400d32012-09-30 12:35:45 -07002010 break;
2011 }
2012
2013 // Check if third party app has set window to system window type.
2014 return mContext.checkCallingOrSelfPermission(
2015 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
2016 != PackageManager.PERMISSION_GRANTED;
2017 }
2018
Craig Mautner967212c2013-04-13 21:10:58 -07002019 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002020 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
2021 switch (attrs.type) {
2022 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07002023 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002024 // These types of windows can't receive input events.
2025 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2026 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002027 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002028 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002029 case TYPE_STATUS_BAR:
2030
2031 // If the Keyguard is in a hidden state (occluded by another window), we force to
2032 // remove the wallpaper and keyguard flag so that any change in-flight after setting
2033 // the keyguard as occluded wouldn't set these flags again.
2034 // See {@link #processKeyguardSetHiddenResultLw}.
2035 if (mKeyguardHidden) {
2036 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2037 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2038 }
2039 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002040 }
Adrian Roos38502112014-04-09 21:04:11 +02002041
2042 if (attrs.type != TYPE_STATUS_BAR) {
2043 // The status bar is the only window allowed to exhibit keyguard behavior.
2044 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2045 }
Adrian Roosea562512014-05-05 13:33:03 +02002046
2047 if (ActivityManager.isHighEndGfx()
2048 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02002049 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02002050 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
2051 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002052 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002053
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002054 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07002055 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002056 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002057
Michael Wright3818c922014-09-02 13:59:07 -07002058 private void readCameraLensCoverState() {
2059 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
2060 }
2061
Jeff Browndaa37532012-05-01 15:54:03 -07002062 private boolean isHidden(int accessibilityMode) {
2063 switch (accessibilityMode) {
2064 case 1:
2065 return mLidState == LID_CLOSED;
2066 case 2:
2067 return mLidState == LID_OPEN;
2068 default:
2069 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002070 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002071 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002072
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002073 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002074 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07002075 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
2076 int navigationPresence) {
2077 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
2078
Jeff Brownf71343d2013-05-31 17:59:11 -07002079 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002080 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07002081 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08002082
Jeff Browndaa37532012-05-01 15:54:03 -07002083 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
2084 || (keyboardPresence == PRESENCE_INTERNAL
2085 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002086 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07002087 if (!mHasSoftInput) {
2088 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
2089 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002090 }
2091
Jeff Browndaa37532012-05-01 15:54:03 -07002092 if (config.navigation == Configuration.NAVIGATION_NONAV
2093 || (navigationPresence == PRESENCE_INTERNAL
2094 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002095 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08002096 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002097 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002098
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002099 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002100 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002101 public int windowTypeToLayerLw(int type) {
2102 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002103 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002104 }
2105 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07002106 case TYPE_PRIVATE_PRESENTATION:
2107 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002108 case TYPE_WALLPAPER:
2109 // wallpaper is at the bottom, though the window manager may move it.
2110 return 2;
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002111 case TYPE_DOCK_DIVIDER:
2112 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002113 case TYPE_PHONE:
2114 return 3;
2115 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002116 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002117 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002118 case TYPE_VOICE_INTERACTION:
2119 // voice interaction layer is almost immediately above apps.
2120 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07002121 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002122 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07002123 case TYPE_SYSTEM_DIALOG:
2124 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002125 case TYPE_TOAST:
2126 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07002127 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002128 case TYPE_PRIORITY_PHONE:
2129 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07002130 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002131 case TYPE_DREAM:
2132 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07002133 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002134 case TYPE_SYSTEM_ALERT:
2135 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002136 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002137 case TYPE_INPUT_METHOD:
2138 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002139 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002140 case TYPE_INPUT_METHOD_DIALOG:
2141 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002142 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08002143 case TYPE_KEYGUARD_SCRIM:
2144 // the safety window that shows behind keyguard while keyguard is starting
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002145 return 14;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002146 case TYPE_STATUS_BAR_SUB_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002147 return 15;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002148 case TYPE_STATUS_BAR:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002149 return 16;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002150 case TYPE_STATUS_BAR_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002151 return 17;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002152 case TYPE_KEYGUARD_DIALOG:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002153 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002154 case TYPE_VOLUME_OVERLAY:
2155 // the on-screen volume indicator and controller shown when the user
2156 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002157 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002158 case TYPE_SYSTEM_OVERLAY:
2159 // the on-screen volume indicator and controller shown when the user
2160 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002161 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002162 case TYPE_NAVIGATION_BAR:
2163 // the navigation bar, if available, shows atop most things
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002164 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002165 case TYPE_NAVIGATION_BAR_PANEL:
2166 // some panels (e.g. search) need to show on top of the navigation bar
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002167 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002168 case TYPE_SYSTEM_ERROR:
2169 // system-level error dialogs
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002170 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002171 case TYPE_MAGNIFICATION_OVERLAY:
2172 // used to highlight the magnified portion of a display
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002173 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002174 case TYPE_DISPLAY_OVERLAY:
2175 // used to simulate secondary display devices
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002176 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002177 case TYPE_DRAG:
2178 // the drag layer: input for drag-and-drop is associated with this window,
2179 // which sits above all other focusable windows
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002180 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002181 case TYPE_ACCESSIBILITY_OVERLAY:
2182 // overlay put by accessibility services to intercept user interaction
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002183 return 27;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002184 case TYPE_SECURE_SYSTEM_OVERLAY:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002185 return 28;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002186 case TYPE_BOOT_PROGRESS:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002187 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002188 case TYPE_POINTER:
2189 // the (mouse) pointer layer
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002190 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002191 }
2192 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002193 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002194 }
2195
2196 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002197 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002198 public int subWindowTypeToLayerLw(int type) {
2199 switch (type) {
2200 case TYPE_APPLICATION_PANEL:
2201 case TYPE_APPLICATION_ATTACHED_DIALOG:
2202 return APPLICATION_PANEL_SUBLAYER;
2203 case TYPE_APPLICATION_MEDIA:
2204 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002205 case TYPE_APPLICATION_MEDIA_OVERLAY:
2206 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002207 case TYPE_APPLICATION_SUB_PANEL:
2208 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002209 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2210 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002211 }
2212 Log.e(TAG, "Unknown sub-window type: " + type);
2213 return 0;
2214 }
2215
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002216 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002217 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002218 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002219 }
2220
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002221 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002222 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002223 if (mHasNavigationBar) {
2224 // For a basic navigation bar, when we are in landscape mode we place
2225 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002226 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2227 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002228 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002229 }
2230 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002231 }
2232
Jose Lima9546b202014-07-02 17:21:51 -07002233 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002234 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002235 if (mHasNavigationBar) {
2236 // For a basic navigation bar, when we are in portrait mode we place
2237 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002238 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2239 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002240 }
2241 }
2242 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002243 }
2244
Jose Lima9546b202014-07-02 17:21:51 -07002245 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002246 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2247 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002248 }
2249
Jose Lima9546b202014-07-02 17:21:51 -07002250 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002251 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002252 // There is a separate status bar at the top of the display. We don't count that as part
2253 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002254 // we do want to exclude it since applications can't generally use that part
2255 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002256 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002257 }
2258
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002259 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002260 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2261 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002262 (isKeyguardHostWindow(attrs) &&
2263 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002264 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002265 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002266
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002267 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002268 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2269 return attrs.type == TYPE_STATUS_BAR;
2270 }
2271
2272 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002273 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002274 switch (attrs.type) {
2275 case TYPE_STATUS_BAR:
2276 case TYPE_NAVIGATION_BAR:
2277 case TYPE_WALLPAPER:
2278 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002279 case TYPE_KEYGUARD_SCRIM:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002280 case TYPE_DOCK_DIVIDER:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002281 return false;
2282 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002283 // Hide only windows below the keyguard host window.
2284 return windowTypeToLayerLw(win.getBaseType())
2285 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002286 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002287 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002288
Craig Mautner7d7808f2014-09-11 18:02:38 -07002289 @Override
2290 public WindowState getWinShowWhenLockedLw() {
2291 return mWinShowWhenLocked;
2292 }
2293
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002294 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002295 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002296 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2297 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002298 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002299 if (!SHOW_STARTING_ANIMATIONS) {
2300 return null;
2301 }
2302 if (packageName == null) {
2303 return null;
2304 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002305
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002306 WindowManager wm = null;
2307 View view = null;
2308
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002309 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002310 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002311 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2312 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2313 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002314 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002315 try {
2316 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002317 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002318 } catch (PackageManager.NameNotFoundException e) {
2319 // Ignore
2320 }
2321 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002322
Jorim Jaggia16cc152015-06-01 16:55:05 -07002323 PhoneWindow win = new PhoneWindow(context);
2324 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002325
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002326 Resources r = context.getResources();
2327 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002328
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002329 win.setType(
2330 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002331
2332 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2333 // Assumes it's safe to show starting windows of launched apps while
2334 // the keyguard is being hidden. This is okay because starting windows never show
2335 // secret information.
2336 if (mKeyguardHidden) {
2337 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2338 }
2339 }
2340
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002341 // Force the window flags: this is a fake window, so it is not really
2342 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2343 // flag because we do know that the next window will take input
2344 // focus, so we want to get the IME window up on top of us right away.
2345 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002346 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002347 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2348 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2349 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002350 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002351 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2352 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2353 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002354
Adam Powell04fe6eb2013-05-31 14:39:48 -07002355 win.setDefaultIcon(icon);
2356 win.setDefaultLogo(logo);
2357
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002358 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002359 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002360
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002361 final WindowManager.LayoutParams params = win.getAttributes();
2362 params.token = appToken;
2363 params.packageName = packageName;
2364 params.windowAnimations = win.getWindowStyle().getResourceId(
2365 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002366 params.privateFlags |=
2367 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002368 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002369
2370 if (!compatInfo.supportsScreen()) {
2371 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2372 }
2373
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002374 params.setTitle("Starting " + packageName);
2375
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002376 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2377 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002378
Craig Mautner6fbda632012-07-03 09:26:39 -07002379 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002380 TAG, "Adding starting window for " + packageName
2381 + " / " + appToken + ": "
2382 + (view.getParent() != null ? view : null));
2383
2384 wm.addView(view, params);
2385
2386 // Only return the view if it was successfully added to the
2387 // window manager... which we can tell by it having a parent.
2388 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002389 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002390 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002391 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2392 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002393 } catch (RuntimeException e) {
2394 // don't crash if something else bad happens, for example a
2395 // failure loading resources because we are loading from an app
2396 // on external storage that has been unmounted.
2397 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002398 } finally {
2399 if (view != null && view.getParent() == null) {
2400 Log.w(TAG, "view not successfully added to wm, removing view");
2401 wm.removeViewImmediate(view);
2402 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002403 }
2404
2405 return null;
2406 }
2407
2408 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002409 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002410 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002411 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2412 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002413
2414 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002415 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002416 wm.removeView(window);
2417 }
2418 }
2419
2420 /**
2421 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002422 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002423 * Currently enforces that three window types are singletons:
2424 * <ul>
2425 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002426 * <li>KEYGUARD_TYPE</li>
2427 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002428 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002429 * @param win The window to be added
2430 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002431 *
Jeff Brown98365d72012-08-19 20:30:52 -07002432 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2433 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002434 */
Jose Lima9546b202014-07-02 17:21:51 -07002435 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002436 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2437 switch (attrs.type) {
2438 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002439 mContext.enforceCallingOrSelfPermission(
2440 android.Manifest.permission.STATUS_BAR_SERVICE,
2441 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002442 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002443 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002444 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002445 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002446 }
2447 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002448 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002449 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002450 case TYPE_NAVIGATION_BAR:
2451 mContext.enforceCallingOrSelfPermission(
2452 android.Manifest.permission.STATUS_BAR_SERVICE,
2453 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002454 if (mNavigationBar != null) {
2455 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002456 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002457 }
2458 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002459 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002460 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002461 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002462 break;
Jim Millere898ac52012-04-06 17:10:57 -07002463 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002464 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002465 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002466 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002467 mContext.enforceCallingOrSelfPermission(
2468 android.Manifest.permission.STATUS_BAR_SERVICE,
2469 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002470 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002471 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002472 if (mKeyguardScrim != null) {
2473 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2474 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002475 mKeyguardScrim = win;
2476 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002477 }
Jeff Brown98365d72012-08-19 20:30:52 -07002478 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002479 }
2480
2481 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002482 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002483 public void removeWindowLw(WindowState win) {
2484 if (mStatusBar == win) {
2485 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002486 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002487 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002488 } else if (mKeyguardScrim == win) {
2489 Log.v(TAG, "Removing keyguard scrim");
2490 mKeyguardScrim = null;
2491 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002492 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002493 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002494 }
2495 }
2496
2497 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002498
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002499 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002500 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002501 public int selectAnimationLw(WindowState win, int transit) {
2502 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2503 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002504 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002505 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002506 if (transit == TRANSIT_EXIT
2507 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002508 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002509 } else if (transit == TRANSIT_ENTER
2510 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002511 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002512 }
2513 } else if (win == mNavigationBar) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002514 if (win.getAttrs().windowAnimations != 0) {
2515 return 0;
2516 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002517 // This can be on either the bottom or the right.
2518 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002519 if (transit == TRANSIT_EXIT
2520 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002521 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002522 } else if (transit == TRANSIT_ENTER
2523 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002524 return R.anim.dock_bottom_enter;
2525 }
2526 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002527 if (transit == TRANSIT_EXIT
2528 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002529 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002530 } else if (transit == TRANSIT_ENTER
2531 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002532 return R.anim.dock_right_enter;
2533 }
2534 }
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08002535 } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) {
2536 if (transit == TRANSIT_ENTER) {
2537 return R.anim.fade_in;
2538 } else if (transit == TRANSIT_EXIT) {
2539 return R.anim.fade_out;
2540 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002541 }
2542
2543 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002544 if (win.hasAppShownWindows()) {
2545 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2546 return com.android.internal.R.anim.app_starting_exit;
2547 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002548 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002549 && transit == TRANSIT_ENTER) {
2550 // Special case: we are animating in a dream, while the keyguard
2551 // is shown. We don't want an animation on the dream, because
2552 // we need it shown immediately with the keyguard animating away
2553 // to reveal it.
2554 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002555 }
2556
2557 return 0;
2558 }
2559
Craig Mautner3c174372013-02-21 17:54:37 -08002560 @Override
2561 public void selectRotationAnimationLw(int anim[]) {
2562 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2563 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2564 + (mTopFullscreenOpaqueWindowState == null ?
2565 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2566 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2567 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2568 case ROTATION_ANIMATION_CROSSFADE:
2569 anim[0] = R.anim.rotation_animation_xfade_exit;
2570 anim[1] = R.anim.rotation_animation_enter;
2571 break;
2572 case ROTATION_ANIMATION_JUMPCUT:
2573 anim[0] = R.anim.rotation_animation_jump_exit;
2574 anim[1] = R.anim.rotation_animation_enter;
2575 break;
2576 case ROTATION_ANIMATION_ROTATE:
2577 default:
2578 anim[0] = anim[1] = 0;
2579 break;
2580 }
2581 } else {
2582 anim[0] = anim[1] = 0;
2583 }
2584 }
2585
2586 @Override
2587 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2588 boolean forceDefault) {
2589 switch (exitAnimId) {
2590 case R.anim.rotation_animation_xfade_exit:
2591 case R.anim.rotation_animation_jump_exit:
2592 // These are the only cases that matter.
2593 if (forceDefault) {
2594 return false;
2595 }
2596 int anim[] = new int[2];
2597 selectRotationAnimationLw(anim);
2598 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2599 default:
2600 return true;
2601 }
2602 }
2603
2604 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002605 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2606 boolean goingToNotificationShade) {
2607 if (goingToNotificationShade) {
2608 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002609 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002610
2611 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2612 R.anim.lock_screen_behind_enter_wallpaper :
2613 R.anim.lock_screen_behind_enter);
2614
2615 // TODO: Use XML interpolators when we have log interpolators available in XML.
2616 final List<Animation> animations = set.getAnimations();
2617 for (int i = animations.size() - 1; i >= 0; --i) {
2618 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2619 }
2620
2621 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002622 }
2623
2624
2625 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002626 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2627 if (goingToNotificationShade) {
2628 return null;
2629 } else {
2630 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2631 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002632 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002633
2634 private static void awakenDreams() {
2635 IDreamManager dreamManager = getDreamManager();
2636 if (dreamManager != null) {
2637 try {
2638 dreamManager.awaken();
2639 } catch (RemoteException e) {
2640 // fine, stay asleep then
2641 }
2642 }
2643 }
2644
2645 static IDreamManager getDreamManager() {
2646 return IDreamManager.Stub.asInterface(
2647 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2648 }
2649
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002650 TelecomManager getTelecommService() {
2651 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002652 }
2653
Jeff Brown4d396052010-10-29 21:50:21 -07002654 static IAudioService getAudioService() {
2655 IAudioService audioService = IAudioService.Stub.asInterface(
2656 ServiceManager.checkService(Context.AUDIO_SERVICE));
2657 if (audioService == null) {
2658 Log.w(TAG, "Unable to find IAudioService interface.");
2659 }
2660 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002661 }
2662
2663 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002664 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002665 }
2666
2667 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2668 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2669 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2670 };
2671
2672 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002673 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002674 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002675 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002676 final int keyCode = event.getKeyCode();
2677 final int repeatCount = event.getRepeatCount();
2678 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002679 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002680 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2681 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002682
Jeff Brown40013652012-05-16 21:22:36 -07002683 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002684 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002685 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2686 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002687 }
2688
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002689 // If we think we might have a volume down & power key chord on the way
2690 // but we're not sure, then tell the dispatcher to wait a little while and
2691 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002692 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002693 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002694 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002695 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2696 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002697 if (now < timeoutTime) {
2698 return timeoutTime - now;
2699 }
2700 }
2701 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002702 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002703 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002704 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002705 }
2706 return -1;
2707 }
2708 }
2709
Michael Wright6a62e552014-06-03 19:19:48 -07002710 // Cancel any pending meta actions if we see any other keys being pressed between the down
2711 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002712 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002713 mPendingMetaAction = false;
2714 }
2715
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002716 // First we always handle the home key here, so applications
2717 // can never break it, although if keyguard is on, we do let
2718 // it handle it, because that gives us the correct 5 second
2719 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002720 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002721
Jeff Brown49ed71d2010-12-06 17:13:33 -08002722 // If we have released the home key, and didn't do anything else
2723 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002724 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002725 cancelPreloadRecentApps();
2726
Jeff Brown49ed71d2010-12-06 17:13:33 -08002727 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002728 if (mHomeConsumed) {
2729 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002730 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002731 }
Jeff Browncaca8812013-05-09 13:34:33 -07002732
2733 if (canceled) {
2734 Log.i(TAG, "Ignoring HOME; event canceled.");
2735 return -1;
2736 }
2737
Yorke Lee4f803242014-12-15 23:22:06 +00002738 // If an incoming call is ringing, HOME is totally disabled.
2739 // (The user is already on the InCallUI at this point,
2740 // and his ONLY options are to answer or reject the call.)
2741 TelecomManager telecomManager = getTelecommService();
2742 if (telecomManager != null && telecomManager.isRinging()) {
2743 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2744 return -1;
2745 }
2746
Jeff Browncaca8812013-05-09 13:34:33 -07002747 // Delay handling home if a double-tap is possible.
2748 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2749 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2750 mHomeDoubleTapPending = true;
2751 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2752 ViewConfiguration.getDoubleTapTimeout());
2753 return -1;
2754 }
2755
Jeff Brown13f00f02014-10-31 14:45:50 -07002756 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002757 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002758 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002759
2760 // If a system window has focus, then it doesn't make sense
2761 // right now to interact with applications.
2762 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2763 if (attrs != null) {
2764 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002765 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2766 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2767 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002768 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002769 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002770 }
2771 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2772 for (int i=0; i<typeCount; i++) {
2773 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2774 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002775 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002776 }
2777 }
2778 }
Jeff Browncaca8812013-05-09 13:34:33 -07002779
2780 // Remember that home is pressed and handle special actions.
2781 if (repeatCount == 0) {
2782 mHomePressed = true;
2783 if (mHomeDoubleTapPending) {
2784 mHomeDoubleTapPending = false;
2785 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2786 handleDoubleTapOnHome();
2787 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2788 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2789 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002790 }
Jeff Browncaca8812013-05-09 13:34:33 -07002791 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2792 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002793 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002794 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002795 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002796 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002797 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002798 // Hijack modified menu keys for debugging features
2799 final int chordBug = KeyEvent.META_SHIFT_ON;
2800
2801 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002802 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002803 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002804 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2805 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002806 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002807 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002808 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002809 Intent service = new Intent();
2810 service.setClassName(mContext, "com.android.server.LoadAverageService");
2811 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002812 boolean shown = Settings.Global.getInt(
2813 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002814 if (!shown) {
2815 mContext.startService(service);
2816 } else {
2817 mContext.stopService(service);
2818 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002819 Settings.Global.putInt(
2820 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002821 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002822 }
2823 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002824 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002825 if (down) {
2826 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002827 mSearchKeyShortcutPending = true;
2828 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002829 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002830 } else {
2831 mSearchKeyShortcutPending = false;
2832 if (mConsumeSearchKeyUp) {
2833 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002834 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002835 }
2836 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002837 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002838 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002839 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002840 if (down && repeatCount == 0) {
2841 preloadRecentApps();
2842 } else if (!down) {
2843 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002844 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002845 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002846 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002847 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2848 if (down) {
2849 IStatusBarService service = getStatusBarService();
2850 if (service != null) {
2851 try {
2852 service.expandNotificationsPanel();
2853 } catch (RemoteException e) {
2854 // do nothing.
2855 }
2856 }
2857 }
Clara Bayarrif2debb12015-07-10 14:47:17 +01002858 } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) {
2859 if (down) {
2860 if (repeatCount == 0) {
2861 showKeyboardShortcutsMenu();
2862 }
2863 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002864 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2865 if (down) {
2866 if (repeatCount == 0) {
2867 mAssistKeyLongPressed = false;
2868 } else if (repeatCount == 1) {
2869 mAssistKeyLongPressed = true;
2870 if (!keyguardOn) {
2871 launchAssistLongPressAction();
2872 }
2873 }
2874 } else {
2875 if (mAssistKeyLongPressed) {
2876 mAssistKeyLongPressed = false;
2877 } else {
2878 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002879 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002880 }
2881 }
2882 }
2883 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002884 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2885 if (!down) {
2886 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002887 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002888 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2889 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07002890 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
2891 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
2892 if (dic != null) {
2893 try {
2894 dic.exitIdle("voice-search");
2895 } catch (RemoteException e) {
2896 }
2897 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002898 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002899 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002900 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002901 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002902 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002903 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2904 if (down && repeatCount == 0) {
2905 mHandler.post(mScreenshotRunnable);
2906 }
2907 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002908 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2909 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2910 if (down) {
2911 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2912
2913 // Disable autobrightness if it's on
2914 int auto = Settings.System.getIntForUser(
2915 mContext.getContentResolver(),
2916 Settings.System.SCREEN_BRIGHTNESS_MODE,
2917 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2918 UserHandle.USER_CURRENT_OR_SELF);
2919 if (auto != 0) {
2920 Settings.System.putIntForUser(mContext.getContentResolver(),
2921 Settings.System.SCREEN_BRIGHTNESS_MODE,
2922 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2923 UserHandle.USER_CURRENT_OR_SELF);
2924 }
2925
2926 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2927 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2928 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2929 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2930 Settings.System.SCREEN_BRIGHTNESS,
2931 mPowerManager.getDefaultScreenBrightnessSetting(),
2932 UserHandle.USER_CURRENT_OR_SELF);
2933 brightness += step;
2934 // Make sure we don't go beyond the limits.
2935 brightness = Math.min(max, brightness);
2936 brightness = Math.max(min, brightness);
2937
2938 Settings.System.putIntForUser(mContext.getContentResolver(),
2939 Settings.System.SCREEN_BRIGHTNESS, brightness,
2940 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002941 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002942 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002943 }
2944 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002945 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002946 if (down) {
2947 mPendingMetaAction = true;
2948 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002949 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07002950 }
2951 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002952 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002953
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002954 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002955 // Any printing key that is chorded with Search should be consumed
2956 // even if no shortcut was invoked. This prevents text from being
2957 // inadvertently inserted when using a keyboard that has built-in macro
2958 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002959 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002960 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2961 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002962 mConsumeSearchKeyUp = true;
2963 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002964 if (down && repeatCount == 0 && !keyguardOn) {
2965 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2966 if (shortcutIntent != null) {
2967 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002968 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002969 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002970 } catch (ActivityNotFoundException ex) {
2971 Slog.w(TAG, "Dropping shortcut key combination because "
2972 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002973 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002974 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002975 } else {
2976 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002977 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002978 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002979 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002980 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002981 }
2982 }
2983
Jeff Brown68b909d2011-12-07 16:36:01 -08002984 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002985 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002986 && (metaState & KeyEvent.META_META_ON) != 0) {
2987 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002988 if (kcm.isPrintingKey(keyCode)) {
2989 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2990 metaState & ~(KeyEvent.META_META_ON
2991 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2992 if (shortcutIntent != null) {
2993 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2994 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002995 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002996 } catch (ActivityNotFoundException ex) {
2997 Slog.w(TAG, "Dropping shortcut key combination because "
2998 + "the activity to which it is registered was not found: "
2999 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
3000 }
3001 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08003002 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003003 }
3004 }
3005
Jeff Brown6651a632011-11-28 12:59:11 -08003006 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07003007 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08003008 String category = sApplicationLaunchKeyCategories.get(keyCode);
3009 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08003010 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08003011 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3012 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003013 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08003014 } catch (ActivityNotFoundException ex) {
3015 Slog.w(TAG, "Dropping application launch key because "
3016 + "the activity to which it is registered was not found: "
3017 + "keyCode=" + keyCode + ", category=" + category, ex);
3018 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003019 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08003020 }
3021 }
3022
Michael Wright61c46752014-08-21 16:57:33 -07003023 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08003024 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Michael Wrightd847ad52015-10-24 13:24:15 +01003025 if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) {
Jeff Brown68b909d2011-12-07 16:36:01 -08003026 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07003027 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003028 mRecentAppsHeldModifiers = shiftlessModifiers;
3029 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08003030 return -1;
3031 }
3032 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07003033 } else if (!down && mRecentAppsHeldModifiers != 0
3034 && (metaState & mRecentAppsHeldModifiers) == 0) {
3035 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07003036 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003037 }
3038
Jeff Browncf39bdf2012-05-18 14:41:19 -07003039 // Handle keyboard language switching.
3040 if (down && repeatCount == 0
3041 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3042 || (keyCode == KeyEvent.KEYCODE_SPACE
3043 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
3044 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
3045 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
3046 return -1;
3047 }
3048 if (mLanguageSwitchKeyPressed && !down
3049 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3050 || keyCode == KeyEvent.KEYCODE_SPACE)) {
3051 mLanguageSwitchKeyPressed = false;
3052 return -1;
3053 }
3054
Jeff Brown13f00f02014-10-31 14:45:50 -07003055 if (isValidGlobalKey(keyCode)
3056 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07003057 return -1;
3058 }
3059
Michael Wright6a62e552014-06-03 19:19:48 -07003060 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07003061 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07003062 return -1;
3063 }
3064
Jeff Brown68b909d2011-12-07 16:36:01 -08003065 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003066 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003067 }
3068
Jeff Brown3915bb82010-11-05 15:02:16 -07003069 /** {@inheritDoc} */
3070 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08003071 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07003072 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07003073 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08003074 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
3075 + ", flags=" + event.getFlags()
3076 + ", keyCode=" + event.getKeyCode()
3077 + ", scanCode=" + event.getScanCode()
3078 + ", metaState=" + event.getMetaState()
3079 + ", repeatCount=" + event.getRepeatCount()
3080 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07003081 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003082
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003083 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003084 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3085 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003086 final int keyCode = event.getKeyCode();
3087 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003088 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
3089 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003090
Jeff Brown54875002011-04-06 15:33:01 -07003091 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003092 final FallbackAction fallbackAction;
3093 if (initialDown) {
3094 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
3095 } else {
3096 fallbackAction = mFallbackActions.get(keyCode);
3097 }
3098
3099 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07003100 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003101 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
3102 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003103 }
3104
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003105 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
3106 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08003107 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003108 event.getAction(), fallbackAction.keyCode,
3109 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08003110 event.getDeviceId(), event.getScanCode(),
3111 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003112
3113 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
3114 fallbackEvent.recycle();
3115 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003116 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003117
3118 if (initialDown) {
3119 mFallbackActions.put(keyCode, fallbackAction);
3120 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3121 mFallbackActions.remove(keyCode);
3122 fallbackAction.recycle();
3123 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003124 }
3125 }
3126
Jeff Brown40013652012-05-16 21:22:36 -07003127 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003128 if (fallbackEvent == null) {
3129 Slog.d(TAG, "No fallback.");
3130 } else {
3131 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3132 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003133 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003134 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003135 }
3136
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003137 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003138 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003139 if ((actions & ACTION_PASS_TO_USER) != 0) {
3140 long delayMillis = interceptKeyBeforeDispatching(
3141 win, fallbackEvent, policyFlags);
3142 if (delayMillis == 0) {
3143 return true;
3144 }
3145 }
3146 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003147 }
3148
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003149 private void launchAssistLongPressAction() {
3150 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3151 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3152
3153 // launch the search activity
3154 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3155 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3156 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003157 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003158 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003159 SearchManager searchManager = getSearchManager();
3160 if (searchManager != null) {
3161 searchManager.stopSearch();
3162 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003163 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003164 } catch (ActivityNotFoundException e) {
3165 Slog.w(TAG, "No activity to handle assist long press action.", e);
3166 }
3167 }
3168
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003169 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003170 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Maurice Lam39d13812015-07-23 20:49:20 -07003171 if (!isUserSetupComplete()) {
3172 // Disable opening assist window during setup
3173 return;
3174 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003175 Bundle args = null;
3176 if (deviceId > Integer.MIN_VALUE) {
3177 args = new Bundle();
3178 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003179 }
Jorim Jaggi165ce062015-07-06 16:18:11 -07003180 if ((mContext.getResources().getConfiguration().uiMode
3181 & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
3182 // On TV, use legacy handling until assistants are implemented in the proper way.
3183 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3184 .launchLegacyAssist(hint, UserHandle.myUserId(), args);
3185 } else {
3186 try {
3187 if (hint != null) {
3188 if (args == null) {
3189 args = new Bundle();
3190 }
3191 args.putBoolean(hint, true);
3192 }
3193 IStatusBarService statusbar = getStatusBarService();
3194 if (statusbar != null) {
3195 statusbar.startAssist(args);
3196 }
3197 } catch (RemoteException e) {
3198 Slog.e(TAG, "RemoteException when starting assist", e);
3199 // re-acquire status bar service next time it is needed.
3200 mStatusBarService = null;
3201 }
3202 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003203 }
3204
Bart Sears8b1c27c2015-03-18 23:51:02 +00003205 private void startActivityAsUser(Intent intent, UserHandle handle) {
3206 if (isUserSetupComplete()) {
3207 mContext.startActivityAsUser(intent, handle);
3208 } else {
3209 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3210 }
3211 }
3212
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003213 private SearchManager getSearchManager() {
3214 if (mSearchManager == null) {
3215 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3216 }
3217 return mSearchManager;
3218 }
3219
Jeff Browncaca8812013-05-09 13:34:33 -07003220 private void preloadRecentApps() {
3221 mPreloadedRecentApps = true;
3222 try {
3223 IStatusBarService statusbar = getStatusBarService();
3224 if (statusbar != null) {
3225 statusbar.preloadRecentApps();
3226 }
3227 } catch (RemoteException e) {
3228 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3229 // re-acquire status bar service next time it is needed.
3230 mStatusBarService = null;
3231 }
3232 }
3233
3234 private void cancelPreloadRecentApps() {
3235 if (mPreloadedRecentApps) {
3236 mPreloadedRecentApps = false;
3237 try {
3238 IStatusBarService statusbar = getStatusBarService();
3239 if (statusbar != null) {
3240 statusbar.cancelPreloadRecentApps();
3241 }
3242 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003243 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003244 // re-acquire status bar service next time it is needed.
3245 mStatusBarService = null;
3246 }
3247 }
3248 }
3249
3250 private void toggleRecentApps() {
3251 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003252 try {
3253 IStatusBarService statusbar = getStatusBarService();
3254 if (statusbar != null) {
3255 statusbar.toggleRecentApps();
3256 }
3257 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003258 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3259 // re-acquire status bar service next time it is needed.
3260 mStatusBarService = null;
3261 }
3262 }
3263
Craig Mautner84984fa2014-06-19 11:19:20 -07003264 @Override
3265 public void showRecentApps() {
3266 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3267 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3268 }
3269
Winson Chung1e8d71b2014-05-16 17:05:22 -07003270 private void showRecentApps(boolean triggeredFromAltTab) {
3271 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3272 try {
3273 IStatusBarService statusbar = getStatusBarService();
3274 if (statusbar != null) {
3275 statusbar.showRecentApps(triggeredFromAltTab);
3276 }
3277 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003278 Slog.e(TAG, "RemoteException when showing recent apps", e);
3279 // re-acquire status bar service next time it is needed.
3280 mStatusBarService = null;
3281 }
3282 }
3283
Clara Bayarrif2debb12015-07-10 14:47:17 +01003284 private void showKeyboardShortcutsMenu() {
3285 try {
3286 IStatusBarService statusbar = getStatusBarService();
3287 if (statusbar != null) {
3288 statusbar.showKeyboardShortcutsMenu();
3289 }
3290 } catch (RemoteException e) {
3291 Slog.e(TAG, "RemoteException when showing keyboard shortcuts menu", e);
3292 }
3293 }
3294
Winson Chungcdcd4872014-08-05 18:00:13 -07003295 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003296 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3297 try {
3298 IStatusBarService statusbar = getStatusBarService();
3299 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003300 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003301 }
3302 } catch (RemoteException e) {
3303 Slog.e(TAG, "RemoteException when closing recent apps", e);
3304 // re-acquire status bar service next time it is needed.
3305 mStatusBarService = null;
3306 }
3307 }
3308
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003309 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003310 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003311 }
3312
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003313 /**
3314 * A home key -> launch home action was detected. Take the appropriate action
3315 * given the situation with the keyguard.
3316 */
Bryce Lee662ed802015-04-10 20:11:39 +00003317 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3318 if (respectKeyguard) {
3319 if (isKeyguardShowingAndNotOccluded()) {
3320 // don't launch home if keyguard showing
3321 return;
3322 }
3323
3324 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3325 // when in keyguard restricted mode, must first verify unlock
3326 // before launching home
3327 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3328 @Override
3329 public void onKeyguardExitResult(boolean success) {
3330 if (success) {
3331 try {
3332 ActivityManagerNative.getDefault().stopAppSwitches();
3333 } catch (RemoteException e) {
3334 }
3335 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3336 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003337 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003338 }
Bryce Lee662ed802015-04-10 20:11:39 +00003339 });
3340 return;
3341 }
3342 }
3343
3344 // no keyguard stuff to worry about, just launch home!
3345 try {
3346 ActivityManagerNative.getDefault().stopAppSwitches();
3347 } catch (RemoteException e) {
3348 }
3349 if (mRecentsVisible) {
3350 // Hide Recents and notify it to launch Home
3351 if (awakenFromDreams) {
3352 awakenDreams();
3353 }
3354 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3355 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003356 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003357 // Otherwise, just launch Home
3358 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3359 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003360 }
3361 }
3362
John Spurlock04db1762013-05-13 12:46:41 -04003363 private final Runnable mClearHideNavigationFlag = new Runnable() {
3364 @Override
3365 public void run() {
3366 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3367 // Clear flags.
3368 mForceClearedSystemUiFlags &=
3369 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3370 }
3371 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003372 }
3373 };
3374
3375 /**
3376 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3377 * to determine when the nav bar should be shown and prevent applications from
3378 * receiving those touches.
3379 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003380 final class HideNavInputEventReceiver extends InputEventReceiver {
3381 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3382 super(inputChannel, looper);
3383 }
3384
Dianne Hackborndf89e652011-10-06 22:35:11 -07003385 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003386 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003387 boolean handled = false;
3388 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003389 if (event instanceof MotionEvent
3390 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3391 final MotionEvent motionEvent = (MotionEvent)event;
3392 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003393 // When the user taps down, we re-show the nav bar.
3394 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003395 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003396 // Any user activity always causes us to show the
3397 // navigation controls, if they had been hidden.
3398 // We also clear the low profile and only content
3399 // flags so that tapping on the screen will atomically
3400 // restore all currently hidden screen decorations.
3401 int newVal = mResettingSystemUiFlags |
3402 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3403 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3404 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003405 if (mResettingSystemUiFlags != newVal) {
3406 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003407 changed = true;
3408 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003409 // We don't allow the system's nav bar to be hidden
3410 // again for 1 second, to prevent applications from
3411 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003412 newVal = mForceClearedSystemUiFlags |
3413 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003414 if (mForceClearedSystemUiFlags != newVal) {
3415 mForceClearedSystemUiFlags = newVal;
3416 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003417 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003418 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003419 }
3420 if (changed) {
3421 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3422 }
3423 }
3424 }
3425 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003426 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003427 }
3428 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003429 }
3430 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3431 new InputEventReceiver.Factory() {
3432 @Override
3433 public InputEventReceiver createInputEventReceiver(
3434 InputChannel inputChannel, Looper looper) {
3435 return new HideNavInputEventReceiver(inputChannel, looper);
3436 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003437 };
3438
3439 @Override
3440 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003441 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3442 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003443 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003444
Dianne Hackborndf89e652011-10-06 22:35:11 -07003445 // Reset any bits in mForceClearingStatusBarVisibility that
3446 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003447 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003448 // Clear any bits in the new visibility that are currently being
3449 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003450 return visibility & ~mResettingSystemUiFlags
3451 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003452 }
3453
Craig Mautner69b08182012-09-05 13:07:13 -07003454 @Override
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003455 public void getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation,
3456 Rect outContentInsets, Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003457 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003458 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3459 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003460
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003461 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
3462 if (useOutsets) {
3463 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
3464 if (outset > 0) {
3465 if (displayRotation == Surface.ROTATION_0) {
3466 outOutsets.bottom += outset;
3467 } else if (displayRotation == Surface.ROTATION_90) {
3468 outOutsets.right += outset;
3469 } else if (displayRotation == Surface.ROTATION_180) {
3470 outOutsets.top += outset;
3471 } else if (displayRotation == Surface.ROTATION_270) {
3472 outOutsets.left += outset;
3473 }
3474 }
3475 }
3476
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003477 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003478 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003479 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003480 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003481 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003482 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3483 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3484 } else {
3485 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3486 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3487 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003488 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3489 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003490 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003491 availRight - mStableFullscreenRight,
3492 availBottom - mStableFullscreenBottom);
3493 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003494 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003495 availRight - mStableRight, availBottom - mStableBottom);
3496 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003497 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003498 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003499 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003500 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003501 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003502 availRight - mCurRight, availBottom - mCurBottom);
3503 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003504 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003505 availRight - mCurRight, availBottom - mCurBottom);
3506 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003507
3508 outStableInsets.set(mStableLeft, mStableTop,
3509 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003510 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003511 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003512 outContentInsets.setEmpty();
3513 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003514 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003515
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003516 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
3517 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
3518 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
3519 }
3520
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003521 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003522 @Override
3523 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3524 int displayRotation) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003525 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003526 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3527 if (isDefaultDisplay) {
3528 switch (displayRotation) {
3529 case Surface.ROTATION_90:
3530 overscanLeft = mOverscanTop;
3531 overscanTop = mOverscanRight;
3532 overscanRight = mOverscanBottom;
3533 overscanBottom = mOverscanLeft;
3534 break;
3535 case Surface.ROTATION_180:
3536 overscanLeft = mOverscanRight;
3537 overscanTop = mOverscanBottom;
3538 overscanRight = mOverscanLeft;
3539 overscanBottom = mOverscanTop;
3540 break;
3541 case Surface.ROTATION_270:
3542 overscanLeft = mOverscanBottom;
3543 overscanTop = mOverscanLeft;
3544 overscanRight = mOverscanTop;
3545 overscanBottom = mOverscanRight;
3546 break;
3547 default:
3548 overscanLeft = mOverscanLeft;
3549 overscanTop = mOverscanTop;
3550 overscanRight = mOverscanRight;
3551 overscanBottom = mOverscanBottom;
3552 break;
3553 }
3554 } else {
3555 overscanLeft = 0;
3556 overscanTop = 0;
3557 overscanRight = 0;
3558 overscanBottom = 0;
3559 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003560 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3561 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3562 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3563 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003564 mSystemLeft = 0;
3565 mSystemTop = 0;
3566 mSystemRight = displayWidth;
3567 mSystemBottom = displayHeight;
3568 mUnrestrictedScreenLeft = overscanLeft;
3569 mUnrestrictedScreenTop = overscanTop;
3570 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3571 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3572 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3573 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003574 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3575 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003576 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003577 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003578 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003579 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003580 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003581 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003582 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003583 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003584 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003585 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003586
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003587 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3588 final Rect pf = mTmpParentFrame;
3589 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003590 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003591 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003592 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003593 pf.left = df.left = of.left = vf.left = mDockLeft;
3594 pf.top = df.top = of.top = vf.top = mDockTop;
3595 pf.right = df.right = of.right = vf.right = mDockRight;
3596 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003597 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003598
Craig Mautner69b08182012-09-05 13:07:13 -07003599 if (isDefaultDisplay) {
3600 // For purposes of putting out fake window up to steal focus, we will
3601 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003602 final int sysui = mLastSystemUiFlags;
3603 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003604 boolean navTranslucent = (sysui
3605 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003606 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3607 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3608 boolean navAllowedHidden = immersive || immersiveSticky;
3609 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003610 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3611 if (!isKeyguardShowing) {
3612 navTranslucent &= areTranslucentBarsAllowed();
3613 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003614
Craig Mautner69b08182012-09-05 13:07:13 -07003615 // When the navigation bar isn't visible, we put up a fake
3616 // input window to catch all touch events. This way we can
3617 // detect when the user presses anywhere to bring back the nav
3618 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003619 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003620 if (mInputConsumer != null) {
3621 mInputConsumer.dismiss();
3622 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003623 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003624 } else if (mInputConsumer == null) {
3625 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3626 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003627 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003628
Craig Mautner69b08182012-09-05 13:07:13 -07003629 // For purposes of positioning and showing the nav bar, if we have
3630 // decided that it can't be hidden (because of the screen aspect ratio),
3631 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003632 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003633
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003634 boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight,
3635 displayRotation, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
3636 navAllowedHidden);
Craig Mautnereda67292013-04-28 13:50:14 -07003637 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003638 mDockLeft, mDockTop, mDockRight, mDockBottom));
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003639 updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003640 if (updateSysUiVisibility) {
3641 updateSystemUiVisibilityLw();
3642 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003643 }
3644 }
3645
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003646 private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui,
3647 boolean isKeyguardShowing) {
3648 // decide where the status bar goes ahead of time
3649 if (mStatusBar != null) {
3650 // apply any navigation bar insets
3651 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3652 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3653 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3654 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3655 + mUnrestrictedScreenTop;
3656 vf.left = mStableLeft;
3657 vf.top = mStableTop;
3658 vf.right = mStableRight;
3659 vf.bottom = mStableBottom;
3660
3661 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3662
3663 // Let the status bar determine its size.
3664 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3665 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3666 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
3667
3668 // For layout, the status bar is always at the top with our fixed height.
3669 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3670
3671 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
3672 boolean statusBarTranslucent = (sysui
3673 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
3674 if (!isKeyguardShowing) {
3675 statusBarTranslucent &= areTranslucentBarsAllowed();
3676 }
3677
3678 // If the status bar is hidden, we don't want to cause
3679 // windows behind it to scroll.
3680 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
3681 // Status bar may go away, so the screen area it occupies
3682 // is available to apps but just covering them when the
3683 // status bar is visible.
3684 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3685
3686 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3687 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3688 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3689 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3690
3691 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
3692 String.format(
3693 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3694 mDockLeft, mDockTop, mDockRight, mDockBottom,
3695 mContentLeft, mContentTop, mContentRight, mContentBottom,
3696 mCurLeft, mCurTop, mCurRight, mCurBottom));
3697 }
3698 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
3699 && !statusBarTransient && !statusBarTranslucent
3700 && !mStatusBarController.wasRecentlyTranslucent()) {
3701 // If the opaque status bar is currently requested to be visible,
3702 // and not in the process of animating on or off, then
3703 // we can tell the app that it is covered by it.
3704 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3705 }
3706 if (mStatusBarController.checkHiddenLw()) {
3707 return true;
3708 }
3709 }
3710 return false;
3711 }
3712
3713 private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation,
3714 int overscanRight, int overscanBottom, Rect dcf, boolean navVisible,
3715 boolean navTranslucent, boolean navAllowedHidden) {
3716 if (mNavigationBar != null) {
3717 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
3718 // Force the navigation bar to its appropriate place and
3719 // size. We need to do this directly, instead of relying on
3720 // it to bubble up from the nav bar, because this needs to
3721 // change atomically with screen rotations.
3722 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3723 if (mNavigationBarOnBottom) {
3724 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
3725 int top = displayHeight - overscanBottom
3726 - mNavigationBarHeightForRotation[displayRotation];
3727 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
3728 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
3729 if (transientNavBarShowing) {
3730 mNavigationBarController.setBarShowingLw(true);
3731 } else if (navVisible) {
3732 mNavigationBarController.setBarShowingLw(true);
3733 mDockBottom = mTmpNavigationFrame.top;
3734 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3735 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
3736 } else {
3737 // We currently want to hide the navigation UI.
3738 mNavigationBarController.setBarShowingLw(false);
3739 }
3740 if (navVisible && !navTranslucent && !navAllowedHidden
3741 && !mNavigationBar.isAnimatingLw()
3742 && !mNavigationBarController.wasRecentlyTranslucent()) {
3743 // If the opaque nav bar is currently requested to be visible,
3744 // and not in the process of animating on or off, then
3745 // we can tell the app that it is covered by it.
3746 mSystemBottom = mTmpNavigationFrame.top;
3747 }
3748 } else {
3749 // Landscape screen; nav bar goes to the right.
3750 int left = displayWidth - overscanRight
3751 - mNavigationBarWidthForRotation[displayRotation];
3752 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
3753 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
3754 if (transientNavBarShowing) {
3755 mNavigationBarController.setBarShowingLw(true);
3756 } else if (navVisible) {
3757 mNavigationBarController.setBarShowingLw(true);
3758 mDockRight = mTmpNavigationFrame.left;
3759 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3760 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
3761 } else {
3762 // We currently want to hide the navigation UI.
3763 mNavigationBarController.setBarShowingLw(false);
3764 }
3765 if (navVisible && !navTranslucent && !navAllowedHidden
3766 && !mNavigationBar.isAnimatingLw()
3767 && !mNavigationBarController.wasRecentlyTranslucent()) {
3768 // If the nav bar is currently requested to be visible,
3769 // and not in the process of animating on or off, then
3770 // we can tell the app that it is covered by it.
3771 mSystemRight = mTmpNavigationFrame.left;
3772 }
3773 }
3774 // Make sure the content and current rectangles are updated to
3775 // account for the restrictions from the navigation bar.
3776 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3777 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3778 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3779 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3780 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3781 // And compute the final frame.
3782 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
3783 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3784 mTmpNavigationFrame, mTmpNavigationFrame);
3785 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
3786 if (mNavigationBarController.checkHiddenLw()) {
3787 return true;
3788 }
3789 }
3790 return false;
3791 }
3792
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003793 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003794 @Override
John Spurlock46646232013-09-30 22:32:42 -04003795 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003796 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3797 return mStatusBar.getSurfaceLayer();
3798 }
3799
3800 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3801 return mNavigationBar.getSurfaceLayer();
3802 }
3803
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003804 return 0;
3805 }
3806
Craig Mautner967212c2013-04-13 21:10:58 -07003807 @Override
3808 public void getContentRectLw(Rect r) {
3809 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3810 }
3811
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003812 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3813 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003814 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3815 // Here's a special case: if this attached window is a panel that is
3816 // above the dock window, and the window it is attached to is below
3817 // the dock window, then the frames we computed for the window it is
3818 // attached to can not be used because the dock is effectively part
3819 // of the underlying window and the attached window is floating on top
3820 // of the whole thing. So, we ignore the attached window and explicitly
3821 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003822 df.left = of.left = cf.left = vf.left = mDockLeft;
3823 df.top = of.top = cf.top = vf.top = mDockTop;
3824 df.right = of.right = cf.right = vf.right = mDockRight;
3825 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003826 } else {
3827 // The effective display frame of the attached window depends on
3828 // whether it is taking care of insetting its content. If not,
3829 // we need to use the parent's content frame so that the entire
3830 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003831 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003832 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003833 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003834 // Set the content frame of the attached window to the parent's decor frame
3835 // (same as content frame when IME isn't present) if specifically requested by
3836 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3837 // Otherwise, use the overscan frame.
3838 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3839 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003840 } else {
3841 // If the window is resizing, then we want to base the content
3842 // frame on our attached content frame to resize... however,
3843 // things can be tricky if the attached window is NOT in resize
3844 // mode, in which case its content frame will be larger.
3845 // Ungh. So to deal with that, make sure the content frame
3846 // we end up using is not covering the IM dock.
3847 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003848 if (attached.isVoiceInteraction()) {
3849 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3850 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3851 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3852 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3853 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003854 if (cf.left < mContentLeft) cf.left = mContentLeft;
3855 if (cf.top < mContentTop) cf.top = mContentTop;
3856 if (cf.right > mContentRight) cf.right = mContentRight;
3857 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3858 }
3859 }
3860 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003861 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003862 vf.set(attached.getVisibleFrameLw());
3863 }
3864 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3865 // window should be positioned relative to its parent or the entire
3866 // screen.
3867 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3868 ? attached.getFrameLw() : df);
3869 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003870
3871 private void applyStableConstraints(int sysui, int fl, Rect r) {
3872 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3873 // If app is requesting a stable layout, don't let the
3874 // content insets go below the stable values.
3875 if ((fl & FLAG_FULLSCREEN) != 0) {
3876 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3877 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3878 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3879 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3880 } else {
3881 if (r.left < mStableLeft) r.left = mStableLeft;
3882 if (r.top < mStableTop) r.top = mStableTop;
3883 if (r.right > mStableRight) r.right = mStableRight;
3884 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3885 }
3886 }
3887 }
3888
Jorim Jaggiaa806142015-05-20 18:04:16 -07003889 private boolean canReceiveInput(WindowState win) {
3890 boolean notFocusable =
3891 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
3892 boolean altFocusableIm =
3893 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
3894 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
3895 return !notFocusableForIm;
3896 }
3897
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003898 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003899 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003900 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07003901 // We've already done the navigation bar and status bar. If the status bar can receive
3902 // input, we need to layout it again to accomodate for the IME window.
3903 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003904 return;
3905 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07003906 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07003907 final boolean isDefaultDisplay = win.isDefaultDisplay();
3908 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003909 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3910 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003911 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003912 offsetInputMethodWindowLw(mLastInputMethodWindow);
3913 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003914
John Spurlockc6d1c602014-01-17 15:22:06 -05003915 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003916 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003917 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003918
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003919 final Rect pf = mTmpParentFrame;
3920 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003921 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003922 final Rect cf = mTmpContentFrame;
3923 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003924 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003925 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003926 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04003927 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003928
3929 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003930 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003931
Craig Mautnerf683b562012-10-02 11:10:57 -07003932 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3933
Adrian Roosfa104232014-06-20 16:10:14 -07003934 if (isDefaultDisplay) {
3935 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3936 } else {
3937 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3938 }
3939
Craig Mautner69b08182012-09-05 13:07:13 -07003940 if (!isDefaultDisplay) {
3941 if (attached != null) {
3942 // If this window is attached to another, our display
3943 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003944 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003945 } else {
3946 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003947 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3948 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3949 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003950 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003951 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003952 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003953 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003954 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003955 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3956 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3957 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003958 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003959 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003960 // ...with content insets above the nav bar
3961 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003962 // IM dock windows always go to the bottom of the screen.
3963 attrs.gravity = Gravity.BOTTOM;
3964 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003965 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003966 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003967 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003968 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3969 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003970 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003971 // Note: In Phone landscape mode, the button bar should also be excluded.
3972 cf.right = vf.right = mStableRight;
3973 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003974 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07003975 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02003976 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3977 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3978 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3979 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3980 cf.left = vf.left = mStableLeft;
3981 cf.top = vf.top = mStableTop;
3982 cf.right = vf.right = mStableRight;
3983 vf.bottom = mStableBottom;
3984 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003985 } else {
John Spurlock46646232013-09-30 22:32:42 -04003986
3987 // Default policy decor for the default display
3988 dcf.left = mSystemLeft;
3989 dcf.top = mSystemTop;
3990 dcf.right = mSystemRight;
3991 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003992 final boolean inheritTranslucentDecor = (attrs.privateFlags
3993 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003994 final boolean isAppWindow =
3995 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3996 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3997 final boolean topAtRest =
3998 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3999 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04004000 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
4001 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004002 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
4003 && (fl & WindowManager.LayoutParams.
4004 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004005 // Ensure policy decor includes status bar
4006 dcf.top = mStableTop;
4007 }
John Spurlockbd957402013-10-03 11:38:39 -04004008 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004009 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
4010 && (fl & WindowManager.LayoutParams.
4011 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004012 // Ensure policy decor includes navigation bar
4013 dcf.bottom = mStableBottom;
4014 dcf.right = mStableRight;
4015 }
4016 }
4017
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004018 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
4019 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07004020 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004021 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004022 // This is the case for a normal activity window: we want it
4023 // to cover all of the screen space, and it can take care of
4024 // moving its contents to account for screen decorations that
4025 // intrude into that space.
4026 if (attached != null) {
4027 // If this window is attached to another, our display
4028 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004029 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004030 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004031 if (attrs.type == TYPE_STATUS_BAR_PANEL
4032 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08004033 // Status bar panels are the only windows who can go on top of
4034 // the status bar. They are protected by the STATUS_BAR_SERVICE
4035 // permission, so they have the same privileges as the status
4036 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004037 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004038 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004039
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004040 pf.left = df.left = of.left = hasNavBar
4041 ? mDockLeft : mUnrestrictedScreenLeft;
4042 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4043 pf.right = df.right = of.right = hasNavBar
4044 ? mRestrictedScreenLeft+mRestrictedScreenWidth
4045 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4046 pf.bottom = df.bottom = of.bottom = hasNavBar
4047 ? mRestrictedScreenTop+mRestrictedScreenHeight
4048 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004049
Craig Mautnereda67292013-04-28 13:50:14 -07004050 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004051 "Laying out status bar window: (%d,%d - %d,%d)",
4052 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04004053 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004054 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4055 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4056 // Asking to layout into the overscan region, so give it that pure
4057 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004058 pf.left = df.left = of.left = mOverscanScreenLeft;
4059 pf.top = df.top = of.top = mOverscanScreenTop;
4060 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
4061 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
4062 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004063 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004064 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004065 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4066 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004067 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08004068 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004069 // only do this for application windows to ensure no window that
4070 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08004071 pf.left = df.left = mOverscanScreenLeft;
4072 pf.top = df.top = mOverscanScreenTop;
4073 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4074 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004075 // We need to tell the app about where the frame inside the overscan
4076 // is, so it can inset its content by that amount -- it didn't ask
4077 // to actually extend itself into the overscan region.
4078 of.left = mUnrestrictedScreenLeft;
4079 of.top = mUnrestrictedScreenTop;
4080 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4081 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004082 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08004083 pf.left = df.left = mRestrictedOverscanScreenLeft;
4084 pf.top = df.top = mRestrictedOverscanScreenTop;
4085 pf.right = df.right = mRestrictedOverscanScreenLeft
4086 + mRestrictedOverscanScreenWidth;
4087 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
4088 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004089 // We need to tell the app about where the frame inside the overscan
4090 // is, so it can inset its content by that amount -- it didn't ask
4091 // to actually extend itself into the overscan region.
4092 of.left = mUnrestrictedScreenLeft;
4093 of.top = mUnrestrictedScreenTop;
4094 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4095 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004096 }
Craig Mautner69b08182012-09-05 13:07:13 -07004097
John Spurlock46646232013-09-30 22:32:42 -04004098 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004099 if (win.isVoiceInteraction()) {
4100 cf.left = mVoiceContentLeft;
4101 cf.top = mVoiceContentTop;
4102 cf.right = mVoiceContentRight;
4103 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004104 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004105 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4106 cf.left = mDockLeft;
4107 cf.top = mDockTop;
4108 cf.right = mDockRight;
4109 cf.bottom = mDockBottom;
4110 } else {
4111 cf.left = mContentLeft;
4112 cf.top = mContentTop;
4113 cf.right = mContentRight;
4114 cf.bottom = mContentBottom;
4115 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004116 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004117 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004118 // Full screen windows are always given a layout that is as if the
4119 // status bar and other transient decors are gone. This is to avoid
4120 // bad states when moving from a window that is not hding the
4121 // status bar to one that is.
4122 cf.left = mRestrictedScreenLeft;
4123 cf.top = mRestrictedScreenTop;
4124 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4125 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004126 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004127 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004128 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4129 vf.left = mCurLeft;
4130 vf.top = mCurTop;
4131 vf.right = mCurRight;
4132 vf.bottom = mCurBottom;
4133 } else {
4134 vf.set(cf);
4135 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004136 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004137 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
4138 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
4139 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07004140 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4141 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004142 // A window that has requested to fill the entire screen just
4143 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004144 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04004145 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
4146 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004147 pf.left = df.left = of.left = cf.left = hasNavBar
4148 ? mDockLeft : mUnrestrictedScreenLeft;
4149 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4150 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004151 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08004152 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004153 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004154 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004155 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004156 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04004157 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
4158 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07004159 } else if (attrs.type == TYPE_NAVIGATION_BAR
4160 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004161 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004162 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4163 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4164 pf.right = df.right = of.right = mUnrestrictedScreenLeft
4165 + mUnrestrictedScreenWidth;
4166 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
4167 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004168 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004169 "Laying out navigation bar window: (%d,%d - %d,%d)",
4170 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08004171 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
4172 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07004173 && ((fl & FLAG_FULLSCREEN) != 0)) {
4174 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004175 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4176 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4177 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4178 + mOverscanScreenWidth;
4179 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4180 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08004181 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08004182 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004183 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4184 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4185 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4186 + mOverscanScreenWidth;
4187 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4188 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04004189 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004190 // The wallpaper also has Real Ultimate Power, but we want to tell
4191 // it about the overscan area.
4192 pf.left = df.left = mOverscanScreenLeft;
4193 pf.top = df.top = mOverscanScreenTop;
4194 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4195 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4196 of.left = cf.left = mUnrestrictedScreenLeft;
4197 of.top = cf.top = mUnrestrictedScreenTop;
4198 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4199 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004200 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004201 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4202 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4203 // Asking to layout into the overscan region, so give it that pure
4204 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004205 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4206 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4207 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004208 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004209 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004210 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004211 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004212 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004213 && (attrs.type == TYPE_STATUS_BAR
4214 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004215 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004216 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4217 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004218 // Asking for layout as if the nav bar is hidden, lets the
4219 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004220 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004221 // can be above the nav bar can do this.
4222 // XXX This assumes that an app asking for this will also
4223 // ask for layout in only content. We can't currently figure out
4224 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004225 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4226 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4227 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4228 + mUnrestrictedScreenWidth;
4229 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4230 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004231 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004232 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4233 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4234 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4235 + mRestrictedScreenWidth;
4236 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4237 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004238 }
Craig Mautner69b08182012-09-05 13:07:13 -07004239
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004240 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004241
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004242 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4243 vf.left = mCurLeft;
4244 vf.top = mCurTop;
4245 vf.right = mCurRight;
4246 vf.bottom = mCurBottom;
4247 } else {
4248 vf.set(cf);
4249 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004250 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004251 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4252 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004253 // A child window should be placed inside of the same visible
4254 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004255 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004256 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004257 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4258 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004259 // Otherwise, a normal window must be placed inside the content
4260 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004261 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4262 // Status bar panels and the volume dialog are the only windows who can go on
4263 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004264 // permission, so they have the same privileges as the status
4265 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004266 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4267 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4268 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4269 + mRestrictedScreenWidth;
4270 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4271 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004272 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004273 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004274 pf.left = df.left = of.left = cf.left = mStableLeft;
4275 pf.top = df.top = of.top = cf.top = mStableTop;
4276 pf.right = df.right = of.right = cf.right = mStableRight;
4277 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004278 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004279 pf.left = mContentLeft;
4280 pf.top = mContentTop;
4281 pf.right = mContentRight;
4282 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004283 if (win.isVoiceInteraction()) {
4284 df.left = of.left = cf.left = mVoiceContentLeft;
4285 df.top = of.top = cf.top = mVoiceContentTop;
4286 df.right = of.right = cf.right = mVoiceContentRight;
4287 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4288 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004289 df.left = of.left = cf.left = mDockLeft;
4290 df.top = of.top = cf.top = mDockTop;
4291 df.right = of.right = cf.right = mDockRight;
4292 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004293 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004294 df.left = of.left = cf.left = mContentLeft;
4295 df.top = of.top = cf.top = mContentTop;
4296 df.right = of.right = cf.right = mContentRight;
4297 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004298 }
4299 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4300 vf.left = mCurLeft;
4301 vf.top = mCurTop;
4302 vf.right = mCurRight;
4303 vf.bottom = mCurBottom;
4304 } else {
4305 vf.set(cf);
4306 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004307 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004308 }
4309 }
Craig Mautner69b08182012-09-05 13:07:13 -07004310
Craig Mautnerb816bed2013-07-23 10:26:17 -07004311 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4312 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004313 df.left = df.top = -10000;
4314 df.right = df.bottom = 10000;
4315 if (attrs.type != TYPE_WALLPAPER) {
4316 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4317 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4318 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004319 }
4320
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004321 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4322 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004323 // We only want to apply outsets to certain types of windows. For example, we never want to
4324 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004325 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004326 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004327 osf = mTmpOutsetFrame;
4328 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4329 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4330 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004331 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004332 if (rotation == Surface.ROTATION_0) {
4333 osf.bottom += outset;
4334 } else if (rotation == Surface.ROTATION_90) {
4335 osf.right += outset;
4336 } else if (rotation == Surface.ROTATION_180) {
4337 osf.top -= outset;
4338 } else if (rotation == Surface.ROTATION_270) {
4339 osf.left -= outset;
4340 }
4341 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4342 + " with rotation " + rotation + ", result: " + osf);
4343 }
4344 }
4345
Craig Mautnereda67292013-04-28 13:50:14 -07004346 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004347 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004348 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004349 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004350 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004351 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004352 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004353 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004354 + " sf=" + sf.toShortString()
4355 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004356
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004357 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004358
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004359 // Dock windows carve out the bottom of the screen, so normal windows
4360 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004361 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4362 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004363 setLastInputMethodWindowLw(null, null);
4364 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004365 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004366 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4367 && !win.getGivenInsetsPendingLw()) {
4368 offsetVoiceInputWindowLw(win);
4369 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004370 }
4371
satok1bc0a492012-04-25 22:47:12 +09004372 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004373 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004374 top += win.getGivenContentInsetsLw().top;
4375 if (mContentBottom > top) {
4376 mContentBottom = top;
4377 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004378 if (mVoiceContentBottom > top) {
4379 mVoiceContentBottom = top;
4380 }
satok1bc0a492012-04-25 22:47:12 +09004381 top = win.getVisibleFrameLw().top;
4382 top += win.getGivenVisibleInsetsLw().top;
4383 if (mCurBottom > top) {
4384 mCurBottom = top;
4385 }
Craig Mautnereda67292013-04-28 13:50:14 -07004386 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004387 + mDockBottom + " mContentBottom="
4388 + mContentBottom + " mCurBottom=" + mCurBottom);
4389 }
4390
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004391 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004392 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004393 top += win.getGivenContentInsetsLw().top;
4394 if (mVoiceContentBottom > top) {
4395 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004396 }
4397 }
4398
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004399 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004400 @Override
4401 public void finishLayoutLw() {
4402 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004403 }
4404
4405 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004406 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004407 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004408 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004409 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004410 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004411 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004412 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004413 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004414 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004415 mForcingShowNavBar = false;
4416 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004417
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004418 mHideLockScreen = false;
4419 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004420 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004421 mShowingLockscreen = false;
4422 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004423 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004424 mKeyguardSecure = isKeyguardSecure();
4425 mKeyguardSecureIncludingHidden = mKeyguardSecure
4426 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004427 }
4428
4429 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004430 @Override
Yohei Yukawad1a09222015-06-30 16:22:05 -07004431 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,
4432 WindowState attached) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004433 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4434 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004435 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004436 if (mTopFullscreenOpaqueWindowState == null
4437 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4438 mForcingShowNavBar = true;
4439 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004440 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004441 if (attrs.type == TYPE_STATUS_BAR) {
4442 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4443 mForceStatusBarFromKeyguard = true;
Jorim Jaggie1de9f62015-09-23 14:59:50 -07004444 mShowingLockscreen = true;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004445 }
4446 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4447 mForceStatusBarTransparent = true;
4448 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004449 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004450
4451 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4452 && attrs.type < FIRST_SYSTEM_WINDOW;
4453 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4454 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4455
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004456 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004457 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004458 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004459 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004460 mForceStatusBarFromKeyguard = true;
4461 } else {
4462 mForceStatusBar = true;
4463 }
4464 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004465 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004466 // If the lockscreen was showing when the dream started then wait
4467 // for the dream to draw before hiding the lockscreen.
4468 if (!mDreamingLockscreen
4469 || (win.isVisibleLw() && win.hasDrawnLw())) {
4470 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004471 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004472 }
4473 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004474
Yohei Yukawad1a09222015-06-30 16:22:05 -07004475 final IApplicationToken appToken = win.getAppToken();
4476
4477 // For app windows that are not attached, we decide if all windows in the app they
4478 // represent should be hidden or if we should hide the lockscreen. For attached app
4479 // windows we defer the decision to the window it is attached to.
4480 if (appWindow && attached == null) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004481 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004482 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004483 mAppsToBeHidden.remove(appToken);
4484 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004485 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004486 if (dismissKeyguard && !mKeyguardSecure) {
4487 mAppsThatDismissKeyguard.add(appToken);
Selim Cinek90b5e072015-08-28 17:05:56 -07004488 } else if (win.isDrawnLw() || win.hasAppShownWindows()) {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004489 mWinShowWhenLocked = win;
4490 mHideLockScreen = true;
4491 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004492 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004493 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004494 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004495 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004496 mAppsToBeHidden.add(appToken);
4497 } else {
4498 mAppsToBeHidden.remove(appToken);
4499 }
4500 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004501 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004502 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004503 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004504 if (attrs.x == 0 && attrs.y == 0
4505 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4506 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4507 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4508 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004509 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4510 mTopFullscreenOpaqueOrDimmingWindowState = win;
4511 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004512 if (!mAppsThatDismissKeyguard.isEmpty() &&
4513 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4514 if (DEBUG_LAYOUT) Slog.v(TAG,
4515 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004516 mDismissKeyguard = (mWinDismissingKeyguard == win
4517 && mSecureDismissingKeyguard == mKeyguardSecure)
4518 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004519 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004520 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004521 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Selim Cinek90b5e072015-08-28 17:05:56 -07004522 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked
4523 && (win.isDrawnLw() || win.hasAppShownWindows())) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004524 if (DEBUG_LAYOUT) Slog.v(TAG,
4525 "Setting mHideLockScreen to true by win " + win);
4526 mHideLockScreen = true;
4527 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004528 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004529 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004530 mAllowLockscreenWhenOn = true;
4531 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004532 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004533
4534 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004535 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4536 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004537 win.hideLw(false);
4538 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004539 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004540 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4541 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4542 // that is being hidden in an animation - keep the
4543 // keyguard hidden until the new window shows up and
4544 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004545 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004546 mHideLockScreen = true;
4547 mWinShowWhenLocked = win;
4548 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004549 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004550 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4551 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4552 && win.isDimming()) {
4553 mTopFullscreenOpaqueOrDimmingWindowState = win;
4554 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004555 }
4556
4557 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004558 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004559 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004560 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4561 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4562 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004563 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4564 // fullscreen window.
4565 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4566 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4567 mTopFullscreenOpaqueWindowState.hideLw(false);
4568 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4569 }
4570
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004571 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004572 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004573
4574 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4575 ? mTopFullscreenOpaqueWindowState.getAttrs()
4576 : null;
4577
Jeff Brownc8018eb2012-10-29 21:33:27 -07004578 // If we are not currently showing a dream then remember the current
4579 // lockscreen state. We will use this to determine whether the dream
4580 // started while the lockscreen was showing and remember this state
4581 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004582 if (!mShowingDream) {
4583 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004584 if (mDreamingSleepTokenNeeded) {
4585 mDreamingSleepTokenNeeded = false;
4586 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4587 }
4588 } else {
4589 if (!mDreamingSleepTokenNeeded) {
4590 mDreamingSleepTokenNeeded = true;
4591 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4592 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004593 }
4594
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004595 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004596 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004597 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004598 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004599 boolean shouldBeTransparent = mForceStatusBarTransparent
4600 && !mForceStatusBar
4601 && !mForceStatusBarFromKeyguard;
4602 if (!shouldBeTransparent) {
4603 mStatusBarController.setShowTransparent(false /* transparent */);
4604 } else if (!mStatusBar.isVisibleLw()) {
4605 mStatusBarController.setShowTransparent(true /* transparent */);
4606 }
4607 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004608 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004609 if (mStatusBarController.setBarShowingLw(true)) {
4610 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4611 }
Craig Mautner81defc72013-10-29 11:10:42 -07004612 // Maintain fullscreen layout until incoming animation is complete.
4613 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004614 // Transient status bar on the lockscreen is not allowed
4615 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4616 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4617 mLastSystemUiFlags, mLastSystemUiFlags);
4618 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004619 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004620 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004621 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004622 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07004623 + " shown position: "
4624 + mTopFullscreenOpaqueWindowState.getShownPositionLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004625 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004626 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004627 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004628 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004629 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004630 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004631 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004632 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4633 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004634 if (mStatusBarController.isTransientShowing()) {
4635 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004636 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4637 }
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07004638 } else if (topIsFullscreen
4639 && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID)
4640 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) {
Craig Mautnereda67292013-04-28 13:50:14 -07004641 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004642 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004643 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004644 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004645 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004646 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004647 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004648 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004649 if (mStatusBarController.setBarShowingLw(true)) {
4650 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4651 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004652 }
4653 }
4654 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004655
Craig Mautner81defc72013-10-29 11:10:42 -07004656 if (mTopIsFullscreen != topIsFullscreen) {
4657 if (!topIsFullscreen) {
4658 // Force another layout when status bar becomes fully shown.
4659 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4660 }
4661 mTopIsFullscreen = topIsFullscreen;
4662 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004663
Craig Mautner39834192012-09-02 07:47:24 -07004664 // Hide the key guard if a visible window explicitly specifies that it wants to be
4665 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004666 if (mKeyguardDelegate != null && mStatusBar != null) {
4667 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4668 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004669 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004670 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004671 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004672 changes |= FINISH_LAYOUT_REDO_LAYOUT
4673 | FINISH_LAYOUT_REDO_CONFIG
4674 | FINISH_LAYOUT_REDO_WALLPAPER;
4675 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004676 if (mKeyguardDelegate.isShowing()) {
4677 mHandler.post(new Runnable() {
4678 @Override
4679 public void run() {
4680 mKeyguardDelegate.keyguardDone(false, false);
4681 }
4682 });
4683 }
4684 } else if (mHideLockScreen) {
4685 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004686 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004687 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004688 changes |= FINISH_LAYOUT_REDO_LAYOUT
4689 | FINISH_LAYOUT_REDO_CONFIG
4690 | FINISH_LAYOUT_REDO_WALLPAPER;
4691 }
4692 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004693 mKeyguardHidden = false;
4694 if (setKeyguardOccludedLw(false)) {
4695 changes |= FINISH_LAYOUT_REDO_LAYOUT
4696 | FINISH_LAYOUT_REDO_CONFIG
4697 | FINISH_LAYOUT_REDO_WALLPAPER;
4698 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004699 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4700 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004701 mHandler.post(new Runnable() {
4702 @Override
4703 public void run() {
4704 mKeyguardDelegate.dismiss();
4705 }
4706 });
4707 }
4708 } else {
4709 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004710 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004711 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004712 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004713 changes |= FINISH_LAYOUT_REDO_LAYOUT
4714 | FINISH_LAYOUT_REDO_CONFIG
4715 | FINISH_LAYOUT_REDO_WALLPAPER;
4716 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004717 }
4718 }
Joe Onorato664644d2011-01-23 17:53:23 -08004719
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004720 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004721 // If the navigation bar has been hidden or shown, we need to do another
4722 // layout pass to update that window.
4723 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4724 }
Joe Onorato664644d2011-01-23 17:53:23 -08004725
Mike Lockwood28569302010-01-28 11:54:40 -05004726 // update since mAllowLockscreenWhenOn might have changed
4727 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004728 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004729 }
4730
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004731 /**
Jim Millerab954542014-10-10 18:21:49 -07004732 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004733 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004734 * @return Whether the flags have changed and we have to redo the layout.
4735 */
Jim Millerab954542014-10-10 18:21:49 -07004736 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4737 boolean wasOccluded = mKeyguardOccluded;
4738 boolean showing = mKeyguardDelegate.isShowing();
4739 if (wasOccluded && !isOccluded && showing) {
4740 mKeyguardOccluded = false;
4741 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004742 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4743 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4744 return true;
Jim Millerab954542014-10-10 18:21:49 -07004745 } else if (!wasOccluded && isOccluded && showing) {
4746 mKeyguardOccluded = true;
4747 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004748 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4749 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4750 return true;
4751 } else {
4752 return false;
4753 }
4754 }
4755
4756 private boolean isStatusBarKeyguard() {
4757 return mStatusBar != null
4758 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4759 }
4760
Jose Lima9546b202014-07-02 17:21:51 -07004761 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004762 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004763 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004764 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004765 return false;
4766 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004767 return true;
4768 }
4769
Jose Lima9546b202014-07-02 17:21:51 -07004770 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004771 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004772 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004773 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004774 // If the navigation bar has been hidden or shown, we need to do another
4775 // layout pass to update that window.
4776 return FINISH_LAYOUT_REDO_LAYOUT;
4777 }
4778 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004779 }
4780
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004781 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004782 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004783 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4784 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004785 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4786 if (newLidState == mLidState) {
4787 return;
4788 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004789
Jeff Brownc458ce92012-04-30 14:58:40 -07004790 mLidState = newLidState;
4791 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004792 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004793
4794 if (lidOpen) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07004795 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch,
4796 "android.policy:LID");
Jeff Brownc458ce92012-04-30 14:58:40 -07004797 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004798 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004799 }
4800 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004801
Michael Wright3818c922014-09-02 13:59:07 -07004802 @Override
4803 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4804 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4805 if (mCameraLensCoverState == lensCoverState) {
4806 return;
4807 }
4808 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4809 lensCoverState == CAMERA_LENS_UNCOVERED) {
4810 Intent intent;
4811 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4812 mKeyguardDelegate.isShowing();
4813 if (keyguardActive) {
4814 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4815 } else {
4816 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4817 }
Dianne Hackborn280a64e2015-07-13 14:48:08 -07004818 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens,
4819 "android.policy:CAMERA_COVER");
Bart Sears8b1c27c2015-03-18 23:51:02 +00004820 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004821 }
4822 mCameraLensCoverState = lensCoverState;
4823 }
4824
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004825 void setHdmiPlugged(boolean plugged) {
4826 if (mHdmiPlugged != plugged) {
4827 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004828 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004829 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004830 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004831 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004832 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004833 }
4834 }
4835
Joe Onoratoea495d42011-04-06 11:41:11 -07004836 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004837 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004838 // watch for HDMI plug messages if the hdmi switch exists
4839 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4840 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4841
Joe Onoratoea495d42011-04-06 11:41:11 -07004842 final String filename = "/sys/class/switch/hdmi/state";
4843 FileReader reader = null;
4844 try {
4845 reader = new FileReader(filename);
4846 char[] buf = new char[15];
4847 int n = reader.read(buf);
4848 if (n > 1) {
4849 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4850 }
4851 } catch (IOException ex) {
4852 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4853 } catch (NumberFormatException ex) {
4854 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4855 } finally {
4856 if (reader != null) {
4857 try {
4858 reader.close();
4859 } catch (IOException ex) {
4860 }
Joe Onoratodc100302011-01-11 17:07:41 -08004861 }
4862 }
4863 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004864 // This dance forces the code in setHdmiPlugged to run.
4865 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4866 mHdmiPlugged = !plugged;
4867 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004868 }
4869
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004870 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004871 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004872
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004873 final Runnable mScreenshotTimeout = new Runnable() {
4874 @Override public void run() {
4875 synchronized (mScreenshotLock) {
4876 if (mScreenshotConnection != null) {
4877 mContext.unbindService(mScreenshotConnection);
4878 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004879 }
Winson Chung9112ec32011-06-27 13:15:32 -07004880 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004881 }
4882 };
4883
4884 // Assume this is called from the Handler thread.
4885 private void takeScreenshot() {
4886 synchronized (mScreenshotLock) {
4887 if (mScreenshotConnection != null) {
4888 return;
4889 }
4890 ComponentName cn = new ComponentName("com.android.systemui",
4891 "com.android.systemui.screenshot.TakeScreenshotService");
4892 Intent intent = new Intent();
4893 intent.setComponent(cn);
4894 ServiceConnection conn = new ServiceConnection() {
4895 @Override
4896 public void onServiceConnected(ComponentName name, IBinder service) {
4897 synchronized (mScreenshotLock) {
4898 if (mScreenshotConnection != this) {
4899 return;
4900 }
4901 Messenger messenger = new Messenger(service);
4902 Message msg = Message.obtain(null, 1);
4903 final ServiceConnection myConn = this;
4904 Handler h = new Handler(mHandler.getLooper()) {
4905 @Override
4906 public void handleMessage(Message msg) {
4907 synchronized (mScreenshotLock) {
4908 if (mScreenshotConnection == myConn) {
4909 mContext.unbindService(mScreenshotConnection);
4910 mScreenshotConnection = null;
4911 mHandler.removeCallbacks(mScreenshotTimeout);
4912 }
4913 }
4914 }
4915 };
4916 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004917 msg.arg1 = msg.arg2 = 0;
4918 if (mStatusBar != null && mStatusBar.isVisibleLw())
4919 msg.arg1 = 1;
4920 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4921 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004922 try {
4923 messenger.send(msg);
4924 } catch (RemoteException e) {
4925 }
4926 }
4927 }
4928 @Override
4929 public void onServiceDisconnected(ComponentName name) {}
4930 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004931 if (mContext.bindServiceAsUser(
4932 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004933 mScreenshotConnection = conn;
4934 mHandler.postDelayed(mScreenshotTimeout, 10000);
4935 }
4936 }
Winson Chung9112ec32011-06-27 13:15:32 -07004937 }
4938
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004939 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004940 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004941 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004942 if (!mSystemBooted) {
4943 // If we have not yet booted, don't let key events do anything.
4944 return 0;
4945 }
4946
Jeff Brown037c33e2014-04-09 00:31:55 -07004947 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004948 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4949 final boolean canceled = event.isCanceled();
4950 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004951
Jeff Brown3122e442010-10-11 23:32:49 -07004952 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004953
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004954 // If screen is off then we treat the case where the keyguard is open but hidden
4955 // the same as if it were open and in front.
4956 // This will prevent any keys other than the power button from waking the screen
4957 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004958 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004959 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004960 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004961 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004962
Jeff Brown40013652012-05-16 21:22:36 -07004963 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004964 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004965 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004966 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004967 }
4968
Jeff Brown037c33e2014-04-09 00:31:55 -07004969 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004970 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004971 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4972 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004973 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004974 // When the device is interactive or the key is injected pass the
4975 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004976 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004977 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004978 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4979 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4980 // to the application but preserve its wake key status to make sure we still move
4981 // from dozing to fully interactive if we would normally go from off to fully
4982 // interactive.
4983 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004984 } else {
4985 // When the screen is off and the key is not injected, determine whether
4986 // to wake the device but don't pass the key to the application.
4987 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004988 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4989 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004990 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004991 }
4992
Justin Kohd378ad72013-04-01 12:18:26 -07004993 // If the key would be handled globally, just return the result, don't worry about special
4994 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004995 if (isValidGlobalKey(keyCode)
4996 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004997 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07004998 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Michael Wright85b1af62014-06-04 14:51:58 -07004999 }
Justin Kohd378ad72013-04-01 12:18:26 -07005000 return result;
5001 }
5002
Jeff Brownbae8e772014-06-12 19:59:45 -07005003 boolean useHapticFeedback = down
5004 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
5005 && event.getRepeatCount() == 0;
5006
Jeff Brown4d396052010-10-29 21:50:21 -07005007 // Handle special keys.
5008 switch (keyCode) {
5009 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07005010 case KeyEvent.KEYCODE_VOLUME_UP:
5011 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08005012 if (mUseTvRouting) {
5013 // On TVs volume keys never go to the foreground app
5014 result &= ~ACTION_PASS_TO_USER;
5015 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005016 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
5017 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005018 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005019 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005020 mScreenshotChordVolumeDownKeyTriggered = true;
5021 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
5022 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005023 cancelPendingPowerKeyAction();
5024 interceptScreenshotChord();
5025 }
5026 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005027 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005028 cancelPendingScreenshotChordAction();
5029 }
5030 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
5031 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005032 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005033 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005034 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005035 cancelPendingPowerKeyAction();
5036 cancelPendingScreenshotChordAction();
5037 }
5038 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005039 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005040 cancelPendingScreenshotChordAction();
5041 }
5042 }
Jeff Brown4d396052010-10-29 21:50:21 -07005043 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005044 TelecomManager telecomManager = getTelecommService();
5045 if (telecomManager != null) {
5046 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005047 // If an incoming call is ringing, either VOLUME key means
5048 // "silence ringer". We handle these keys here, rather than
5049 // in the InCallScreen, to make sure we'll respond to them
5050 // even if the InCallScreen hasn't come to the foreground yet.
5051 // Look for the DOWN event here, to agree with the "fallback"
5052 // behavior in the InCallScreen.
5053 Log.i(TAG, "interceptKeyBeforeQueueing:"
5054 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07005055
Santos Cordon6848f722014-05-21 15:22:12 -07005056 // Silence the ringer. (It's safe to call this
5057 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005058 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07005059
Santos Cordon6848f722014-05-21 15:22:12 -07005060 // And *don't* pass this key thru to the current activity
5061 // (which is probably the InCallScreen.)
5062 result &= ~ACTION_PASS_TO_USER;
5063 break;
5064 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005065 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07005066 && (result & ACTION_PASS_TO_USER) == 0) {
5067 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07005068 // the application, just pass it to the session service.
5069
5070 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07005071 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07005072 break;
Jeff Brown4d396052010-10-29 21:50:21 -07005073 }
5074 }
5075
RoboErik430fc482014-06-12 15:49:20 -07005076 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08005077 if (mUseTvRouting) {
5078 dispatchDirectAudioEvent(event);
5079 } else {
5080 // If we aren't passing to the user and no one else
5081 // handled it send it to the session manager to
5082 // figure out.
5083 MediaSessionLegacyHelper.getHelper(mContext)
5084 .sendVolumeKeyEvent(event, true);
5085 }
Jeff Brown4d396052010-10-29 21:50:21 -07005086 break;
5087 }
5088 }
5089 break;
5090 }
5091
5092 case KeyEvent.KEYCODE_ENDCALL: {
5093 result &= ~ACTION_PASS_TO_USER;
5094 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005095 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07005096 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005097 if (telecomManager != null) {
5098 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07005099 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005100 if (interactive && !hungUp) {
5101 mEndCallKeyHandled = false;
5102 mHandler.postDelayed(mEndCallLongPress,
5103 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
5104 } else {
5105 mEndCallKeyHandled = true;
5106 }
Jeff Brown4d396052010-10-29 21:50:21 -07005107 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005108 if (!mEndCallKeyHandled) {
5109 mHandler.removeCallbacks(mEndCallLongPress);
5110 if (!canceled) {
5111 if ((mEndcallBehavior
5112 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
5113 if (goHome()) {
5114 break;
5115 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07005116 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005117 if ((mEndcallBehavior
5118 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
5119 mPowerManager.goToSleep(event.getEventTime(),
5120 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
5121 isWakeKey = false;
5122 }
Jeff Brown4d396052010-10-29 21:50:21 -07005123 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005124 }
Jeff Brown4d396052010-10-29 21:50:21 -07005125 }
5126 break;
5127 }
5128
5129 case KeyEvent.KEYCODE_POWER: {
5130 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07005131 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07005132 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005133 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005134 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005135 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07005136 }
5137 break;
5138 }
5139
Jeff Brown6212a492014-03-07 13:58:47 -08005140 case KeyEvent.KEYCODE_SLEEP: {
5141 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005142 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07005143 if (!mPowerManager.isInteractive()) {
5144 useHapticFeedback = false; // suppress feedback if already non-interactive
5145 }
Nick Vaccarob593a812015-05-15 11:23:05 -07005146 if (down) {
5147 sleepPress(event.getEventTime());
5148 } else {
5149 sleepRelease(event.getEventTime());
5150 }
Jeff Brown6212a492014-03-07 13:58:47 -08005151 break;
5152 }
5153
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -07005154 case KeyEvent.KEYCODE_SOFT_SLEEP: {
5155 result &= ~ACTION_PASS_TO_USER;
5156 isWakeKey = false;
5157 if (!down) {
5158 mPowerManagerInternal.setUserInactiveOverrideFromWindowManager();
5159 }
5160 break;
5161 }
5162
Jeff Brown6212a492014-03-07 13:58:47 -08005163 case KeyEvent.KEYCODE_WAKEUP: {
5164 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005165 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08005166 break;
5167 }
5168
Jeff Brown4d396052010-10-29 21:50:21 -07005169 case KeyEvent.KEYCODE_MEDIA_PLAY:
5170 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5171 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07005172 case KeyEvent.KEYCODE_HEADSETHOOK:
5173 case KeyEvent.KEYCODE_MUTE:
5174 case KeyEvent.KEYCODE_MEDIA_STOP:
5175 case KeyEvent.KEYCODE_MEDIA_NEXT:
5176 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5177 case KeyEvent.KEYCODE_MEDIA_REWIND:
5178 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005179 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
5180 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07005181 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
5182 // If the global session is active pass all media keys to it
5183 // instead of the active window.
5184 result &= ~ACTION_PASS_TO_USER;
5185 }
Jeff Brown4d396052010-10-29 21:50:21 -07005186 if ((result & ACTION_PASS_TO_USER) == 0) {
5187 // Only do this if we would otherwise not pass it to the user. In that
5188 // case, the PhoneWindow class will do the same thing, except it will
5189 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07005190 // Note that we need to make a copy of the key event here because the
5191 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07005192 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07005193 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
5194 new KeyEvent(event));
5195 msg.setAsynchronous(true);
5196 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005197 }
5198 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005199 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005200
Jeff Brown4d396052010-10-29 21:50:21 -07005201 case KeyEvent.KEYCODE_CALL: {
5202 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005203 TelecomManager telecomManager = getTelecommService();
5204 if (telecomManager != null) {
5205 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005206 Log.i(TAG, "interceptKeyBeforeQueueing:"
5207 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005208 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005209
Santos Cordon6848f722014-05-21 15:22:12 -07005210 // And *don't* pass this key thru to the current activity
5211 // (which is presumably the InCallScreen.)
5212 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005213 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005214 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005215 }
Jeff Brown4d396052010-10-29 21:50:21 -07005216 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005217 }
Michael Wright869a67c2014-08-26 19:33:06 -07005218 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5219 // Only do this if we would otherwise not pass it to the user. In that case,
5220 // interceptKeyBeforeDispatching would apply a similar but different policy in
5221 // order to invoke voice assist actions. Note that we need to make a copy of the
5222 // key event here because the original key event will be recycled when we return.
5223 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5224 mBroadcastWakeLock.acquire();
5225 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5226 keyguardActive ? 1 : 0, 0);
5227 msg.setAsynchronous(true);
5228 msg.sendToTarget();
5229 }
5230 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005231 }
Jeff Brown26875502014-01-30 21:47:47 -08005232
Jeff Brownbae8e772014-06-12 19:59:45 -07005233 if (useHapticFeedback) {
5234 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5235 }
5236
Jeff Brown26875502014-01-30 21:47:47 -08005237 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005238 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Jeff Brown26875502014-01-30 21:47:47 -08005239 }
Bryce Lee584a4452014-10-21 15:55:55 -07005240
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005241 return result;
5242 }
5243
Jeff Brown1c2e4942012-11-06 16:32:01 -08005244 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005245 * Returns true if the key can have global actions attached to it.
5246 * We reserve all power management keys for the system since they require
5247 * very careful handling.
5248 */
5249 private static boolean isValidGlobalKey(int keyCode) {
5250 switch (keyCode) {
5251 case KeyEvent.KEYCODE_POWER:
5252 case KeyEvent.KEYCODE_WAKEUP:
5253 case KeyEvent.KEYCODE_SLEEP:
5254 return false;
5255 default:
5256 return true;
5257 }
5258 }
5259
5260 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005261 * When the screen is off we ignore some keys that might otherwise typically
5262 * be considered wake keys. We filter them out here.
5263 *
5264 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5265 * is always considered a wake key.
5266 */
5267 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5268 switch (keyCode) {
5269 // ignore volume keys unless docked
5270 case KeyEvent.KEYCODE_VOLUME_UP:
5271 case KeyEvent.KEYCODE_VOLUME_DOWN:
5272 case KeyEvent.KEYCODE_VOLUME_MUTE:
5273 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5274
5275 // ignore media and camera keys
5276 case KeyEvent.KEYCODE_MUTE:
5277 case KeyEvent.KEYCODE_HEADSETHOOK:
5278 case KeyEvent.KEYCODE_MEDIA_PLAY:
5279 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5280 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5281 case KeyEvent.KEYCODE_MEDIA_STOP:
5282 case KeyEvent.KEYCODE_MEDIA_NEXT:
5283 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5284 case KeyEvent.KEYCODE_MEDIA_REWIND:
5285 case KeyEvent.KEYCODE_MEDIA_RECORD:
5286 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005287 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005288 case KeyEvent.KEYCODE_CAMERA:
5289 return false;
5290 }
5291 return true;
5292 }
5293
5294
Jeff Brown56194eb2011-03-02 19:23:13 -08005295 /** {@inheritDoc} */
5296 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005297 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5298 if ((policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005299 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion,
5300 "android.policy:MOTION")) {
Bryce Lee5c138322014-11-03 08:26:09 -08005301 return 0;
5302 }
Michael Wright70af00a2014-09-03 19:30:20 -07005303 }
Bryce Lee5c138322014-11-03 08:26:09 -08005304
Michael Wright70af00a2014-09-03 19:30:20 -07005305 if (shouldDispatchInputWhenNonInteractive()) {
5306 return ACTION_PASS_TO_USER;
5307 }
Bryce Lee5c138322014-11-03 08:26:09 -08005308
Bryce Lee812d7022014-11-10 13:33:28 -08005309 // If we have not passed the action up and we are in theater mode without dreaming,
5310 // there will be no dream to intercept the touch and wake into ambient. The device should
5311 // wake up in this case.
5312 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005313 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming,
5314 "android.policy:MOTION");
Bryce Lee812d7022014-11-10 13:33:28 -08005315 }
5316
Jeff Brown037c33e2014-04-09 00:31:55 -07005317 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005318 }
5319
Michael Wright70af00a2014-09-03 19:30:20 -07005320 private boolean shouldDispatchInputWhenNonInteractive() {
Michael Wright2ccf0c82015-08-04 23:03:03 +01005321 if (mDisplay == null || mDisplay.getState() == Display.STATE_OFF) {
5322 return false;
5323 }
5324 // Send events to keyguard while the screen is on and it's showing.
5325 if (isKeyguardShowingAndNotOccluded()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005326 return true;
5327 }
5328
5329 // Send events to a dozing dream even if the screen is off since the dream
5330 // is in control of the state of the screen.
5331 IDreamManager dreamManager = getDreamManager();
5332
5333 try {
5334 if (dreamManager != null && dreamManager.isDreaming()) {
5335 return true;
5336 }
5337 } catch (RemoteException e) {
5338 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5339 }
5340
5341 // Otherwise, consume events since the user can't see what is being
5342 // interacted with.
5343 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005344 }
5345
RoboErik001c59c2015-01-26 15:53:51 -08005346 private void dispatchDirectAudioEvent(KeyEvent event) {
5347 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5348 return;
5349 }
5350 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005351 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5352 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005353 String pkgName = mContext.getOpPackageName();
5354 switch (keyCode) {
5355 case KeyEvent.KEYCODE_VOLUME_UP:
5356 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005357 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005358 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005359 } catch (RemoteException e) {
5360 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5361 }
5362 break;
5363 case KeyEvent.KEYCODE_VOLUME_DOWN:
5364 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005365 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005366 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005367 } catch (RemoteException e) {
5368 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5369 }
5370 break;
5371 case KeyEvent.KEYCODE_VOLUME_MUTE:
5372 try {
5373 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005374 getAudioService().adjustSuggestedStreamVolume(
5375 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005376 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005377 }
5378 } catch (RemoteException e) {
5379 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5380 }
5381 break;
5382 }
5383 }
5384
Jeff Brown40013652012-05-16 21:22:36 -07005385 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5386 if (DEBUG_INPUT) {
5387 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005388 }
5389
Jeff Brown40013652012-05-16 21:22:36 -07005390 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5391 if (DEBUG_INPUT) {
5392 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5393 }
5394
5395 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5396 mHavePendingMediaKeyRepeatWithWakeLock = false;
5397 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5398 }
5399
5400 dispatchMediaKeyWithWakeLockToAudioService(event);
5401
5402 if (event.getAction() == KeyEvent.ACTION_DOWN
5403 && event.getRepeatCount() == 0) {
5404 mHavePendingMediaKeyRepeatWithWakeLock = true;
5405
5406 Message msg = mHandler.obtainMessage(
5407 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5408 msg.setAsynchronous(true);
5409 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5410 } else {
5411 mBroadcastWakeLock.release();
5412 }
5413 }
5414
5415 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5416 mHavePendingMediaKeyRepeatWithWakeLock = false;
5417
5418 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5419 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5420 if (DEBUG_INPUT) {
5421 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5422 }
5423
5424 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5425 mBroadcastWakeLock.release();
5426 }
5427
5428 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5429 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005430 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005431 }
5432 }
5433
Michael Wright869a67c2014-08-26 19:33:06 -07005434 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005435 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5436 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5437 if (dic != null) {
5438 try {
5439 dic.exitIdle("voice-search");
5440 } catch (RemoteException e) {
5441 }
5442 }
Michael Wright869a67c2014-08-26 19:33:06 -07005443 Intent voiceIntent =
5444 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5445 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005446 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005447 mBroadcastWakeLock.release();
5448 }
5449
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005450 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005451 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005452 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005453 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5454 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5455 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005456 } else {
5457 try {
5458 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5459 ServiceManager.getService(Context.UI_MODE_SERVICE));
5460 mUiMode = uiModeService.getCurrentModeType();
5461 } catch (RemoteException e) {
5462 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005463 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005464 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005465 synchronized (mLock) {
5466 updateOrientationListenerLp();
5467 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005468 }
5469 };
5470
Jeff Brown6aaf2952012-10-05 16:01:08 -07005471 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5472 @Override
5473 public void onReceive(Context context, Intent intent) {
5474 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005475 if (mKeyguardDelegate != null) {
5476 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005477 }
5478 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005479 if (mKeyguardDelegate != null) {
5480 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005481 }
5482 }
5483 }
5484 };
5485
Christopher Tate5e08af02012-09-21 17:17:22 -07005486 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5487 @Override
5488 public void onReceive(Context context, Intent intent) {
5489 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5490 // tickle the settings observer: this first ensures that we're
5491 // observing the relevant settings for the newly-active user,
5492 // and then updates our own bookkeeping based on the now-
5493 // current user.
5494 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005495
5496 // force a re-application of focused window sysui visibility.
5497 // the window may never have been shown for this user
5498 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005499 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005500 mLastSystemUiFlags = 0;
5501 updateSystemUiVisibilityLw();
5502 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005503 }
5504 }
5505 };
5506
Adrian Roosddc8b272015-05-21 16:28:27 -07005507 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005508 @Override
5509 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005510 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5511 if (!isUserSetupComplete()) {
5512 // Swipe-up for navigation bar is disabled during setup
5513 return;
5514 }
5515 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5516 mNavigationBarController.showTransient();
5517 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005518 }
5519 };
5520
John Spurlocke1f366f2013-08-05 12:22:40 -04005521 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005522 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005523 if (!isUserSetupComplete()) {
5524 // Swipe-up for navigation bar is disabled during setup
5525 return;
5526 }
John Spurlock27735a42013-08-14 17:57:38 -04005527 boolean sb = mStatusBarController.checkShowTransientBarLw();
5528 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005529 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005530 // Don't show status bar when swiping on already visible navigation bar
5531 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005532 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005533 return;
5534 }
John Spurlock27735a42013-08-14 17:57:38 -04005535 if (sb) mStatusBarController.showTransient();
5536 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005537 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005538 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005539 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005540 }
5541 }
5542
Jeff Brown3ee549c2014-09-22 20:14:39 -07005543 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005544 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005545 public void startedGoingToSleep(int why) {
5546 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005547 if (mKeyguardDelegate != null) {
5548 mKeyguardDelegate.onStartedGoingToSleep(why);
5549 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005550 }
5551
5552 // Called on the PowerManager's Notifier thread.
5553 @Override
5554 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005555 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005556 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04005557 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005558
5559 // We must get this work done here because the power manager will drop
5560 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005561 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005562 mAwake = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005563 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005564 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005565 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005566 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005567 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005568 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005569 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005570 }
5571
Jeff Brown3ee549c2014-09-22 20:14:39 -07005572 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005573 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005574 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005575 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005576 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005577
Jeff Brown3ee549c2014-09-22 20:14:39 -07005578 // Since goToSleep performs these functions synchronously, we must
5579 // do the same here. We cannot post this work to a handler because
5580 // that might cause it to become reordered with respect to what
5581 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005582 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005583 mAwake = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005584
Jeff Browna20dda42014-05-27 20:57:24 -07005585 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005586 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005587 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005588 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005589
Jim Miller5ecd8112013-01-09 18:50:26 -08005590 if (mKeyguardDelegate != null) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005591 mKeyguardDelegate.onStartedWakingUp();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005592 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005593 }
5594
Jeff Brown416c49c2015-05-26 19:50:18 -07005595 // Called on the PowerManager's Notifier thread.
5596 @Override
5597 public void finishedWakingUp() {
5598 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5599 }
5600
5601 private void wakeUpFromPowerKey(long eventTime) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005602 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER");
Jeff Brown416c49c2015-05-26 19:50:18 -07005603 }
5604
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005605 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) {
Bryce Leed3896842015-06-23 17:06:51 -07005606 final boolean theaterModeEnabled = isTheaterModeEnabled();
5607 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07005608 return false;
5609 }
5610
Bryce Leed3896842015-06-23 17:06:51 -07005611 if (theaterModeEnabled) {
5612 Settings.Global.putInt(mContext.getContentResolver(),
5613 Settings.Global.THEATER_MODE_ON, 0);
5614 }
5615
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005616 mPowerManager.wakeUp(wakeTime, reason);
Jeff Brown416c49c2015-05-26 19:50:18 -07005617 return true;
5618 }
5619
Jeff Brown36c4db82014-09-19 12:05:31 -07005620 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005621 synchronized (mLock) {
Jorim Jaggif3255482015-07-24 12:32:42 -07005622 if (!mScreenOnEarly || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005623 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005624 }
5625
Jeff Brown36c4db82014-09-19 12:05:31 -07005626 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005627 if (mKeyguardDelegate != null) {
5628 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5629 }
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005630 mWindowManagerDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005631 }
5632
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005633 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
5634 // as well as enabling the orientation change logic/sensor.
5635 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5636 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005637 }
5638
5639 // Called on the DisplayManager's DisplayPowerController thread.
5640 @Override
5641 public void screenTurnedOff() {
5642 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5643
Jeff Brown48d1b142015-06-10 16:36:03 -07005644 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005645 synchronized (mLock) {
5646 mScreenOnEarly = false;
5647 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005648 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005649 mWindowManagerDrawComplete = false;
5650 mScreenOnListener = null;
5651 updateOrientationListenerLp();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005652
5653 if (mKeyguardDelegate != null) {
5654 mKeyguardDelegate.onScreenTurnedOff();
5655 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005656 }
5657 }
5658
Jeff Brown3ee549c2014-09-22 20:14:39 -07005659 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005660 @Override
5661 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005662 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005663
Jeff Brown48d1b142015-06-10 16:36:03 -07005664 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005665 synchronized (mLock) {
5666 mScreenOnEarly = true;
5667 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005668 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005669 mWindowManagerDrawComplete = false;
5670 mScreenOnListener = screenOnListener;
Jeff Brown36c4db82014-09-19 12:05:31 -07005671
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005672 if (mKeyguardDelegate != null) {
Jorim Jaggia4b51bc2015-08-10 18:20:43 -07005673 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5674 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005675 mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback);
5676 } else {
5677 if (DEBUG_WAKEUP) Slog.d(TAG,
5678 "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
5679 finishKeyguardDrawn();
5680 }
5681 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005682 }
5683
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005684 // Called on the DisplayManager's DisplayPowerController thread.
5685 @Override
5686 public void screenTurnedOn() {
5687 synchronized (mLock) {
5688 if (mKeyguardDelegate != null) {
5689 mKeyguardDelegate.onScreenTurnedOn();
5690 }
5691 }
5692 }
5693
Jeff Brown36c4db82014-09-19 12:05:31 -07005694 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005695 synchronized (mLock) {
5696 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005697 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005698 }
5699
Jeff Brown36c4db82014-09-19 12:05:31 -07005700 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005701 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005702
5703 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005704 }
5705
Craig Mautner8a0da012014-05-31 15:13:37 -07005706 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005707 synchronized (mLock) {
5708 // We have just finished drawing screen content. Since the orientation listener
5709 // gets only installed when all windows are drawn, we try to install it again.
5710 updateOrientationListenerLp();
5711 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005712 final ScreenOnListener listener;
5713 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005714 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005715 if (DEBUG_WAKEUP) Slog.d(TAG,
5716 "finishScreenTurningOn: mAwake=" + mAwake
5717 + ", mScreenOnEarly=" + mScreenOnEarly
5718 + ", mScreenOnFully=" + mScreenOnFully
5719 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5720 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5721
5722 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5723 || (mAwake && !mKeyguardDrawComplete)) {
5724 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005725 }
5726
Jeff Brown3ee549c2014-09-22 20:14:39 -07005727 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5728 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005729 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005730 mScreenOnFully = true;
5731
5732 // Remember the first time we draw the keyguard so we know when we're done with
5733 // the main part of booting and can enable the screen and hide boot messages.
5734 if (!mKeyguardDrawnOnce && mAwake) {
5735 mKeyguardDrawnOnce = true;
5736 enableScreen = true;
5737 if (mBootMessageNeedsHiding) {
5738 mBootMessageNeedsHiding = false;
5739 hideBootMessages();
5740 }
5741 } else {
5742 enableScreen = false;
5743 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005744 }
5745
Jeff Brown3ee549c2014-09-22 20:14:39 -07005746 if (listener != null) {
5747 listener.onScreenOn();
5748 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005749
Jeff Brown3ee549c2014-09-22 20:14:39 -07005750 if (enableScreen) {
5751 try {
5752 mWindowManager.enableScreenIfNeeded();
5753 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005754 }
Craig Mautnera631d492014-08-05 15:16:01 -07005755 }
5756 }
5757
5758 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005759 synchronized (mLock) {
5760 if (!mKeyguardDrawnOnce) {
5761 mBootMessageNeedsHiding = true;
5762 return; // keyguard hasn't drawn the first time yet, not done booting
5763 }
Craig Mautnera631d492014-08-05 15:16:01 -07005764 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005765
5766 if (mBootMsgDialog != null) {
5767 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5768 mBootMsgDialog.dismiss();
5769 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005770 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005771 }
5772
5773 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005774 public boolean isScreenOn() {
5775 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005776 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005777
Dianne Hackborn08743722009-12-21 12:16:51 -08005778 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005779 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005780 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005781 if (mKeyguardDelegate != null) {
5782 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005783 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005784 }
5785
5786 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005787 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005788 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005789 if (mKeyguardDelegate != null) {
5790 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005791 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005792 }
5793
Jim Millerab954542014-10-10 18:21:49 -07005794 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005795 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005796 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005797 }
5798
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005799 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005800 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005801 public boolean isKeyguardLocked() {
5802 return keyguardOn();
5803 }
5804
5805 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005806 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005807 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005808 if (mKeyguardDelegate == null) return false;
5809 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005810 }
5811
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005812 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005813 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07005814 public boolean isKeyguardShowingOrOccluded() {
5815 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
5816 }
5817
5818 /** {@inheritDoc} */
5819 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005820 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005821 if (mKeyguardDelegate == null) return false;
5822 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005823 }
5824
Jose Lima9546b202014-07-02 17:21:51 -07005825 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005826 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005827 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005828 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005829 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005830 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005831 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005832 // ask the keyguard to prompt the user to authenticate if necessary
5833 mKeyguardDelegate.dismiss();
5834 }
5835 });
5836 }
5837 }
5838
5839 public void notifyActivityDrawnForKeyguardLw() {
5840 if (mKeyguardDelegate != null) {
5841 mHandler.post(new Runnable() {
5842 @Override
5843 public void run() {
5844 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005845 }
5846 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005847 }
5848 }
5849
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005850 @Override
5851 public boolean isKeyguardDrawnLw() {
5852 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005853 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005854 }
5855 }
5856
Jorim Jaggi0d674622014-05-21 01:34:15 +02005857 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005858 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005859 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005860 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005861 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005862 }
5863 }
5864
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005865 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005866 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005867 }
5868
5869 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005870 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005871 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005872
Jeff Brown01a98dd2011-09-20 15:08:29 -07005873 @Override
5874 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005875 if (false) {
5876 Slog.v(TAG, "rotationForOrientationLw(orient="
5877 + orientation + ", last=" + lastRotation
5878 + "); user=" + mUserRotation + " "
5879 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5880 ? "USER_ROTATION_LOCKED" : "")
5881 );
5882 }
5883
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005884 if (mForceDefaultOrientation) {
5885 return Surface.ROTATION_0;
5886 }
5887
The Android Open Source Project0727d222009-03-11 12:11:58 -07005888 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005889 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5890 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005891 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005892 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005893
Jeff Browndec6cf42011-11-15 14:08:20 -08005894 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005895 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005896 // Ignore sensor when lid switch is open and rotation is forced.
5897 preferredRotation = mLidOpenRotation;
5898 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005899 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005900 // Ignore sensor when in car dock unless explicitly enabled.
5901 // This case can override the behavior of NOSENSOR, and can also
5902 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005903 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005904 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005905 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5906 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5907 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005908 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005909 // Ignore sensor when in desk dock unless explicitly enabled.
5910 // This case can override the behavior of NOSENSOR, and can also
5911 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005912 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005913 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005914 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5915 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005916 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005917 preferredRotation = mDemoHdmiRotation;
5918 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5919 && mUndockedHdmiRotation >= 0) {
5920 // Ignore sensor when plugged into HDMI and an undocked orientation has
5921 // been specified in the configuration (only for legacy devices without
5922 // full multi-display support).
5923 // Note that the dock orientation overrides the HDMI orientation.
5924 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005925 } else if (mDemoRotationLock) {
5926 // Ignore sensor when demo rotation lock is enabled.
5927 // Note that the dock orientation and HDMI rotation lock override this.
5928 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005929 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5930 // Application just wants to remain locked in the last rotation.
5931 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005932 } else if (!mSupportAutoRotation) {
5933 // If we don't support auto-rotation then bail out here and ignore
5934 // the sensor and any rotation lock settings.
5935 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005936 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005937 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005938 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5939 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5940 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5941 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005942 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5943 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5944 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5945 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5946 // Otherwise, use sensor only if requested by the application or enabled
5947 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005948 if (mAllowAllRotations < 0) {
5949 // Can't read this during init() because the context doesn't
5950 // have display metrics at that time so we cannot determine
5951 // tablet vs. phone then.
5952 mAllowAllRotations = mContext.getResources().getBoolean(
5953 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5954 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005955 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005956 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005957 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5958 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005959 preferredRotation = sensorRotation;
5960 } else {
5961 preferredRotation = lastRotation;
5962 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005963 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5964 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5965 // Apply rotation lock. Does not apply to NOSENSOR.
5966 // The idea is that the user rotation expresses a weak preference for the direction
5967 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5968 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005969 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005970 } else {
5971 // No overriding preference.
5972 // We will do exactly what the application asked us to do.
5973 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005974 }
5975
Dianne Hackborne5439f22010-10-02 16:53:50 -07005976 switch (orientation) {
5977 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005978 // Return portrait unless overridden.
5979 if (isAnyPortrait(preferredRotation)) {
5980 return preferredRotation;
5981 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005982 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005983
Jeff Brown01a98dd2011-09-20 15:08:29 -07005984 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005985 // Return landscape unless overridden.
5986 if (isLandscapeOrSeascape(preferredRotation)) {
5987 return preferredRotation;
5988 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005989 return mLandscapeRotation;
5990
5991 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005992 // Return reverse portrait unless overridden.
5993 if (isAnyPortrait(preferredRotation)) {
5994 return preferredRotation;
5995 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005996 return mUpsideDownRotation;
5997
5998 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005999 // Return seascape unless overridden.
6000 if (isLandscapeOrSeascape(preferredRotation)) {
6001 return preferredRotation;
6002 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006003 return mSeascapeRotation;
6004
6005 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006006 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006007 // Return either landscape rotation.
6008 if (isLandscapeOrSeascape(preferredRotation)) {
6009 return preferredRotation;
6010 }
6011 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08006012 return lastRotation;
6013 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006014 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006015
Jeff Brown01a98dd2011-09-20 15:08:29 -07006016 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006017 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006018 // Return either portrait rotation.
6019 if (isAnyPortrait(preferredRotation)) {
6020 return preferredRotation;
6021 }
6022 if (isAnyPortrait(lastRotation)) {
6023 return lastRotation;
6024 }
6025 return mPortraitRotation;
6026
6027 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07006028 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
6029 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07006030 if (preferredRotation >= 0) {
6031 return preferredRotation;
6032 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07006033 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05006034 }
6035 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006036 }
6037
Jeff Brown01a98dd2011-09-20 15:08:29 -07006038 @Override
6039 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
6040 switch (orientation) {
6041 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
6042 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
6043 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
6044 return isAnyPortrait(rotation);
6045
6046 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
6047 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
6048 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
6049 return isLandscapeOrSeascape(rotation);
6050
6051 default:
6052 return true;
6053 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006054 }
6055
Jeff Brownc0347aa2011-09-23 17:26:09 -07006056 @Override
6057 public void setRotationLw(int rotation) {
6058 mOrientationListener.setCurrentRotation(rotation);
6059 }
6060
Jeff Brown01a98dd2011-09-20 15:08:29 -07006061 private boolean isLandscapeOrSeascape(int rotation) {
6062 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006063 }
6064
Jeff Brown01a98dd2011-09-20 15:08:29 -07006065 private boolean isAnyPortrait(int rotation) {
6066 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006067 }
6068
Jose Lima9546b202014-07-02 17:21:51 -07006069 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006070 public int getUserRotationMode() {
6071 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07006072 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
6073 WindowManagerPolicy.USER_ROTATION_FREE :
6074 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006075 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006076
6077 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07006078 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006079 public void setUserRotationMode(int mode, int rot) {
6080 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006081
6082 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006083 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07006084 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006085 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006086 rot,
6087 UserHandle.USER_CURRENT);
6088 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006089 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006090 0,
6091 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006092 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07006093 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006094 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006095 1,
6096 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006097 }
6098 }
6099
Jose Lima9546b202014-07-02 17:21:51 -07006100 @Override
Jeff Brownac143512012-04-05 18:57:33 -07006101 public void setSafeMode(boolean safeMode) {
6102 mSafeMode = safeMode;
6103 performHapticFeedbackLw(null, safeMode
6104 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
6105 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006106 }
Craig Mautnereda67292013-04-28 13:50:14 -07006107
Dianne Hackborn181ceb52009-08-27 22:16:40 -07006108 static long[] getLongIntArray(Resources r, int resid) {
6109 int[] ar = r.getIntArray(resid);
6110 if (ar == null) {
6111 return null;
6112 }
6113 long[] out = new long[ar.length];
6114 for (int i=0; i<ar.length; i++) {
6115 out[i] = ar[i];
6116 }
6117 return out;
6118 }
Craig Mautnereda67292013-04-28 13:50:14 -07006119
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006120 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006121 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006122 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07006123 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08006124 mKeyguardDelegate.onSystemReady();
6125
Michael Wright3818c922014-09-02 13:59:07 -07006126 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07006127 updateUiMode();
Adrian Roos3542f7d2015-07-13 15:57:53 -07006128 boolean bindKeyguardNow;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006129 synchronized (mLock) {
6130 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08006131 mSystemReady = true;
6132 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006133 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08006134 public void run() {
6135 updateSettings();
6136 }
6137 });
Adrian Roos3542f7d2015-07-13 15:57:53 -07006138
6139 bindKeyguardNow = mDeferBindKeyguard;
6140 if (bindKeyguardNow) {
6141 // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now.
6142 mDeferBindKeyguard = false;
6143 }
6144 }
6145
6146 if (bindKeyguardNow) {
6147 mKeyguardDelegate.bindService(mContext);
6148 mKeyguardDelegate.onBootCompleted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006149 }
Michael Wrighta4d22d72015-09-16 23:19:26 +01006150 mSystemGestures.systemReady();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006151 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006152
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006153 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006154 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006155 public void systemBooted() {
Adrian Roos3542f7d2015-07-13 15:57:53 -07006156 boolean bindKeyguardNow = false;
6157 synchronized (mLock) {
6158 // Time to bind Keyguard; take care to only bind it once, either here if ready or
6159 // in systemReady if not.
6160 if (mKeyguardDelegate != null) {
6161 bindKeyguardNow = true;
6162 } else {
6163 // Because mKeyguardDelegate is null, we know that the synchronized block in
6164 // systemReady didn't run yet and setting this will actually have an effect.
6165 mDeferBindKeyguard = true;
6166 }
6167 }
6168 if (bindKeyguardNow) {
Jason Monk5eeebf52014-09-26 12:36:51 -04006169 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07006170 mKeyguardDelegate.onBootCompleted();
6171 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006172 synchronized (mLock) {
6173 mSystemBooted = true;
6174 }
Jeff Brown416c49c2015-05-26 19:50:18 -07006175 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07006176 screenTurningOn(null);
Jorim Jaggic0496072015-08-19 15:14:52 -07006177 screenTurnedOn();
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006178 }
6179
Dianne Hackborn661cd522011-08-22 00:26:20 -07006180 ProgressDialog mBootMsgDialog = null;
6181
6182 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006183 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006184 public void showBootMessage(final CharSequence msg, final boolean always) {
6185 mHandler.post(new Runnable() {
6186 @Override public void run() {
6187 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006188 int theme;
6189 if (mContext.getPackageManager().hasSystemFeature(
6190 PackageManager.FEATURE_WATCH)) {
6191 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
6192 } else if (mContext.getPackageManager().hasSystemFeature(
6193 PackageManager.FEATURE_TELEVISION)) {
6194 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
6195 } else {
6196 theme = 0;
6197 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07006198
6199 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07006200 // This dialog will consume all events coming in to
6201 // it, to avoid it trying to do things too early in boot.
6202 @Override public boolean dispatchKeyEvent(KeyEvent event) {
6203 return true;
6204 }
6205 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
6206 return true;
6207 }
6208 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
6209 return true;
6210 }
6211 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
6212 return true;
6213 }
6214 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
6215 return true;
6216 }
6217 @Override public boolean dispatchPopulateAccessibilityEvent(
6218 AccessibilityEvent event) {
6219 return true;
6220 }
6221 };
Jeff Hao9f60c082014-10-28 18:51:07 -07006222 if (mContext.getPackageManager().isUpgrade()) {
6223 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
6224 } else {
6225 mBootMsgDialog.setTitle(R.string.android_start_title);
6226 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006227 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
6228 mBootMsgDialog.setIndeterminate(true);
6229 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07006230 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006231 mBootMsgDialog.getWindow().addFlags(
6232 WindowManager.LayoutParams.FLAG_DIM_BEHIND
6233 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
6234 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08006235 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
6236 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
6237 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006238 mBootMsgDialog.setCancelable(false);
6239 mBootMsgDialog.show();
6240 }
6241 mBootMsgDialog.setMessage(msg);
6242 }
6243 });
6244 }
6245
6246 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006247 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006248 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07006249 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006250 }
6251
Mike Lockwood28569302010-01-28 11:54:40 -05006252 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006253 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006254 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006255 // ***************************************
6256 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
6257 // ***************************************
6258 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
6259 // WITH ITS LOCKS HELD.
6260 //
6261 // This code must be VERY careful about the locks
6262 // it acquires.
6263 // In fact, the current code acquires way too many,
6264 // and probably has lurking deadlocks.
6265
Mike Lockwood28569302010-01-28 11:54:40 -05006266 synchronized (mScreenLockTimeout) {
6267 if (mLockScreenTimerActive) {
6268 // reset the timer
6269 mHandler.removeCallbacks(mScreenLockTimeout);
6270 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6271 }
6272 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006273 }
6274
Adam Cohenf7522022012-10-03 20:03:18 -07006275 class ScreenLockTimeout implements Runnable {
6276 Bundle options;
6277
6278 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006279 public void run() {
6280 synchronized (this) {
6281 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006282 if (mKeyguardDelegate != null) {
6283 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006284 }
Mike Lockwood28569302010-01-28 11:54:40 -05006285 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006286 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006287 }
6288 }
Mike Lockwood28569302010-01-28 11:54:40 -05006289
Adam Cohenf7522022012-10-03 20:03:18 -07006290 public void setLockOptions(Bundle options) {
6291 this.options = options;
6292 }
6293 }
6294
6295 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6296
Jose Lima9546b202014-07-02 17:21:51 -07006297 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006298 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006299 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6300 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006301 if (options != null) {
6302 // In case multiple calls are made to lockNow, we don't wipe out the options
6303 // until the runnable actually executes.
6304 mScreenLockTimeout.setLockOptions(options);
6305 }
Jim Miller93c518e2012-01-17 15:55:31 -08006306 mHandler.post(mScreenLockTimeout);
6307 }
6308
Mike Lockwood28569302010-01-28 11:54:40 -05006309 private void updateLockScreenTimeout() {
6310 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006311 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006312 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006313 if (mLockScreenTimerActive != enable) {
6314 if (enable) {
6315 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
6316 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6317 } else {
6318 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6319 mHandler.removeCallbacks(mScreenLockTimeout);
6320 }
6321 mLockScreenTimerActive = enable;
6322 }
6323 }
6324 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006325
Jeff Brown061ea992015-04-17 19:55:47 -07006326 private void updateDreamingSleepToken(boolean acquire) {
6327 if (acquire) {
6328 if (mDreamingSleepToken == null) {
6329 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6330 }
6331 } else {
6332 if (mDreamingSleepToken != null) {
6333 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006334 mDreamingSleepToken = null;
6335 }
6336 }
6337 }
6338
6339 private void updateScreenOffSleepToken(boolean acquire) {
6340 if (acquire) {
6341 if (mScreenOffSleepToken == null) {
6342 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6343 }
6344 } else {
6345 if (mScreenOffSleepToken != null) {
6346 mScreenOffSleepToken.release();
6347 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006348 }
6349 }
6350 }
6351
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006352 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006353 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006354 public void enableScreenAfterBoot() {
6355 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006356 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006357 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006358 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006359
Jeff Brownc458ce92012-04-30 14:58:40 -07006360 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006361 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006362 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006363 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006364 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07006365 }
Jeff Browna20dda42014-05-27 20:57:24 -07006366
6367 synchronized (mLock) {
6368 updateWakeGestureListenerLp();
6369 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006370 }
6371
Jeff Brown4f5fa282014-06-12 19:19:15 -07006372 void updateUiMode() {
6373 if (mUiModeManager == null) {
6374 mUiModeManager = IUiModeManager.Stub.asInterface(
6375 ServiceManager.getService(Context.UI_MODE_SERVICE));
6376 }
6377 try {
6378 mUiMode = mUiModeManager.getCurrentModeType();
6379 } catch (RemoteException e) {
6380 }
6381 }
6382
Jeff Brown01a98dd2011-09-20 15:08:29 -07006383 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006384 try {
6385 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006386 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6387 } catch (RemoteException e) {
6388 // Ignore
6389 }
6390 }
6391
6392 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6393 try {
6394 //set orientation on WindowManager
6395 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006396 } catch (RemoteException e) {
6397 // Ignore
6398 }
6399 }
6400
Daniel Sandler6396c722013-04-16 20:19:09 -04006401 /**
6402 * Return an Intent to launch the currently active dock app as home. Returns
6403 * null if the standard home should be launched, which is the case if any of the following is
6404 * true:
6405 * <ul>
6406 * <li>The device is not in either car mode or desk mode
6407 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
6408 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6409 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6410 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6411 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006412 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006413 */
6414 Intent createHomeDockIntent() {
6415 Intent intent = null;
6416
6417 // What home does is based on the mode, not the dock state. That
6418 // is, when in car mode you should be taken to car home regardless
6419 // of whether we are actually in a car dock.
6420 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6421 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
6422 intent = mCarDockIntent;
6423 }
6424 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6425 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6426 intent = mDeskDockIntent;
6427 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006428 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6429 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6430 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6431 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6432 // Always launch dock home from home when watch is docked, if it exists.
6433 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006434 }
6435
6436 if (intent == null) {
6437 return null;
6438 }
6439
6440 ActivityInfo ai = null;
6441 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6442 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006443 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006444 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006445 if (info != null) {
6446 ai = info.activityInfo;
6447 }
6448 if (ai != null
6449 && ai.metaData != null
6450 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6451 intent = new Intent(intent);
6452 intent.setClassName(ai.packageName, ai.name);
6453 return intent;
6454 }
6455
6456 return null;
6457 }
6458
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006459 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6460 if (awakenFromDreams) {
6461 awakenDreams();
6462 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006463
6464 Intent dock = createHomeDockIntent();
6465 if (dock != null) {
6466 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006467 if (fromHomeKey) {
6468 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6469 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006470 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006471 return;
6472 } catch (ActivityNotFoundException e) {
6473 }
6474 }
6475
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006476 Intent intent;
6477
6478 if (fromHomeKey) {
6479 intent = new Intent(mHomeIntent);
6480 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6481 } else {
6482 intent = mHomeIntent;
6483 }
6484
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006485 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006486 }
Craig Mautnereda67292013-04-28 13:50:14 -07006487
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006488 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006489 * goes to the home screen
6490 * @return whether it did anything
6491 */
6492 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006493 if (!isUserSetupComplete()) {
6494 Slog.i(TAG, "Not going home because user setup is in progress.");
6495 return false;
6496 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006497 if (false) {
6498 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006499 try {
6500 ActivityManagerNative.getDefault().stopAppSwitches();
6501 } catch (RemoteException e) {
6502 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006503 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006504 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006505 } else {
6506 // This code brings home to the front or, if it is already
6507 // at the front, puts the device to sleep.
6508 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006509 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6510 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6511 Log.d(TAG, "UTS-TEST-MODE");
6512 } else {
6513 ActivityManagerNative.getDefault().stopAppSwitches();
6514 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006515 Intent dock = createHomeDockIntent();
6516 if (dock != null) {
6517 int result = ActivityManagerNative.getDefault()
6518 .startActivityAsUser(null, null, dock,
6519 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6520 null, null, 0,
6521 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006522 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006523 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6524 return false;
6525 }
6526 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006527 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006528 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006529 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006530 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006531 null, null, 0,
6532 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006533 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006534 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006535 return false;
6536 }
6537 } catch (RemoteException ex) {
6538 // bummer, the activity manager, which is in this process, is dead
6539 }
6540 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006541 return true;
6542 }
Craig Mautnereda67292013-04-28 13:50:14 -07006543
6544 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006545 public void setCurrentOrientationLw(int newOrientation) {
6546 synchronized (mLock) {
6547 if (newOrientation != mCurrentAppOrientation) {
6548 mCurrentAppOrientation = newOrientation;
6549 updateOrientationListenerLp();
6550 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006551 }
6552 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006553
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006554 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6555 if (!isGlobalAccessibilityGestureEnabled()) {
6556 return;
6557 }
6558 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6559 Context.AUDIO_SERVICE);
6560 if (audioManager.isSilentMode()) {
6561 return;
6562 }
6563 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6564 Settings.System.DEFAULT_NOTIFICATION_URI);
6565 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6566 ringTone.play();
6567 }
Craig Mautnereda67292013-04-28 13:50:14 -07006568
Bryce Lee584a4452014-10-21 15:55:55 -07006569 private boolean isTheaterModeEnabled() {
6570 return Settings.Global.getInt(mContext.getContentResolver(),
6571 Settings.Global.THEATER_MODE_ON, 0) == 1;
6572 }
6573
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006574 private boolean isGlobalAccessibilityGestureEnabled() {
6575 return Settings.Global.getInt(mContext.getContentResolver(),
6576 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6577 }
6578
Craig Mautnereda67292013-04-28 13:50:14 -07006579 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006580 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006581 if (!mVibrator.hasVibrator()) {
6582 return false;
6583 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006584 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6585 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006586 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006587 return false;
6588 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006589 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006590 switch (effectId) {
6591 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006592 pattern = mLongPressVibePattern;
6593 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006594 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006595 pattern = mVirtualKeyVibePattern;
6596 break;
6597 case HapticFeedbackConstants.KEYBOARD_TAP:
6598 pattern = mKeyboardTapVibePattern;
6599 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006600 case HapticFeedbackConstants.CLOCK_TICK:
6601 pattern = mClockTickVibePattern;
6602 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006603 case HapticFeedbackConstants.CALENDAR_DATE:
6604 pattern = mCalendarDateVibePattern;
6605 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006606 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006607 pattern = mSafeModeDisabledVibePattern;
6608 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006609 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006610 pattern = mSafeModeEnabledVibePattern;
6611 break;
Mady Mellore8608912015-06-05 09:02:55 -07006612 case HapticFeedbackConstants.CONTEXT_CLICK:
6613 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006614 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006615 default:
6616 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006617 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006618 int owningUid;
6619 String owningPackage;
6620 if (win != null) {
6621 owningUid = win.getOwningUid();
6622 owningPackage = win.getOwningPackage();
6623 } else {
6624 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006625 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006626 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006627 if (pattern.length == 1) {
6628 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006629 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006630 } else {
6631 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006632 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006633 }
6634 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006635 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006636
6637 @Override
6638 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006639 }
6640
Jeff Brownc38c9be2012-10-04 13:16:19 -07006641 @Override
6642 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006643 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006644 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006645 }
6646 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006647
Dianne Hackborndf89e652011-10-06 22:35:11 -07006648 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006649 // If there is no window focused, there will be nobody to handle the events
6650 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006651 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6652 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006653 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006654 return 0;
6655 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006656 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006657 // We are updating at a point where the keyguard has gotten
6658 // focus, but we were last in a state where the top window is
6659 // hiding it. This is probably because the keyguard as been
6660 // shown while the top window was displayed, so we want to ignore
6661 // it here because this is just a very transient change and it
6662 // will quickly lose focus once it correctly gets hidden.
6663 return 0;
6664 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006665
John Spurlock1db8b682014-02-18 11:18:59 -05006666 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006667 & ~mResettingSystemUiFlags
6668 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006669 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006670 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006671 }
Thanh Hai Mai6c009f52015-09-01 16:27:32 -07006672
6673 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6674 tmpVisibility |= StatusBarManager.DISABLE_RECENT;
6675 }
6676
Adrian Rooscd3884d2015-02-18 17:25:23 +01006677 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006678 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006679 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006680 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006681 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006682 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006683 return 0;
6684 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006685 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006686 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006687 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006688 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006689 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006690 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006691 try {
6692 IStatusBarService statusbar = getStatusBarService();
6693 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006694 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006695 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006696 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006697 } catch (RemoteException e) {
6698 // re-acquire status bar service next time it is needed.
6699 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006700 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006701 }
6702 });
6703 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006704 }
6705
Adrian Rooscd3884d2015-02-18 17:25:23 +01006706 private int updateLightStatusBarLw(int vis) {
6707 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6708 ? mStatusBar
6709 : mTopFullscreenOpaqueOrDimmingWindowState;
6710
6711 if (statusColorWin != null) {
6712 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6713 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6714 // its light flag.
6715 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6716 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6717 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6718 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6719 // Otherwise if it's dimming, clear the light flag.
6720 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6721 }
6722 }
6723 return vis;
6724 }
6725
John Spurlock79da8332013-09-20 12:04:47 -04006726 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006727 final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
6728 final boolean freeformStackVisible =
6729 mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID);
6730 final boolean forceShowSystemBars = dockedStackVisible || freeformStackVisible;
6731 // TODO(multi-window): Update to force opaque independently for status bar and nav bar.
6732 // This will require refactoring the code to have separate vis flag for each bar so it can
6733 // be adjusted independently.
6734 final boolean forceOpaqueSystemBars = forceShowSystemBars;
6735
John Spurlockbd957402013-10-03 11:38:39 -04006736 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006737 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6738 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006739 : mTopFullscreenOpaqueWindowState;
6740 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6741 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6742
John Spurlock27735a42013-08-14 17:57:38 -04006743 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006744 int type = win.getAttrs().type;
6745 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006746 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006747 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6748 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006749 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006750 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6751 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006752 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006753 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6754 }
John Spurlockbd957402013-10-03 11:38:39 -04006755 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006756 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006757
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006758 if ((!areTranslucentBarsAllowed() && transWin != mStatusBar)
6759 || forceOpaqueSystemBars) {
Adrian Roosea562512014-05-05 13:33:03 +02006760 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6761 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006762 }
6763
John Spurlock27735a42013-08-14 17:57:38 -04006764 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006765 boolean immersiveSticky =
6766 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006767 final boolean hideStatusBarWM =
6768 mTopFullscreenOpaqueWindowState != null
6769 && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006770 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006771 final boolean hideStatusBarSysui =
John Spurlock27735a42013-08-14 17:57:38 -04006772 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006773 final boolean hideNavBarSysui =
John Spurlockf1a36642013-10-12 17:50:42 -04006774 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006775
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006776 final boolean transientStatusBarAllowed = mStatusBar != null
6777 && (statusBarHasFocus || (!forceShowSystemBars
6778 && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky))));
John Spurlock27735a42013-08-14 17:57:38 -04006779
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006780 final boolean transientNavBarAllowed = mNavigationBar != null
6781 && !forceShowSystemBars && hideNavBarSysui && immersiveSticky;
John Spurlockf1a36642013-10-12 17:50:42 -04006782
Adrian Roosddc8b272015-05-21 16:28:27 -07006783 final long now = SystemClock.uptimeMillis();
6784 final boolean pendingPanic = mPendingPanicGestureUptime != 0
6785 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
6786 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
6787 // The user performed the panic gesture recently, we're about to hide the bars,
6788 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
6789 mPendingPanicGestureUptime = 0;
6790 mStatusBarController.showTransient();
6791 mNavigationBarController.showTransient();
6792 }
6793
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006794 final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006795 && !transientStatusBarAllowed && hideStatusBarSysui;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006796 final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006797 && !transientNavBarAllowed;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006798 if (denyTransientStatus || denyTransientNav || forceShowSystemBars) {
John Spurlock27735a42013-08-14 17:57:38 -04006799 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006800 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006801 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006802 }
John Spurlock27735a42013-08-14 17:57:38 -04006803
Selim Cinekf98702e2015-05-20 22:48:40 -07006804 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
6805 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
6806 final boolean navAllowedHidden = immersive || immersiveSticky;
6807
Selim Cinekd6623612015-05-22 18:56:22 -07006808 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
6809 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07006810 // We can't hide the navbar from this window otherwise the input consumer would not get
6811 // the input events.
6812 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
6813 }
6814
John Spurlock27735a42013-08-14 17:57:38 -04006815 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6816
6817 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006818 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6819 boolean newImmersiveMode = isImmersiveMode(vis);
6820 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006821 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006822 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6823 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006824 }
John Spurlock27735a42013-08-14 17:57:38 -04006825
John Spurlockf1a36642013-10-12 17:50:42 -04006826 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6827
John Spurlocke1f366f2013-08-05 12:22:40 -04006828 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006829 }
6830
John Spurlockf1a36642013-10-12 17:50:42 -04006831 private void clearClearableFlagsLw() {
6832 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6833 if (newVal != mResettingSystemUiFlags) {
6834 mResettingSystemUiFlags = newVal;
6835 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6836 }
6837 }
6838
6839 private boolean isImmersiveMode(int vis) {
6840 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006841 return mNavigationBar != null
6842 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006843 && (vis & flags) != 0
6844 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006845 }
6846
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006847 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006848 * @return whether the navigation or status bar can be made translucent
6849 *
6850 * This should return true unless touch exploration is not enabled or
6851 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006852 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006853 private boolean areTranslucentBarsAllowed() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04006854 return mTranslucentDecorEnabled;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006855 }
6856
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006857 // Use this instead of checking config_showNavigationBar so that it can be consistently
6858 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006859 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006860 public boolean hasNavigationBar() {
6861 return mHasNavigationBar;
6862 }
6863
satok1bc0a492012-04-25 22:47:12 +09006864 @Override
6865 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6866 mLastInputMethodWindow = ime;
6867 mLastInputMethodTargetWindow = target;
6868 }
6869
Craig Mautnerf1b67412012-09-19 13:18:29 -07006870 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006871 public int getInputMethodWindowVisibleHeightLw() {
6872 return mDockBottom - mCurBottom;
6873 }
6874
6875 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006876 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006877 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006878 if (mKeyguardDelegate != null) {
6879 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006880 }
John Spurlock13451a22012-09-28 14:40:41 -04006881 if (mStatusBarService != null) {
6882 try {
6883 mStatusBarService.setCurrentUser(newUserId);
6884 } catch (RemoteException e) {
6885 // oh well
6886 }
6887 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006888 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006889 }
6890
6891 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006892 public boolean canMagnifyWindow(int windowType) {
6893 switch (windowType) {
6894 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6895 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6896 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6897 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6898 return false;
6899 }
6900 }
6901 return true;
6902 }
6903
6904 @Override
6905 public boolean isTopLevelWindow(int windowType) {
6906 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6907 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6908 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6909 }
6910 return true;
6911 }
6912
Jim Miller4eeb4f62012-11-08 00:04:29 -08006913 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006914 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006915 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006916 pw.print(" mSystemReady="); pw.print(mSystemReady);
6917 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006918 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006919 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006920 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006921 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006922 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6923 || mForceClearedSystemUiFlags != 0) {
6924 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6925 pw.print(Integer.toHexString(mLastSystemUiFlags));
6926 pw.print(" mResettingSystemUiFlags=0x");
6927 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6928 pw.print(" mForceClearedSystemUiFlags=0x");
6929 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006930 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006931 if (mLastFocusNeedsMenu) {
6932 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6933 pw.println(mLastFocusNeedsMenu);
6934 }
Jeff Browna20dda42014-05-27 20:57:24 -07006935 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6936 pw.println(mWakeGestureEnabledSetting);
6937
Jeff Brownbcdfc622014-03-06 19:13:04 -08006938 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006939 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6940 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006941 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6942 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6943 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6944 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006945 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006946 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006947 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6948 pw.print(mCarDockEnablesAccelerometer);
6949 pw.print(" mDeskDockEnablesAccelerometer=");
6950 pw.println(mDeskDockEnablesAccelerometer);
6951 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6952 pw.print(mLidKeyboardAccessibility);
6953 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006954 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006955 pw.print(prefix);
6956 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6957 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006958 pw.print(prefix);
6959 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6960 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006961 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006962 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6963 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6964 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6965 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6966 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6967 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6968 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006969 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6970 pw.print(","); pw.print(mOverscanScreenTop);
6971 pw.print(") "); pw.print(mOverscanScreenWidth);
6972 pw.print("x"); pw.println(mOverscanScreenHeight);
6973 if (mOverscanLeft != 0 || mOverscanTop != 0
6974 || mOverscanRight != 0 || mOverscanBottom != 0) {
6975 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6976 pw.print(" top="); pw.print(mOverscanTop);
6977 pw.print(" right="); pw.print(mOverscanRight);
6978 pw.print(" bottom="); pw.println(mOverscanBottom);
6979 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006980 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6981 pw.print(mRestrictedOverscanScreenLeft);
6982 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6983 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6984 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006985 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6986 pw.print(","); pw.print(mUnrestrictedScreenTop);
6987 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6988 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6989 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6990 pw.print(","); pw.print(mRestrictedScreenTop);
6991 pw.print(") "); pw.print(mRestrictedScreenWidth);
6992 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006993 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6994 pw.print(","); pw.print(mStableFullscreenTop);
6995 pw.print(")-("); pw.print(mStableFullscreenRight);
6996 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006997 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6998 pw.print(","); pw.print(mStableTop);
6999 pw.print(")-("); pw.print(mStableRight);
7000 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007001 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
7002 pw.print(","); pw.print(mSystemTop);
7003 pw.print(")-("); pw.print(mSystemRight);
7004 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007005 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
7006 pw.print(","); pw.print(mCurTop);
7007 pw.print(")-("); pw.print(mCurRight);
7008 pw.print(","); pw.print(mCurBottom); pw.println(")");
7009 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
7010 pw.print(","); pw.print(mContentTop);
7011 pw.print(")-("); pw.print(mContentRight);
7012 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07007013 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
7014 pw.print(","); pw.print(mVoiceContentTop);
7015 pw.print(")-("); pw.print(mVoiceContentRight);
7016 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007017 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
7018 pw.print(","); pw.print(mDockTop);
7019 pw.print(")-("); pw.print(mDockRight);
7020 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007021 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
7022 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007023 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
7024 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07007025 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
7026 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007027 if (mLastInputMethodWindow != null) {
7028 pw.print(prefix); pw.print("mLastInputMethodWindow=");
7029 pw.println(mLastInputMethodWindow);
7030 }
7031 if (mLastInputMethodTargetWindow != null) {
7032 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
7033 pw.println(mLastInputMethodTargetWindow);
7034 }
7035 if (mStatusBar != null) {
7036 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08007037 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
7038 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007039 }
7040 if (mNavigationBar != null) {
7041 pw.print(prefix); pw.print("mNavigationBar=");
7042 pw.println(mNavigationBar);
7043 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007044 if (mFocusedWindow != null) {
7045 pw.print(prefix); pw.print("mFocusedWindow=");
7046 pw.println(mFocusedWindow);
7047 }
7048 if (mFocusedApp != null) {
7049 pw.print(prefix); pw.print("mFocusedApp=");
7050 pw.println(mFocusedApp);
7051 }
7052 if (mWinDismissingKeyguard != null) {
7053 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
7054 pw.println(mWinDismissingKeyguard);
7055 }
7056 if (mTopFullscreenOpaqueWindowState != null) {
7057 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
7058 pw.println(mTopFullscreenOpaqueWindowState);
7059 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01007060 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
7061 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
7062 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
7063 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007064 if (mForcingShowNavBar) {
7065 pw.print(prefix); pw.print("mForcingShowNavBar=");
7066 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
7067 pw.println(mForcingShowNavBarLayer);
7068 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007069 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007070 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007071 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
7072 pw.print(" mForceStatusBarFromKeyguard=");
7073 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007074 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07007075 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007076 pw.print(" mHomePressed="); pw.println(mHomePressed);
7077 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
7078 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
7079 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
7080 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
7081 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
7082 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
7083 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
7084 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
7085 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
7086 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07007087 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
7088 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
7089 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07007090
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07007091 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04007092 mStatusBarController.dump(pw, prefix);
7093 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05007094 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07007095
Jeff Browna20dda42014-05-27 20:57:24 -07007096 if (mWakeGestureListener != null) {
7097 mWakeGestureListener.dump(pw, prefix);
7098 }
Jeff Brown600f0032014-05-22 17:06:00 -07007099 if (mOrientationListener != null) {
7100 mOrientationListener.dump(pw, prefix);
7101 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00007102 if (mBurnInProtectionHelper != null) {
7103 mBurnInProtectionHelper.dump(prefix, pw);
7104 }
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07007105 if (mKeyguardDelegate != null) {
7106 mKeyguardDelegate.dump(prefix, pw);
7107 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007108 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007109}