blob: 9a7d1531cee24a322efe68dea2a3b0b961cc3d64 [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;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800111import android.view.Surface;
112import android.view.View;
113import android.view.ViewConfiguration;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800114import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800115import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700116import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800117import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800118import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800119import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800120import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200121import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800122import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800123import com.android.internal.R;
Jason Monk8f7f3182015-11-18 16:35:14 -0500124import com.android.internal.logging.MetricsLogger;
125import com.android.internal.policy.PhoneWindow;
Craig Mautnerae446592012-12-06 19:05:05 -0800126import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700127import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800128import com.android.internal.widget.PointerLocationView;
Adrian Roos5941c982015-09-03 15:59:49 -0700129import com.android.server.GestureLauncherService;
Craig Mautner8a0da012014-05-31 15:13:37 -0700130import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100131import com.android.server.policy.keyguard.KeyguardServiceDelegate;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700132import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800133
134import java.io.File;
135import java.io.FileReader;
136import java.io.IOException;
137import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700138import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800139import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800140
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800141/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700142 * WindowManagerPolicy implementation for the Android phone UI. This
143 * introduces a new method suffix, Lp, for an internal lock of the
144 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400145 * 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 -0700146 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800147 */
148public class PhoneWindowManager implements WindowManagerPolicy {
149 static final String TAG = "WindowManager";
150 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700151 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700152 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700153 static final boolean DEBUG_KEYGUARD = false;
154 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700155 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700156 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800157 static final boolean SHOW_STARTING_ANIMATIONS = true;
158 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400159
Daniel Sandler6396c722013-04-16 20:19:09 -0400160 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
Keun-young Park3b741e02015-12-03 02:11:00 +0000161 // No longer recommended for desk docks; still useful in car docks.
162 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
Daniel Sandler6396c722013-04-16 20:19:09 -0400163 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
164
Jeff Brown6d8fd272014-05-20 21:24:38 -0700165 static final int SHORT_PRESS_POWER_NOTHING = 0;
166 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
167 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
168 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800169 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700170
Joe Onoratod208e702010-10-08 16:22:43 -0400171 static final int LONG_PRESS_POWER_NOTHING = 0;
172 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
173 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700174 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700175
Jeff Brown13f00f02014-10-31 14:45:50 -0700176 static final int MULTI_PRESS_POWER_NOTHING = 0;
177 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
178 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
179
Michael Jurka3b1fc472011-06-13 10:54:40 -0700180 // These need to match the documentation/constant in
181 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800182 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800183 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700184 static final int LONG_PRESS_HOME_ASSIST = 2;
185
186 static final int DOUBLE_TAP_HOME_NOTHING = 0;
187 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800188
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000189 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
190 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
191
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700192 static final int APPLICATION_MEDIA_SUBLAYER = -2;
193 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800194 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800195 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700196 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700197
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800198 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
199 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
200 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500201 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700202 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800203
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700204 /**
205 * These are the system UI flags that, when changing, can cause the layout
206 * of the screen to change.
207 */
208 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400209 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400210 | View.SYSTEM_UI_FLAG_FULLSCREEN
211 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200212 | View.NAVIGATION_BAR_TRANSLUCENT
213 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700214
John Spurlock7b414672014-07-18 13:02:39 -0400215 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
216 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
217 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
218 .build();
219
Adrian Roosddc8b272015-05-21 16:28:27 -0700220 // The panic gesture may become active only after the keyguard is dismissed and the immersive
221 // app shows again. If that doesn't happen for 30s we drop the gesture.
222 private static final long PANIC_GESTURE_EXPIRATION = 30000;
223
Jim Miller5ecd8112013-01-09 18:50:26 -0800224 /**
225 * Keyguard stuff
226 */
227 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100228 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700229 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800230
Jeff Brown6651a632011-11-28 12:59:11 -0800231 /* Table of Application Launch keys. Maps from key codes to intent categories.
232 *
233 * These are special keys that are used to launch particular kinds of applications,
234 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
235 * usage page. We don't support quite that many yet...
236 */
237 static SparseArray<String> sApplicationLaunchKeyCategories;
238 static {
239 sApplicationLaunchKeyCategories = new SparseArray<String>();
240 sApplicationLaunchKeyCategories.append(
241 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
242 sApplicationLaunchKeyCategories.append(
243 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
244 sApplicationLaunchKeyCategories.append(
245 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
246 sApplicationLaunchKeyCategories.append(
247 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
248 sApplicationLaunchKeyCategories.append(
249 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
250 sApplicationLaunchKeyCategories.append(
251 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
252 }
253
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700254 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700255 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700256
Dianne Hackborndf89e652011-10-06 22:35:11 -0700257 /**
258 * Lock protecting internal state. Must not call out into window
259 * manager with lock held. (This lock will be acquired in places
260 * where the window manager is calling in with its own lock held.)
261 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800262 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700263
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800264 Context mContext;
265 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700266 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700267 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700268 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700269 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700270 DreamManagerInternal mDreamManagerInternal;
Michael Wrighta4d22d72015-09-16 23:19:26 +0100271 PowerManagerInternal mPowerManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400272 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700273 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700274 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800275 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700276 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800277 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000278 BurnInProtectionHelper mBurnInProtectionHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100279 AppOpsManager mAppOpsManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800280
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700281 // Vibrator pattern for haptic feedback of a long press.
282 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700283
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700284 // Vibrator pattern for haptic feedback of virtual key press.
285 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700286
Amith Yamasanic33cb712010-02-10 15:21:49 -0800287 // Vibrator pattern for a short vibration.
288 long[] mKeyboardTapVibePattern;
289
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700290 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
291 long[] mClockTickVibePattern;
292
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700293 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
294 long[] mCalendarDateVibePattern;
295
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700296 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
297 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700298
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700299 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
300 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700301
Mady Mellore8608912015-06-05 09:02:55 -0700302 // Vibrator pattern for haptic feedback of a context click.
303 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700304
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800305 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
306 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400307
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800308 boolean mSafeMode;
309 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700310 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400311 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400312 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700313 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400314 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
315 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
316 int[] mNavigationBarHeightForRotation = new int[4];
317 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400318
Craig Mautnera631d492014-08-05 15:16:01 -0700319 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800320 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700321 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700322 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700323 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700324 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
325 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
326 }
327 };
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700328 final DrawnListener mKeyguardDrawnCallback = new DrawnListener() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700329 @Override
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700330 public void onDrawn() {
331 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn.");
Craig Mautner8a0da012014-05-31 15:13:37 -0700332 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
333 }
334 };
335
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800336 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800337 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900338 WindowState mLastInputMethodWindow = null;
339 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800340
Jeff Brown13f00f02014-10-31 14:45:50 -0700341 // FIXME This state is shared between the input reader and handler thread.
342 // Technically it's broken and buggy but it has been like this for many years
343 // and we have not yet seen any problems. Someday we'll rewrite this logic
344 // so that only one thread is involved in handling input policy. Unfortunately
345 // it's on a critical path for power management so we can't just post the work to the
346 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
347 // to hold wakelocks during dispatch and eliminating the critical path.
348 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800349 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700350 volatile int mPowerKeyPressCounter;
351 volatile boolean mEndCallKeyHandled;
352
Winson Chungd42a6cf2014-06-03 16:24:04 -0700353 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700354 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700355 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800356
Jeff Brown2e7760e2012-04-11 15:14:55 -0700357 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700358 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700359 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800360
Dianne Hackbornc777e072010-02-12 13:07:59 -0800361 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700362 boolean mSystemBooted;
Adrian Roos3542f7d2015-07-13 15:57:53 -0700363 private boolean mDeferBindKeyguard;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800364 boolean mHdmiPlugged;
Jinsuk Kime601b712015-07-07 08:01:02 +0900365 HdmiControl mHdmiControl;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700366 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400367 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700368 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700369 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400370 int mCarDockRotation;
371 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700372 int mUndockedHdmiRotation;
373 int mDemoHdmiRotation;
374 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800375 int mDemoRotation;
376 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400377
Jeff Browna20dda42014-05-27 20:57:24 -0700378 boolean mWakeGestureEnabledSetting;
379 MyWakeGestureListener mWakeGestureListener;
380
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700381 // Default display does not rotate, apps that require non-default orientation will have to
382 // have the orientation emulated.
383 private boolean mForceDefaultOrientation = false;
384
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400385 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
386 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700387 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400388
Jeff Brownbcdfc622014-03-06 19:13:04 -0800389 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700390 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400391 boolean mCarDockEnablesAccelerometer;
392 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700393 int mLidKeyboardAccessibility;
394 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700395 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700396 int mShortPressOnPowerBehavior;
397 int mLongPressOnPowerBehavior;
398 int mDoublePressOnPowerBehavior;
399 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000400 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700401 boolean mAwake;
402 boolean mScreenOnEarly;
403 boolean mScreenOnFully;
404 ScreenOnListener mScreenOnListener;
405 boolean mKeyguardDrawComplete;
406 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800407 boolean mOrientationSensorEnabled = false;
408 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800409 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400410 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800411 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700412
Jeff Brown70825162012-03-28 17:27:48 -0700413 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800414
415 // The last window we were told about in focusChanged.
416 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800417 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800418
Jeff Brown70825162012-03-28 17:27:48 -0700419 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800420
Dianne Hackbornc652de82013-02-15 16:32:56 -0800421 // The current size of the screen; really; extends into the overscan area of
422 // the screen and doesn't account for any system elements like the status bar.
423 int mOverscanScreenLeft, mOverscanScreenTop;
424 int mOverscanScreenWidth, mOverscanScreenHeight;
425 // The current visible size of the screen; really; (ir)regardless of whether the status
426 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800427 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
428 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800429 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
430 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
431 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700432 // The current size of the screen; these may be different than (0,0)-(dw,dh)
433 // if the status bar can't be hidden; in that case it effectively carves out
434 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800435 int mRestrictedScreenLeft, mRestrictedScreenTop;
436 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700437 // During layout, the current screen borders accounting for any currently
438 // visible system UI elements.
439 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700440 // For applications requesting stable content insets, these are them.
441 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700442 // For applications requesting stable content insets but have also set the
443 // fullscreen window flag, these are the stable dimensions without the status bar.
444 int mStableFullscreenLeft, mStableFullscreenTop;
445 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800446 // During layout, the current screen borders with all outer decoration
447 // (status bar, input method dock) accounted for.
448 int mCurLeft, mCurTop, mCurRight, mCurBottom;
449 // During layout, the frame in which content should be displayed
450 // to the user, accounting for all screen decoration except for any
451 // space they deem as available for other content. This is usually
452 // the same as mCur*, but may be larger if the screen decor has supplied
453 // content insets.
454 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700455 // During layout, the frame in which voice content should be displayed
456 // to the user, accounting for all screen decoration except for any
457 // space they deem as available for other content.
458 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800459 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800460 // windows are placed.
461 int mDockLeft, mDockTop, mDockRight, mDockBottom;
462 // During layout, the layer at which the doc window is placed.
463 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700464 // During layout, this is the layer of the status bar.
465 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700466 int mLastSystemUiFlags;
467 // Bits that we are in the process of clearing, so we want to prevent
468 // them from being set by applications until everything has been updated
469 // to have them clear.
470 int mResettingSystemUiFlags = 0;
471 // Bits that we are currently always keeping cleared.
472 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800473 // What we last reported to system UI about whether the compatibility
474 // menu needs to be displayed.
475 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700476 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
477 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700478
Selim Cinekf83e8242015-05-19 18:08:14 -0700479 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700480
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800481 static final Rect mTmpParentFrame = new Rect();
482 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800483 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800484 static final Rect mTmpContentFrame = new Rect();
485 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400486 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700487 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700488 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700489 static final Rect mTmpOutsetFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700490
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800491 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100492 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700493 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200494 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400495 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800496 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700497 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700498 private boolean mForceStatusBarTransparent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700499 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800500 boolean mForcingShowNavBar;
501 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700502
503 // States of keyguard dismiss.
504 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
505 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
506 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
507 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
508
509 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
510 * be done once per window. */
511 private WindowState mWinDismissingKeyguard;
512
tingna_sunge785ffa2015-05-12 13:23:15 +0800513 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
514 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
515 * lock SIM card. This variable is used to record the previous keyguard secure state for
516 * monitoring secure state change on window dismissing keyguard. */
517 private boolean mSecureDismissingKeyguard;
518
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700519 /** The window that is currently showing "over" the keyguard. If there is an app window
520 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
521 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
522 * the wallpaper. */
523 private WindowState mWinShowWhenLocked;
524
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700525 boolean mShowingLockscreen;
526 boolean mShowingDream;
527 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700528 boolean mDreamingSleepTokenNeeded;
529 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700530 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700531 boolean mKeyguardSecure;
532 boolean mKeyguardSecureIncludingHidden;
533 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800534 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700535 boolean mHomeConsumed;
536 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800537 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700538 Intent mCarDockIntent;
539 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700540 boolean mSearchKeyShortcutPending;
541 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700542 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700543 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800544
Mike Lockwood28569302010-01-28 11:54:40 -0500545 // support for activating the lock screen while the screen is on
546 boolean mAllowLockscreenWhenOn;
547 int mLockScreenTimeout;
548 boolean mLockScreenTimerActive;
549
David Brownbaf8d092010-03-08 21:52:59 -0800550 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800551 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800552
553 // Behavior of POWER button while in-call and screen on.
554 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
555 int mIncallPowerBehavior;
556
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700557 Display mDisplay;
558
Filip Gruszczynski2987f612015-06-30 15:03:30 -0700559 private int mDisplayRotation;
560
Dianne Hackborn9d132642011-04-21 17:26:39 -0700561 int mLandscapeRotation = 0; // default landscape rotation
562 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
563 int mPortraitRotation = 0; // default portrait rotation
564 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700565
Dianne Hackbornc652de82013-02-15 16:32:56 -0800566 int mOverscanLeft = 0;
567 int mOverscanTop = 0;
568 int mOverscanRight = 0;
569 int mOverscanBottom = 0;
570
Joe Onorato46b0d682010-11-22 17:37:27 -0800571 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700572 private int mLongPressOnHomeBehavior;
573
574 // What we do when the user double-taps on home
575 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800576
Bryce Lee584a4452014-10-21 15:55:55 -0700577 // Allowed theater mode wake actions
578 private boolean mAllowTheaterModeWakeFromKey;
579 private boolean mAllowTheaterModeWakeFromPowerKey;
580 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800581 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700582 private boolean mAllowTheaterModeWakeFromCameraLens;
583 private boolean mAllowTheaterModeWakeFromLidSwitch;
584 private boolean mAllowTheaterModeWakeFromWakeGesture;
585
Bryce Leed3b28402015-03-09 15:49:13 +0000586 // Whether to support long press from power button in non-interactive mode
587 private boolean mSupportLongPressPowerWhenNonInteractive;
588
Bryce Lee55e846d2014-11-04 12:43:44 -0800589 // Whether to go to sleep entering theater mode from power button
590 private boolean mGoToSleepOnButtonPressTheaterMode;
591
Winson Chung9112ec32011-06-27 13:15:32 -0700592 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700593 // Time to volume and power must be pressed within this interval of each other.
594 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700595 // Increase the chord delay when taking a screenshot from the keyguard
596 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800597 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700598 private boolean mScreenshotChordVolumeDownKeyTriggered;
599 private long mScreenshotChordVolumeDownKeyTime;
600 private boolean mScreenshotChordVolumeDownKeyConsumed;
601 private boolean mScreenshotChordVolumeUpKeyTriggered;
602 private boolean mScreenshotChordPowerKeyTriggered;
603 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700604
Michael Wrightb854e242013-02-05 17:54:02 -0800605 /* The number of steps between min and max brightness */
606 private static final int BRIGHTNESS_STEPS = 10;
607
Christopher Tate5e08af02012-09-21 17:17:22 -0700608 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800609 ShortcutManager mShortcutManager;
610 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700611 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700612 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800613
Craig Mautnerd625ab22013-09-06 13:40:31 -0700614 private int mCurrentUserId;
615
Justin Kohd378ad72013-04-01 12:18:26 -0700616 // Maps global key codes to the components that will handle them.
617 private GlobalKeyManager mGlobalKeyManager;
618
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700619 // Fallback actions by key code.
620 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
621 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800622
Jorim Jaggi76a16232014-08-08 17:00:47 +0200623 private final LogDecelerateInterpolator mLogDecelerateInterpolator
624 = new LogDecelerateInterpolator(100, 0);
625
Jeff Brown70825162012-03-28 17:27:48 -0700626 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
627 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700628 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
629 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700630 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
631 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
632 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700633 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700634 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700635 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700636 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700637 private static final int MSG_POWER_DELAYED_PRESS = 13;
638 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700639 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700640 private static final int MSG_REQUEST_TRANSIENT_BARS = 16;
641
642 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
643 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
Jeff Brown70825162012-03-28 17:27:48 -0700644
645 private class PolicyHandler extends Handler {
646 @Override
647 public void handleMessage(Message msg) {
648 switch (msg.what) {
649 case MSG_ENABLE_POINTER_LOCATION:
650 enablePointerLocation();
651 break;
652 case MSG_DISABLE_POINTER_LOCATION:
653 disablePointerLocation();
654 break;
Jeff Brown40013652012-05-16 21:22:36 -0700655 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
656 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
657 break;
658 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
659 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
660 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700661 case MSG_DISPATCH_SHOW_RECENTS:
662 showRecentApps(false);
663 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700664 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
665 showGlobalActionsInternal();
666 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700667 case MSG_KEYGUARD_DRAWN_COMPLETE:
668 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700669 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700670 break;
671 case MSG_KEYGUARD_DRAWN_TIMEOUT:
672 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700673 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700674 break;
675 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
676 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700677 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700678 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700679 case MSG_HIDE_BOOT_MESSAGE:
680 handleHideBootMessage();
681 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700682 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
683 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
684 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700685 case MSG_POWER_DELAYED_PRESS:
686 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
687 finishPowerKeyPress();
688 break;
689 case MSG_POWER_LONG_PRESS:
690 powerLongPress();
691 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700692 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
693 updateDreamingSleepToken(msg.arg1 != 0);
694 break;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700695 case MSG_REQUEST_TRANSIENT_BARS:
696 WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ?
697 mStatusBar : mNavigationBar;
698 if (targetBar != null) {
699 requestTransientBars(targetBar);
700 }
701 break;
Jeff Brown70825162012-03-28 17:27:48 -0700702 }
703 }
704 }
705
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800706 private UEventObserver mHDMIObserver = new UEventObserver() {
707 @Override
708 public void onUEvent(UEventObserver.UEvent event) {
709 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
710 }
711 };
712
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800713 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800714 SettingsObserver(Handler handler) {
715 super(handler);
716 }
David Brownbaf8d092010-03-08 21:52:59 -0800717
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800718 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700719 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800720 ContentResolver resolver = mContext.getContentResolver();
721 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700722 Settings.System.END_BUTTON_BEHAVIOR), false, this,
723 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800724 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700725 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
726 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700727 resolver.registerContentObserver(Settings.Secure.getUriFor(
728 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
729 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800730 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700731 Settings.System.ACCELEROMETER_ROTATION), false, this,
732 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500733 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700734 Settings.System.USER_ROTATION), false, this,
735 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400736 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700737 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
738 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800739 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700740 Settings.System.POINTER_LOCATION), false, this,
741 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800742 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700743 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
744 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500745 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400746 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700747 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500748 resolver.registerContentObserver(Settings.Global.getUriFor(
749 Settings.Global.POLICY_CONTROL), false, this,
750 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800751 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800752 }
753
754 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800755 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700756 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800757 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800758 }
Craig Mautner967212c2013-04-13 21:10:58 -0700759
Jeff Browna20dda42014-05-27 20:57:24 -0700760 class MyWakeGestureListener extends WakeGestureListener {
761 MyWakeGestureListener(Context context, Handler handler) {
762 super(context, handler);
763 }
764
765 @Override
766 public void onWakeUp() {
767 synchronized (mLock) {
768 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700769 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700770 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture,
771 "android.policy:GESTURE");
Jeff Browna20dda42014-05-27 20:57:24 -0700772 }
773 }
774 }
775 }
776
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800777 class MyOrientationListener extends WindowOrientationListener {
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700778 private final Runnable mUpdateRotationRunnable = new Runnable() {
779 @Override
780 public void run() {
Tim Murray1f407642015-10-01 17:07:12 -0700781 // send interaction hint to improve redraw performance
782 mPowerManagerInternal.powerHint(PowerManagerInternal.POWER_HINT_INTERACTION, 0);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700783 updateRotation(false);
784 }
785 };
786
Craig Mautnereee29c42013-01-17 14:44:34 -0800787 MyOrientationListener(Context context, Handler handler) {
788 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800789 }
Craig Mautner967212c2013-04-13 21:10:58 -0700790
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800791 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700792 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700793 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700794 mHandler.post(mUpdateRotationRunnable);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700795 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800796 }
797 MyOrientationListener mOrientationListener;
798
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100799 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400800
John Spurlock27735a42013-08-14 17:57:38 -0400801 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400802 View.NAVIGATION_BAR_TRANSIENT,
803 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400804 View.NAVIGATION_BAR_TRANSLUCENT,
805 StatusBarManager.WINDOW_NAVIGATION_BAR,
806 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400807
John Spurlockf1a36642013-10-12 17:50:42 -0400808 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400809
Craig Mautner037aa8d2013-06-07 10:35:44 -0700810 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400811
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700812 IStatusBarService getStatusBarService() {
813 synchronized (mServiceAquireLock) {
814 if (mStatusBarService == null) {
815 mStatusBarService = IStatusBarService.Stub.asInterface(
816 ServiceManager.getService("statusbar"));
817 }
818 return mStatusBarService;
819 }
820 }
821
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700822 /*
823 * We always let the sensor be switched on by default except when
824 * the user has explicitly disabled sensor based rotation or when the
825 * screen is switched off.
826 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700827 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800828 if (mSupportAutoRotation) {
829 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
830 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
831 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
832 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
833 // If the application has explicitly requested to follow the
834 // orientation, then we need to turn the sensor on.
835 return true;
836 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800837 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700838 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800839 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
840 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
841 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400842 // enable accelerometer if we are docked in a dock that enables accelerometer
843 // orientation management,
844 return true;
845 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700846 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800847 // If the setting for using the sensor by default is enabled, then
848 // we will always leave it on. Note that the user could go to
849 // a window that forces an orientation that does not use the
850 // sensor and in theory we could turn it off... however, when next
851 // turning it on we won't have a good value for the current
852 // orientation for a little bit, which can cause orientation
853 // changes to lag, so we'd like to keep it always on. (It will
854 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700855 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800856 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800857 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800858 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700859
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800860 /*
861 * Various use cases for invoking this function
862 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700863 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800864 * if not already enabled
865 * screen turned on and current app does not have sensor orientation, disable listeners if
866 * already enabled
867 * screen turning on and current app has sensor based orientation, enable listeners if needed
868 * screen turning on and current app has nosensor based orientation, do nothing
869 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700870 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800871 if (!mOrientationListener.canDetectOrientation()) {
872 // If sensor is turned off or nonexistent for some reason
873 return;
874 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000875 // Could have been invoked due to screen turning on or off or
876 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -0700877 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
878 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000879 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
880 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
881 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800882 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000883 // Note: We postpone the rotating of the screen until the keyguard as well as the
884 // window manager have reported a draw complete.
885 if (mScreenOnEarly && mAwake &&
886 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700887 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800888 disable = false;
889 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700890 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800891 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700892 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800893 mOrientationSensorEnabled = true;
894 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700895 }
896 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800897 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700898 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800899 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700900 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800901 mOrientationSensorEnabled = false;
902 }
903 }
904
Jeff Brown13f00f02014-10-31 14:45:50 -0700905 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
906 // Hold a wake lock until the power key is released.
907 if (!mPowerKeyWakeLock.isHeld()) {
908 mPowerKeyWakeLock.acquire();
909 }
910
911 // Cancel multi-press detection timeout.
912 if (mPowerKeyPressCounter != 0) {
913 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
914 }
915
916 // Detect user pressing the power button in panic when an application has
917 // taken over the whole screen.
918 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800919 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700920 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700921 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700922 }
923
924 // Latch power key state to detect screenshot chord.
925 if (interactive && !mScreenshotChordPowerKeyTriggered
926 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
927 mScreenshotChordPowerKeyTriggered = true;
928 mScreenshotChordPowerKeyTime = event.getDownTime();
929 interceptScreenshotChord();
930 }
931
932 // Stop ringing or end call if configured to do so when power is pressed.
933 TelecomManager telecomManager = getTelecommService();
934 boolean hungUp = false;
935 if (telecomManager != null) {
936 if (telecomManager.isRinging()) {
937 // Pressing Power while there's a ringing incoming
938 // call should silence the ringer.
939 telecomManager.silenceRinger();
940 } else if ((mIncallPowerBehavior
941 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
942 && telecomManager.isInCall() && interactive) {
943 // Otherwise, if "Power button ends call" is enabled,
944 // the Power button will hang up any current active call.
945 hungUp = telecomManager.endCall();
946 }
947 }
948
Adrian Roos5941c982015-09-03 15:59:49 -0700949 GestureLauncherService gestureService = LocalServices.getService(
950 GestureLauncherService.class);
951 boolean gesturedServiceIntercepted = false;
952 if (gestureService != null) {
953 gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive);
954 }
955
Jeff Brown13f00f02014-10-31 14:45:50 -0700956 // If the power key has still not yet been handled, then detect short
957 // press, long press, or multi press and decide what to do.
958 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
Adrian Roos5941c982015-09-03 15:59:49 -0700959 || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted;
Jeff Brown13f00f02014-10-31 14:45:50 -0700960 if (!mPowerKeyHandled) {
961 if (interactive) {
962 // When interactive, we're already awake.
963 // Wait for a long press or for the button to be released to decide what to do.
964 if (hasLongPressOnPowerBehavior()) {
965 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
966 msg.setAsynchronous(true);
967 mHandler.sendMessageDelayed(msg,
968 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
969 }
970 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800971 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800972
Bryce Leed3b28402015-03-09 15:49:13 +0000973 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
974 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
975 msg.setAsynchronous(true);
976 mHandler.sendMessageDelayed(msg,
977 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800978 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000979 } else {
980 final int maxCount = getMaxMultiPressPowerCount();
981
982 if (maxCount <= 1) {
983 mPowerKeyHandled = true;
984 } else {
985 mBeganFromNonInteractive = true;
986 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700987 }
988 }
Jeff Brown4d396052010-10-29 21:50:21 -0700989 }
990 }
991
Jeff Brown13f00f02014-10-31 14:45:50 -0700992 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
993 final boolean handled = canceled || mPowerKeyHandled;
994 mScreenshotChordPowerKeyTriggered = false;
995 cancelPendingScreenshotChordAction();
996 cancelPendingPowerKeyAction();
997
998 if (!handled) {
999 // Figure out how to handle the key now that it has been released.
1000 mPowerKeyPressCounter += 1;
1001
1002 final int maxCount = getMaxMultiPressPowerCount();
1003 final long eventTime = event.getDownTime();
1004 if (mPowerKeyPressCounter < maxCount) {
1005 // This could be a multi-press. Wait a little bit longer to confirm.
1006 // Continue holding the wake lock.
1007 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
1008 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
1009 msg.setAsynchronous(true);
1010 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
1011 return;
1012 }
1013
1014 // No other actions. Handle it immediately.
1015 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -07001016 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001017
1018 // Done. Reset our state.
1019 finishPowerKeyPress();
1020 }
1021
1022 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -08001023 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001024 mPowerKeyPressCounter = 0;
1025 if (mPowerKeyWakeLock.isHeld()) {
1026 mPowerKeyWakeLock.release();
1027 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001028 }
1029
1030 private void cancelPendingPowerKeyAction() {
1031 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001032 mPowerKeyHandled = true;
1033 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001034 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001035 }
1036
1037 private void powerPress(long eventTime, boolean interactive, int count) {
1038 if (mScreenOnEarly && !mScreenOnFully) {
1039 Slog.i(TAG, "Suppressed redundant power key press while "
1040 + "already in the process of turning the screen on.");
1041 return;
Jeff Brownff204712011-10-25 21:27:54 -07001042 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001043
1044 if (count == 2) {
1045 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1046 } else if (count == 3) {
1047 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001048 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001049 switch (mShortPressOnPowerBehavior) {
1050 case SHORT_PRESS_POWER_NOTHING:
1051 break;
1052 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1053 mPowerManager.goToSleep(eventTime,
1054 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1055 break;
1056 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1057 mPowerManager.goToSleep(eventTime,
1058 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1059 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1060 break;
1061 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1062 mPowerManager.goToSleep(eventTime,
1063 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1064 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1065 launchHomeFromHotKey();
1066 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001067 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001068 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001069 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001070 }
1071 }
1072 }
1073
1074 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1075 switch (behavior) {
1076 case MULTI_PRESS_POWER_NOTHING:
1077 break;
1078 case MULTI_PRESS_POWER_THEATER_MODE:
Bryce Lee3ae447e2015-06-30 12:31:41 -07001079 if (!isUserSetupComplete()) {
1080 Slog.i(TAG, "Ignoring toggling theater mode - device not setup.");
1081 break;
1082 }
1083
Jeff Brown13f00f02014-10-31 14:45:50 -07001084 if (isTheaterModeEnabled()) {
1085 Slog.i(TAG, "Toggling theater mode off.");
1086 Settings.Global.putInt(mContext.getContentResolver(),
1087 Settings.Global.THEATER_MODE_ON, 0);
1088 if (!interactive) {
1089 wakeUpFromPowerKey(eventTime);
1090 }
1091 } else {
1092 Slog.i(TAG, "Toggling theater mode on.");
1093 Settings.Global.putInt(mContext.getContentResolver(),
1094 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001095
1096 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001097 mPowerManager.goToSleep(eventTime,
1098 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1099 }
1100 }
1101 break;
1102 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001103 Slog.i(TAG, "Starting brightness boost.");
1104 if (!interactive) {
1105 wakeUpFromPowerKey(eventTime);
1106 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001107 mPowerManager.boostScreenBrightness(eventTime);
1108 break;
1109 }
1110 }
1111
1112 private int getMaxMultiPressPowerCount() {
1113 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1114 return 3;
1115 }
1116 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1117 return 2;
1118 }
1119 return 1;
1120 }
1121
1122 private void powerLongPress() {
1123 final int behavior = getResolvedLongPressOnPowerBehavior();
1124 switch (behavior) {
1125 case LONG_PRESS_POWER_NOTHING:
1126 break;
1127 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1128 mPowerKeyHandled = true;
1129 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1130 performAuditoryFeedbackForAccessibilityIfNeed();
1131 }
1132 showGlobalActionsInternal();
1133 break;
1134 case LONG_PRESS_POWER_SHUT_OFF:
1135 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1136 mPowerKeyHandled = true;
1137 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1138 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1139 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1140 break;
1141 }
1142 }
1143
Nick Vaccarob593a812015-05-15 11:23:05 -07001144 private void sleepPress(long eventTime) {
1145 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1146 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1147 }
1148 }
1149
1150 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001151 switch (mShortPressOnSleepBehavior) {
1152 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001153 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001154 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1155 mPowerManager.goToSleep(eventTime,
1156 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001157 break;
1158 }
1159 }
1160
Jeff Brown13f00f02014-10-31 14:45:50 -07001161 private int getResolvedLongPressOnPowerBehavior() {
1162 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1163 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1164 }
1165 return mLongPressOnPowerBehavior;
1166 }
1167
1168 private boolean hasLongPressOnPowerBehavior() {
1169 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001170 }
1171
1172 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001173 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001174 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1175 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001176 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001177 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1178 && now <= mScreenshotChordPowerKeyTime
1179 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1180 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001181 cancelPendingPowerKeyAction();
1182
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001183 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001184 }
1185 }
1186 }
1187
Winson Chung1cea2f32012-10-08 20:42:01 -07001188 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001189 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001190 // Double the time it takes to take a screenshot from the keyguard
1191 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001192 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001193 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001194 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001195 }
1196
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001197 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001198 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001199 }
1200
Jeff Brown13f00f02014-10-31 14:45:50 -07001201 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001202 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001203 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001204 mEndCallKeyHandled = true;
1205 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1206 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001207 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001208 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001209 }
1210 };
1211
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001212 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001213 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001214 public void run() {
1215 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001216 }
1217 };
1218
Alan Viverettee34560b22014-07-10 14:50:06 -07001219 @Override
1220 public void showGlobalActions() {
1221 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1222 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1223 }
1224
1225 void showGlobalActionsInternal() {
1226 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001227 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001228 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001229 }
Jim Millerab954542014-10-10 18:21:49 -07001230 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001231 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1232 if (keyguardShowing) {
1233 // since it took two seconds of long press to bring this up,
1234 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001235 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001236 }
1237 }
1238
1239 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001240 return Settings.Global.getInt(
1241 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001242 }
1243
Maurice Lam99c6e072014-04-28 18:24:28 -07001244 boolean isUserSetupComplete() {
1245 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1246 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1247 }
1248
Jeff Brown13f00f02014-10-31 14:45:50 -07001249 private void handleShortPressOnHome() {
Jinsuk Kime601b712015-07-07 08:01:02 +09001250 // Turn on the connected TV and switch HDMI input if we're a HDMI playback device.
1251 getHdmiControl().turnOnTv();
1252
Jeff Brown13f00f02014-10-31 14:45:50 -07001253 // If there's a dream running then use home to escape the dream
1254 // but don't actually go home.
1255 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1256 mDreamManagerInternal.stopDream(false /*immediate*/);
1257 return;
1258 }
1259
1260 // Go home!
1261 launchHomeFromHotKey();
1262 }
1263
Jinsuk Kime601b712015-07-07 08:01:02 +09001264 /**
1265 * Creates an accessor to HDMI control service that performs the operation of
1266 * turning on TV (optional) and switching input to us. If HDMI control service
1267 * is not available or we're not a HDMI playback device, the operation is no-op.
1268 */
1269 private HdmiControl getHdmiControl() {
1270 if (null == mHdmiControl) {
1271 HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService(
1272 Context.HDMI_CONTROL_SERVICE);
1273 HdmiPlaybackClient client = null;
1274 if (manager != null) {
1275 client = manager.getPlaybackClient();
1276 }
1277 mHdmiControl = new HdmiControl(client);
1278 }
1279 return mHdmiControl;
1280 }
1281
1282 private static class HdmiControl {
1283 private final HdmiPlaybackClient mClient;
1284
1285 private HdmiControl(HdmiPlaybackClient client) {
1286 mClient = client;
1287 }
1288
1289 public void turnOnTv() {
1290 if (mClient == null) {
1291 return;
1292 }
1293 mClient.oneTouchPlay(new OneTouchPlayCallback() {
1294 @Override
1295 public void onComplete(int result) {
1296 if (result != HdmiControlManager.RESULT_SUCCESS) {
1297 Log.w(TAG, "One touch play failed: " + result);
1298 }
1299 }
1300 });
1301 }
1302 }
1303
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001304 private void handleLongPressOnHome(int deviceId) {
Joe Onorato46b0d682010-11-22 17:37:27 -08001305 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001306 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001307 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001308
Jeff Browncaca8812013-05-09 13:34:33 -07001309 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1310 toggleRecentApps();
1311 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001312 launchAssistAction(null, deviceId);
Jim Millere6ad1a82010-08-20 19:25:39 -07001313 }
1314 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001315 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001316
Jeff Browncaca8812013-05-09 13:34:33 -07001317 private void handleDoubleTapOnHome() {
1318 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1319 mHomeConsumed = true;
1320 toggleRecentApps();
1321 }
1322 }
1323
1324 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1325 @Override
1326 public void run() {
1327 if (mHomeDoubleTapPending) {
1328 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001329 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001330 }
1331 }
1332 };
1333
Mark Renoufc1256912015-03-11 14:38:23 -04001334 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001335 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001336 }
1337
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001338 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001339 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001340 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001341 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001342 mContext = context;
1343 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001344 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001345 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001346 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001347 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Michael Wrighta4d22d72015-09-16 23:19:26 +01001348 mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001349 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Mark Renoufc1256912015-03-11 14:38:23 -04001350
1351 // Init display burn-in protection
1352 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1353 com.android.internal.R.bool.config_enableBurnInProtection);
1354 // Allow a system property to override this. Used by developer settings.
1355 boolean burnInProtectionDevMode =
1356 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1357 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1358 final int minHorizontal;
1359 final int maxHorizontal;
1360 final int minVertical;
1361 final int maxVertical;
1362 final int maxRadius;
1363 if (burnInProtectionDevMode) {
1364 minHorizontal = -8;
1365 maxHorizontal = 8;
1366 minVertical = -8;
1367 maxVertical = -4;
1368 maxRadius = (isRoundWindow()) ? 6 : -1;
1369 } else {
1370 Resources resources = context.getResources();
1371 minHorizontal = resources.getInteger(
1372 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1373 maxHorizontal = resources.getInteger(
1374 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1375 minVertical = resources.getInteger(
1376 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1377 maxVertical = resources.getInteger(
1378 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1379 maxRadius = resources.getInteger(
1380 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1381 }
1382 mBurnInProtectionHelper = new BurnInProtectionHelper(
1383 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001384 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001385
Jeff Brown70825162012-03-28 17:27:48 -07001386 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001387 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001388 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001389 try {
1390 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1391 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001392 mSettingsObserver = new SettingsObserver(mHandler);
1393 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001394 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001395 mUiMode = context.getResources().getInteger(
1396 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001397 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1398 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1399 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1400 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001401 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1402 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1403 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1404 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1405 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1406 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1407 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1408 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001409
Jeff Brown96307042012-07-27 15:51:34 -07001410 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1411 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001412 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001413 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1414 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001415 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001416 mSupportAutoRotation = mContext.getResources().getBoolean(
1417 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001418 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001419 com.android.internal.R.integer.config_lidOpenRotation);
1420 mCarDockRotation = readRotation(
1421 com.android.internal.R.integer.config_carDockRotation);
1422 mDeskDockRotation = readRotation(
1423 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001424 mUndockedHdmiRotation = readRotation(
1425 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001426 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1427 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1428 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1429 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001430 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1431 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1432 mLidNavigationAccessibility = mContext.getResources().getInteger(
1433 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001434 mLidControlsSleep = mContext.getResources().getBoolean(
1435 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001436 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1437 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001438
1439 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1440 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1441 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1442 || mContext.getResources().getBoolean(
1443 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1444 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1445 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001446 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1447 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001448 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1449 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1450 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1451 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1452 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1453 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1454
Bryce Lee55e846d2014-11-04 12:43:44 -08001455 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1456 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1457
Bryce Leed3b28402015-03-09 15:49:13 +00001458 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1459 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1460
Jeff Brown13f00f02014-10-31 14:45:50 -07001461 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1462 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1463 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1464 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1465 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1466 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1467 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1468 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001469 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1470 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001471
John Spurlock61560172015-02-06 19:46:04 -05001472 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001473
Jeff Brownf71343d2013-05-31 17:59:11 -07001474 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001475
Svetoslav8e3feb12014-02-24 13:46:47 -08001476 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1477 Context.ACCESSIBILITY_SERVICE);
1478
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001479 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001480 IntentFilter filter = new IntentFilter();
1481 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1482 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1483 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1484 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001485 filter.addAction(Intent.ACTION_DOCK_EVENT);
1486 Intent intent = context.registerReceiver(mDockReceiver, filter);
1487 if (intent != null) {
1488 // Retrieve current sticky dock event broadcast.
1489 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1490 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1491 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001492
Jeff Brown6aaf2952012-10-05 16:01:08 -07001493 // register for dream-related broadcasts
1494 filter = new IntentFilter();
1495 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1496 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1497 context.registerReceiver(mDreamReceiver, filter);
1498
Christopher Tate5e08af02012-09-21 17:17:22 -07001499 // register for multiuser-relevant broadcasts
1500 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1501 context.registerReceiver(mMultiuserReceiver, filter);
1502
John Spurlock57306e62013-04-22 09:48:49 -04001503 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001504 mSystemGestures = new SystemGesturesPointerEventListener(context,
1505 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001506 @Override
1507 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001508 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001509 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001510 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001511 }
1512 @Override
1513 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001514 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001515 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001516 }
1517 }
1518 @Override
1519 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001520 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001521 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001522 }
1523 }
1524 @Override
Michael Wrighta4d22d72015-09-16 23:19:26 +01001525 public void onFling(int duration) {
1526 if (mPowerManagerInternal != null) {
1527 mPowerManagerInternal.powerHint(
1528 PowerManagerInternal.POWER_HINT_INTERACTION, duration);
1529 }
1530 }
1531 @Override
John Spurlockad3e6cb2013-04-30 08:47:43 -04001532 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001533 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001534 }
Adrian Roos3595be42015-03-05 16:31:15 +01001535 @Override
1536 public void onDown() {
1537 mOrientationListener.onTouchStart();
1538 }
1539 @Override
1540 public void onUpOrCancel() {
1541 mOrientationListener.onTouchEnd();
1542 }
Jun Mukaid2e7e352015-07-22 17:14:02 -07001543 @Override
1544 public void onMouseHoverAtTop() {
1545 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1546 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1547 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS;
1548 mHandler.sendMessageDelayed(msg, 500);
1549 }
1550 @Override
1551 public void onMouseHoverAtBottom() {
1552 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1553 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1554 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION;
1555 mHandler.sendMessageDelayed(msg, 500);
1556 }
1557 @Override
1558 public void onMouseLeaveFromEdge() {
1559 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1560 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001561 });
John Spurlockf1a36642013-10-12 17:50:42 -04001562 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001563 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001564
Jeff Brownc2346132012-04-13 01:55:38 -07001565 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001566 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1567 com.android.internal.R.array.config_longPressVibePattern);
1568 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1569 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001570 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1571 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001572 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1573 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001574 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1575 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001576 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1577 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1578 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1579 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001580 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1581 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001582
Christopher Tatee90585f2012-03-05 18:56:25 -08001583 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1584 com.android.internal.R.bool.config_enableScreenshotChord);
1585
Justin Kohd378ad72013-04-01 12:18:26 -07001586 mGlobalKeyManager = new GlobalKeyManager(mContext);
1587
Joe Onoratoea495d42011-04-06 11:41:11 -07001588 // Controls rotation and the like.
1589 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001590
1591 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001592 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001593 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1594 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001595 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001596
1597 mWindowManagerInternal.registerAppTransitionListener(
1598 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001599 }
1600
Jeff Brownf71343d2013-05-31 17:59:11 -07001601 /**
1602 * Read values from config.xml that may be overridden depending on
1603 * the configuration of the device.
1604 * eg. Disable long press on home goes to recents on sw600dp.
1605 */
1606 private void readConfigurationDependentBehaviors() {
1607 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1608 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1609 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1610 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1611 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1612 }
1613
1614 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1615 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1616 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1617 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1618 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1619 }
1620 }
1621
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001622 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001623 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001624 // This method might be called before the policy has been fully initialized
1625 // or for other displays we don't care about.
1626 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1627 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001628 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001629 mDisplay = display;
1630
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001631 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001632 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001633 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001634 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001635 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001636 mLandscapeRotation = Surface.ROTATION_0;
1637 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001638 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001639 mPortraitRotation = Surface.ROTATION_90;
1640 mUpsideDownRotation = Surface.ROTATION_270;
1641 } else {
1642 mPortraitRotation = Surface.ROTATION_270;
1643 mUpsideDownRotation = Surface.ROTATION_90;
1644 }
1645 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001646 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001647 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001648 mPortraitRotation = Surface.ROTATION_0;
1649 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001650 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001651 mLandscapeRotation = Surface.ROTATION_270;
1652 mSeascapeRotation = Surface.ROTATION_90;
1653 } else {
1654 mLandscapeRotation = Surface.ROTATION_90;
1655 mSeascapeRotation = Surface.ROTATION_270;
1656 }
1657 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001658
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001659 mStatusBarHeight =
1660 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001661
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001662 // Height of the navigation bar when presented horizontally at bottom
1663 mNavigationBarHeightForRotation[mPortraitRotation] =
1664 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001665 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001666 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001667 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1668 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001669
1670 // Width of the navigation bar when presented vertically along one side
1671 mNavigationBarWidthForRotation[mPortraitRotation] =
1672 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1673 mNavigationBarWidthForRotation[mLandscapeRotation] =
1674 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001675 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001676
1677 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001678 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001679 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001680
Devin Kimd7b12b42014-05-05 14:34:58 -07001681 // Allow the navigation bar to move on non-square small devices (phones).
1682 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001683
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001684 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001685 // Allow a system property to override this. Used by the emulator.
1686 // See also hasNavigationBar().
1687 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1688 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001689 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001690 } else if ("0".equals(navBarOverride)) {
1691 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001692 }
1693
Jeff Brown27f1d672012-10-17 18:32:34 -07001694 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1695 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001696 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001697 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001698 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001699 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001700 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001701 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001702
Chong Zhangae6119ff2014-11-11 18:54:39 -08001703 // For demo purposes, allow the rotation of the remote display to be controlled.
1704 // By default, remote display locks rotation to landscape.
1705 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1706 mDemoRotation = mPortraitRotation;
1707 } else {
1708 mDemoRotation = mLandscapeRotation;
1709 }
1710 mDemoRotationLock = SystemProperties.getBoolean(
1711 "persist.demo.rotationlock", false);
1712
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001713 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1714 // http://developer.android.com/guide/practices/screens_support.html#range
1715 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1716 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1717 // For debug purposes the next line turns this feature off with:
1718 // $ adb shell setprop config.override_forced_orient true
1719 // $ adb shell wm size reset
1720 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1721 }
1722
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001723 /**
1724 * @return whether the navigation bar can be hidden, e.g. the device has a
1725 * navigation bar and touch exploration is not enabled
1726 */
1727 private boolean canHideNavigationBar() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04001728 return mHasNavigationBar;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001729 }
1730
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001731 @Override
1732 public boolean isDefaultOrientationForced() {
1733 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001734 }
1735
Dianne Hackbornc652de82013-02-15 16:32:56 -08001736 @Override
1737 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1738 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1739 mOverscanLeft = left;
1740 mOverscanTop = top;
1741 mOverscanRight = right;
1742 mOverscanBottom = bottom;
1743 }
1744 }
1745
Dianne Hackbornc777e072010-02-12 13:07:59 -08001746 public void updateSettings() {
1747 ContentResolver resolver = mContext.getContentResolver();
1748 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001749 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001750 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001751 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001752 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1753 UserHandle.USER_CURRENT);
1754 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001755 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001756 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1757 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001758
Jeff Browna20dda42014-05-27 20:57:24 -07001759 // Configure wake gesture.
1760 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1761 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1762 UserHandle.USER_CURRENT) != 0;
1763 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1764 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1765 updateWakeGestureListenerLp();
1766 }
1767
Jeff Brown207673cd2012-06-05 17:47:11 -07001768 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001769 int userRotation = Settings.System.getIntForUser(resolver,
1770 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1771 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001772 if (mUserRotation != userRotation) {
1773 mUserRotation = userRotation;
1774 updateRotation = true;
1775 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001776 int userRotationMode = Settings.System.getIntForUser(resolver,
1777 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001778 WindowManagerPolicy.USER_ROTATION_FREE :
1779 WindowManagerPolicy.USER_ROTATION_LOCKED;
1780 if (mUserRotationMode != userRotationMode) {
1781 mUserRotationMode = userRotationMode;
1782 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001783 updateOrientationListenerLp();
1784 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001785
Dianne Hackbornc777e072010-02-12 13:07:59 -08001786 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001787 int pointerLocation = Settings.System.getIntForUser(resolver,
1788 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001789 if (mPointerLocationMode != pointerLocation) {
1790 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001791 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1792 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001793 }
1794 }
1795 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001796 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1797 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1798 String imId = Settings.Secure.getStringForUser(resolver,
1799 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001800 boolean hasSoftInput = imId != null && imId.length() > 0;
1801 if (mHasSoftInput != hasSoftInput) {
1802 mHasSoftInput = hasSoftInput;
1803 updateRotation = true;
1804 }
John Spurlockf1a36642013-10-12 17:50:42 -04001805 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001806 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001807 }
tiger_huangcc6366d2015-06-29 17:17:30 +08001808 }
1809 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05001810 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001811 }
1812 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001813 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001814 }
Jeff Brown70825162012-03-28 17:27:48 -07001815 }
1816
Jeff Browna20dda42014-05-27 20:57:24 -07001817 private void updateWakeGestureListenerLp() {
1818 if (shouldEnableWakeGestureLp()) {
1819 mWakeGestureListener.requestWakeUpTrigger();
1820 } else {
1821 mWakeGestureListener.cancelWakeUpTrigger();
1822 }
1823 }
1824
1825 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001826 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001827 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1828 && mWakeGestureListener.isSupported();
1829 }
1830
Jeff Brown70825162012-03-28 17:27:48 -07001831 private void enablePointerLocation() {
1832 if (mPointerLocationView == null) {
1833 mPointerLocationView = new PointerLocationView(mContext);
1834 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001835 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1836 WindowManager.LayoutParams.MATCH_PARENT,
1837 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001838 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001839 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1840 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1841 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1842 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001843 if (ActivityManager.isHighEndGfx()) {
1844 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1845 lp.privateFlags |=
1846 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1847 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001848 lp.format = PixelFormat.TRANSLUCENT;
1849 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001850 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001851 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001852 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001853 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001854 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001855 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001856 }
Jeff Brown70825162012-03-28 17:27:48 -07001857
1858 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001859 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001860 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1861 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001862 wm.removeView(mPointerLocationView);
1863 mPointerLocationView = null;
1864 }
1865 }
1866
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001867 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001868 try {
1869 int rotation = mContext.getResources().getInteger(resID);
1870 switch (rotation) {
1871 case 0:
1872 return Surface.ROTATION_0;
1873 case 90:
1874 return Surface.ROTATION_90;
1875 case 180:
1876 return Surface.ROTATION_180;
1877 case 270:
1878 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001879 }
1880 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001881 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001882 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001883 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001884 }
1885
1886 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001887 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001888 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001889 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001890
1891 outAppOp[0] = AppOpsManager.OP_NONE;
1892
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001893 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1894 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1895 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1896 return WindowManagerGlobal.ADD_INVALID_TYPE;
1897 }
1898
1899 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1900 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001901 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001902 }
1903 String permission = null;
1904 switch (type) {
1905 case TYPE_TOAST:
1906 // XXX right now the app process has complete control over
1907 // this... should introduce a token to let the system
1908 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001909 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001910 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001911 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001912 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001913 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001914 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001915 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001916 case TYPE_ACCESSIBILITY_OVERLAY:
Jason Monk8f7f3182015-11-18 16:35:14 -05001917 case TYPE_QS_DIALOG:
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;
Jason Monk8f7f3182015-11-18 16:35:14 -05002113 case TYPE_QS_DIALOG:
2114 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002115 case TYPE_PHONE:
2116 return 3;
2117 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002118 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002119 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002120 case TYPE_VOICE_INTERACTION:
2121 // voice interaction layer is almost immediately above apps.
2122 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07002123 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002124 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07002125 case TYPE_SYSTEM_DIALOG:
2126 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002127 case TYPE_TOAST:
2128 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07002129 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002130 case TYPE_PRIORITY_PHONE:
2131 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07002132 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002133 case TYPE_DREAM:
2134 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07002135 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002136 case TYPE_SYSTEM_ALERT:
2137 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002138 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002139 case TYPE_INPUT_METHOD:
2140 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002141 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002142 case TYPE_INPUT_METHOD_DIALOG:
2143 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002144 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08002145 case TYPE_KEYGUARD_SCRIM:
2146 // the safety window that shows behind keyguard while keyguard is starting
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002147 return 14;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002148 case TYPE_STATUS_BAR_SUB_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002149 return 15;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002150 case TYPE_STATUS_BAR:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002151 return 16;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002152 case TYPE_STATUS_BAR_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002153 return 17;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002154 case TYPE_KEYGUARD_DIALOG:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002155 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002156 case TYPE_VOLUME_OVERLAY:
2157 // the on-screen volume indicator and controller shown when the user
2158 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002159 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002160 case TYPE_SYSTEM_OVERLAY:
2161 // the on-screen volume indicator and controller shown when the user
2162 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002163 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002164 case TYPE_NAVIGATION_BAR:
2165 // the navigation bar, if available, shows atop most things
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002166 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002167 case TYPE_NAVIGATION_BAR_PANEL:
2168 // some panels (e.g. search) need to show on top of the navigation bar
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002169 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002170 case TYPE_SYSTEM_ERROR:
2171 // system-level error dialogs
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002172 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002173 case TYPE_MAGNIFICATION_OVERLAY:
2174 // used to highlight the magnified portion of a display
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002175 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002176 case TYPE_DISPLAY_OVERLAY:
2177 // used to simulate secondary display devices
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002178 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002179 case TYPE_DRAG:
2180 // the drag layer: input for drag-and-drop is associated with this window,
2181 // which sits above all other focusable windows
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002182 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002183 case TYPE_ACCESSIBILITY_OVERLAY:
2184 // overlay put by accessibility services to intercept user interaction
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002185 return 27;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002186 case TYPE_SECURE_SYSTEM_OVERLAY:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002187 return 28;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002188 case TYPE_BOOT_PROGRESS:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002189 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002190 case TYPE_POINTER:
2191 // the (mouse) pointer layer
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002192 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002193 }
2194 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002195 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002196 }
2197
2198 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002199 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002200 public int subWindowTypeToLayerLw(int type) {
2201 switch (type) {
2202 case TYPE_APPLICATION_PANEL:
2203 case TYPE_APPLICATION_ATTACHED_DIALOG:
2204 return APPLICATION_PANEL_SUBLAYER;
2205 case TYPE_APPLICATION_MEDIA:
2206 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002207 case TYPE_APPLICATION_MEDIA_OVERLAY:
2208 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002209 case TYPE_APPLICATION_SUB_PANEL:
2210 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002211 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2212 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002213 }
2214 Log.e(TAG, "Unknown sub-window type: " + type);
2215 return 0;
2216 }
2217
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002218 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002219 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002220 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002221 }
2222
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002223 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002224 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002225 if (mHasNavigationBar) {
2226 // For a basic navigation bar, when we are in landscape mode we place
2227 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002228 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2229 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002230 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002231 }
2232 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002233 }
2234
Jose Lima9546b202014-07-02 17:21:51 -07002235 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002236 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002237 if (mHasNavigationBar) {
2238 // For a basic navigation bar, when we are in portrait mode we place
2239 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002240 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2241 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002242 }
2243 }
2244 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002245 }
2246
Jose Lima9546b202014-07-02 17:21:51 -07002247 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002248 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2249 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002250 }
2251
Jose Lima9546b202014-07-02 17:21:51 -07002252 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002253 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002254 // There is a separate status bar at the top of the display. We don't count that as part
2255 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002256 // we do want to exclude it since applications can't generally use that part
2257 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002258 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002259 }
2260
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002261 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002262 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2263 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002264 (isKeyguardHostWindow(attrs) &&
2265 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002266 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002267 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002268
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002269 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002270 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2271 return attrs.type == TYPE_STATUS_BAR;
2272 }
2273
2274 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002275 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002276 switch (attrs.type) {
2277 case TYPE_STATUS_BAR:
2278 case TYPE_NAVIGATION_BAR:
2279 case TYPE_WALLPAPER:
2280 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002281 case TYPE_KEYGUARD_SCRIM:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002282 case TYPE_DOCK_DIVIDER:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002283 return false;
2284 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002285 // Hide only windows below the keyguard host window.
2286 return windowTypeToLayerLw(win.getBaseType())
2287 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002288 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002289 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002290
Craig Mautner7d7808f2014-09-11 18:02:38 -07002291 @Override
2292 public WindowState getWinShowWhenLockedLw() {
2293 return mWinShowWhenLocked;
2294 }
2295
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002296 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002297 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002298 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2299 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002300 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002301 if (!SHOW_STARTING_ANIMATIONS) {
2302 return null;
2303 }
2304 if (packageName == null) {
2305 return null;
2306 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002307
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002308 WindowManager wm = null;
2309 View view = null;
2310
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002311 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002312 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002313 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2314 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2315 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002316 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002317 try {
2318 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002319 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002320 } catch (PackageManager.NameNotFoundException e) {
2321 // Ignore
2322 }
2323 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002324
Jorim Jaggia16cc152015-06-01 16:55:05 -07002325 PhoneWindow win = new PhoneWindow(context);
2326 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002327
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002328 Resources r = context.getResources();
2329 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002330
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002331 win.setType(
2332 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002333
2334 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2335 // Assumes it's safe to show starting windows of launched apps while
2336 // the keyguard is being hidden. This is okay because starting windows never show
2337 // secret information.
2338 if (mKeyguardHidden) {
2339 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2340 }
2341 }
2342
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002343 // Force the window flags: this is a fake window, so it is not really
2344 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2345 // flag because we do know that the next window will take input
2346 // focus, so we want to get the IME window up on top of us right away.
2347 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002348 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002349 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2350 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2351 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002352 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002353 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2354 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2355 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002356
Adam Powell04fe6eb2013-05-31 14:39:48 -07002357 win.setDefaultIcon(icon);
2358 win.setDefaultLogo(logo);
2359
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002360 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002361 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002362
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002363 final WindowManager.LayoutParams params = win.getAttributes();
2364 params.token = appToken;
2365 params.packageName = packageName;
2366 params.windowAnimations = win.getWindowStyle().getResourceId(
2367 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002368 params.privateFlags |=
2369 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002370 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002371
2372 if (!compatInfo.supportsScreen()) {
2373 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2374 }
2375
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002376 params.setTitle("Starting " + packageName);
2377
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002378 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2379 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002380
Craig Mautner6fbda632012-07-03 09:26:39 -07002381 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002382 TAG, "Adding starting window for " + packageName
2383 + " / " + appToken + ": "
2384 + (view.getParent() != null ? view : null));
2385
2386 wm.addView(view, params);
2387
2388 // Only return the view if it was successfully added to the
2389 // window manager... which we can tell by it having a parent.
2390 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002391 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002392 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002393 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2394 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002395 } catch (RuntimeException e) {
2396 // don't crash if something else bad happens, for example a
2397 // failure loading resources because we are loading from an app
2398 // on external storage that has been unmounted.
2399 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002400 } finally {
2401 if (view != null && view.getParent() == null) {
2402 Log.w(TAG, "view not successfully added to wm, removing view");
2403 wm.removeViewImmediate(view);
2404 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002405 }
2406
2407 return null;
2408 }
2409
2410 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002411 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002412 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002413 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2414 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002415
2416 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002417 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002418 wm.removeView(window);
2419 }
2420 }
2421
2422 /**
2423 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002424 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002425 * Currently enforces that three window types are singletons:
2426 * <ul>
2427 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002428 * <li>KEYGUARD_TYPE</li>
2429 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002430 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002431 * @param win The window to be added
2432 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002433 *
Jeff Brown98365d72012-08-19 20:30:52 -07002434 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2435 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002436 */
Jose Lima9546b202014-07-02 17:21:51 -07002437 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002438 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2439 switch (attrs.type) {
2440 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002441 mContext.enforceCallingOrSelfPermission(
2442 android.Manifest.permission.STATUS_BAR_SERVICE,
2443 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002444 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002445 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002446 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002447 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002448 }
2449 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002450 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002451 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002452 case TYPE_NAVIGATION_BAR:
2453 mContext.enforceCallingOrSelfPermission(
2454 android.Manifest.permission.STATUS_BAR_SERVICE,
2455 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002456 if (mNavigationBar != null) {
2457 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002458 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002459 }
2460 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002461 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002462 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002463 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002464 break;
Jim Millere898ac52012-04-06 17:10:57 -07002465 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002466 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002467 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002468 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002469 mContext.enforceCallingOrSelfPermission(
2470 android.Manifest.permission.STATUS_BAR_SERVICE,
2471 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002472 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002473 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002474 if (mKeyguardScrim != null) {
2475 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2476 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002477 mKeyguardScrim = win;
2478 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002479 }
Jeff Brown98365d72012-08-19 20:30:52 -07002480 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002481 }
2482
2483 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002484 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002485 public void removeWindowLw(WindowState win) {
2486 if (mStatusBar == win) {
2487 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002488 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002489 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002490 } else if (mKeyguardScrim == win) {
2491 Log.v(TAG, "Removing keyguard scrim");
2492 mKeyguardScrim = null;
2493 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002494 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002495 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002496 }
2497 }
2498
2499 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002500
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002501 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002502 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002503 public int selectAnimationLw(WindowState win, int transit) {
2504 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2505 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002506 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002507 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002508 if (transit == TRANSIT_EXIT
2509 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002510 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002511 } else if (transit == TRANSIT_ENTER
2512 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002513 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002514 }
2515 } else if (win == mNavigationBar) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002516 if (win.getAttrs().windowAnimations != 0) {
2517 return 0;
2518 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002519 // This can be on either the bottom or the right.
2520 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002521 if (transit == TRANSIT_EXIT
2522 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002523 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002524 } else if (transit == TRANSIT_ENTER
2525 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002526 return R.anim.dock_bottom_enter;
2527 }
2528 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002529 if (transit == TRANSIT_EXIT
2530 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002531 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002532 } else if (transit == TRANSIT_ENTER
2533 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002534 return R.anim.dock_right_enter;
2535 }
2536 }
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08002537 } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -08002538 if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08002539 return R.anim.fade_in;
2540 } else if (transit == TRANSIT_EXIT) {
2541 return R.anim.fade_out;
2542 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002543 }
2544
2545 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002546 if (win.hasAppShownWindows()) {
2547 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2548 return com.android.internal.R.anim.app_starting_exit;
2549 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002550 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002551 && transit == TRANSIT_ENTER) {
2552 // Special case: we are animating in a dream, while the keyguard
2553 // is shown. We don't want an animation on the dream, because
2554 // we need it shown immediately with the keyguard animating away
2555 // to reveal it.
2556 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002557 }
2558
2559 return 0;
2560 }
2561
Craig Mautner3c174372013-02-21 17:54:37 -08002562 @Override
2563 public void selectRotationAnimationLw(int anim[]) {
2564 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2565 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2566 + (mTopFullscreenOpaqueWindowState == null ?
2567 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2568 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2569 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2570 case ROTATION_ANIMATION_CROSSFADE:
2571 anim[0] = R.anim.rotation_animation_xfade_exit;
2572 anim[1] = R.anim.rotation_animation_enter;
2573 break;
2574 case ROTATION_ANIMATION_JUMPCUT:
2575 anim[0] = R.anim.rotation_animation_jump_exit;
2576 anim[1] = R.anim.rotation_animation_enter;
2577 break;
2578 case ROTATION_ANIMATION_ROTATE:
2579 default:
2580 anim[0] = anim[1] = 0;
2581 break;
2582 }
2583 } else {
2584 anim[0] = anim[1] = 0;
2585 }
2586 }
2587
2588 @Override
2589 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2590 boolean forceDefault) {
2591 switch (exitAnimId) {
2592 case R.anim.rotation_animation_xfade_exit:
2593 case R.anim.rotation_animation_jump_exit:
2594 // These are the only cases that matter.
2595 if (forceDefault) {
2596 return false;
2597 }
2598 int anim[] = new int[2];
2599 selectRotationAnimationLw(anim);
2600 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2601 default:
2602 return true;
2603 }
2604 }
2605
2606 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002607 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2608 boolean goingToNotificationShade) {
2609 if (goingToNotificationShade) {
2610 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002611 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002612
2613 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2614 R.anim.lock_screen_behind_enter_wallpaper :
2615 R.anim.lock_screen_behind_enter);
2616
2617 // TODO: Use XML interpolators when we have log interpolators available in XML.
2618 final List<Animation> animations = set.getAnimations();
2619 for (int i = animations.size() - 1; i >= 0; --i) {
2620 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2621 }
2622
2623 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002624 }
2625
2626
2627 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002628 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2629 if (goingToNotificationShade) {
2630 return null;
2631 } else {
2632 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2633 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002634 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002635
2636 private static void awakenDreams() {
2637 IDreamManager dreamManager = getDreamManager();
2638 if (dreamManager != null) {
2639 try {
2640 dreamManager.awaken();
2641 } catch (RemoteException e) {
2642 // fine, stay asleep then
2643 }
2644 }
2645 }
2646
2647 static IDreamManager getDreamManager() {
2648 return IDreamManager.Stub.asInterface(
2649 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2650 }
2651
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002652 TelecomManager getTelecommService() {
2653 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002654 }
2655
Jeff Brown4d396052010-10-29 21:50:21 -07002656 static IAudioService getAudioService() {
2657 IAudioService audioService = IAudioService.Stub.asInterface(
2658 ServiceManager.checkService(Context.AUDIO_SERVICE));
2659 if (audioService == null) {
2660 Log.w(TAG, "Unable to find IAudioService interface.");
2661 }
2662 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002663 }
2664
2665 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002666 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002667 }
2668
2669 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2670 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2671 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2672 };
2673
2674 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002675 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002676 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002677 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002678 final int keyCode = event.getKeyCode();
2679 final int repeatCount = event.getRepeatCount();
2680 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002681 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002682 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2683 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002684
Jeff Brown40013652012-05-16 21:22:36 -07002685 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002686 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002687 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2688 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002689 }
2690
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002691 // If we think we might have a volume down & power key chord on the way
2692 // but we're not sure, then tell the dispatcher to wait a little while and
2693 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002694 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002695 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002696 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002697 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2698 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002699 if (now < timeoutTime) {
2700 return timeoutTime - now;
2701 }
2702 }
2703 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002704 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002705 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002706 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002707 }
2708 return -1;
2709 }
2710 }
2711
Michael Wright6a62e552014-06-03 19:19:48 -07002712 // Cancel any pending meta actions if we see any other keys being pressed between the down
2713 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002714 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002715 mPendingMetaAction = false;
2716 }
2717
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002718 // First we always handle the home key here, so applications
2719 // can never break it, although if keyguard is on, we do let
2720 // it handle it, because that gives us the correct 5 second
2721 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002722 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002723
Jeff Brown49ed71d2010-12-06 17:13:33 -08002724 // If we have released the home key, and didn't do anything else
2725 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002726 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002727 cancelPreloadRecentApps();
2728
Jeff Brown49ed71d2010-12-06 17:13:33 -08002729 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002730 if (mHomeConsumed) {
2731 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002732 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002733 }
Jeff Browncaca8812013-05-09 13:34:33 -07002734
2735 if (canceled) {
2736 Log.i(TAG, "Ignoring HOME; event canceled.");
2737 return -1;
2738 }
2739
Yorke Lee4f803242014-12-15 23:22:06 +00002740 // If an incoming call is ringing, HOME is totally disabled.
2741 // (The user is already on the InCallUI at this point,
2742 // and his ONLY options are to answer or reject the call.)
2743 TelecomManager telecomManager = getTelecommService();
2744 if (telecomManager != null && telecomManager.isRinging()) {
2745 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2746 return -1;
2747 }
2748
Jeff Browncaca8812013-05-09 13:34:33 -07002749 // Delay handling home if a double-tap is possible.
2750 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2751 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2752 mHomeDoubleTapPending = true;
2753 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2754 ViewConfiguration.getDoubleTapTimeout());
2755 return -1;
2756 }
2757
Jeff Brown13f00f02014-10-31 14:45:50 -07002758 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002759 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002760 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002761
2762 // If a system window has focus, then it doesn't make sense
2763 // right now to interact with applications.
2764 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2765 if (attrs != null) {
2766 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002767 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2768 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2769 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002770 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002771 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002772 }
2773 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2774 for (int i=0; i<typeCount; i++) {
2775 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2776 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002777 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002778 }
2779 }
2780 }
Jeff Browncaca8812013-05-09 13:34:33 -07002781
2782 // Remember that home is pressed and handle special actions.
2783 if (repeatCount == 0) {
2784 mHomePressed = true;
2785 if (mHomeDoubleTapPending) {
2786 mHomeDoubleTapPending = false;
2787 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2788 handleDoubleTapOnHome();
2789 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2790 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2791 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002792 }
Jeff Browncaca8812013-05-09 13:34:33 -07002793 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2794 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002795 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002796 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002797 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002798 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002799 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002800 // Hijack modified menu keys for debugging features
2801 final int chordBug = KeyEvent.META_SHIFT_ON;
2802
2803 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002804 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002805 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002806 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2807 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002808 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002809 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002810 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002811 Intent service = new Intent();
2812 service.setClassName(mContext, "com.android.server.LoadAverageService");
2813 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002814 boolean shown = Settings.Global.getInt(
2815 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002816 if (!shown) {
2817 mContext.startService(service);
2818 } else {
2819 mContext.stopService(service);
2820 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002821 Settings.Global.putInt(
2822 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002823 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002824 }
2825 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002826 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002827 if (down) {
2828 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002829 mSearchKeyShortcutPending = true;
2830 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002831 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002832 } else {
2833 mSearchKeyShortcutPending = false;
2834 if (mConsumeSearchKeyUp) {
2835 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002836 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002837 }
2838 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002839 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002840 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002841 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002842 if (down && repeatCount == 0) {
2843 preloadRecentApps();
2844 } else if (!down) {
2845 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002846 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002847 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002848 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002849 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2850 if (down) {
2851 IStatusBarService service = getStatusBarService();
2852 if (service != null) {
2853 try {
2854 service.expandNotificationsPanel();
2855 } catch (RemoteException e) {
2856 // do nothing.
2857 }
2858 }
2859 }
Clara Bayarrif2debb12015-07-10 14:47:17 +01002860 } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) {
2861 if (down) {
2862 if (repeatCount == 0) {
2863 showKeyboardShortcutsMenu();
2864 }
2865 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002866 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2867 if (down) {
2868 if (repeatCount == 0) {
2869 mAssistKeyLongPressed = false;
2870 } else if (repeatCount == 1) {
2871 mAssistKeyLongPressed = true;
2872 if (!keyguardOn) {
2873 launchAssistLongPressAction();
2874 }
2875 }
2876 } else {
2877 if (mAssistKeyLongPressed) {
2878 mAssistKeyLongPressed = false;
2879 } else {
2880 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002881 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002882 }
2883 }
2884 }
2885 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002886 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2887 if (!down) {
2888 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002889 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002890 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2891 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07002892 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
2893 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
2894 if (dic != null) {
2895 try {
2896 dic.exitIdle("voice-search");
2897 } catch (RemoteException e) {
2898 }
2899 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002900 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002901 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002902 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002903 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002904 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002905 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2906 if (down && repeatCount == 0) {
2907 mHandler.post(mScreenshotRunnable);
2908 }
2909 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002910 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2911 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2912 if (down) {
2913 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2914
2915 // Disable autobrightness if it's on
2916 int auto = Settings.System.getIntForUser(
2917 mContext.getContentResolver(),
2918 Settings.System.SCREEN_BRIGHTNESS_MODE,
2919 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2920 UserHandle.USER_CURRENT_OR_SELF);
2921 if (auto != 0) {
2922 Settings.System.putIntForUser(mContext.getContentResolver(),
2923 Settings.System.SCREEN_BRIGHTNESS_MODE,
2924 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2925 UserHandle.USER_CURRENT_OR_SELF);
2926 }
2927
2928 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2929 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2930 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2931 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2932 Settings.System.SCREEN_BRIGHTNESS,
2933 mPowerManager.getDefaultScreenBrightnessSetting(),
2934 UserHandle.USER_CURRENT_OR_SELF);
2935 brightness += step;
2936 // Make sure we don't go beyond the limits.
2937 brightness = Math.min(max, brightness);
2938 brightness = Math.max(min, brightness);
2939
2940 Settings.System.putIntForUser(mContext.getContentResolver(),
2941 Settings.System.SCREEN_BRIGHTNESS, brightness,
2942 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002943 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002944 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002945 }
2946 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002947 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002948 if (down) {
2949 mPendingMetaAction = true;
2950 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002951 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07002952 }
2953 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002954 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002955
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002956 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002957 // Any printing key that is chorded with Search should be consumed
2958 // even if no shortcut was invoked. This prevents text from being
2959 // inadvertently inserted when using a keyboard that has built-in macro
2960 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002961 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002962 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2963 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002964 mConsumeSearchKeyUp = true;
2965 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002966 if (down && repeatCount == 0 && !keyguardOn) {
2967 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2968 if (shortcutIntent != null) {
2969 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002970 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002971 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002972 } catch (ActivityNotFoundException ex) {
2973 Slog.w(TAG, "Dropping shortcut key combination because "
2974 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002975 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002976 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002977 } else {
2978 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002979 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002980 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002981 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002982 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002983 }
2984 }
2985
Jeff Brown68b909d2011-12-07 16:36:01 -08002986 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002987 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002988 && (metaState & KeyEvent.META_META_ON) != 0) {
2989 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002990 if (kcm.isPrintingKey(keyCode)) {
2991 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2992 metaState & ~(KeyEvent.META_META_ON
2993 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2994 if (shortcutIntent != null) {
2995 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2996 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002997 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002998 } catch (ActivityNotFoundException ex) {
2999 Slog.w(TAG, "Dropping shortcut key combination because "
3000 + "the activity to which it is registered was not found: "
3001 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
3002 }
3003 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08003004 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003005 }
3006 }
3007
Jeff Brown6651a632011-11-28 12:59:11 -08003008 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07003009 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08003010 String category = sApplicationLaunchKeyCategories.get(keyCode);
3011 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08003012 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08003013 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3014 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003015 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08003016 } catch (ActivityNotFoundException ex) {
3017 Slog.w(TAG, "Dropping application launch key because "
3018 + "the activity to which it is registered was not found: "
3019 + "keyCode=" + keyCode + ", category=" + category, ex);
3020 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003021 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08003022 }
3023 }
3024
Michael Wright61c46752014-08-21 16:57:33 -07003025 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08003026 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Michael Wrightd847ad52015-10-24 13:24:15 +01003027 if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) {
Jeff Brown68b909d2011-12-07 16:36:01 -08003028 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07003029 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003030 mRecentAppsHeldModifiers = shiftlessModifiers;
3031 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08003032 return -1;
3033 }
3034 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07003035 } else if (!down && mRecentAppsHeldModifiers != 0
3036 && (metaState & mRecentAppsHeldModifiers) == 0) {
3037 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07003038 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003039 }
3040
Jeff Browncf39bdf2012-05-18 14:41:19 -07003041 // Handle keyboard language switching.
3042 if (down && repeatCount == 0
3043 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3044 || (keyCode == KeyEvent.KEYCODE_SPACE
3045 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
3046 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
3047 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
3048 return -1;
3049 }
3050 if (mLanguageSwitchKeyPressed && !down
3051 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3052 || keyCode == KeyEvent.KEYCODE_SPACE)) {
3053 mLanguageSwitchKeyPressed = false;
3054 return -1;
3055 }
3056
Jeff Brown13f00f02014-10-31 14:45:50 -07003057 if (isValidGlobalKey(keyCode)
3058 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07003059 return -1;
3060 }
3061
Michael Wright6a62e552014-06-03 19:19:48 -07003062 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07003063 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07003064 return -1;
3065 }
3066
Jeff Brown68b909d2011-12-07 16:36:01 -08003067 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003068 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003069 }
3070
Jeff Brown3915bb82010-11-05 15:02:16 -07003071 /** {@inheritDoc} */
3072 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08003073 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07003074 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07003075 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08003076 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
3077 + ", flags=" + event.getFlags()
3078 + ", keyCode=" + event.getKeyCode()
3079 + ", scanCode=" + event.getScanCode()
3080 + ", metaState=" + event.getMetaState()
3081 + ", repeatCount=" + event.getRepeatCount()
3082 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07003083 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003084
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003085 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003086 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3087 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003088 final int keyCode = event.getKeyCode();
3089 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003090 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
3091 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003092
Jeff Brown54875002011-04-06 15:33:01 -07003093 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003094 final FallbackAction fallbackAction;
3095 if (initialDown) {
3096 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
3097 } else {
3098 fallbackAction = mFallbackActions.get(keyCode);
3099 }
3100
3101 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07003102 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003103 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
3104 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003105 }
3106
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003107 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
3108 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08003109 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003110 event.getAction(), fallbackAction.keyCode,
3111 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08003112 event.getDeviceId(), event.getScanCode(),
3113 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003114
3115 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
3116 fallbackEvent.recycle();
3117 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003118 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003119
3120 if (initialDown) {
3121 mFallbackActions.put(keyCode, fallbackAction);
3122 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3123 mFallbackActions.remove(keyCode);
3124 fallbackAction.recycle();
3125 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003126 }
3127 }
3128
Jeff Brown40013652012-05-16 21:22:36 -07003129 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003130 if (fallbackEvent == null) {
3131 Slog.d(TAG, "No fallback.");
3132 } else {
3133 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3134 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003135 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003136 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003137 }
3138
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003139 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003140 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003141 if ((actions & ACTION_PASS_TO_USER) != 0) {
3142 long delayMillis = interceptKeyBeforeDispatching(
3143 win, fallbackEvent, policyFlags);
3144 if (delayMillis == 0) {
3145 return true;
3146 }
3147 }
3148 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003149 }
3150
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003151 private void launchAssistLongPressAction() {
3152 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3153 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3154
3155 // launch the search activity
3156 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3157 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3158 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003159 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003160 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003161 SearchManager searchManager = getSearchManager();
3162 if (searchManager != null) {
3163 searchManager.stopSearch();
3164 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003165 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003166 } catch (ActivityNotFoundException e) {
3167 Slog.w(TAG, "No activity to handle assist long press action.", e);
3168 }
3169 }
3170
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003171 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003172 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Maurice Lam39d13812015-07-23 20:49:20 -07003173 if (!isUserSetupComplete()) {
3174 // Disable opening assist window during setup
3175 return;
3176 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003177 Bundle args = null;
3178 if (deviceId > Integer.MIN_VALUE) {
3179 args = new Bundle();
3180 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003181 }
Jorim Jaggi165ce062015-07-06 16:18:11 -07003182 if ((mContext.getResources().getConfiguration().uiMode
3183 & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
3184 // On TV, use legacy handling until assistants are implemented in the proper way.
3185 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3186 .launchLegacyAssist(hint, UserHandle.myUserId(), args);
3187 } else {
3188 try {
3189 if (hint != null) {
3190 if (args == null) {
3191 args = new Bundle();
3192 }
3193 args.putBoolean(hint, true);
3194 }
3195 IStatusBarService statusbar = getStatusBarService();
3196 if (statusbar != null) {
3197 statusbar.startAssist(args);
3198 }
3199 } catch (RemoteException e) {
3200 Slog.e(TAG, "RemoteException when starting assist", e);
3201 // re-acquire status bar service next time it is needed.
3202 mStatusBarService = null;
3203 }
3204 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003205 }
3206
Bart Sears8b1c27c2015-03-18 23:51:02 +00003207 private void startActivityAsUser(Intent intent, UserHandle handle) {
3208 if (isUserSetupComplete()) {
3209 mContext.startActivityAsUser(intent, handle);
3210 } else {
3211 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3212 }
3213 }
3214
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003215 private SearchManager getSearchManager() {
3216 if (mSearchManager == null) {
3217 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3218 }
3219 return mSearchManager;
3220 }
3221
Jeff Browncaca8812013-05-09 13:34:33 -07003222 private void preloadRecentApps() {
3223 mPreloadedRecentApps = true;
3224 try {
3225 IStatusBarService statusbar = getStatusBarService();
3226 if (statusbar != null) {
3227 statusbar.preloadRecentApps();
3228 }
3229 } catch (RemoteException e) {
3230 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3231 // re-acquire status bar service next time it is needed.
3232 mStatusBarService = null;
3233 }
3234 }
3235
3236 private void cancelPreloadRecentApps() {
3237 if (mPreloadedRecentApps) {
3238 mPreloadedRecentApps = false;
3239 try {
3240 IStatusBarService statusbar = getStatusBarService();
3241 if (statusbar != null) {
3242 statusbar.cancelPreloadRecentApps();
3243 }
3244 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003245 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003246 // re-acquire status bar service next time it is needed.
3247 mStatusBarService = null;
3248 }
3249 }
3250 }
3251
3252 private void toggleRecentApps() {
3253 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003254 try {
3255 IStatusBarService statusbar = getStatusBarService();
3256 if (statusbar != null) {
3257 statusbar.toggleRecentApps();
3258 }
3259 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003260 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3261 // re-acquire status bar service next time it is needed.
3262 mStatusBarService = null;
3263 }
3264 }
3265
Craig Mautner84984fa2014-06-19 11:19:20 -07003266 @Override
3267 public void showRecentApps() {
3268 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3269 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3270 }
3271
Winson Chung1e8d71b2014-05-16 17:05:22 -07003272 private void showRecentApps(boolean triggeredFromAltTab) {
3273 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3274 try {
3275 IStatusBarService statusbar = getStatusBarService();
3276 if (statusbar != null) {
3277 statusbar.showRecentApps(triggeredFromAltTab);
3278 }
3279 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003280 Slog.e(TAG, "RemoteException when showing recent apps", e);
3281 // re-acquire status bar service next time it is needed.
3282 mStatusBarService = null;
3283 }
3284 }
3285
Clara Bayarrif2debb12015-07-10 14:47:17 +01003286 private void showKeyboardShortcutsMenu() {
3287 try {
3288 IStatusBarService statusbar = getStatusBarService();
3289 if (statusbar != null) {
3290 statusbar.showKeyboardShortcutsMenu();
3291 }
3292 } catch (RemoteException e) {
3293 Slog.e(TAG, "RemoteException when showing keyboard shortcuts menu", e);
3294 }
3295 }
3296
Winson Chungcdcd4872014-08-05 18:00:13 -07003297 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003298 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3299 try {
3300 IStatusBarService statusbar = getStatusBarService();
3301 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003302 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003303 }
3304 } catch (RemoteException e) {
3305 Slog.e(TAG, "RemoteException when closing recent apps", e);
3306 // re-acquire status bar service next time it is needed.
3307 mStatusBarService = null;
3308 }
3309 }
3310
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003311 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003312 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003313 }
3314
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003315 /**
3316 * A home key -> launch home action was detected. Take the appropriate action
3317 * given the situation with the keyguard.
3318 */
Bryce Lee662ed802015-04-10 20:11:39 +00003319 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3320 if (respectKeyguard) {
3321 if (isKeyguardShowingAndNotOccluded()) {
3322 // don't launch home if keyguard showing
3323 return;
3324 }
3325
3326 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3327 // when in keyguard restricted mode, must first verify unlock
3328 // before launching home
3329 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3330 @Override
3331 public void onKeyguardExitResult(boolean success) {
3332 if (success) {
3333 try {
3334 ActivityManagerNative.getDefault().stopAppSwitches();
3335 } catch (RemoteException e) {
3336 }
3337 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3338 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003339 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003340 }
Bryce Lee662ed802015-04-10 20:11:39 +00003341 });
3342 return;
3343 }
3344 }
3345
3346 // no keyguard stuff to worry about, just launch home!
3347 try {
3348 ActivityManagerNative.getDefault().stopAppSwitches();
3349 } catch (RemoteException e) {
3350 }
3351 if (mRecentsVisible) {
3352 // Hide Recents and notify it to launch Home
3353 if (awakenFromDreams) {
3354 awakenDreams();
3355 }
3356 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3357 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003358 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003359 // Otherwise, just launch Home
3360 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3361 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003362 }
3363 }
3364
John Spurlock04db1762013-05-13 12:46:41 -04003365 private final Runnable mClearHideNavigationFlag = new Runnable() {
3366 @Override
3367 public void run() {
3368 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3369 // Clear flags.
3370 mForceClearedSystemUiFlags &=
3371 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3372 }
3373 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003374 }
3375 };
3376
3377 /**
3378 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3379 * to determine when the nav bar should be shown and prevent applications from
3380 * receiving those touches.
3381 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003382 final class HideNavInputEventReceiver extends InputEventReceiver {
3383 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3384 super(inputChannel, looper);
3385 }
3386
Dianne Hackborndf89e652011-10-06 22:35:11 -07003387 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003388 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003389 boolean handled = false;
3390 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003391 if (event instanceof MotionEvent
3392 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3393 final MotionEvent motionEvent = (MotionEvent)event;
3394 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003395 // When the user taps down, we re-show the nav bar.
3396 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003397 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003398 // Any user activity always causes us to show the
3399 // navigation controls, if they had been hidden.
3400 // We also clear the low profile and only content
3401 // flags so that tapping on the screen will atomically
3402 // restore all currently hidden screen decorations.
3403 int newVal = mResettingSystemUiFlags |
3404 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3405 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3406 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003407 if (mResettingSystemUiFlags != newVal) {
3408 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003409 changed = true;
3410 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003411 // We don't allow the system's nav bar to be hidden
3412 // again for 1 second, to prevent applications from
3413 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003414 newVal = mForceClearedSystemUiFlags |
3415 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003416 if (mForceClearedSystemUiFlags != newVal) {
3417 mForceClearedSystemUiFlags = newVal;
3418 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003419 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003420 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003421 }
3422 if (changed) {
3423 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3424 }
3425 }
3426 }
3427 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003428 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003429 }
3430 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003431 }
3432 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3433 new InputEventReceiver.Factory() {
3434 @Override
3435 public InputEventReceiver createInputEventReceiver(
3436 InputChannel inputChannel, Looper looper) {
3437 return new HideNavInputEventReceiver(inputChannel, looper);
3438 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003439 };
3440
3441 @Override
3442 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003443 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3444 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003445 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003446
Dianne Hackborndf89e652011-10-06 22:35:11 -07003447 // Reset any bits in mForceClearingStatusBarVisibility that
3448 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003449 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003450 // Clear any bits in the new visibility that are currently being
3451 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003452 return visibility & ~mResettingSystemUiFlags
3453 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003454 }
3455
Craig Mautner69b08182012-09-05 13:07:13 -07003456 @Override
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003457 public void getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation,
3458 Rect outContentInsets, Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003459 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003460 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3461 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003462
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003463 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
3464 if (useOutsets) {
3465 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
3466 if (outset > 0) {
3467 if (displayRotation == Surface.ROTATION_0) {
3468 outOutsets.bottom += outset;
3469 } else if (displayRotation == Surface.ROTATION_90) {
3470 outOutsets.right += outset;
3471 } else if (displayRotation == Surface.ROTATION_180) {
3472 outOutsets.top += outset;
3473 } else if (displayRotation == Surface.ROTATION_270) {
3474 outOutsets.left += outset;
3475 }
3476 }
3477 }
3478
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003479 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003480 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003481 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003482 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003483 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003484 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3485 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3486 } else {
3487 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3488 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3489 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003490 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3491 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003492 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003493 availRight - mStableFullscreenRight,
3494 availBottom - mStableFullscreenBottom);
3495 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003496 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003497 availRight - mStableRight, availBottom - mStableBottom);
3498 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003499 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003500 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003501 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003502 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003503 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003504 availRight - mCurRight, availBottom - mCurBottom);
3505 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003506 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003507 availRight - mCurRight, availBottom - mCurBottom);
3508 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003509
3510 outStableInsets.set(mStableLeft, mStableTop,
3511 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003512 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003513 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003514 outContentInsets.setEmpty();
3515 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003516 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003517
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003518 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
3519 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
3520 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
3521 }
3522
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003523 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003524 @Override
3525 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3526 int displayRotation) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003527 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003528 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3529 if (isDefaultDisplay) {
3530 switch (displayRotation) {
3531 case Surface.ROTATION_90:
3532 overscanLeft = mOverscanTop;
3533 overscanTop = mOverscanRight;
3534 overscanRight = mOverscanBottom;
3535 overscanBottom = mOverscanLeft;
3536 break;
3537 case Surface.ROTATION_180:
3538 overscanLeft = mOverscanRight;
3539 overscanTop = mOverscanBottom;
3540 overscanRight = mOverscanLeft;
3541 overscanBottom = mOverscanTop;
3542 break;
3543 case Surface.ROTATION_270:
3544 overscanLeft = mOverscanBottom;
3545 overscanTop = mOverscanLeft;
3546 overscanRight = mOverscanTop;
3547 overscanBottom = mOverscanRight;
3548 break;
3549 default:
3550 overscanLeft = mOverscanLeft;
3551 overscanTop = mOverscanTop;
3552 overscanRight = mOverscanRight;
3553 overscanBottom = mOverscanBottom;
3554 break;
3555 }
3556 } else {
3557 overscanLeft = 0;
3558 overscanTop = 0;
3559 overscanRight = 0;
3560 overscanBottom = 0;
3561 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003562 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3563 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3564 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3565 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003566 mSystemLeft = 0;
3567 mSystemTop = 0;
3568 mSystemRight = displayWidth;
3569 mSystemBottom = displayHeight;
3570 mUnrestrictedScreenLeft = overscanLeft;
3571 mUnrestrictedScreenTop = overscanTop;
3572 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3573 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3574 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3575 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003576 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3577 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003578 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003579 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003580 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003581 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003582 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003583 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003584 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003585 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003586 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003587 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003588
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003589 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3590 final Rect pf = mTmpParentFrame;
3591 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003592 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003593 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003594 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003595 pf.left = df.left = of.left = vf.left = mDockLeft;
3596 pf.top = df.top = of.top = vf.top = mDockTop;
3597 pf.right = df.right = of.right = vf.right = mDockRight;
3598 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003599 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003600
Craig Mautner69b08182012-09-05 13:07:13 -07003601 if (isDefaultDisplay) {
3602 // For purposes of putting out fake window up to steal focus, we will
3603 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003604 final int sysui = mLastSystemUiFlags;
3605 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003606 boolean navTranslucent = (sysui
3607 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003608 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3609 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3610 boolean navAllowedHidden = immersive || immersiveSticky;
3611 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003612 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3613 if (!isKeyguardShowing) {
3614 navTranslucent &= areTranslucentBarsAllowed();
3615 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003616
Craig Mautner69b08182012-09-05 13:07:13 -07003617 // When the navigation bar isn't visible, we put up a fake
3618 // input window to catch all touch events. This way we can
3619 // detect when the user presses anywhere to bring back the nav
3620 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003621 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003622 if (mInputConsumer != null) {
3623 mInputConsumer.dismiss();
3624 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003625 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003626 } else if (mInputConsumer == null) {
3627 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3628 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003629 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003630
Craig Mautner69b08182012-09-05 13:07:13 -07003631 // For purposes of positioning and showing the nav bar, if we have
3632 // decided that it can't be hidden (because of the screen aspect ratio),
3633 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003634 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003635
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003636 boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight,
3637 displayRotation, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
3638 navAllowedHidden);
Craig Mautnereda67292013-04-28 13:50:14 -07003639 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003640 mDockLeft, mDockTop, mDockRight, mDockBottom));
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003641 updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003642 if (updateSysUiVisibility) {
3643 updateSystemUiVisibilityLw();
3644 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003645 }
3646 }
3647
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003648 private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui,
3649 boolean isKeyguardShowing) {
3650 // decide where the status bar goes ahead of time
3651 if (mStatusBar != null) {
3652 // apply any navigation bar insets
3653 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3654 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3655 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3656 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3657 + mUnrestrictedScreenTop;
3658 vf.left = mStableLeft;
3659 vf.top = mStableTop;
3660 vf.right = mStableRight;
3661 vf.bottom = mStableBottom;
3662
3663 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3664
3665 // Let the status bar determine its size.
3666 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3667 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3668 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
3669
3670 // For layout, the status bar is always at the top with our fixed height.
3671 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3672
3673 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
3674 boolean statusBarTranslucent = (sysui
3675 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
3676 if (!isKeyguardShowing) {
3677 statusBarTranslucent &= areTranslucentBarsAllowed();
3678 }
3679
3680 // If the status bar is hidden, we don't want to cause
3681 // windows behind it to scroll.
3682 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
3683 // Status bar may go away, so the screen area it occupies
3684 // is available to apps but just covering them when the
3685 // status bar is visible.
3686 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3687
3688 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3689 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3690 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3691 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3692
3693 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
3694 String.format(
3695 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3696 mDockLeft, mDockTop, mDockRight, mDockBottom,
3697 mContentLeft, mContentTop, mContentRight, mContentBottom,
3698 mCurLeft, mCurTop, mCurRight, mCurBottom));
3699 }
3700 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
3701 && !statusBarTransient && !statusBarTranslucent
3702 && !mStatusBarController.wasRecentlyTranslucent()) {
3703 // If the opaque status bar is currently requested to be visible,
3704 // and not in the process of animating on or off, then
3705 // we can tell the app that it is covered by it.
3706 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3707 }
3708 if (mStatusBarController.checkHiddenLw()) {
3709 return true;
3710 }
3711 }
3712 return false;
3713 }
3714
3715 private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation,
3716 int overscanRight, int overscanBottom, Rect dcf, boolean navVisible,
3717 boolean navTranslucent, boolean navAllowedHidden) {
3718 if (mNavigationBar != null) {
3719 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
3720 // Force the navigation bar to its appropriate place and
3721 // size. We need to do this directly, instead of relying on
3722 // it to bubble up from the nav bar, because this needs to
3723 // change atomically with screen rotations.
3724 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3725 if (mNavigationBarOnBottom) {
3726 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
3727 int top = displayHeight - overscanBottom
3728 - mNavigationBarHeightForRotation[displayRotation];
3729 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
3730 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
3731 if (transientNavBarShowing) {
3732 mNavigationBarController.setBarShowingLw(true);
3733 } else if (navVisible) {
3734 mNavigationBarController.setBarShowingLw(true);
3735 mDockBottom = mTmpNavigationFrame.top;
3736 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3737 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
3738 } else {
3739 // We currently want to hide the navigation UI.
3740 mNavigationBarController.setBarShowingLw(false);
3741 }
3742 if (navVisible && !navTranslucent && !navAllowedHidden
3743 && !mNavigationBar.isAnimatingLw()
3744 && !mNavigationBarController.wasRecentlyTranslucent()) {
3745 // If the opaque nav bar is currently requested to be visible,
3746 // and not in the process of animating on or off, then
3747 // we can tell the app that it is covered by it.
3748 mSystemBottom = mTmpNavigationFrame.top;
3749 }
3750 } else {
3751 // Landscape screen; nav bar goes to the right.
3752 int left = displayWidth - overscanRight
3753 - mNavigationBarWidthForRotation[displayRotation];
3754 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
3755 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
3756 if (transientNavBarShowing) {
3757 mNavigationBarController.setBarShowingLw(true);
3758 } else if (navVisible) {
3759 mNavigationBarController.setBarShowingLw(true);
3760 mDockRight = mTmpNavigationFrame.left;
3761 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3762 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
3763 } else {
3764 // We currently want to hide the navigation UI.
3765 mNavigationBarController.setBarShowingLw(false);
3766 }
3767 if (navVisible && !navTranslucent && !navAllowedHidden
3768 && !mNavigationBar.isAnimatingLw()
3769 && !mNavigationBarController.wasRecentlyTranslucent()) {
3770 // If the nav bar is currently requested to be visible,
3771 // and not in the process of animating on or off, then
3772 // we can tell the app that it is covered by it.
3773 mSystemRight = mTmpNavigationFrame.left;
3774 }
3775 }
3776 // Make sure the content and current rectangles are updated to
3777 // account for the restrictions from the navigation bar.
3778 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3779 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3780 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3781 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3782 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3783 // And compute the final frame.
3784 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
3785 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3786 mTmpNavigationFrame, mTmpNavigationFrame);
3787 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
3788 if (mNavigationBarController.checkHiddenLw()) {
3789 return true;
3790 }
3791 }
3792 return false;
3793 }
3794
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003795 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003796 @Override
John Spurlock46646232013-09-30 22:32:42 -04003797 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003798 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3799 return mStatusBar.getSurfaceLayer();
3800 }
3801
3802 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3803 return mNavigationBar.getSurfaceLayer();
3804 }
3805
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003806 return 0;
3807 }
3808
Craig Mautner967212c2013-04-13 21:10:58 -07003809 @Override
3810 public void getContentRectLw(Rect r) {
3811 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3812 }
3813
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003814 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3815 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003816 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3817 // Here's a special case: if this attached window is a panel that is
3818 // above the dock window, and the window it is attached to is below
3819 // the dock window, then the frames we computed for the window it is
3820 // attached to can not be used because the dock is effectively part
3821 // of the underlying window and the attached window is floating on top
3822 // of the whole thing. So, we ignore the attached window and explicitly
3823 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003824 df.left = of.left = cf.left = vf.left = mDockLeft;
3825 df.top = of.top = cf.top = vf.top = mDockTop;
3826 df.right = of.right = cf.right = vf.right = mDockRight;
3827 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003828 } else {
3829 // The effective display frame of the attached window depends on
3830 // whether it is taking care of insetting its content. If not,
3831 // we need to use the parent's content frame so that the entire
3832 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003833 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003834 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003835 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003836 // Set the content frame of the attached window to the parent's decor frame
3837 // (same as content frame when IME isn't present) if specifically requested by
3838 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3839 // Otherwise, use the overscan frame.
3840 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3841 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003842 } else {
3843 // If the window is resizing, then we want to base the content
3844 // frame on our attached content frame to resize... however,
3845 // things can be tricky if the attached window is NOT in resize
3846 // mode, in which case its content frame will be larger.
3847 // Ungh. So to deal with that, make sure the content frame
3848 // we end up using is not covering the IM dock.
3849 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003850 if (attached.isVoiceInteraction()) {
3851 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3852 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3853 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3854 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3855 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003856 if (cf.left < mContentLeft) cf.left = mContentLeft;
3857 if (cf.top < mContentTop) cf.top = mContentTop;
3858 if (cf.right > mContentRight) cf.right = mContentRight;
3859 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3860 }
3861 }
3862 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003863 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003864 vf.set(attached.getVisibleFrameLw());
3865 }
3866 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3867 // window should be positioned relative to its parent or the entire
3868 // screen.
3869 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3870 ? attached.getFrameLw() : df);
3871 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003872
3873 private void applyStableConstraints(int sysui, int fl, Rect r) {
3874 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3875 // If app is requesting a stable layout, don't let the
3876 // content insets go below the stable values.
3877 if ((fl & FLAG_FULLSCREEN) != 0) {
3878 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3879 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3880 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3881 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3882 } else {
3883 if (r.left < mStableLeft) r.left = mStableLeft;
3884 if (r.top < mStableTop) r.top = mStableTop;
3885 if (r.right > mStableRight) r.right = mStableRight;
3886 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3887 }
3888 }
3889 }
3890
Jorim Jaggiaa806142015-05-20 18:04:16 -07003891 private boolean canReceiveInput(WindowState win) {
3892 boolean notFocusable =
3893 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
3894 boolean altFocusableIm =
3895 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
3896 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
3897 return !notFocusableForIm;
3898 }
3899
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003900 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003901 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003902 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07003903 // We've already done the navigation bar and status bar. If the status bar can receive
3904 // input, we need to layout it again to accomodate for the IME window.
3905 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003906 return;
3907 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07003908 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07003909 final boolean isDefaultDisplay = win.isDefaultDisplay();
3910 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003911 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3912 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003913 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003914 offsetInputMethodWindowLw(mLastInputMethodWindow);
3915 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003916
John Spurlockc6d1c602014-01-17 15:22:06 -05003917 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003918 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003919 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003920
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003921 final Rect pf = mTmpParentFrame;
3922 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003923 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003924 final Rect cf = mTmpContentFrame;
3925 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003926 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003927 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003928 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04003929 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003930
3931 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003932 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003933
Craig Mautnerf683b562012-10-02 11:10:57 -07003934 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3935
Adrian Roosfa104232014-06-20 16:10:14 -07003936 if (isDefaultDisplay) {
3937 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3938 } else {
3939 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3940 }
3941
Craig Mautner69b08182012-09-05 13:07:13 -07003942 if (!isDefaultDisplay) {
3943 if (attached != null) {
3944 // If this window is attached to another, our display
3945 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003946 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003947 } else {
3948 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003949 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3950 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3951 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003952 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003953 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003954 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003955 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003956 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003957 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3958 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3959 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003960 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003961 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003962 // ...with content insets above the nav bar
3963 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003964 // IM dock windows always go to the bottom of the screen.
3965 attrs.gravity = Gravity.BOTTOM;
3966 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003967 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003968 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003969 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003970 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3971 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003972 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003973 // Note: In Phone landscape mode, the button bar should also be excluded.
3974 cf.right = vf.right = mStableRight;
3975 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003976 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07003977 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02003978 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3979 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3980 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3981 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3982 cf.left = vf.left = mStableLeft;
3983 cf.top = vf.top = mStableTop;
3984 cf.right = vf.right = mStableRight;
3985 vf.bottom = mStableBottom;
3986 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003987 } else {
John Spurlock46646232013-09-30 22:32:42 -04003988
3989 // Default policy decor for the default display
3990 dcf.left = mSystemLeft;
3991 dcf.top = mSystemTop;
3992 dcf.right = mSystemRight;
3993 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003994 final boolean inheritTranslucentDecor = (attrs.privateFlags
3995 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003996 final boolean isAppWindow =
3997 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3998 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3999 final boolean topAtRest =
4000 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
4001 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04004002 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
4003 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004004 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
4005 && (fl & WindowManager.LayoutParams.
4006 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004007 // Ensure policy decor includes status bar
4008 dcf.top = mStableTop;
4009 }
John Spurlockbd957402013-10-03 11:38:39 -04004010 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004011 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
4012 && (fl & WindowManager.LayoutParams.
4013 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004014 // Ensure policy decor includes navigation bar
4015 dcf.bottom = mStableBottom;
4016 dcf.right = mStableRight;
4017 }
4018 }
4019
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004020 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
4021 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07004022 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004023 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004024 // This is the case for a normal activity window: we want it
4025 // to cover all of the screen space, and it can take care of
4026 // moving its contents to account for screen decorations that
4027 // intrude into that space.
4028 if (attached != null) {
4029 // If this window is attached to another, our display
4030 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004031 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004032 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004033 if (attrs.type == TYPE_STATUS_BAR_PANEL
4034 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08004035 // Status bar panels are the only windows who can go on top of
4036 // the status bar. They are protected by the STATUS_BAR_SERVICE
4037 // permission, so they have the same privileges as the status
4038 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004039 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004040 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004041
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004042 pf.left = df.left = of.left = hasNavBar
4043 ? mDockLeft : mUnrestrictedScreenLeft;
4044 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4045 pf.right = df.right = of.right = hasNavBar
4046 ? mRestrictedScreenLeft+mRestrictedScreenWidth
4047 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4048 pf.bottom = df.bottom = of.bottom = hasNavBar
4049 ? mRestrictedScreenTop+mRestrictedScreenHeight
4050 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004051
Craig Mautnereda67292013-04-28 13:50:14 -07004052 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004053 "Laying out status bar window: (%d,%d - %d,%d)",
4054 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04004055 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004056 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4057 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4058 // Asking to layout into the overscan region, so give it that pure
4059 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004060 pf.left = df.left = of.left = mOverscanScreenLeft;
4061 pf.top = df.top = of.top = mOverscanScreenTop;
4062 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
4063 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
4064 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004065 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004066 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004067 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4068 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004069 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08004070 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004071 // only do this for application windows to ensure no window that
4072 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08004073 pf.left = df.left = mOverscanScreenLeft;
4074 pf.top = df.top = mOverscanScreenTop;
4075 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4076 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004077 // We need to tell the app about where the frame inside the overscan
4078 // is, so it can inset its content by that amount -- it didn't ask
4079 // to actually extend itself into the overscan region.
4080 of.left = mUnrestrictedScreenLeft;
4081 of.top = mUnrestrictedScreenTop;
4082 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4083 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004084 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08004085 pf.left = df.left = mRestrictedOverscanScreenLeft;
4086 pf.top = df.top = mRestrictedOverscanScreenTop;
4087 pf.right = df.right = mRestrictedOverscanScreenLeft
4088 + mRestrictedOverscanScreenWidth;
4089 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
4090 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004091 // We need to tell the app about where the frame inside the overscan
4092 // is, so it can inset its content by that amount -- it didn't ask
4093 // to actually extend itself into the overscan region.
4094 of.left = mUnrestrictedScreenLeft;
4095 of.top = mUnrestrictedScreenTop;
4096 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4097 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004098 }
Craig Mautner69b08182012-09-05 13:07:13 -07004099
John Spurlock46646232013-09-30 22:32:42 -04004100 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004101 if (win.isVoiceInteraction()) {
4102 cf.left = mVoiceContentLeft;
4103 cf.top = mVoiceContentTop;
4104 cf.right = mVoiceContentRight;
4105 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004106 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004107 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4108 cf.left = mDockLeft;
4109 cf.top = mDockTop;
4110 cf.right = mDockRight;
4111 cf.bottom = mDockBottom;
4112 } else {
4113 cf.left = mContentLeft;
4114 cf.top = mContentTop;
4115 cf.right = mContentRight;
4116 cf.bottom = mContentBottom;
4117 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004118 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004119 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004120 // Full screen windows are always given a layout that is as if the
4121 // status bar and other transient decors are gone. This is to avoid
4122 // bad states when moving from a window that is not hding the
4123 // status bar to one that is.
4124 cf.left = mRestrictedScreenLeft;
4125 cf.top = mRestrictedScreenTop;
4126 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4127 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004128 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004129 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004130 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4131 vf.left = mCurLeft;
4132 vf.top = mCurTop;
4133 vf.right = mCurRight;
4134 vf.bottom = mCurBottom;
4135 } else {
4136 vf.set(cf);
4137 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004138 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004139 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
4140 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
4141 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07004142 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4143 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004144 // A window that has requested to fill the entire screen just
4145 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004146 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04004147 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
4148 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004149 pf.left = df.left = of.left = cf.left = hasNavBar
4150 ? mDockLeft : mUnrestrictedScreenLeft;
4151 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4152 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004153 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08004154 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004155 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004156 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004157 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004158 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04004159 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
4160 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07004161 } else if (attrs.type == TYPE_NAVIGATION_BAR
4162 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004163 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004164 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4165 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4166 pf.right = df.right = of.right = mUnrestrictedScreenLeft
4167 + mUnrestrictedScreenWidth;
4168 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
4169 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004170 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004171 "Laying out navigation bar window: (%d,%d - %d,%d)",
4172 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08004173 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
4174 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07004175 && ((fl & FLAG_FULLSCREEN) != 0)) {
4176 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004177 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4178 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4179 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4180 + mOverscanScreenWidth;
4181 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4182 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08004183 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08004184 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004185 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4186 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4187 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4188 + mOverscanScreenWidth;
4189 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4190 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04004191 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004192 // The wallpaper also has Real Ultimate Power, but we want to tell
4193 // it about the overscan area.
4194 pf.left = df.left = mOverscanScreenLeft;
4195 pf.top = df.top = mOverscanScreenTop;
4196 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4197 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4198 of.left = cf.left = mUnrestrictedScreenLeft;
4199 of.top = cf.top = mUnrestrictedScreenTop;
4200 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4201 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004202 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004203 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4204 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4205 // Asking to layout into the overscan region, so give it that pure
4206 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004207 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4208 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4209 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004210 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004211 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004212 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004213 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004214 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004215 && (attrs.type == TYPE_STATUS_BAR
4216 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004217 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004218 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4219 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004220 // Asking for layout as if the nav bar is hidden, lets the
4221 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004222 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004223 // can be above the nav bar can do this.
4224 // XXX This assumes that an app asking for this will also
4225 // ask for layout in only content. We can't currently figure out
4226 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004227 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4228 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4229 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4230 + mUnrestrictedScreenWidth;
4231 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4232 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004233 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004234 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4235 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4236 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4237 + mRestrictedScreenWidth;
4238 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4239 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004240 }
Craig Mautner69b08182012-09-05 13:07:13 -07004241
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004242 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004243
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004244 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4245 vf.left = mCurLeft;
4246 vf.top = mCurTop;
4247 vf.right = mCurRight;
4248 vf.bottom = mCurBottom;
4249 } else {
4250 vf.set(cf);
4251 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004252 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004253 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4254 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004255 // A child window should be placed inside of the same visible
4256 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004257 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004258 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004259 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4260 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004261 // Otherwise, a normal window must be placed inside the content
4262 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004263 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4264 // Status bar panels and the volume dialog are the only windows who can go on
4265 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004266 // permission, so they have the same privileges as the status
4267 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004268 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4269 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4270 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4271 + mRestrictedScreenWidth;
4272 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4273 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004274 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004275 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004276 pf.left = df.left = of.left = cf.left = mStableLeft;
4277 pf.top = df.top = of.top = cf.top = mStableTop;
4278 pf.right = df.right = of.right = cf.right = mStableRight;
4279 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004280 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004281 pf.left = mContentLeft;
4282 pf.top = mContentTop;
4283 pf.right = mContentRight;
4284 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004285 if (win.isVoiceInteraction()) {
4286 df.left = of.left = cf.left = mVoiceContentLeft;
4287 df.top = of.top = cf.top = mVoiceContentTop;
4288 df.right = of.right = cf.right = mVoiceContentRight;
4289 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4290 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004291 df.left = of.left = cf.left = mDockLeft;
4292 df.top = of.top = cf.top = mDockTop;
4293 df.right = of.right = cf.right = mDockRight;
4294 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004295 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004296 df.left = of.left = cf.left = mContentLeft;
4297 df.top = of.top = cf.top = mContentTop;
4298 df.right = of.right = cf.right = mContentRight;
4299 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004300 }
4301 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4302 vf.left = mCurLeft;
4303 vf.top = mCurTop;
4304 vf.right = mCurRight;
4305 vf.bottom = mCurBottom;
4306 } else {
4307 vf.set(cf);
4308 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004309 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004310 }
4311 }
Craig Mautner69b08182012-09-05 13:07:13 -07004312
Craig Mautnerb816bed2013-07-23 10:26:17 -07004313 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4314 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004315 df.left = df.top = -10000;
4316 df.right = df.bottom = 10000;
4317 if (attrs.type != TYPE_WALLPAPER) {
4318 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4319 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4320 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004321 }
4322
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004323 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4324 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004325 // We only want to apply outsets to certain types of windows. For example, we never want to
4326 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004327 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004328 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004329 osf = mTmpOutsetFrame;
4330 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4331 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4332 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004333 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004334 if (rotation == Surface.ROTATION_0) {
4335 osf.bottom += outset;
4336 } else if (rotation == Surface.ROTATION_90) {
4337 osf.right += outset;
4338 } else if (rotation == Surface.ROTATION_180) {
4339 osf.top -= outset;
4340 } else if (rotation == Surface.ROTATION_270) {
4341 osf.left -= outset;
4342 }
4343 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4344 + " with rotation " + rotation + ", result: " + osf);
4345 }
4346 }
4347
Craig Mautnereda67292013-04-28 13:50:14 -07004348 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004349 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004350 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004351 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004352 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004353 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004354 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004355 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004356 + " sf=" + sf.toShortString()
4357 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004358
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004359 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004360
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004361 // Dock windows carve out the bottom of the screen, so normal windows
4362 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004363 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4364 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004365 setLastInputMethodWindowLw(null, null);
4366 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004367 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004368 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4369 && !win.getGivenInsetsPendingLw()) {
4370 offsetVoiceInputWindowLw(win);
4371 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004372 }
4373
satok1bc0a492012-04-25 22:47:12 +09004374 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004375 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004376 top += win.getGivenContentInsetsLw().top;
4377 if (mContentBottom > top) {
4378 mContentBottom = top;
4379 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004380 if (mVoiceContentBottom > top) {
4381 mVoiceContentBottom = top;
4382 }
satok1bc0a492012-04-25 22:47:12 +09004383 top = win.getVisibleFrameLw().top;
4384 top += win.getGivenVisibleInsetsLw().top;
4385 if (mCurBottom > top) {
4386 mCurBottom = top;
4387 }
Craig Mautnereda67292013-04-28 13:50:14 -07004388 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004389 + mDockBottom + " mContentBottom="
4390 + mContentBottom + " mCurBottom=" + mCurBottom);
4391 }
4392
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004393 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004394 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004395 top += win.getGivenContentInsetsLw().top;
4396 if (mVoiceContentBottom > top) {
4397 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004398 }
4399 }
4400
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004401 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004402 @Override
4403 public void finishLayoutLw() {
4404 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004405 }
4406
4407 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004408 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004409 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004410 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004411 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004412 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004413 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004414 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004415 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004416 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004417 mForcingShowNavBar = false;
4418 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004419
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004420 mHideLockScreen = false;
4421 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004422 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004423 mShowingLockscreen = false;
4424 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004425 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004426 mKeyguardSecure = isKeyguardSecure();
4427 mKeyguardSecureIncludingHidden = mKeyguardSecure
4428 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004429 }
4430
4431 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004432 @Override
Yohei Yukawad1a09222015-06-30 16:22:05 -07004433 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,
4434 WindowState attached) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004435 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4436 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004437 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004438 if (mTopFullscreenOpaqueWindowState == null
4439 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4440 mForcingShowNavBar = true;
4441 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004442 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004443 if (attrs.type == TYPE_STATUS_BAR) {
4444 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4445 mForceStatusBarFromKeyguard = true;
Jorim Jaggie1de9f62015-09-23 14:59:50 -07004446 mShowingLockscreen = true;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004447 }
4448 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4449 mForceStatusBarTransparent = true;
4450 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004451 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004452
4453 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4454 && attrs.type < FIRST_SYSTEM_WINDOW;
4455 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4456 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4457
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004458 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004459 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004460 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004461 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004462 mForceStatusBarFromKeyguard = true;
4463 } else {
4464 mForceStatusBar = true;
4465 }
4466 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004467 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004468 // If the lockscreen was showing when the dream started then wait
4469 // for the dream to draw before hiding the lockscreen.
4470 if (!mDreamingLockscreen
4471 || (win.isVisibleLw() && win.hasDrawnLw())) {
4472 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004473 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004474 }
4475 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004476
Yohei Yukawad1a09222015-06-30 16:22:05 -07004477 final IApplicationToken appToken = win.getAppToken();
4478
4479 // For app windows that are not attached, we decide if all windows in the app they
4480 // represent should be hidden or if we should hide the lockscreen. For attached app
4481 // windows we defer the decision to the window it is attached to.
4482 if (appWindow && attached == null) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004483 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004484 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004485 mAppsToBeHidden.remove(appToken);
4486 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004487 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004488 if (dismissKeyguard && !mKeyguardSecure) {
4489 mAppsThatDismissKeyguard.add(appToken);
Selim Cinek90b5e072015-08-28 17:05:56 -07004490 } else if (win.isDrawnLw() || win.hasAppShownWindows()) {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004491 mWinShowWhenLocked = win;
4492 mHideLockScreen = true;
4493 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004494 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004495 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004496 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004497 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004498 mAppsToBeHidden.add(appToken);
4499 } else {
4500 mAppsToBeHidden.remove(appToken);
4501 }
4502 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004503 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004504 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004505 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004506 if (attrs.x == 0 && attrs.y == 0
4507 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4508 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4509 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4510 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004511 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4512 mTopFullscreenOpaqueOrDimmingWindowState = win;
4513 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004514 if (!mAppsThatDismissKeyguard.isEmpty() &&
4515 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4516 if (DEBUG_LAYOUT) Slog.v(TAG,
4517 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004518 mDismissKeyguard = (mWinDismissingKeyguard == win
4519 && mSecureDismissingKeyguard == mKeyguardSecure)
4520 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004521 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004522 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004523 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Selim Cinek90b5e072015-08-28 17:05:56 -07004524 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked
4525 && (win.isDrawnLw() || win.hasAppShownWindows())) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004526 if (DEBUG_LAYOUT) Slog.v(TAG,
4527 "Setting mHideLockScreen to true by win " + win);
4528 mHideLockScreen = true;
4529 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004530 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004531 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004532 mAllowLockscreenWhenOn = true;
4533 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004534 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004535
4536 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004537 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4538 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004539 win.hideLw(false);
4540 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004541 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004542 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4543 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4544 // that is being hidden in an animation - keep the
4545 // keyguard hidden until the new window shows up and
4546 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004547 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004548 mHideLockScreen = true;
4549 mWinShowWhenLocked = win;
4550 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004551 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004552 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4553 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4554 && win.isDimming()) {
4555 mTopFullscreenOpaqueOrDimmingWindowState = win;
4556 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004557 }
4558
4559 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004560 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004561 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004562 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4563 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4564 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004565 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4566 // fullscreen window.
4567 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4568 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4569 mTopFullscreenOpaqueWindowState.hideLw(false);
4570 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4571 }
4572
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004573 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004574 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004575
4576 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4577 ? mTopFullscreenOpaqueWindowState.getAttrs()
4578 : null;
4579
Jeff Brownc8018eb2012-10-29 21:33:27 -07004580 // If we are not currently showing a dream then remember the current
4581 // lockscreen state. We will use this to determine whether the dream
4582 // started while the lockscreen was showing and remember this state
4583 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004584 if (!mShowingDream) {
4585 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004586 if (mDreamingSleepTokenNeeded) {
4587 mDreamingSleepTokenNeeded = false;
4588 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4589 }
4590 } else {
4591 if (!mDreamingSleepTokenNeeded) {
4592 mDreamingSleepTokenNeeded = true;
4593 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4594 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004595 }
4596
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004597 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004598 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004599 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004600 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004601 boolean shouldBeTransparent = mForceStatusBarTransparent
4602 && !mForceStatusBar
4603 && !mForceStatusBarFromKeyguard;
4604 if (!shouldBeTransparent) {
4605 mStatusBarController.setShowTransparent(false /* transparent */);
4606 } else if (!mStatusBar.isVisibleLw()) {
4607 mStatusBarController.setShowTransparent(true /* transparent */);
4608 }
4609 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004610 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004611 if (mStatusBarController.setBarShowingLw(true)) {
4612 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4613 }
Craig Mautner81defc72013-10-29 11:10:42 -07004614 // Maintain fullscreen layout until incoming animation is complete.
4615 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004616 // Transient status bar on the lockscreen is not allowed
4617 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4618 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4619 mLastSystemUiFlags, mLastSystemUiFlags);
4620 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004621 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004622 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004623 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004624 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07004625 + " shown position: "
4626 + mTopFullscreenOpaqueWindowState.getShownPositionLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004627 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004628 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004629 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004630 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004631 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004632 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004633 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004634 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4635 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004636 if (mStatusBarController.isTransientShowing()) {
4637 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004638 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4639 }
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07004640 } else if (topIsFullscreen
4641 && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID)
4642 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) {
Craig Mautnereda67292013-04-28 13:50:14 -07004643 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004644 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004645 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004646 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004647 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004648 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004649 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004650 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004651 if (mStatusBarController.setBarShowingLw(true)) {
4652 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4653 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004654 }
4655 }
4656 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004657
Craig Mautner81defc72013-10-29 11:10:42 -07004658 if (mTopIsFullscreen != topIsFullscreen) {
4659 if (!topIsFullscreen) {
4660 // Force another layout when status bar becomes fully shown.
4661 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4662 }
4663 mTopIsFullscreen = topIsFullscreen;
4664 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004665
Craig Mautner39834192012-09-02 07:47:24 -07004666 // Hide the key guard if a visible window explicitly specifies that it wants to be
4667 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004668 if (mKeyguardDelegate != null && mStatusBar != null) {
4669 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4670 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004671 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004672 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004673 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004674 changes |= FINISH_LAYOUT_REDO_LAYOUT
4675 | FINISH_LAYOUT_REDO_CONFIG
4676 | FINISH_LAYOUT_REDO_WALLPAPER;
4677 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004678 if (mKeyguardDelegate.isShowing()) {
4679 mHandler.post(new Runnable() {
4680 @Override
4681 public void run() {
4682 mKeyguardDelegate.keyguardDone(false, false);
4683 }
4684 });
4685 }
4686 } else if (mHideLockScreen) {
4687 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004688 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004689 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004690 changes |= FINISH_LAYOUT_REDO_LAYOUT
4691 | FINISH_LAYOUT_REDO_CONFIG
4692 | FINISH_LAYOUT_REDO_WALLPAPER;
4693 }
4694 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004695 mKeyguardHidden = false;
4696 if (setKeyguardOccludedLw(false)) {
4697 changes |= FINISH_LAYOUT_REDO_LAYOUT
4698 | FINISH_LAYOUT_REDO_CONFIG
4699 | FINISH_LAYOUT_REDO_WALLPAPER;
4700 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004701 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4702 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004703 mHandler.post(new Runnable() {
4704 @Override
4705 public void run() {
4706 mKeyguardDelegate.dismiss();
4707 }
4708 });
4709 }
4710 } else {
4711 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004712 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004713 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004714 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004715 changes |= FINISH_LAYOUT_REDO_LAYOUT
4716 | FINISH_LAYOUT_REDO_CONFIG
4717 | FINISH_LAYOUT_REDO_WALLPAPER;
4718 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004719 }
4720 }
Joe Onorato664644d2011-01-23 17:53:23 -08004721
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004722 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004723 // If the navigation bar has been hidden or shown, we need to do another
4724 // layout pass to update that window.
4725 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4726 }
Joe Onorato664644d2011-01-23 17:53:23 -08004727
Mike Lockwood28569302010-01-28 11:54:40 -05004728 // update since mAllowLockscreenWhenOn might have changed
4729 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004730 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004731 }
4732
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004733 /**
Jim Millerab954542014-10-10 18:21:49 -07004734 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004735 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004736 * @return Whether the flags have changed and we have to redo the layout.
4737 */
Jim Millerab954542014-10-10 18:21:49 -07004738 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4739 boolean wasOccluded = mKeyguardOccluded;
4740 boolean showing = mKeyguardDelegate.isShowing();
4741 if (wasOccluded && !isOccluded && showing) {
4742 mKeyguardOccluded = false;
4743 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004744 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4745 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4746 return true;
Jim Millerab954542014-10-10 18:21:49 -07004747 } else if (!wasOccluded && isOccluded && showing) {
4748 mKeyguardOccluded = true;
4749 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004750 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4751 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4752 return true;
4753 } else {
4754 return false;
4755 }
4756 }
4757
4758 private boolean isStatusBarKeyguard() {
4759 return mStatusBar != null
4760 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4761 }
4762
Jose Lima9546b202014-07-02 17:21:51 -07004763 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004764 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004765 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004766 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004767 return false;
4768 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004769 return true;
4770 }
4771
Jose Lima9546b202014-07-02 17:21:51 -07004772 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004773 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004774 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004775 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004776 // If the navigation bar has been hidden or shown, we need to do another
4777 // layout pass to update that window.
4778 return FINISH_LAYOUT_REDO_LAYOUT;
4779 }
4780 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004781 }
4782
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004783 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004784 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004785 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4786 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004787 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4788 if (newLidState == mLidState) {
4789 return;
4790 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004791
Jeff Brownc458ce92012-04-30 14:58:40 -07004792 mLidState = newLidState;
4793 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004794 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004795
4796 if (lidOpen) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07004797 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch,
4798 "android.policy:LID");
Jeff Brownc458ce92012-04-30 14:58:40 -07004799 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004800 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004801 }
4802 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004803
Michael Wright3818c922014-09-02 13:59:07 -07004804 @Override
4805 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4806 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4807 if (mCameraLensCoverState == lensCoverState) {
4808 return;
4809 }
4810 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4811 lensCoverState == CAMERA_LENS_UNCOVERED) {
4812 Intent intent;
4813 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4814 mKeyguardDelegate.isShowing();
4815 if (keyguardActive) {
4816 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4817 } else {
4818 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4819 }
Dianne Hackborn280a64e2015-07-13 14:48:08 -07004820 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens,
4821 "android.policy:CAMERA_COVER");
Bart Sears8b1c27c2015-03-18 23:51:02 +00004822 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004823 }
4824 mCameraLensCoverState = lensCoverState;
4825 }
4826
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004827 void setHdmiPlugged(boolean plugged) {
4828 if (mHdmiPlugged != plugged) {
4829 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004830 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004831 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004832 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004833 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004834 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004835 }
4836 }
4837
Joe Onoratoea495d42011-04-06 11:41:11 -07004838 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004839 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004840 // watch for HDMI plug messages if the hdmi switch exists
4841 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4842 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4843
Joe Onoratoea495d42011-04-06 11:41:11 -07004844 final String filename = "/sys/class/switch/hdmi/state";
4845 FileReader reader = null;
4846 try {
4847 reader = new FileReader(filename);
4848 char[] buf = new char[15];
4849 int n = reader.read(buf);
4850 if (n > 1) {
4851 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4852 }
4853 } catch (IOException ex) {
4854 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4855 } catch (NumberFormatException ex) {
4856 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4857 } finally {
4858 if (reader != null) {
4859 try {
4860 reader.close();
4861 } catch (IOException ex) {
4862 }
Joe Onoratodc100302011-01-11 17:07:41 -08004863 }
4864 }
4865 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004866 // This dance forces the code in setHdmiPlugged to run.
4867 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4868 mHdmiPlugged = !plugged;
4869 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004870 }
4871
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004872 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004873 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004874
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004875 final Runnable mScreenshotTimeout = new Runnable() {
4876 @Override public void run() {
4877 synchronized (mScreenshotLock) {
4878 if (mScreenshotConnection != null) {
4879 mContext.unbindService(mScreenshotConnection);
4880 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004881 }
Winson Chung9112ec32011-06-27 13:15:32 -07004882 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004883 }
4884 };
4885
4886 // Assume this is called from the Handler thread.
4887 private void takeScreenshot() {
4888 synchronized (mScreenshotLock) {
4889 if (mScreenshotConnection != null) {
4890 return;
4891 }
4892 ComponentName cn = new ComponentName("com.android.systemui",
4893 "com.android.systemui.screenshot.TakeScreenshotService");
4894 Intent intent = new Intent();
4895 intent.setComponent(cn);
4896 ServiceConnection conn = new ServiceConnection() {
4897 @Override
4898 public void onServiceConnected(ComponentName name, IBinder service) {
4899 synchronized (mScreenshotLock) {
4900 if (mScreenshotConnection != this) {
4901 return;
4902 }
4903 Messenger messenger = new Messenger(service);
4904 Message msg = Message.obtain(null, 1);
4905 final ServiceConnection myConn = this;
4906 Handler h = new Handler(mHandler.getLooper()) {
4907 @Override
4908 public void handleMessage(Message msg) {
4909 synchronized (mScreenshotLock) {
4910 if (mScreenshotConnection == myConn) {
4911 mContext.unbindService(mScreenshotConnection);
4912 mScreenshotConnection = null;
4913 mHandler.removeCallbacks(mScreenshotTimeout);
4914 }
4915 }
4916 }
4917 };
4918 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004919 msg.arg1 = msg.arg2 = 0;
4920 if (mStatusBar != null && mStatusBar.isVisibleLw())
4921 msg.arg1 = 1;
4922 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4923 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004924 try {
4925 messenger.send(msg);
4926 } catch (RemoteException e) {
4927 }
4928 }
4929 }
4930 @Override
4931 public void onServiceDisconnected(ComponentName name) {}
4932 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004933 if (mContext.bindServiceAsUser(
4934 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004935 mScreenshotConnection = conn;
4936 mHandler.postDelayed(mScreenshotTimeout, 10000);
4937 }
4938 }
Winson Chung9112ec32011-06-27 13:15:32 -07004939 }
4940
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004941 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004942 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004943 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004944 if (!mSystemBooted) {
4945 // If we have not yet booted, don't let key events do anything.
4946 return 0;
4947 }
4948
Jeff Brown037c33e2014-04-09 00:31:55 -07004949 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004950 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4951 final boolean canceled = event.isCanceled();
4952 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004953
Jeff Brown3122e442010-10-11 23:32:49 -07004954 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004955
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004956 // If screen is off then we treat the case where the keyguard is open but hidden
4957 // the same as if it were open and in front.
4958 // This will prevent any keys other than the power button from waking the screen
4959 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004960 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004961 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004962 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004963 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004964
Jeff Brown40013652012-05-16 21:22:36 -07004965 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004966 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004967 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004968 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004969 }
4970
Jeff Brown037c33e2014-04-09 00:31:55 -07004971 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004972 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004973 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4974 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004975 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004976 // When the device is interactive or the key is injected pass the
4977 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004978 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004979 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004980 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4981 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4982 // to the application but preserve its wake key status to make sure we still move
4983 // from dozing to fully interactive if we would normally go from off to fully
4984 // interactive.
4985 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004986 } else {
4987 // When the screen is off and the key is not injected, determine whether
4988 // to wake the device but don't pass the key to the application.
4989 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004990 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4991 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004992 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004993 }
4994
Justin Kohd378ad72013-04-01 12:18:26 -07004995 // If the key would be handled globally, just return the result, don't worry about special
4996 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004997 if (isValidGlobalKey(keyCode)
4998 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004999 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005000 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Michael Wright85b1af62014-06-04 14:51:58 -07005001 }
Justin Kohd378ad72013-04-01 12:18:26 -07005002 return result;
5003 }
5004
Jeff Brownbae8e772014-06-12 19:59:45 -07005005 boolean useHapticFeedback = down
5006 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
5007 && event.getRepeatCount() == 0;
5008
Jeff Brown4d396052010-10-29 21:50:21 -07005009 // Handle special keys.
5010 switch (keyCode) {
5011 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07005012 case KeyEvent.KEYCODE_VOLUME_UP:
5013 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08005014 if (mUseTvRouting) {
5015 // On TVs volume keys never go to the foreground app
5016 result &= ~ACTION_PASS_TO_USER;
5017 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005018 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
5019 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005020 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005021 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005022 mScreenshotChordVolumeDownKeyTriggered = true;
5023 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
5024 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005025 cancelPendingPowerKeyAction();
5026 interceptScreenshotChord();
5027 }
5028 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005029 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005030 cancelPendingScreenshotChordAction();
5031 }
5032 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
5033 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005034 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005035 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005036 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005037 cancelPendingPowerKeyAction();
5038 cancelPendingScreenshotChordAction();
5039 }
5040 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005041 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005042 cancelPendingScreenshotChordAction();
5043 }
5044 }
Jeff Brown4d396052010-10-29 21:50:21 -07005045 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005046 TelecomManager telecomManager = getTelecommService();
5047 if (telecomManager != null) {
5048 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005049 // If an incoming call is ringing, either VOLUME key means
5050 // "silence ringer". We handle these keys here, rather than
5051 // in the InCallScreen, to make sure we'll respond to them
5052 // even if the InCallScreen hasn't come to the foreground yet.
5053 // Look for the DOWN event here, to agree with the "fallback"
5054 // behavior in the InCallScreen.
5055 Log.i(TAG, "interceptKeyBeforeQueueing:"
5056 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07005057
Santos Cordon6848f722014-05-21 15:22:12 -07005058 // Silence the ringer. (It's safe to call this
5059 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005060 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07005061
Santos Cordon6848f722014-05-21 15:22:12 -07005062 // And *don't* pass this key thru to the current activity
5063 // (which is probably the InCallScreen.)
5064 result &= ~ACTION_PASS_TO_USER;
5065 break;
5066 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005067 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07005068 && (result & ACTION_PASS_TO_USER) == 0) {
5069 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07005070 // the application, just pass it to the session service.
5071
5072 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07005073 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07005074 break;
Jeff Brown4d396052010-10-29 21:50:21 -07005075 }
5076 }
5077
RoboErik430fc482014-06-12 15:49:20 -07005078 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08005079 if (mUseTvRouting) {
5080 dispatchDirectAudioEvent(event);
5081 } else {
5082 // If we aren't passing to the user and no one else
5083 // handled it send it to the session manager to
5084 // figure out.
5085 MediaSessionLegacyHelper.getHelper(mContext)
5086 .sendVolumeKeyEvent(event, true);
5087 }
Jeff Brown4d396052010-10-29 21:50:21 -07005088 break;
5089 }
5090 }
5091 break;
5092 }
5093
5094 case KeyEvent.KEYCODE_ENDCALL: {
5095 result &= ~ACTION_PASS_TO_USER;
5096 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005097 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07005098 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005099 if (telecomManager != null) {
5100 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07005101 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005102 if (interactive && !hungUp) {
5103 mEndCallKeyHandled = false;
5104 mHandler.postDelayed(mEndCallLongPress,
5105 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
5106 } else {
5107 mEndCallKeyHandled = true;
5108 }
Jeff Brown4d396052010-10-29 21:50:21 -07005109 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005110 if (!mEndCallKeyHandled) {
5111 mHandler.removeCallbacks(mEndCallLongPress);
5112 if (!canceled) {
5113 if ((mEndcallBehavior
5114 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
5115 if (goHome()) {
5116 break;
5117 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07005118 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005119 if ((mEndcallBehavior
5120 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
5121 mPowerManager.goToSleep(event.getEventTime(),
5122 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
5123 isWakeKey = false;
5124 }
Jeff Brown4d396052010-10-29 21:50:21 -07005125 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005126 }
Jeff Brown4d396052010-10-29 21:50:21 -07005127 }
5128 break;
5129 }
5130
5131 case KeyEvent.KEYCODE_POWER: {
5132 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07005133 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07005134 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005135 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005136 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005137 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07005138 }
5139 break;
5140 }
5141
Jeff Brown6212a492014-03-07 13:58:47 -08005142 case KeyEvent.KEYCODE_SLEEP: {
5143 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005144 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07005145 if (!mPowerManager.isInteractive()) {
5146 useHapticFeedback = false; // suppress feedback if already non-interactive
5147 }
Nick Vaccarob593a812015-05-15 11:23:05 -07005148 if (down) {
5149 sleepPress(event.getEventTime());
5150 } else {
5151 sleepRelease(event.getEventTime());
5152 }
Jeff Brown6212a492014-03-07 13:58:47 -08005153 break;
5154 }
5155
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -07005156 case KeyEvent.KEYCODE_SOFT_SLEEP: {
5157 result &= ~ACTION_PASS_TO_USER;
5158 isWakeKey = false;
5159 if (!down) {
5160 mPowerManagerInternal.setUserInactiveOverrideFromWindowManager();
5161 }
5162 break;
5163 }
5164
Jeff Brown6212a492014-03-07 13:58:47 -08005165 case KeyEvent.KEYCODE_WAKEUP: {
5166 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005167 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08005168 break;
5169 }
5170
Jeff Brown4d396052010-10-29 21:50:21 -07005171 case KeyEvent.KEYCODE_MEDIA_PLAY:
5172 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5173 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07005174 case KeyEvent.KEYCODE_HEADSETHOOK:
5175 case KeyEvent.KEYCODE_MUTE:
5176 case KeyEvent.KEYCODE_MEDIA_STOP:
5177 case KeyEvent.KEYCODE_MEDIA_NEXT:
5178 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5179 case KeyEvent.KEYCODE_MEDIA_REWIND:
5180 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005181 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
5182 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07005183 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
5184 // If the global session is active pass all media keys to it
5185 // instead of the active window.
5186 result &= ~ACTION_PASS_TO_USER;
5187 }
Jeff Brown4d396052010-10-29 21:50:21 -07005188 if ((result & ACTION_PASS_TO_USER) == 0) {
5189 // Only do this if we would otherwise not pass it to the user. In that
5190 // case, the PhoneWindow class will do the same thing, except it will
5191 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07005192 // Note that we need to make a copy of the key event here because the
5193 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07005194 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07005195 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
5196 new KeyEvent(event));
5197 msg.setAsynchronous(true);
5198 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005199 }
5200 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005201 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005202
Jeff Brown4d396052010-10-29 21:50:21 -07005203 case KeyEvent.KEYCODE_CALL: {
5204 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005205 TelecomManager telecomManager = getTelecommService();
5206 if (telecomManager != null) {
5207 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005208 Log.i(TAG, "interceptKeyBeforeQueueing:"
5209 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005210 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005211
Santos Cordon6848f722014-05-21 15:22:12 -07005212 // And *don't* pass this key thru to the current activity
5213 // (which is presumably the InCallScreen.)
5214 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005215 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005216 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005217 }
Jeff Brown4d396052010-10-29 21:50:21 -07005218 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005219 }
Michael Wright869a67c2014-08-26 19:33:06 -07005220 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5221 // Only do this if we would otherwise not pass it to the user. In that case,
5222 // interceptKeyBeforeDispatching would apply a similar but different policy in
5223 // order to invoke voice assist actions. Note that we need to make a copy of the
5224 // key event here because the original key event will be recycled when we return.
5225 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5226 mBroadcastWakeLock.acquire();
5227 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5228 keyguardActive ? 1 : 0, 0);
5229 msg.setAsynchronous(true);
5230 msg.sendToTarget();
5231 }
5232 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005233 }
Jeff Brown26875502014-01-30 21:47:47 -08005234
Jeff Brownbae8e772014-06-12 19:59:45 -07005235 if (useHapticFeedback) {
5236 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5237 }
5238
Jeff Brown26875502014-01-30 21:47:47 -08005239 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005240 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Jeff Brown26875502014-01-30 21:47:47 -08005241 }
Bryce Lee584a4452014-10-21 15:55:55 -07005242
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005243 return result;
5244 }
5245
Jeff Brown1c2e4942012-11-06 16:32:01 -08005246 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005247 * Returns true if the key can have global actions attached to it.
5248 * We reserve all power management keys for the system since they require
5249 * very careful handling.
5250 */
5251 private static boolean isValidGlobalKey(int keyCode) {
5252 switch (keyCode) {
5253 case KeyEvent.KEYCODE_POWER:
5254 case KeyEvent.KEYCODE_WAKEUP:
5255 case KeyEvent.KEYCODE_SLEEP:
5256 return false;
5257 default:
5258 return true;
5259 }
5260 }
5261
5262 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005263 * When the screen is off we ignore some keys that might otherwise typically
5264 * be considered wake keys. We filter them out here.
5265 *
5266 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5267 * is always considered a wake key.
5268 */
5269 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5270 switch (keyCode) {
5271 // ignore volume keys unless docked
5272 case KeyEvent.KEYCODE_VOLUME_UP:
5273 case KeyEvent.KEYCODE_VOLUME_DOWN:
5274 case KeyEvent.KEYCODE_VOLUME_MUTE:
5275 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5276
5277 // ignore media and camera keys
5278 case KeyEvent.KEYCODE_MUTE:
5279 case KeyEvent.KEYCODE_HEADSETHOOK:
5280 case KeyEvent.KEYCODE_MEDIA_PLAY:
5281 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5282 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5283 case KeyEvent.KEYCODE_MEDIA_STOP:
5284 case KeyEvent.KEYCODE_MEDIA_NEXT:
5285 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5286 case KeyEvent.KEYCODE_MEDIA_REWIND:
5287 case KeyEvent.KEYCODE_MEDIA_RECORD:
5288 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005289 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005290 case KeyEvent.KEYCODE_CAMERA:
5291 return false;
5292 }
5293 return true;
5294 }
5295
5296
Jeff Brown56194eb2011-03-02 19:23:13 -08005297 /** {@inheritDoc} */
5298 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005299 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5300 if ((policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005301 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion,
5302 "android.policy:MOTION")) {
Bryce Lee5c138322014-11-03 08:26:09 -08005303 return 0;
5304 }
Michael Wright70af00a2014-09-03 19:30:20 -07005305 }
Bryce Lee5c138322014-11-03 08:26:09 -08005306
Michael Wright70af00a2014-09-03 19:30:20 -07005307 if (shouldDispatchInputWhenNonInteractive()) {
5308 return ACTION_PASS_TO_USER;
5309 }
Bryce Lee5c138322014-11-03 08:26:09 -08005310
Bryce Lee812d7022014-11-10 13:33:28 -08005311 // If we have not passed the action up and we are in theater mode without dreaming,
5312 // there will be no dream to intercept the touch and wake into ambient. The device should
5313 // wake up in this case.
5314 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005315 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming,
5316 "android.policy:MOTION");
Bryce Lee812d7022014-11-10 13:33:28 -08005317 }
5318
Jeff Brown037c33e2014-04-09 00:31:55 -07005319 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005320 }
5321
Michael Wright70af00a2014-09-03 19:30:20 -07005322 private boolean shouldDispatchInputWhenNonInteractive() {
Joe LaPennaf2b9b2d2015-11-17 22:22:37 +00005323 // Send events to keyguard while the screen is on.
5324 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5325 && mDisplay.getState() != Display.STATE_OFF) {
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
Keun-young Park3b741e02015-12-03 02:11:00 +00006407 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
Daniel Sandler6396c722013-04-16 20:19:09 -04006408 * <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) {
Keun-young Park3b741e02015-12-03 02:11:00 +00006421 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
Daniel Sandler6396c722013-04-16 20:19:09 -04006422 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}