blob: e51a2e1aa526d7d1c971117925c411f88746d791 [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;
Jorim Jaggi86905582016-02-09 21:36:09 -080021import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
22import static android.app.ActivityManager.StackId.HOME_STACK_ID;
Jaewan Kim49117872016-01-19 17:24:08 +090023import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE;
24import static android.content.pm.PackageManager.FEATURE_TELEVISION;
25import static android.content.pm.PackageManager.FEATURE_WATCH;
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -080026import static android.content.res.Configuration.UI_MODE_TYPE_CAR;
27import static android.content.res.Configuration.UI_MODE_TYPE_MASK;
Jorim Jaggi5060bd82016-02-19 17:12:19 -080028import static android.view.WindowManager.DOCKED_TOP;
29import static android.view.WindowManager.DOCKED_LEFT;
30import static android.view.WindowManager.DOCKED_RIGHT;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070031import static android.view.WindowManager.LayoutParams.*;
Jaewan Kim49117872016-01-19 17:24:08 +090032import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070033import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
34import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
Jaewan Kim49117872016-01-19 17:24:08 +090035import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
36import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
37import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070038
Svet Ganov9cea80cd2016-02-16 11:47:00 -080039import android.Manifest;
Dianne Hackborna4972e92012-03-14 10:38:05 -070040import android.app.ActivityManager;
Jorim Jaggi86905582016-02-09 21:36:09 -080041import android.app.ActivityManager.StackId;
Jeff Brown061ea992015-04-17 19:55:47 -070042import android.app.ActivityManagerInternal;
43import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080044import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080045import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040046import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070047import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070048import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040049import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080050import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070051import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080052import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040053import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080054import android.content.ContentResolver;
55import android.content.Context;
56import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070057import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070058import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080059import android.content.pm.ActivityInfo;
Svet Ganov03f2afc2016-03-04 16:13:03 -080060import android.content.pm.ApplicationInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080061import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040062import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070063import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080064import android.content.res.Configuration;
65import android.content.res.Resources;
66import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080067import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080068import android.graphics.Rect;
Jinsuk Kime601b712015-07-07 08:01:02 +090069import android.hardware.hdmi.HdmiControlManager;
70import android.hardware.hdmi.HdmiPlaybackClient;
71import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback;
John Spurlock7b414672014-07-18 13:02:39 -040072import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080073import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050074import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080075import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070076import android.media.Ringtone;
77import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070078import android.media.session.MediaSessionLegacyHelper;
Billy Laucbe540f2015-06-25 01:51:44 +010079import android.os.Binder;
Svet Ganov03f2afc2016-03-04 16:13:03 -080080import android.os.Build;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070081import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080082import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070083import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080084import android.os.Handler;
85import android.os.IBinder;
Dianne Hackbornb6683c42015-06-18 17:40:33 -070086import android.os.IDeviceIdleController;
Jeff Brown32cbc38552011-12-01 14:01:49 -080087import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070088import android.os.Message;
89import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080090import android.os.PowerManager;
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -070091import android.os.PowerManagerInternal;
Billy Laucbe540f2015-06-25 01:51:44 +010092import android.os.Process;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080093import android.os.RemoteException;
94import android.os.ServiceManager;
95import android.os.SystemClock;
96import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080097import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070098import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080099import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -0700100import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800101import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -0700102import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -0400103import android.service.dreams.DreamService;
104import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -0700105import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700106import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700107import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800108import android.util.EventLog;
109import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -0700110import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -0800111import android.util.SparseArray;
Muyuan Li94ce94e2016-02-24 16:20:54 -0800112import android.util.LongSparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700113import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800114import android.view.Gravity;
115import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800116import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800117import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -0700118import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -0700119import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -0800120import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800121import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -0800122import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -0800123import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800124import android.view.KeyEvent;
125import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800126import android.view.Surface;
127import android.view.View;
128import android.view.ViewConfiguration;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800129import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800130import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700131import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800132import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800133import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800134import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800135import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200136import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800137import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800138import com.android.internal.R;
Jason Monk8f7f3182015-11-18 16:35:14 -0500139import com.android.internal.logging.MetricsLogger;
140import com.android.internal.policy.PhoneWindow;
Muyuan Li94ce94e2016-02-24 16:20:54 -0800141import com.android.internal.policy.IShortcutService;
Craig Mautnerae446592012-12-06 19:05:05 -0800142import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700143import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800144import com.android.internal.widget.PointerLocationView;
Adrian Roos5941c982015-09-03 15:59:49 -0700145import com.android.server.GestureLauncherService;
Craig Mautner8a0da012014-05-31 15:13:37 -0700146import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100147import com.android.server.policy.keyguard.KeyguardServiceDelegate;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700148import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
Jorim Jaggi86905582016-02-09 21:36:09 -0800149import com.android.server.statusbar.StatusBarManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800150
151import java.io.File;
152import java.io.FileReader;
153import java.io.IOException;
154import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700155import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800156import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800157
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800158/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700159 * WindowManagerPolicy implementation for the Android phone UI. This
160 * introduces a new method suffix, Lp, for an internal lock of the
161 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400162 * 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 -0700163 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800164 */
165public class PhoneWindowManager implements WindowManagerPolicy {
166 static final String TAG = "WindowManager";
167 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700168 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700169 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700170 static final boolean DEBUG_KEYGUARD = false;
171 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700172 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700173 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800174 static final boolean SHOW_STARTING_ANIMATIONS = true;
175 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400176
Daniel Sandler6396c722013-04-16 20:19:09 -0400177 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
keunyounga7710492015-09-23 11:33:58 -0700178 // No longer recommended for desk docks;
Daniel Sandler6396c722013-04-16 20:19:09 -0400179 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
180
Jeff Brown6d8fd272014-05-20 21:24:38 -0700181 static final int SHORT_PRESS_POWER_NOTHING = 0;
182 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
183 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
184 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800185 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700186
Joe Onoratod208e702010-10-08 16:22:43 -0400187 static final int LONG_PRESS_POWER_NOTHING = 0;
188 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
189 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700190 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700191
Jeff Brown13f00f02014-10-31 14:45:50 -0700192 static final int MULTI_PRESS_POWER_NOTHING = 0;
193 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
194 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
195
Michael Jurka3b1fc472011-06-13 10:54:40 -0700196 // These need to match the documentation/constant in
197 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800198 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800199 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700200 static final int LONG_PRESS_HOME_ASSIST = 2;
Jaewan Kim76b7d0d2016-02-12 19:01:02 +0900201 static final int LAST_LONG_PRESS_HOME_BEHAVIOR = LONG_PRESS_HOME_ASSIST;
Jeff Browncaca8812013-05-09 13:34:33 -0700202
203 static final int DOUBLE_TAP_HOME_NOTHING = 0;
204 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800205
Jaewan Kim49117872016-01-19 17:24:08 +0900206 static final int SHORT_PRESS_WINDOW_NOTHING = 0;
207 static final int SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE = 1;
208
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000209 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
210 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
211
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700212 static final int APPLICATION_MEDIA_SUBLAYER = -2;
213 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800214 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800215 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700216 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700217
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800218 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
219 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
220 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500221 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700222 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800223
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700224 /**
225 * These are the system UI flags that, when changing, can cause the layout
226 * of the screen to change.
227 */
228 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400229 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400230 | View.SYSTEM_UI_FLAG_FULLSCREEN
231 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200232 | View.NAVIGATION_BAR_TRANSLUCENT
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800233 | View.STATUS_BAR_TRANSPARENT
234 | View.NAVIGATION_BAR_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700235
John Spurlock7b414672014-07-18 13:02:39 -0400236 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
237 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
238 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
239 .build();
240
Adrian Roosddc8b272015-05-21 16:28:27 -0700241 // The panic gesture may become active only after the keyguard is dismissed and the immersive
242 // app shows again. If that doesn't happen for 30s we drop the gesture.
243 private static final long PANIC_GESTURE_EXPIRATION = 30000;
244
Jim Miller5ecd8112013-01-09 18:50:26 -0800245 /**
246 * Keyguard stuff
247 */
248 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100249 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700250 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800251
Jeff Brown6651a632011-11-28 12:59:11 -0800252 /* Table of Application Launch keys. Maps from key codes to intent categories.
253 *
254 * These are special keys that are used to launch particular kinds of applications,
255 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
256 * usage page. We don't support quite that many yet...
257 */
258 static SparseArray<String> sApplicationLaunchKeyCategories;
259 static {
260 sApplicationLaunchKeyCategories = new SparseArray<String>();
261 sApplicationLaunchKeyCategories.append(
262 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
263 sApplicationLaunchKeyCategories.append(
264 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
265 sApplicationLaunchKeyCategories.append(
266 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
267 sApplicationLaunchKeyCategories.append(
268 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
269 sApplicationLaunchKeyCategories.append(
270 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
271 sApplicationLaunchKeyCategories.append(
272 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
273 }
274
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700275 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700276 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700277
Dianne Hackborndf89e652011-10-06 22:35:11 -0700278 /**
279 * Lock protecting internal state. Must not call out into window
280 * manager with lock held. (This lock will be acquired in places
281 * where the window manager is calling in with its own lock held.)
282 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800283 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700284
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800285 Context mContext;
286 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700287 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700288 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700289 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700290 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700291 DreamManagerInternal mDreamManagerInternal;
Michael Wrighta4d22d72015-09-16 23:19:26 +0100292 PowerManagerInternal mPowerManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400293 IStatusBarService mStatusBarService;
Jorim Jaggi86905582016-02-09 21:36:09 -0800294 StatusBarManagerInternal mStatusBarManagerInternal;
Jeff Browncaca8812013-05-09 13:34:33 -0700295 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700296 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800297 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700298 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800299 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000300 BurnInProtectionHelper mBurnInProtectionHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100301 AppOpsManager mAppOpsManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800302
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700303 // Vibrator pattern for haptic feedback of a long press.
304 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700305
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700306 // Vibrator pattern for haptic feedback of virtual key press.
307 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700308
Amith Yamasanic33cb712010-02-10 15:21:49 -0800309 // Vibrator pattern for a short vibration.
310 long[] mKeyboardTapVibePattern;
311
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700312 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
313 long[] mClockTickVibePattern;
314
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700315 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
316 long[] mCalendarDateVibePattern;
317
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700318 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
319 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700320
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700321 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
322 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700323
Mady Mellore8608912015-06-05 09:02:55 -0700324 // Vibrator pattern for haptic feedback of a context click.
325 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700326
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800327 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
328 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400329
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800330 boolean mSafeMode;
331 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700332 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400333 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400334 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700335 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400336 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
337 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -0800338 int[] mNavigationBarHeightForRotationDefault = new int[4];
339 int[] mNavigationBarWidthForRotationDefault = new int[4];
340 int[] mNavigationBarHeightForRotationInCarMode = new int[4];
341 int[] mNavigationBarWidthForRotationInCarMode = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400342
Muyuan Li94ce94e2016-02-24 16:20:54 -0800343 private LongSparseArray<IShortcutService> mShortcutKeyServices = new LongSparseArray<>();
344
keunyounga7710492015-09-23 11:33:58 -0700345 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
346 // This is for car dock and this is updated from resource.
347 private boolean mEnableCarDockHomeCapture = true;
348
Craig Mautnera631d492014-08-05 15:16:01 -0700349 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800350 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700351 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700352 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700353 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700354 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
355 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
356 }
357 };
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700358 final DrawnListener mKeyguardDrawnCallback = new DrawnListener() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700359 @Override
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700360 public void onDrawn() {
361 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn.");
Craig Mautner8a0da012014-05-31 15:13:37 -0700362 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
363 }
364 };
365
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800366 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800367 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900368 WindowState mLastInputMethodWindow = null;
369 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800370
Jeff Brown13f00f02014-10-31 14:45:50 -0700371 // FIXME This state is shared between the input reader and handler thread.
372 // Technically it's broken and buggy but it has been like this for many years
373 // and we have not yet seen any problems. Someday we'll rewrite this logic
374 // so that only one thread is involved in handling input policy. Unfortunately
375 // it's on a critical path for power management so we can't just post the work to the
376 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
377 // to hold wakelocks during dispatch and eliminating the critical path.
378 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800379 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700380 volatile int mPowerKeyPressCounter;
381 volatile boolean mEndCallKeyHandled;
382
Winson Chungd42a6cf2014-06-03 16:24:04 -0700383 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700384 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700385 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800386
Jeff Brown2e7760e2012-04-11 15:14:55 -0700387 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700388 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700389 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800390
Dianne Hackbornc777e072010-02-12 13:07:59 -0800391 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700392 boolean mSystemBooted;
Adrian Roos3542f7d2015-07-13 15:57:53 -0700393 private boolean mDeferBindKeyguard;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800394 boolean mHdmiPlugged;
Jinsuk Kime601b712015-07-07 08:01:02 +0900395 HdmiControl mHdmiControl;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700396 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400397 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700398 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700399 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400400 int mCarDockRotation;
401 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700402 int mUndockedHdmiRotation;
403 int mDemoHdmiRotation;
404 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800405 int mDemoRotation;
406 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400407
Jeff Browna20dda42014-05-27 20:57:24 -0700408 boolean mWakeGestureEnabledSetting;
409 MyWakeGestureListener mWakeGestureListener;
410
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700411 // Default display does not rotate, apps that require non-default orientation will have to
412 // have the orientation emulated.
413 private boolean mForceDefaultOrientation = false;
414
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400415 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
416 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700417 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400418
Jeff Brownbcdfc622014-03-06 19:13:04 -0800419 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700420 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400421 boolean mCarDockEnablesAccelerometer;
422 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700423 int mLidKeyboardAccessibility;
424 int mLidNavigationAccessibility;
Edward Savage-Jones7def60d2015-11-13 13:27:03 +0100425 boolean mLidControlsScreenLock;
Jeff Brownc458ce92012-04-30 14:58:40 -0700426 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700427 int mShortPressOnPowerBehavior;
428 int mLongPressOnPowerBehavior;
429 int mDoublePressOnPowerBehavior;
430 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000431 int mShortPressOnSleepBehavior;
Jaewan Kim49117872016-01-19 17:24:08 +0900432 int mShortPressWindowBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700433 boolean mAwake;
434 boolean mScreenOnEarly;
435 boolean mScreenOnFully;
436 ScreenOnListener mScreenOnListener;
437 boolean mKeyguardDrawComplete;
438 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800439 boolean mOrientationSensorEnabled = false;
440 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800441 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400442 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800443 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700444
Jeff Brown70825162012-03-28 17:27:48 -0700445 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800446
447 // The last window we were told about in focusChanged.
448 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800449 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800450
Jeff Brown70825162012-03-28 17:27:48 -0700451 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800452
Dianne Hackbornc652de82013-02-15 16:32:56 -0800453 // The current size of the screen; really; extends into the overscan area of
454 // the screen and doesn't account for any system elements like the status bar.
455 int mOverscanScreenLeft, mOverscanScreenTop;
456 int mOverscanScreenWidth, mOverscanScreenHeight;
457 // The current visible size of the screen; really; (ir)regardless of whether the status
458 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800459 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
460 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800461 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
462 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
463 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700464 // The current size of the screen; these may be different than (0,0)-(dw,dh)
465 // if the status bar can't be hidden; in that case it effectively carves out
466 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800467 int mRestrictedScreenLeft, mRestrictedScreenTop;
468 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700469 // During layout, the current screen borders accounting for any currently
470 // visible system UI elements.
471 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700472 // For applications requesting stable content insets, these are them.
473 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700474 // For applications requesting stable content insets but have also set the
475 // fullscreen window flag, these are the stable dimensions without the status bar.
476 int mStableFullscreenLeft, mStableFullscreenTop;
477 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800478 // During layout, the current screen borders with all outer decoration
479 // (status bar, input method dock) accounted for.
480 int mCurLeft, mCurTop, mCurRight, mCurBottom;
481 // During layout, the frame in which content should be displayed
482 // to the user, accounting for all screen decoration except for any
483 // space they deem as available for other content. This is usually
484 // the same as mCur*, but may be larger if the screen decor has supplied
485 // content insets.
486 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700487 // During layout, the frame in which voice content should be displayed
488 // to the user, accounting for all screen decoration except for any
489 // space they deem as available for other content.
490 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800491 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800492 // windows are placed.
493 int mDockLeft, mDockTop, mDockRight, mDockBottom;
494 // During layout, the layer at which the doc window is placed.
495 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700496 // During layout, this is the layer of the status bar.
497 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700498 int mLastSystemUiFlags;
499 // Bits that we are in the process of clearing, so we want to prevent
500 // them from being set by applications until everything has been updated
501 // to have them clear.
502 int mResettingSystemUiFlags = 0;
503 // Bits that we are currently always keeping cleared.
504 int mForceClearedSystemUiFlags = 0;
Jorim Jaggi86905582016-02-09 21:36:09 -0800505 int mLastFullscreenStackSysUiFlags;
506 int mLastDockedStackSysUiFlags;
507 final Rect mNonDockedStackBounds = new Rect();
508 final Rect mDockedStackBounds = new Rect();
509 final Rect mLastNonDockedStackBounds = new Rect();
510 final Rect mLastDockedStackBounds = new Rect();
511
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800512 // What we last reported to system UI about whether the compatibility
513 // menu needs to be displayed.
514 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700515 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
516 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700517
Selim Cinekf83e8242015-05-19 18:08:14 -0700518 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700519
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800520 static final Rect mTmpParentFrame = new Rect();
521 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800522 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800523 static final Rect mTmpContentFrame = new Rect();
524 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400525 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700526 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700527 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700528 static final Rect mTmpOutsetFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700529
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800530 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100531 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Jorim Jaggi86905582016-02-09 21:36:09 -0800532 WindowState mTopDockedOpaqueWindowState;
533 WindowState mTopDockedOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700534 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200535 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400536 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800537 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700538 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700539 private boolean mForceStatusBarTransparent;
Yorke Lee2e4b7322016-03-02 17:33:06 -0800540 boolean mForceNavBarOpaque;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700541 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800542 boolean mForcingShowNavBar;
543 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700544
545 // States of keyguard dismiss.
546 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
547 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
548 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
549 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
550
551 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
552 * be done once per window. */
553 private WindowState mWinDismissingKeyguard;
554
tingna_sunge785ffa2015-05-12 13:23:15 +0800555 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
556 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
557 * lock SIM card. This variable is used to record the previous keyguard secure state for
558 * monitoring secure state change on window dismissing keyguard. */
559 private boolean mSecureDismissingKeyguard;
560
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700561 /** The window that is currently showing "over" the keyguard. If there is an app window
562 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
563 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
564 * the wallpaper. */
565 private WindowState mWinShowWhenLocked;
566
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700567 boolean mShowingLockscreen;
568 boolean mShowingDream;
569 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700570 boolean mDreamingSleepTokenNeeded;
571 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700572 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700573 boolean mKeyguardSecure;
574 boolean mKeyguardSecureIncludingHidden;
575 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800576 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700577 boolean mHomeConsumed;
578 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800579 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700580 Intent mCarDockIntent;
581 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700582 boolean mSearchKeyShortcutPending;
583 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700584 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700585 boolean mPendingMetaAction;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -0800586 boolean mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800587
Mike Lockwood28569302010-01-28 11:54:40 -0500588 // support for activating the lock screen while the screen is on
589 boolean mAllowLockscreenWhenOn;
590 int mLockScreenTimeout;
591 boolean mLockScreenTimerActive;
592
David Brownbaf8d092010-03-08 21:52:59 -0800593 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800594 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800595
596 // Behavior of POWER button while in-call and screen on.
597 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
598 int mIncallPowerBehavior;
599
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700600 Display mDisplay;
601
Filip Gruszczynski2987f612015-06-30 15:03:30 -0700602 private int mDisplayRotation;
603
Dianne Hackborn9d132642011-04-21 17:26:39 -0700604 int mLandscapeRotation = 0; // default landscape rotation
605 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
606 int mPortraitRotation = 0; // default portrait rotation
607 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700608
Dianne Hackbornc652de82013-02-15 16:32:56 -0800609 int mOverscanLeft = 0;
610 int mOverscanTop = 0;
611 int mOverscanRight = 0;
612 int mOverscanBottom = 0;
613
Joe Onorato46b0d682010-11-22 17:37:27 -0800614 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700615 private int mLongPressOnHomeBehavior;
616
617 // What we do when the user double-taps on home
618 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800619
Bryce Lee584a4452014-10-21 15:55:55 -0700620 // Allowed theater mode wake actions
621 private boolean mAllowTheaterModeWakeFromKey;
622 private boolean mAllowTheaterModeWakeFromPowerKey;
623 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800624 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700625 private boolean mAllowTheaterModeWakeFromCameraLens;
626 private boolean mAllowTheaterModeWakeFromLidSwitch;
627 private boolean mAllowTheaterModeWakeFromWakeGesture;
628
Bryce Leed3b28402015-03-09 15:49:13 +0000629 // Whether to support long press from power button in non-interactive mode
630 private boolean mSupportLongPressPowerWhenNonInteractive;
631
Bryce Lee55e846d2014-11-04 12:43:44 -0800632 // Whether to go to sleep entering theater mode from power button
633 private boolean mGoToSleepOnButtonPressTheaterMode;
634
Winson Chung9112ec32011-06-27 13:15:32 -0700635 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700636 // Time to volume and power must be pressed within this interval of each other.
637 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700638 // Increase the chord delay when taking a screenshot from the keyguard
639 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800640 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700641 private boolean mScreenshotChordVolumeDownKeyTriggered;
642 private long mScreenshotChordVolumeDownKeyTime;
643 private boolean mScreenshotChordVolumeDownKeyConsumed;
644 private boolean mScreenshotChordVolumeUpKeyTriggered;
645 private boolean mScreenshotChordPowerKeyTriggered;
646 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700647
Michael Wrightb854e242013-02-05 17:54:02 -0800648 /* The number of steps between min and max brightness */
649 private static final int BRIGHTNESS_STEPS = 10;
650
Christopher Tate5e08af02012-09-21 17:17:22 -0700651 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800652 ShortcutManager mShortcutManager;
653 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700654 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700655 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800656
Craig Mautnerd625ab22013-09-06 13:40:31 -0700657 private int mCurrentUserId;
658
Justin Kohd378ad72013-04-01 12:18:26 -0700659 // Maps global key codes to the components that will handle them.
660 private GlobalKeyManager mGlobalKeyManager;
661
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700662 // Fallback actions by key code.
663 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
664 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800665
Jorim Jaggi76a16232014-08-08 17:00:47 +0200666 private final LogDecelerateInterpolator mLogDecelerateInterpolator
667 = new LogDecelerateInterpolator(100, 0);
668
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800669 private boolean mForceWindowDrawsStatusBarBackground;
670
Jeff Brown70825162012-03-28 17:27:48 -0700671 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
672 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700673 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
674 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700675 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
676 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
677 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700678 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700679 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700680 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700681 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700682 private static final int MSG_POWER_DELAYED_PRESS = 13;
683 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700684 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700685 private static final int MSG_REQUEST_TRANSIENT_BARS = 16;
Jaewan Kimc552b042016-01-18 16:08:45 +0900686 private static final int MSG_REQUEST_TV_PICTURE_IN_PICTURE = 17;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700687
688 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
689 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
Jeff Brown70825162012-03-28 17:27:48 -0700690
691 private class PolicyHandler extends Handler {
692 @Override
693 public void handleMessage(Message msg) {
694 switch (msg.what) {
695 case MSG_ENABLE_POINTER_LOCATION:
696 enablePointerLocation();
697 break;
698 case MSG_DISABLE_POINTER_LOCATION:
699 disablePointerLocation();
700 break;
Jeff Brown40013652012-05-16 21:22:36 -0700701 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
702 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
703 break;
704 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
705 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
706 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700707 case MSG_DISPATCH_SHOW_RECENTS:
708 showRecentApps(false);
709 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700710 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
711 showGlobalActionsInternal();
712 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700713 case MSG_KEYGUARD_DRAWN_COMPLETE:
714 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700715 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700716 break;
717 case MSG_KEYGUARD_DRAWN_TIMEOUT:
718 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700719 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700720 break;
721 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
722 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700723 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700724 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700725 case MSG_HIDE_BOOT_MESSAGE:
726 handleHideBootMessage();
727 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700728 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
729 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
730 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700731 case MSG_POWER_DELAYED_PRESS:
732 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
733 finishPowerKeyPress();
734 break;
735 case MSG_POWER_LONG_PRESS:
736 powerLongPress();
737 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700738 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
739 updateDreamingSleepToken(msg.arg1 != 0);
740 break;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700741 case MSG_REQUEST_TRANSIENT_BARS:
742 WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ?
743 mStatusBar : mNavigationBar;
744 if (targetBar != null) {
745 requestTransientBars(targetBar);
746 }
747 break;
Jaewan Kimc552b042016-01-18 16:08:45 +0900748 case MSG_REQUEST_TV_PICTURE_IN_PICTURE:
749 requestTvPictureInPictureInternal();
750 break;
Jeff Brown70825162012-03-28 17:27:48 -0700751 }
752 }
753 }
754
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800755 private UEventObserver mHDMIObserver = new UEventObserver() {
756 @Override
757 public void onUEvent(UEventObserver.UEvent event) {
758 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
759 }
760 };
761
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800762 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800763 SettingsObserver(Handler handler) {
764 super(handler);
765 }
David Brownbaf8d092010-03-08 21:52:59 -0800766
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800767 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700768 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800769 ContentResolver resolver = mContext.getContentResolver();
770 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700771 Settings.System.END_BUTTON_BEHAVIOR), false, this,
772 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800773 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700774 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
775 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700776 resolver.registerContentObserver(Settings.Secure.getUriFor(
777 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
778 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800779 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700780 Settings.System.ACCELEROMETER_ROTATION), false, this,
781 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500782 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700783 Settings.System.USER_ROTATION), false, this,
784 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400785 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700786 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
787 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800788 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700789 Settings.System.POINTER_LOCATION), false, this,
790 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800791 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700792 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
793 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500794 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400795 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700796 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500797 resolver.registerContentObserver(Settings.Global.getUriFor(
798 Settings.Global.POLICY_CONTROL), false, this,
799 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800800 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800801 }
802
803 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800804 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700805 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800806 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800807 }
Craig Mautner967212c2013-04-13 21:10:58 -0700808
Jeff Browna20dda42014-05-27 20:57:24 -0700809 class MyWakeGestureListener extends WakeGestureListener {
810 MyWakeGestureListener(Context context, Handler handler) {
811 super(context, handler);
812 }
813
814 @Override
815 public void onWakeUp() {
816 synchronized (mLock) {
817 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700818 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700819 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture,
820 "android.policy:GESTURE");
Jeff Browna20dda42014-05-27 20:57:24 -0700821 }
822 }
823 }
824 }
825
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800826 class MyOrientationListener extends WindowOrientationListener {
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700827 private final Runnable mUpdateRotationRunnable = new Runnable() {
828 @Override
829 public void run() {
Tim Murray1f407642015-10-01 17:07:12 -0700830 // send interaction hint to improve redraw performance
831 mPowerManagerInternal.powerHint(PowerManagerInternal.POWER_HINT_INTERACTION, 0);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700832 updateRotation(false);
833 }
834 };
835
Craig Mautnereee29c42013-01-17 14:44:34 -0800836 MyOrientationListener(Context context, Handler handler) {
837 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800838 }
Craig Mautner967212c2013-04-13 21:10:58 -0700839
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800840 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700841 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700842 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700843 mHandler.post(mUpdateRotationRunnable);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700844 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800845 }
846 MyOrientationListener mOrientationListener;
847
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100848 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400849
John Spurlock27735a42013-08-14 17:57:38 -0400850 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400851 View.NAVIGATION_BAR_TRANSIENT,
852 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400853 View.NAVIGATION_BAR_TRANSLUCENT,
854 StatusBarManager.WINDOW_NAVIGATION_BAR,
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800855 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
856 View.NAVIGATION_BAR_TRANSPARENT);
John Spurlock5b9145b2013-08-20 15:13:47 -0400857
John Spurlockf1a36642013-10-12 17:50:42 -0400858 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400859
Craig Mautner037aa8d2013-06-07 10:35:44 -0700860 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400861
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700862 IStatusBarService getStatusBarService() {
863 synchronized (mServiceAquireLock) {
864 if (mStatusBarService == null) {
865 mStatusBarService = IStatusBarService.Stub.asInterface(
866 ServiceManager.getService("statusbar"));
867 }
868 return mStatusBarService;
869 }
870 }
871
Jorim Jaggi86905582016-02-09 21:36:09 -0800872 StatusBarManagerInternal getStatusBarManagerInternal() {
873 synchronized (mServiceAquireLock) {
874 if (mStatusBarManagerInternal == null) {
875 mStatusBarManagerInternal =
876 LocalServices.getService(StatusBarManagerInternal.class);
877 }
878 return mStatusBarManagerInternal;
879 }
880 }
881
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700882 /*
883 * We always let the sensor be switched on by default except when
884 * the user has explicitly disabled sensor based rotation or when the
885 * screen is switched off.
886 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700887 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800888 if (mSupportAutoRotation) {
889 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
890 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
891 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
892 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
893 // If the application has explicitly requested to follow the
894 // orientation, then we need to turn the sensor on.
895 return true;
896 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800897 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700898 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800899 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
900 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
901 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400902 // enable accelerometer if we are docked in a dock that enables accelerometer
903 // orientation management,
904 return true;
905 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700906 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800907 // If the setting for using the sensor by default is enabled, then
908 // we will always leave it on. Note that the user could go to
909 // a window that forces an orientation that does not use the
910 // sensor and in theory we could turn it off... however, when next
911 // turning it on we won't have a good value for the current
912 // orientation for a little bit, which can cause orientation
913 // changes to lag, so we'd like to keep it always on. (It will
914 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700915 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800916 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800917 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800918 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700919
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800920 /*
921 * Various use cases for invoking this function
922 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700923 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800924 * if not already enabled
925 * screen turned on and current app does not have sensor orientation, disable listeners if
926 * already enabled
927 * screen turning on and current app has sensor based orientation, enable listeners if needed
928 * screen turning on and current app has nosensor based orientation, do nothing
929 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700930 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800931 if (!mOrientationListener.canDetectOrientation()) {
932 // If sensor is turned off or nonexistent for some reason
933 return;
934 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000935 // Could have been invoked due to screen turning on or off or
936 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -0700937 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
938 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000939 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
940 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
941 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800942 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000943 // Note: We postpone the rotating of the screen until the keyguard as well as the
944 // window manager have reported a draw complete.
945 if (mScreenOnEarly && mAwake &&
946 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700947 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800948 disable = false;
949 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700950 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800951 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700952 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800953 mOrientationSensorEnabled = true;
954 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700955 }
956 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800957 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700958 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800959 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700960 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800961 mOrientationSensorEnabled = false;
962 }
963 }
964
Jeff Brown13f00f02014-10-31 14:45:50 -0700965 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
966 // Hold a wake lock until the power key is released.
967 if (!mPowerKeyWakeLock.isHeld()) {
968 mPowerKeyWakeLock.acquire();
969 }
970
971 // Cancel multi-press detection timeout.
972 if (mPowerKeyPressCounter != 0) {
973 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
974 }
975
976 // Detect user pressing the power button in panic when an application has
977 // taken over the whole screen.
978 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800979 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700980 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700981 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700982 }
983
984 // Latch power key state to detect screenshot chord.
985 if (interactive && !mScreenshotChordPowerKeyTriggered
986 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
987 mScreenshotChordPowerKeyTriggered = true;
988 mScreenshotChordPowerKeyTime = event.getDownTime();
989 interceptScreenshotChord();
990 }
991
992 // Stop ringing or end call if configured to do so when power is pressed.
993 TelecomManager telecomManager = getTelecommService();
994 boolean hungUp = false;
995 if (telecomManager != null) {
996 if (telecomManager.isRinging()) {
997 // Pressing Power while there's a ringing incoming
998 // call should silence the ringer.
999 telecomManager.silenceRinger();
1000 } else if ((mIncallPowerBehavior
1001 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
1002 && telecomManager.isInCall() && interactive) {
1003 // Otherwise, if "Power button ends call" is enabled,
1004 // the Power button will hang up any current active call.
1005 hungUp = telecomManager.endCall();
1006 }
1007 }
1008
Adrian Roos5941c982015-09-03 15:59:49 -07001009 GestureLauncherService gestureService = LocalServices.getService(
1010 GestureLauncherService.class);
1011 boolean gesturedServiceIntercepted = false;
1012 if (gestureService != null) {
1013 gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive);
1014 }
1015
Jeff Brown13f00f02014-10-31 14:45:50 -07001016 // If the power key has still not yet been handled, then detect short
1017 // press, long press, or multi press and decide what to do.
1018 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
Adrian Roos5941c982015-09-03 15:59:49 -07001019 || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted;
Jeff Brown13f00f02014-10-31 14:45:50 -07001020 if (!mPowerKeyHandled) {
1021 if (interactive) {
1022 // When interactive, we're already awake.
1023 // Wait for a long press or for the button to be released to decide what to do.
1024 if (hasLongPressOnPowerBehavior()) {
1025 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1026 msg.setAsynchronous(true);
1027 mHandler.sendMessageDelayed(msg,
1028 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
1029 }
1030 } else {
Bryce Leed9268e32014-11-17 17:40:59 -08001031 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -08001032
Bryce Leed3b28402015-03-09 15:49:13 +00001033 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
1034 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1035 msg.setAsynchronous(true);
1036 mHandler.sendMessageDelayed(msg,
1037 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -08001038 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +00001039 } else {
1040 final int maxCount = getMaxMultiPressPowerCount();
1041
1042 if (maxCount <= 1) {
1043 mPowerKeyHandled = true;
1044 } else {
1045 mBeganFromNonInteractive = true;
1046 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001047 }
1048 }
Jeff Brown4d396052010-10-29 21:50:21 -07001049 }
1050 }
1051
Jeff Brown13f00f02014-10-31 14:45:50 -07001052 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
1053 final boolean handled = canceled || mPowerKeyHandled;
1054 mScreenshotChordPowerKeyTriggered = false;
1055 cancelPendingScreenshotChordAction();
1056 cancelPendingPowerKeyAction();
1057
1058 if (!handled) {
1059 // Figure out how to handle the key now that it has been released.
1060 mPowerKeyPressCounter += 1;
1061
1062 final int maxCount = getMaxMultiPressPowerCount();
1063 final long eventTime = event.getDownTime();
1064 if (mPowerKeyPressCounter < maxCount) {
1065 // This could be a multi-press. Wait a little bit longer to confirm.
1066 // Continue holding the wake lock.
1067 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
1068 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
1069 msg.setAsynchronous(true);
1070 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
1071 return;
1072 }
1073
1074 // No other actions. Handle it immediately.
1075 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -07001076 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001077
1078 // Done. Reset our state.
1079 finishPowerKeyPress();
1080 }
1081
1082 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -08001083 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001084 mPowerKeyPressCounter = 0;
1085 if (mPowerKeyWakeLock.isHeld()) {
1086 mPowerKeyWakeLock.release();
1087 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001088 }
1089
1090 private void cancelPendingPowerKeyAction() {
1091 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001092 mPowerKeyHandled = true;
1093 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001094 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001095 }
1096
1097 private void powerPress(long eventTime, boolean interactive, int count) {
1098 if (mScreenOnEarly && !mScreenOnFully) {
1099 Slog.i(TAG, "Suppressed redundant power key press while "
1100 + "already in the process of turning the screen on.");
1101 return;
Jeff Brownff204712011-10-25 21:27:54 -07001102 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001103
1104 if (count == 2) {
1105 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1106 } else if (count == 3) {
1107 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001108 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001109 switch (mShortPressOnPowerBehavior) {
1110 case SHORT_PRESS_POWER_NOTHING:
1111 break;
1112 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1113 mPowerManager.goToSleep(eventTime,
1114 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1115 break;
1116 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1117 mPowerManager.goToSleep(eventTime,
1118 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1119 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1120 break;
1121 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1122 mPowerManager.goToSleep(eventTime,
1123 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1124 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1125 launchHomeFromHotKey();
1126 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001127 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001128 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001129 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001130 }
1131 }
1132 }
1133
1134 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1135 switch (behavior) {
1136 case MULTI_PRESS_POWER_NOTHING:
1137 break;
1138 case MULTI_PRESS_POWER_THEATER_MODE:
Bryce Lee3ae447e2015-06-30 12:31:41 -07001139 if (!isUserSetupComplete()) {
1140 Slog.i(TAG, "Ignoring toggling theater mode - device not setup.");
1141 break;
1142 }
1143
Jeff Brown13f00f02014-10-31 14:45:50 -07001144 if (isTheaterModeEnabled()) {
1145 Slog.i(TAG, "Toggling theater mode off.");
1146 Settings.Global.putInt(mContext.getContentResolver(),
1147 Settings.Global.THEATER_MODE_ON, 0);
1148 if (!interactive) {
1149 wakeUpFromPowerKey(eventTime);
1150 }
1151 } else {
1152 Slog.i(TAG, "Toggling theater mode on.");
1153 Settings.Global.putInt(mContext.getContentResolver(),
1154 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001155
1156 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001157 mPowerManager.goToSleep(eventTime,
1158 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1159 }
1160 }
1161 break;
1162 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001163 Slog.i(TAG, "Starting brightness boost.");
1164 if (!interactive) {
1165 wakeUpFromPowerKey(eventTime);
1166 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001167 mPowerManager.boostScreenBrightness(eventTime);
1168 break;
1169 }
1170 }
1171
1172 private int getMaxMultiPressPowerCount() {
1173 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1174 return 3;
1175 }
1176 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1177 return 2;
1178 }
1179 return 1;
1180 }
1181
1182 private void powerLongPress() {
1183 final int behavior = getResolvedLongPressOnPowerBehavior();
1184 switch (behavior) {
1185 case LONG_PRESS_POWER_NOTHING:
1186 break;
1187 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1188 mPowerKeyHandled = true;
1189 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1190 performAuditoryFeedbackForAccessibilityIfNeed();
1191 }
1192 showGlobalActionsInternal();
1193 break;
1194 case LONG_PRESS_POWER_SHUT_OFF:
1195 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1196 mPowerKeyHandled = true;
1197 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1198 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1199 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1200 break;
1201 }
1202 }
1203
Nick Vaccarob593a812015-05-15 11:23:05 -07001204 private void sleepPress(long eventTime) {
1205 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1206 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1207 }
1208 }
1209
1210 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001211 switch (mShortPressOnSleepBehavior) {
1212 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001213 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001214 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1215 mPowerManager.goToSleep(eventTime,
1216 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001217 break;
1218 }
1219 }
1220
Jeff Brown13f00f02014-10-31 14:45:50 -07001221 private int getResolvedLongPressOnPowerBehavior() {
1222 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1223 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1224 }
1225 return mLongPressOnPowerBehavior;
1226 }
1227
1228 private boolean hasLongPressOnPowerBehavior() {
1229 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001230 }
1231
1232 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001233 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001234 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1235 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001236 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001237 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1238 && now <= mScreenshotChordPowerKeyTime
1239 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1240 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001241 cancelPendingPowerKeyAction();
1242
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001243 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001244 }
1245 }
1246 }
1247
Winson Chung1cea2f32012-10-08 20:42:01 -07001248 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001249 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001250 // Double the time it takes to take a screenshot from the keyguard
1251 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001252 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001253 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001254 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001255 }
1256
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001257 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001258 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001259 }
1260
Jeff Brown13f00f02014-10-31 14:45:50 -07001261 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001262 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001263 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001264 mEndCallKeyHandled = true;
1265 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1266 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001267 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001268 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001269 }
1270 };
1271
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001272 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001273 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001274 public void run() {
1275 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001276 }
1277 };
1278
Alan Viverettee34560b22014-07-10 14:50:06 -07001279 @Override
1280 public void showGlobalActions() {
1281 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1282 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1283 }
1284
1285 void showGlobalActionsInternal() {
1286 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001287 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001288 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001289 }
Jim Millerab954542014-10-10 18:21:49 -07001290 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001291 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1292 if (keyguardShowing) {
1293 // since it took two seconds of long press to bring this up,
1294 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001295 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001296 }
1297 }
1298
1299 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001300 return Settings.Global.getInt(
1301 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001302 }
1303
Maurice Lam99c6e072014-04-28 18:24:28 -07001304 boolean isUserSetupComplete() {
1305 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1306 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1307 }
1308
Jeff Brown13f00f02014-10-31 14:45:50 -07001309 private void handleShortPressOnHome() {
Jinsuk Kime601b712015-07-07 08:01:02 +09001310 // Turn on the connected TV and switch HDMI input if we're a HDMI playback device.
1311 getHdmiControl().turnOnTv();
1312
Jeff Brown13f00f02014-10-31 14:45:50 -07001313 // If there's a dream running then use home to escape the dream
1314 // but don't actually go home.
1315 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1316 mDreamManagerInternal.stopDream(false /*immediate*/);
1317 return;
1318 }
1319
1320 // Go home!
1321 launchHomeFromHotKey();
1322 }
1323
Jinsuk Kime601b712015-07-07 08:01:02 +09001324 /**
1325 * Creates an accessor to HDMI control service that performs the operation of
1326 * turning on TV (optional) and switching input to us. If HDMI control service
1327 * is not available or we're not a HDMI playback device, the operation is no-op.
1328 */
1329 private HdmiControl getHdmiControl() {
1330 if (null == mHdmiControl) {
1331 HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService(
1332 Context.HDMI_CONTROL_SERVICE);
1333 HdmiPlaybackClient client = null;
1334 if (manager != null) {
1335 client = manager.getPlaybackClient();
1336 }
1337 mHdmiControl = new HdmiControl(client);
1338 }
1339 return mHdmiControl;
1340 }
1341
1342 private static class HdmiControl {
1343 private final HdmiPlaybackClient mClient;
1344
1345 private HdmiControl(HdmiPlaybackClient client) {
1346 mClient = client;
1347 }
1348
1349 public void turnOnTv() {
1350 if (mClient == null) {
1351 return;
1352 }
1353 mClient.oneTouchPlay(new OneTouchPlayCallback() {
1354 @Override
1355 public void onComplete(int result) {
1356 if (result != HdmiControlManager.RESULT_SUCCESS) {
1357 Log.w(TAG, "One touch play failed: " + result);
1358 }
1359 }
1360 });
1361 }
1362 }
1363
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001364 private void handleLongPressOnHome(int deviceId) {
Jaewan Kim52632e22016-01-14 18:01:52 +09001365 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) {
1366 return;
1367 }
1368 mHomeConsumed = true;
1369 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001370
Jaewan Kim52632e22016-01-14 18:01:52 +09001371 switch (mLongPressOnHomeBehavior) {
1372 case LONG_PRESS_HOME_RECENT_SYSTEM_UI:
Jeff Browncaca8812013-05-09 13:34:33 -07001373 toggleRecentApps();
Jaewan Kim52632e22016-01-14 18:01:52 +09001374 break;
1375 case LONG_PRESS_HOME_ASSIST:
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001376 launchAssistAction(null, deviceId);
Jaewan Kim52632e22016-01-14 18:01:52 +09001377 break;
Jaewan Kim52632e22016-01-14 18:01:52 +09001378 default:
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001379 Log.w(TAG, "Undefined home long press behavior: " + mLongPressOnHomeBehavior);
Jaewan Kim52632e22016-01-14 18:01:52 +09001380 break;
Jim Millere6ad1a82010-08-20 19:25:39 -07001381 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001382 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001383
Jeff Browncaca8812013-05-09 13:34:33 -07001384 private void handleDoubleTapOnHome() {
1385 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1386 mHomeConsumed = true;
1387 toggleRecentApps();
1388 }
1389 }
1390
Jaewan Kimc552b042016-01-18 16:08:45 +09001391 private void requestTvPictureInPicture(KeyEvent event) {
1392 if (DEBUG_INPUT) Log.d(TAG, "requestTvPictureInPicture event=" + event);
1393 mHandler.removeMessages(MSG_REQUEST_TV_PICTURE_IN_PICTURE);
1394 Message msg = mHandler.obtainMessage(MSG_REQUEST_TV_PICTURE_IN_PICTURE);
1395 msg.setAsynchronous(true);
1396 msg.sendToTarget();
1397 }
1398
1399 private void requestTvPictureInPictureInternal() {
1400 try {
1401 IStatusBarService statusbar = getStatusBarService();
1402 if (statusbar != null) {
1403 statusbar.requestTvPictureInPicture();
1404 }
1405 } catch (RemoteException|IllegalArgumentException e) {
1406 Slog.e(TAG, "Cannot handle picture-in-picture key", e);
1407 // re-acquire status bar service next time it is needed.
1408 mStatusBarService = null;
1409 }
Jaewan Kim52632e22016-01-14 18:01:52 +09001410 }
1411
Jeff Browncaca8812013-05-09 13:34:33 -07001412 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1413 @Override
1414 public void run() {
1415 if (mHomeDoubleTapPending) {
1416 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001417 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001418 }
1419 }
1420 };
1421
Mark Renoufc1256912015-03-11 14:38:23 -04001422 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001423 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001424 }
1425
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001426 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001427 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001428 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001429 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001430 mContext = context;
1431 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001432 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001433 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001434 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001435 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Michael Wrighta4d22d72015-09-16 23:19:26 +01001436 mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001437 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Mark Renoufc1256912015-03-11 14:38:23 -04001438
1439 // Init display burn-in protection
1440 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1441 com.android.internal.R.bool.config_enableBurnInProtection);
1442 // Allow a system property to override this. Used by developer settings.
1443 boolean burnInProtectionDevMode =
1444 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1445 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1446 final int minHorizontal;
1447 final int maxHorizontal;
1448 final int minVertical;
1449 final int maxVertical;
1450 final int maxRadius;
1451 if (burnInProtectionDevMode) {
1452 minHorizontal = -8;
1453 maxHorizontal = 8;
1454 minVertical = -8;
1455 maxVertical = -4;
1456 maxRadius = (isRoundWindow()) ? 6 : -1;
1457 } else {
1458 Resources resources = context.getResources();
1459 minHorizontal = resources.getInteger(
1460 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1461 maxHorizontal = resources.getInteger(
1462 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1463 minVertical = resources.getInteger(
1464 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1465 maxVertical = resources.getInteger(
1466 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1467 maxRadius = resources.getInteger(
1468 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1469 }
1470 mBurnInProtectionHelper = new BurnInProtectionHelper(
1471 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001472 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001473
Jeff Brown70825162012-03-28 17:27:48 -07001474 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001475 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001476 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001477 try {
1478 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1479 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001480 mSettingsObserver = new SettingsObserver(mHandler);
1481 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001482 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001483 mUiMode = context.getResources().getInteger(
1484 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001485 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1486 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1487 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1488 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
keunyounga7710492015-09-23 11:33:58 -07001489 mEnableCarDockHomeCapture = context.getResources().getBoolean(
1490 com.android.internal.R.bool.config_enableCarDockHomeLaunch);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001491 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1492 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1493 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1494 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1495 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1496 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1497 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1498 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001499
Jeff Brown96307042012-07-27 15:51:34 -07001500 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1501 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001502 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001503 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1504 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001505 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001506 mSupportAutoRotation = mContext.getResources().getBoolean(
1507 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001508 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001509 com.android.internal.R.integer.config_lidOpenRotation);
1510 mCarDockRotation = readRotation(
1511 com.android.internal.R.integer.config_carDockRotation);
1512 mDeskDockRotation = readRotation(
1513 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001514 mUndockedHdmiRotation = readRotation(
1515 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001516 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1517 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1518 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1519 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001520 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1521 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1522 mLidNavigationAccessibility = mContext.getResources().getInteger(
1523 com.android.internal.R.integer.config_lidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01001524 mLidControlsScreenLock = mContext.getResources().getBoolean(
1525 com.android.internal.R.bool.config_lidControlsScreenLock);
Jeff Brownc458ce92012-04-30 14:58:40 -07001526 mLidControlsSleep = mContext.getResources().getBoolean(
1527 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001528 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1529 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001530
1531 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1532 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1533 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1534 || mContext.getResources().getBoolean(
1535 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1536 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1537 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001538 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1539 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001540 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1541 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1542 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1543 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1544 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1545 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1546
Bryce Lee55e846d2014-11-04 12:43:44 -08001547 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1548 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1549
Bryce Leed3b28402015-03-09 15:49:13 +00001550 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1551 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1552
Jeff Brown13f00f02014-10-31 14:45:50 -07001553 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1554 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1555 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1556 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1557 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1558 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1559 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1560 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001561 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1562 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001563
John Spurlock61560172015-02-06 19:46:04 -05001564 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001565
Jeff Brownf71343d2013-05-31 17:59:11 -07001566 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001567
Svetoslav8e3feb12014-02-24 13:46:47 -08001568 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1569 Context.ACCESSIBILITY_SERVICE);
1570
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001571 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001572 IntentFilter filter = new IntentFilter();
1573 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1574 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1575 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1576 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001577 filter.addAction(Intent.ACTION_DOCK_EVENT);
1578 Intent intent = context.registerReceiver(mDockReceiver, filter);
1579 if (intent != null) {
1580 // Retrieve current sticky dock event broadcast.
1581 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1582 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1583 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001584
Jeff Brown6aaf2952012-10-05 16:01:08 -07001585 // register for dream-related broadcasts
1586 filter = new IntentFilter();
1587 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1588 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1589 context.registerReceiver(mDreamReceiver, filter);
1590
Christopher Tate5e08af02012-09-21 17:17:22 -07001591 // register for multiuser-relevant broadcasts
1592 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1593 context.registerReceiver(mMultiuserReceiver, filter);
1594
John Spurlock57306e62013-04-22 09:48:49 -04001595 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001596 mSystemGestures = new SystemGesturesPointerEventListener(context,
1597 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001598 @Override
1599 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001600 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001601 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001602 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001603 }
1604 @Override
1605 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001606 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001607 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001608 }
1609 }
1610 @Override
1611 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001612 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001613 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001614 }
1615 }
1616 @Override
Michael Wrighta4d22d72015-09-16 23:19:26 +01001617 public void onFling(int duration) {
1618 if (mPowerManagerInternal != null) {
1619 mPowerManagerInternal.powerHint(
1620 PowerManagerInternal.POWER_HINT_INTERACTION, duration);
1621 }
1622 }
1623 @Override
John Spurlockad3e6cb2013-04-30 08:47:43 -04001624 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001625 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001626 }
Adrian Roos3595be42015-03-05 16:31:15 +01001627 @Override
1628 public void onDown() {
1629 mOrientationListener.onTouchStart();
1630 }
1631 @Override
1632 public void onUpOrCancel() {
1633 mOrientationListener.onTouchEnd();
1634 }
Jun Mukaid2e7e352015-07-22 17:14:02 -07001635 @Override
1636 public void onMouseHoverAtTop() {
1637 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1638 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1639 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS;
1640 mHandler.sendMessageDelayed(msg, 500);
1641 }
1642 @Override
1643 public void onMouseHoverAtBottom() {
1644 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1645 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1646 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION;
1647 mHandler.sendMessageDelayed(msg, 500);
1648 }
1649 @Override
1650 public void onMouseLeaveFromEdge() {
1651 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1652 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001653 });
John Spurlockf1a36642013-10-12 17:50:42 -04001654 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001655 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001656
Jeff Brownc2346132012-04-13 01:55:38 -07001657 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001658 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1659 com.android.internal.R.array.config_longPressVibePattern);
1660 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1661 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001662 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1663 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001664 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1665 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001666 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1667 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001668 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1669 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1670 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1671 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001672 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1673 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001674
Christopher Tatee90585f2012-03-05 18:56:25 -08001675 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1676 com.android.internal.R.bool.config_enableScreenshotChord);
Jorim Jaggi406585a2015-12-21 10:58:56 +01001677 mForceWindowDrawsStatusBarBackground = mContext.getResources().getBoolean(
1678 R.bool.config_forceWindowDrawsStatusBarBackground);
Christopher Tatee90585f2012-03-05 18:56:25 -08001679
Justin Kohd378ad72013-04-01 12:18:26 -07001680 mGlobalKeyManager = new GlobalKeyManager(mContext);
1681
Joe Onoratoea495d42011-04-06 11:41:11 -07001682 // Controls rotation and the like.
1683 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001684
1685 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001686 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001687 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1688 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001689 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001690
1691 mWindowManagerInternal.registerAppTransitionListener(
1692 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001693 }
1694
Jeff Brownf71343d2013-05-31 17:59:11 -07001695 /**
1696 * Read values from config.xml that may be overridden depending on
1697 * the configuration of the device.
1698 * eg. Disable long press on home goes to recents on sw600dp.
1699 */
1700 private void readConfigurationDependentBehaviors() {
Jaewan Kimc552b042016-01-18 16:08:45 +09001701 final Resources res = mContext.getResources();
1702
1703 mLongPressOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001704 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1705 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
Jaewan Kim52632e22016-01-14 18:01:52 +09001706 mLongPressOnHomeBehavior > LAST_LONG_PRESS_HOME_BEHAVIOR) {
Jeff Brownf71343d2013-05-31 17:59:11 -07001707 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1708 }
1709
Jaewan Kimc552b042016-01-18 16:08:45 +09001710 mDoubleTapOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001711 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1712 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1713 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1714 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1715 }
Jaewan Kim49117872016-01-19 17:24:08 +09001716
1717 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_NOTHING;
1718 if (mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)) {
1719 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE;
1720 }
Yorke Lee2e4b7322016-03-02 17:33:06 -08001721
1722 mForceNavBarOpaque = res.getBoolean(
1723 com.android.internal.R.bool.config_forceNavBarAlwaysOpaque);
Jeff Brownf71343d2013-05-31 17:59:11 -07001724 }
1725
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001726 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001727 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001728 // This method might be called before the policy has been fully initialized
1729 // or for other displays we don't care about.
1730 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1731 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001732 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001733 mDisplay = display;
1734
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001735 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001736 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001737 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001738 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001739 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001740 mLandscapeRotation = Surface.ROTATION_0;
1741 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001742 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001743 mPortraitRotation = Surface.ROTATION_90;
1744 mUpsideDownRotation = Surface.ROTATION_270;
1745 } else {
1746 mPortraitRotation = Surface.ROTATION_270;
1747 mUpsideDownRotation = Surface.ROTATION_90;
1748 }
1749 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001750 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001751 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001752 mPortraitRotation = Surface.ROTATION_0;
1753 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001754 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001755 mLandscapeRotation = Surface.ROTATION_270;
1756 mSeascapeRotation = Surface.ROTATION_90;
1757 } else {
1758 mLandscapeRotation = Surface.ROTATION_90;
1759 mSeascapeRotation = Surface.ROTATION_270;
1760 }
1761 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001762
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001763 mStatusBarHeight =
1764 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001765
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001766 // Height of the navigation bar when presented horizontally at bottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001767 mNavigationBarHeightForRotationDefault[mPortraitRotation] =
1768 mNavigationBarHeightForRotationDefault[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001769 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001770 mNavigationBarHeightForRotationDefault[mLandscapeRotation] =
1771 mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize(
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001772 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001773
1774 // Width of the navigation bar when presented vertically along one side
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001775 mNavigationBarWidthForRotationDefault[mPortraitRotation] =
1776 mNavigationBarWidthForRotationDefault[mUpsideDownRotation] =
1777 mNavigationBarWidthForRotationDefault[mLandscapeRotation] =
1778 mNavigationBarWidthForRotationDefault[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001779 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001780
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001781 // Height of the navigation bar when presented horizontally at bottom
1782 mNavigationBarHeightForRotationInCarMode[mPortraitRotation] =
1783 mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] =
1784 res.getDimensionPixelSize(
1785 com.android.internal.R.dimen.navigation_bar_height_car_mode);
1786 mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] =
1787 mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize(
1788 com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode);
1789
1790 // Width of the navigation bar when presented vertically along one side
1791 mNavigationBarWidthForRotationInCarMode[mPortraitRotation] =
1792 mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] =
1793 mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] =
1794 mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] =
1795 res.getDimensionPixelSize(
1796 com.android.internal.R.dimen.navigation_bar_width_car_mode);
1797
Daniel Sandler4a066c52012-04-20 14:49:13 -04001798 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001799 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001800 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001801
Devin Kimd7b12b42014-05-05 14:34:58 -07001802 // Allow the navigation bar to move on non-square small devices (phones).
1803 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001804
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001805 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001806 // Allow a system property to override this. Used by the emulator.
1807 // See also hasNavigationBar().
1808 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1809 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001810 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001811 } else if ("0".equals(navBarOverride)) {
1812 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001813 }
1814
Jeff Brown27f1d672012-10-17 18:32:34 -07001815 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1816 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001817 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001818 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001819 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001820 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001821 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001822 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001823
Chong Zhangae6119ff2014-11-11 18:54:39 -08001824 // For demo purposes, allow the rotation of the remote display to be controlled.
1825 // By default, remote display locks rotation to landscape.
1826 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1827 mDemoRotation = mPortraitRotation;
1828 } else {
1829 mDemoRotation = mLandscapeRotation;
1830 }
1831 mDemoRotationLock = SystemProperties.getBoolean(
1832 "persist.demo.rotationlock", false);
1833
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001834 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1835 // http://developer.android.com/guide/practices/screens_support.html#range
1836 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1837 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1838 // For debug purposes the next line turns this feature off with:
1839 // $ adb shell setprop config.override_forced_orient true
1840 // $ adb shell wm size reset
1841 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1842 }
1843
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001844 /**
1845 * @return whether the navigation bar can be hidden, e.g. the device has a
1846 * navigation bar and touch exploration is not enabled
1847 */
1848 private boolean canHideNavigationBar() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04001849 return mHasNavigationBar;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001850 }
1851
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001852 @Override
1853 public boolean isDefaultOrientationForced() {
1854 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001855 }
1856
Dianne Hackbornc652de82013-02-15 16:32:56 -08001857 @Override
1858 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1859 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1860 mOverscanLeft = left;
1861 mOverscanTop = top;
1862 mOverscanRight = right;
1863 mOverscanBottom = bottom;
1864 }
1865 }
1866
Dianne Hackbornc777e072010-02-12 13:07:59 -08001867 public void updateSettings() {
1868 ContentResolver resolver = mContext.getContentResolver();
1869 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001870 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001871 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001872 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001873 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1874 UserHandle.USER_CURRENT);
1875 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001876 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001877 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1878 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001879
Jeff Browna20dda42014-05-27 20:57:24 -07001880 // Configure wake gesture.
1881 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1882 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1883 UserHandle.USER_CURRENT) != 0;
1884 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1885 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1886 updateWakeGestureListenerLp();
1887 }
1888
Jeff Brown207673cd2012-06-05 17:47:11 -07001889 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001890 int userRotation = Settings.System.getIntForUser(resolver,
1891 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1892 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001893 if (mUserRotation != userRotation) {
1894 mUserRotation = userRotation;
1895 updateRotation = true;
1896 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001897 int userRotationMode = Settings.System.getIntForUser(resolver,
1898 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001899 WindowManagerPolicy.USER_ROTATION_FREE :
1900 WindowManagerPolicy.USER_ROTATION_LOCKED;
1901 if (mUserRotationMode != userRotationMode) {
1902 mUserRotationMode = userRotationMode;
1903 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001904 updateOrientationListenerLp();
1905 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001906
Dianne Hackbornc777e072010-02-12 13:07:59 -08001907 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001908 int pointerLocation = Settings.System.getIntForUser(resolver,
1909 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001910 if (mPointerLocationMode != pointerLocation) {
1911 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001912 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1913 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001914 }
1915 }
1916 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001917 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1918 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1919 String imId = Settings.Secure.getStringForUser(resolver,
1920 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001921 boolean hasSoftInput = imId != null && imId.length() > 0;
1922 if (mHasSoftInput != hasSoftInput) {
1923 mHasSoftInput = hasSoftInput;
1924 updateRotation = true;
1925 }
John Spurlockf1a36642013-10-12 17:50:42 -04001926 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001927 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001928 }
tiger_huangcc6366d2015-06-29 17:17:30 +08001929 }
1930 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05001931 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001932 }
1933 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001934 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001935 }
Jeff Brown70825162012-03-28 17:27:48 -07001936 }
1937
Jeff Browna20dda42014-05-27 20:57:24 -07001938 private void updateWakeGestureListenerLp() {
1939 if (shouldEnableWakeGestureLp()) {
1940 mWakeGestureListener.requestWakeUpTrigger();
1941 } else {
1942 mWakeGestureListener.cancelWakeUpTrigger();
1943 }
1944 }
1945
1946 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001947 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001948 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1949 && mWakeGestureListener.isSupported();
1950 }
1951
Jeff Brown70825162012-03-28 17:27:48 -07001952 private void enablePointerLocation() {
1953 if (mPointerLocationView == null) {
1954 mPointerLocationView = new PointerLocationView(mContext);
1955 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001956 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1957 WindowManager.LayoutParams.MATCH_PARENT,
1958 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001959 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001960 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1961 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1962 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1963 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001964 if (ActivityManager.isHighEndGfx()) {
1965 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1966 lp.privateFlags |=
1967 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1968 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001969 lp.format = PixelFormat.TRANSLUCENT;
1970 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001971 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001972 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001973 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001974 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001975 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001976 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001977 }
Jeff Brown70825162012-03-28 17:27:48 -07001978
1979 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001980 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001981 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1982 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001983 wm.removeView(mPointerLocationView);
1984 mPointerLocationView = null;
1985 }
1986 }
1987
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001988 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001989 try {
1990 int rotation = mContext.getResources().getInteger(resID);
1991 switch (rotation) {
1992 case 0:
1993 return Surface.ROTATION_0;
1994 case 90:
1995 return Surface.ROTATION_90;
1996 case 180:
1997 return Surface.ROTATION_180;
1998 case 270:
1999 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002000 }
2001 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002002 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002003 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002004 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002005 }
2006
2007 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07002008 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08002009 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002010 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08002011
2012 outAppOp[0] = AppOpsManager.OP_NONE;
2013
Wale Ogunwale74bf0652015-01-12 10:24:36 -08002014 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
2015 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
2016 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
2017 return WindowManagerGlobal.ADD_INVALID_TYPE;
2018 }
2019
2020 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
2021 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07002022 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002023 }
2024 String permission = null;
2025 switch (type) {
2026 case TYPE_TOAST:
2027 // XXX right now the app process has complete control over
2028 // this... should introduce a token to let the system
2029 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04002030 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002031 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05002032 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002033 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07002034 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07002035 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002036 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07002037 case TYPE_ACCESSIBILITY_OVERLAY:
Jason Monk8f7f3182015-11-18 16:35:14 -05002038 case TYPE_QS_DIALOG:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07002039 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002040 break;
2041 case TYPE_PHONE:
2042 case TYPE_PRIORITY_PHONE:
2043 case TYPE_SYSTEM_ALERT:
2044 case TYPE_SYSTEM_ERROR:
2045 case TYPE_SYSTEM_OVERLAY:
2046 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08002047 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002048 break;
2049 default:
2050 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
2051 }
2052 if (permission != null) {
Svet Ganov9cea80cd2016-02-16 11:47:00 -08002053 if (android.Manifest.permission.SYSTEM_ALERT_WINDOW.equals(permission)) {
Billy Laucbe540f2015-06-25 01:51:44 +01002054 final int callingUid = Binder.getCallingUid();
Billy Lau060275f2015-07-15 22:29:19 +01002055 // system processes will be automatically allowed privilege to draw
Billy Laucbe540f2015-06-25 01:51:44 +01002056 if (callingUid == Process.SYSTEM_UID) {
2057 return WindowManagerGlobal.ADD_OKAY;
2058 }
2059
Billy Lau060275f2015-07-15 22:29:19 +01002060 // check if user has enabled this operation. SecurityException will be thrown if
2061 // this app has not been allowed by the user
Svet Ganov03f2afc2016-03-04 16:13:03 -08002062 final int mode = mAppOpsManager.checkOpNoThrow(outAppOp[0], callingUid,
Billy Laucbe540f2015-06-25 01:51:44 +01002063 attrs.packageName);
Billy Lau060275f2015-07-15 22:29:19 +01002064 switch (mode) {
2065 case AppOpsManager.MODE_ALLOWED:
2066 case AppOpsManager.MODE_IGNORED:
2067 // although we return ADD_OKAY for MODE_IGNORED, the added window will
2068 // actually be hidden in WindowManagerService
2069 return WindowManagerGlobal.ADD_OKAY;
2070 case AppOpsManager.MODE_ERRORED:
Svet Ganov03f2afc2016-03-04 16:13:03 -08002071 try {
2072 ApplicationInfo appInfo = mContext.getPackageManager()
2073 .getApplicationInfo(attrs.packageName,
2074 UserHandle.getUserId(callingUid));
2075 // Don't crash legacy apps
2076 if (appInfo.targetSdkVersion < Build.VERSION_CODES.M) {
2077 return WindowManagerGlobal.ADD_OKAY;
2078 }
2079 } catch (PackageManager.NameNotFoundException e) {
2080 /* ignore */
2081 }
Billy Laucbe540f2015-06-25 01:51:44 +01002082 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
Billy Lau060275f2015-07-15 22:29:19 +01002083 default:
2084 // in the default mode, we will make a decision here based on
2085 // checkCallingPermission()
2086 if (mContext.checkCallingPermission(permission) !=
2087 PackageManager.PERMISSION_GRANTED) {
2088 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
2089 } else {
2090 return WindowManagerGlobal.ADD_OKAY;
2091 }
Billy Laucbe540f2015-06-25 01:51:44 +01002092 }
Billy Laucbe540f2015-06-25 01:51:44 +01002093 }
2094
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002095 if (mContext.checkCallingOrSelfPermission(permission)
2096 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07002097 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002098 }
2099 }
Jeff Brown98365d72012-08-19 20:30:52 -07002100 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002101 }
Craig Mautner88400d32012-09-30 12:35:45 -07002102
2103 @Override
2104 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
2105
2106 // If this switch statement is modified, modify the comment in the declarations of
2107 // the type in {@link WindowManager.LayoutParams} as well.
2108 switch (attrs.type) {
2109 default:
2110 // These are the windows that by default are shown only to the user that created
2111 // them. If this needs to be overridden, set
2112 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
2113 // {@link WindowManager.LayoutParams}. Note that permission
2114 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
2115 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
2116 return true;
2117 }
2118 break;
2119
2120 // These are the windows that by default are shown to all users. However, to
2121 // protect against spoofing, check permissions below.
2122 case TYPE_APPLICATION_STARTING:
2123 case TYPE_BOOT_PROGRESS:
2124 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07002125 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08002126 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07002127 case TYPE_KEYGUARD_DIALOG:
2128 case TYPE_MAGNIFICATION_OVERLAY:
2129 case TYPE_NAVIGATION_BAR:
2130 case TYPE_NAVIGATION_BAR_PANEL:
2131 case TYPE_PHONE:
2132 case TYPE_POINTER:
2133 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07002134 case TYPE_SEARCH_BAR:
2135 case TYPE_STATUS_BAR:
2136 case TYPE_STATUS_BAR_PANEL:
2137 case TYPE_STATUS_BAR_SUB_PANEL:
2138 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07002139 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07002140 case TYPE_PRIVATE_PRESENTATION:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002141 case TYPE_DOCK_DIVIDER:
Craig Mautner88400d32012-09-30 12:35:45 -07002142 break;
2143 }
2144
2145 // Check if third party app has set window to system window type.
2146 return mContext.checkCallingOrSelfPermission(
2147 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
2148 != PackageManager.PERMISSION_GRANTED;
2149 }
2150
Craig Mautner967212c2013-04-13 21:10:58 -07002151 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002152 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
2153 switch (attrs.type) {
2154 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07002155 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002156 // These types of windows can't receive input events.
2157 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2158 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002159 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002160 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002161 case TYPE_STATUS_BAR:
2162
2163 // If the Keyguard is in a hidden state (occluded by another window), we force to
2164 // remove the wallpaper and keyguard flag so that any change in-flight after setting
2165 // the keyguard as occluded wouldn't set these flags again.
2166 // See {@link #processKeyguardSetHiddenResultLw}.
2167 if (mKeyguardHidden) {
2168 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2169 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2170 }
2171 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002172 }
Adrian Roos38502112014-04-09 21:04:11 +02002173
2174 if (attrs.type != TYPE_STATUS_BAR) {
2175 // The status bar is the only window allowed to exhibit keyguard behavior.
2176 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2177 }
Adrian Roosea562512014-05-05 13:33:03 +02002178
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002179 if (ActivityManager.isHighEndGfx()) {
2180 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
2181 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
2182 }
2183 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0
Jorim Jaggi406585a2015-12-21 10:58:56 +01002184 || (mForceWindowDrawsStatusBarBackground
2185 && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT)) {
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002186 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
2187 }
Adrian Roosea562512014-05-05 13:33:03 +02002188 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002189 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002190
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002191 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07002192 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002193 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002194
Michael Wright3818c922014-09-02 13:59:07 -07002195 private void readCameraLensCoverState() {
2196 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
2197 }
2198
Jeff Browndaa37532012-05-01 15:54:03 -07002199 private boolean isHidden(int accessibilityMode) {
2200 switch (accessibilityMode) {
2201 case 1:
2202 return mLidState == LID_CLOSED;
2203 case 2:
2204 return mLidState == LID_OPEN;
2205 default:
2206 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002207 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002208 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002209
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002210 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002211 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07002212 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
2213 int navigationPresence) {
2214 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
2215
Jeff Brownf71343d2013-05-31 17:59:11 -07002216 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002217 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07002218 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08002219
Jeff Browndaa37532012-05-01 15:54:03 -07002220 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
2221 || (keyboardPresence == PRESENCE_INTERNAL
2222 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002223 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07002224 if (!mHasSoftInput) {
2225 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
2226 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002227 }
2228
Jeff Browndaa37532012-05-01 15:54:03 -07002229 if (config.navigation == Configuration.NAVIGATION_NONAV
2230 || (navigationPresence == PRESENCE_INTERNAL
2231 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002232 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08002233 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002234 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002235
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002236 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002237 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002238 public int windowTypeToLayerLw(int type) {
2239 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002240 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002241 }
2242 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07002243 case TYPE_PRIVATE_PRESENTATION:
2244 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002245 case TYPE_WALLPAPER:
2246 // wallpaper is at the bottom, though the window manager may move it.
2247 return 2;
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002248 case TYPE_DOCK_DIVIDER:
2249 return 2;
Jason Monk8f7f3182015-11-18 16:35:14 -05002250 case TYPE_QS_DIALOG:
2251 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002252 case TYPE_PHONE:
2253 return 3;
2254 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002255 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002256 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002257 case TYPE_VOICE_INTERACTION:
2258 // voice interaction layer is almost immediately above apps.
2259 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07002260 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002261 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07002262 case TYPE_SYSTEM_DIALOG:
2263 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002264 case TYPE_TOAST:
2265 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07002266 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002267 case TYPE_PRIORITY_PHONE:
2268 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07002269 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002270 case TYPE_DREAM:
2271 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07002272 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002273 case TYPE_SYSTEM_ALERT:
2274 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002275 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002276 case TYPE_INPUT_METHOD:
2277 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002278 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002279 case TYPE_INPUT_METHOD_DIALOG:
2280 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002281 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08002282 case TYPE_KEYGUARD_SCRIM:
2283 // the safety window that shows behind keyguard while keyguard is starting
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002284 return 14;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002285 case TYPE_STATUS_BAR_SUB_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002286 return 15;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002287 case TYPE_STATUS_BAR:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002288 return 16;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002289 case TYPE_STATUS_BAR_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002290 return 17;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002291 case TYPE_KEYGUARD_DIALOG:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002292 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002293 case TYPE_VOLUME_OVERLAY:
2294 // the on-screen volume indicator and controller shown when the user
2295 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002296 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002297 case TYPE_SYSTEM_OVERLAY:
2298 // the on-screen volume indicator and controller shown when the user
2299 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002300 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002301 case TYPE_NAVIGATION_BAR:
2302 // the navigation bar, if available, shows atop most things
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002303 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002304 case TYPE_NAVIGATION_BAR_PANEL:
2305 // some panels (e.g. search) need to show on top of the navigation bar
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002306 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002307 case TYPE_SYSTEM_ERROR:
2308 // system-level error dialogs
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002309 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002310 case TYPE_MAGNIFICATION_OVERLAY:
2311 // used to highlight the magnified portion of a display
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002312 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002313 case TYPE_DISPLAY_OVERLAY:
2314 // used to simulate secondary display devices
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002315 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002316 case TYPE_DRAG:
2317 // the drag layer: input for drag-and-drop is associated with this window,
2318 // which sits above all other focusable windows
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002319 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002320 case TYPE_ACCESSIBILITY_OVERLAY:
2321 // overlay put by accessibility services to intercept user interaction
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002322 return 27;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002323 case TYPE_SECURE_SYSTEM_OVERLAY:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002324 return 28;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002325 case TYPE_BOOT_PROGRESS:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002326 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002327 case TYPE_POINTER:
2328 // the (mouse) pointer layer
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002329 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002330 }
2331 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002332 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002333 }
2334
2335 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002336 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002337 public int subWindowTypeToLayerLw(int type) {
2338 switch (type) {
2339 case TYPE_APPLICATION_PANEL:
2340 case TYPE_APPLICATION_ATTACHED_DIALOG:
2341 return APPLICATION_PANEL_SUBLAYER;
2342 case TYPE_APPLICATION_MEDIA:
2343 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002344 case TYPE_APPLICATION_MEDIA_OVERLAY:
2345 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002346 case TYPE_APPLICATION_SUB_PANEL:
2347 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002348 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2349 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002350 }
2351 Log.e(TAG, "Unknown sub-window type: " + type);
2352 return 0;
2353 }
2354
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002355 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002356 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002357 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002358 }
2359
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002360 private int getNavigationBarWidth(int rotation, int uiMode) {
2361 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2362 return mNavigationBarWidthForRotationInCarMode[rotation];
2363 } else {
2364 return mNavigationBarWidthForRotationDefault[rotation];
2365 }
2366 }
2367
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002368 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002369 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation,
2370 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002371 if (mHasNavigationBar) {
2372 // For a basic navigation bar, when we are in landscape mode we place
2373 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002374 if (mNavigationBarCanMove && fullWidth > fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002375 return fullWidth - getNavigationBarWidth(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002376 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002377 }
2378 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002379 }
2380
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002381 private int getNavigationBarHeight(int rotation, int uiMode) {
2382 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2383 return mNavigationBarHeightForRotationInCarMode[rotation];
2384 } else {
2385 return mNavigationBarHeightForRotationDefault[rotation];
2386 }
2387 }
2388
Jose Lima9546b202014-07-02 17:21:51 -07002389 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002390 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation,
2391 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002392 if (mHasNavigationBar) {
2393 // For a basic navigation bar, when we are in portrait mode we place
2394 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002395 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002396 return fullHeight - getNavigationBarHeight(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002397 }
2398 }
2399 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002400 }
2401
Jose Lima9546b202014-07-02 17:21:51 -07002402 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002403 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode) {
2404 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002405 }
2406
Jose Lima9546b202014-07-02 17:21:51 -07002407 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002408 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode) {
John Spurlock80f00c12013-06-13 11:10:51 -04002409 // There is a separate status bar at the top of the display. We don't count that as part
2410 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002411 // we do want to exclude it since applications can't generally use that part
2412 // of the screen.
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002413 return getNonDecorDisplayHeight(
2414 fullWidth, fullHeight, rotation, uiMode) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002415 }
2416
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002417 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002418 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2419 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002420 (isKeyguardHostWindow(attrs) &&
2421 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002422 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002423 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002424
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002425 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002426 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2427 return attrs.type == TYPE_STATUS_BAR;
2428 }
2429
2430 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002431 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002432 switch (attrs.type) {
2433 case TYPE_STATUS_BAR:
2434 case TYPE_NAVIGATION_BAR:
2435 case TYPE_WALLPAPER:
2436 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002437 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002438 return false;
2439 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002440 // Hide only windows below the keyguard host window.
2441 return windowTypeToLayerLw(win.getBaseType())
2442 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002443 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002444 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002445
Craig Mautner7d7808f2014-09-11 18:02:38 -07002446 @Override
2447 public WindowState getWinShowWhenLockedLw() {
2448 return mWinShowWhenLocked;
2449 }
2450
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002451 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002452 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002453 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2454 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002455 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002456 if (!SHOW_STARTING_ANIMATIONS) {
2457 return null;
2458 }
2459 if (packageName == null) {
2460 return null;
2461 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002462
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002463 WindowManager wm = null;
2464 View view = null;
2465
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002466 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002467 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002468 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2469 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2470 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002471 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002472 try {
2473 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002474 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002475 } catch (PackageManager.NameNotFoundException e) {
2476 // Ignore
2477 }
2478 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002479
Jorim Jaggia16cc152015-06-01 16:55:05 -07002480 PhoneWindow win = new PhoneWindow(context);
2481 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002482
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002483 Resources r = context.getResources();
2484 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002485
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002486 win.setType(
2487 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002488
2489 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2490 // Assumes it's safe to show starting windows of launched apps while
2491 // the keyguard is being hidden. This is okay because starting windows never show
2492 // secret information.
2493 if (mKeyguardHidden) {
2494 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2495 }
2496 }
2497
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002498 // Force the window flags: this is a fake window, so it is not really
2499 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2500 // flag because we do know that the next window will take input
2501 // focus, so we want to get the IME window up on top of us right away.
2502 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002503 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002504 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2505 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2506 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002507 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002508 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2509 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2510 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002511
Adam Powell04fe6eb2013-05-31 14:39:48 -07002512 win.setDefaultIcon(icon);
2513 win.setDefaultLogo(logo);
2514
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002515 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002516 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002517
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002518 final WindowManager.LayoutParams params = win.getAttributes();
2519 params.token = appToken;
2520 params.packageName = packageName;
2521 params.windowAnimations = win.getWindowStyle().getResourceId(
2522 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002523 params.privateFlags |=
2524 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002525 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002526
2527 if (!compatInfo.supportsScreen()) {
2528 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2529 }
2530
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002531 params.setTitle("Starting " + packageName);
2532
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002533 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2534 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002535
Craig Mautner6fbda632012-07-03 09:26:39 -07002536 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002537 TAG, "Adding starting window for " + packageName
2538 + " / " + appToken + ": "
2539 + (view.getParent() != null ? view : null));
2540
2541 wm.addView(view, params);
2542
2543 // Only return the view if it was successfully added to the
2544 // window manager... which we can tell by it having a parent.
2545 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002546 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002547 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002548 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2549 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002550 } catch (RuntimeException e) {
2551 // don't crash if something else bad happens, for example a
2552 // failure loading resources because we are loading from an app
2553 // on external storage that has been unmounted.
2554 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002555 } finally {
2556 if (view != null && view.getParent() == null) {
2557 Log.w(TAG, "view not successfully added to wm, removing view");
2558 wm.removeViewImmediate(view);
2559 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002560 }
2561
2562 return null;
2563 }
2564
2565 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002566 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002567 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002568 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2569 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002570
2571 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002572 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002573 wm.removeView(window);
2574 }
2575 }
2576
2577 /**
2578 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002579 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002580 * Currently enforces that three window types are singletons:
2581 * <ul>
2582 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002583 * <li>KEYGUARD_TYPE</li>
2584 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002585 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002586 * @param win The window to be added
2587 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002588 *
Jeff Brown98365d72012-08-19 20:30:52 -07002589 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2590 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002591 */
Jose Lima9546b202014-07-02 17:21:51 -07002592 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002593 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2594 switch (attrs.type) {
2595 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002596 mContext.enforceCallingOrSelfPermission(
2597 android.Manifest.permission.STATUS_BAR_SERVICE,
2598 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002599 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002600 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002601 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002602 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002603 }
2604 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002605 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002606 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002607 case TYPE_NAVIGATION_BAR:
2608 mContext.enforceCallingOrSelfPermission(
2609 android.Manifest.permission.STATUS_BAR_SERVICE,
2610 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002611 if (mNavigationBar != null) {
2612 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002613 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002614 }
2615 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002616 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002617 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002618 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002619 break;
Jim Millere898ac52012-04-06 17:10:57 -07002620 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002621 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002622 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002623 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002624 mContext.enforceCallingOrSelfPermission(
2625 android.Manifest.permission.STATUS_BAR_SERVICE,
2626 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002627 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002628 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002629 if (mKeyguardScrim != null) {
2630 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2631 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002632 mKeyguardScrim = win;
2633 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002634 }
Jeff Brown98365d72012-08-19 20:30:52 -07002635 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002636 }
2637
2638 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002639 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002640 public void removeWindowLw(WindowState win) {
2641 if (mStatusBar == win) {
2642 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002643 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002644 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002645 } else if (mKeyguardScrim == win) {
2646 Log.v(TAG, "Removing keyguard scrim");
2647 mKeyguardScrim = null;
2648 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002649 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002650 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002651 }
2652 }
2653
2654 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002655
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002656 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002657 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002658 public int selectAnimationLw(WindowState win, int transit) {
2659 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2660 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002661 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002662 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002663 if (transit == TRANSIT_EXIT
2664 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002665 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002666 } else if (transit == TRANSIT_ENTER
2667 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002668 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002669 }
2670 } else if (win == mNavigationBar) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002671 if (win.getAttrs().windowAnimations != 0) {
2672 return 0;
2673 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002674 // This can be on either the bottom or the right.
2675 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002676 if (transit == TRANSIT_EXIT
2677 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002678 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002679 } else if (transit == TRANSIT_ENTER
2680 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002681 return R.anim.dock_bottom_enter;
2682 }
2683 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002684 if (transit == TRANSIT_EXIT
2685 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002686 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002687 } else if (transit == TRANSIT_ENTER
2688 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002689 return R.anim.dock_right_enter;
2690 }
2691 }
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08002692 } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08002693 return selectDockedDividerAnimationLw(win, transit);
Craig Mautner4b71aa12012-12-27 17:20:01 -08002694 }
2695
2696 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002697 if (win.hasAppShownWindows()) {
2698 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2699 return com.android.internal.R.anim.app_starting_exit;
2700 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002701 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002702 && transit == TRANSIT_ENTER) {
2703 // Special case: we are animating in a dream, while the keyguard
2704 // is shown. We don't want an animation on the dream, because
2705 // we need it shown immediately with the keyguard animating away
2706 // to reveal it.
2707 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002708 }
2709
2710 return 0;
2711 }
2712
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08002713 private int selectDockedDividerAnimationLw(WindowState win, int transit) {
2714 int insets = mWindowManagerFuncs.getDockedDividerInsetsLw();
2715
2716 // If the divider is behind the navigation bar, don't animate.
2717 if (mNavigationBar != null
2718 && (win.getFrameLw().top + insets >= mNavigationBar.getFrameLw().top
2719 || win.getFrameLw().left + insets >= mNavigationBar.getFrameLw().left)) {
2720 return 0;
2721 }
2722 if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
2723 return R.anim.fade_in;
2724 } else if (transit == TRANSIT_EXIT) {
2725 return R.anim.fade_out;
2726 } else {
2727 return 0;
2728 }
2729 }
2730
Craig Mautner3c174372013-02-21 17:54:37 -08002731 @Override
2732 public void selectRotationAnimationLw(int anim[]) {
2733 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2734 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2735 + (mTopFullscreenOpaqueWindowState == null ?
2736 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2737 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2738 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2739 case ROTATION_ANIMATION_CROSSFADE:
2740 anim[0] = R.anim.rotation_animation_xfade_exit;
2741 anim[1] = R.anim.rotation_animation_enter;
2742 break;
2743 case ROTATION_ANIMATION_JUMPCUT:
2744 anim[0] = R.anim.rotation_animation_jump_exit;
2745 anim[1] = R.anim.rotation_animation_enter;
2746 break;
2747 case ROTATION_ANIMATION_ROTATE:
2748 default:
2749 anim[0] = anim[1] = 0;
2750 break;
2751 }
2752 } else {
2753 anim[0] = anim[1] = 0;
2754 }
2755 }
2756
2757 @Override
2758 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2759 boolean forceDefault) {
2760 switch (exitAnimId) {
2761 case R.anim.rotation_animation_xfade_exit:
2762 case R.anim.rotation_animation_jump_exit:
2763 // These are the only cases that matter.
2764 if (forceDefault) {
2765 return false;
2766 }
2767 int anim[] = new int[2];
2768 selectRotationAnimationLw(anim);
2769 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2770 default:
2771 return true;
2772 }
2773 }
2774
2775 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002776 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2777 boolean goingToNotificationShade) {
2778 if (goingToNotificationShade) {
2779 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002780 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002781
2782 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2783 R.anim.lock_screen_behind_enter_wallpaper :
2784 R.anim.lock_screen_behind_enter);
2785
2786 // TODO: Use XML interpolators when we have log interpolators available in XML.
2787 final List<Animation> animations = set.getAnimations();
2788 for (int i = animations.size() - 1; i >= 0; --i) {
2789 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2790 }
2791
2792 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002793 }
2794
2795
2796 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002797 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2798 if (goingToNotificationShade) {
2799 return null;
2800 } else {
2801 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2802 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002803 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002804
2805 private static void awakenDreams() {
2806 IDreamManager dreamManager = getDreamManager();
2807 if (dreamManager != null) {
2808 try {
2809 dreamManager.awaken();
2810 } catch (RemoteException e) {
2811 // fine, stay asleep then
2812 }
2813 }
2814 }
2815
2816 static IDreamManager getDreamManager() {
2817 return IDreamManager.Stub.asInterface(
2818 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2819 }
2820
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002821 TelecomManager getTelecommService() {
2822 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002823 }
2824
Jeff Brown4d396052010-10-29 21:50:21 -07002825 static IAudioService getAudioService() {
2826 IAudioService audioService = IAudioService.Stub.asInterface(
2827 ServiceManager.checkService(Context.AUDIO_SERVICE));
2828 if (audioService == null) {
2829 Log.w(TAG, "Unable to find IAudioService interface.");
2830 }
2831 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002832 }
2833
2834 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002835 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002836 }
2837
2838 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2839 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2840 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2841 };
2842
2843 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002844 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002845 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002846 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002847 final int keyCode = event.getKeyCode();
2848 final int repeatCount = event.getRepeatCount();
2849 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002850 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002851 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2852 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002853
Jeff Brown40013652012-05-16 21:22:36 -07002854 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002855 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002856 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2857 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002858 }
2859
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002860 // If we think we might have a volume down & power key chord on the way
2861 // but we're not sure, then tell the dispatcher to wait a little while and
2862 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002863 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002864 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002865 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002866 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2867 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002868 if (now < timeoutTime) {
2869 return timeoutTime - now;
2870 }
2871 }
2872 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002873 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002874 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002875 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002876 }
2877 return -1;
2878 }
2879 }
2880
Michael Wright6a62e552014-06-03 19:19:48 -07002881 // Cancel any pending meta actions if we see any other keys being pressed between the down
2882 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002883 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002884 mPendingMetaAction = false;
2885 }
2886
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002887 // First we always handle the home key here, so applications
2888 // can never break it, although if keyguard is on, we do let
2889 // it handle it, because that gives us the correct 5 second
2890 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002891 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002892
Jeff Brown49ed71d2010-12-06 17:13:33 -08002893 // If we have released the home key, and didn't do anything else
2894 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002895 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002896 cancelPreloadRecentApps();
2897
Jeff Brown49ed71d2010-12-06 17:13:33 -08002898 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002899 if (mHomeConsumed) {
2900 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002901 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002902 }
Jeff Browncaca8812013-05-09 13:34:33 -07002903
2904 if (canceled) {
2905 Log.i(TAG, "Ignoring HOME; event canceled.");
2906 return -1;
2907 }
2908
Yorke Lee4f803242014-12-15 23:22:06 +00002909 // If an incoming call is ringing, HOME is totally disabled.
2910 // (The user is already on the InCallUI at this point,
2911 // and his ONLY options are to answer or reject the call.)
2912 TelecomManager telecomManager = getTelecommService();
2913 if (telecomManager != null && telecomManager.isRinging()) {
2914 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2915 return -1;
2916 }
2917
Jeff Browncaca8812013-05-09 13:34:33 -07002918 // Delay handling home if a double-tap is possible.
2919 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2920 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2921 mHomeDoubleTapPending = true;
2922 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2923 ViewConfiguration.getDoubleTapTimeout());
2924 return -1;
2925 }
2926
Jeff Brown13f00f02014-10-31 14:45:50 -07002927 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002928 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002929 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002930
2931 // If a system window has focus, then it doesn't make sense
2932 // right now to interact with applications.
2933 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2934 if (attrs != null) {
2935 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002936 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2937 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2938 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002939 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002940 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002941 }
2942 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2943 for (int i=0; i<typeCount; i++) {
2944 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2945 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002946 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002947 }
2948 }
2949 }
Jeff Browncaca8812013-05-09 13:34:33 -07002950
2951 // Remember that home is pressed and handle special actions.
2952 if (repeatCount == 0) {
2953 mHomePressed = true;
2954 if (mHomeDoubleTapPending) {
2955 mHomeDoubleTapPending = false;
2956 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2957 handleDoubleTapOnHome();
2958 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2959 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2960 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002961 }
Jeff Browncaca8812013-05-09 13:34:33 -07002962 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2963 if (!keyguardOn) {
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09002964 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002965 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002966 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002967 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002968 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002969 // Hijack modified menu keys for debugging features
2970 final int chordBug = KeyEvent.META_SHIFT_ON;
2971
2972 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002973 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002974 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002975 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2976 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002977 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002978 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002979 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002980 Intent service = new Intent();
2981 service.setClassName(mContext, "com.android.server.LoadAverageService");
2982 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002983 boolean shown = Settings.Global.getInt(
2984 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002985 if (!shown) {
2986 mContext.startService(service);
2987 } else {
2988 mContext.stopService(service);
2989 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002990 Settings.Global.putInt(
2991 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002992 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002993 }
2994 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002995 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002996 if (down) {
2997 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002998 mSearchKeyShortcutPending = true;
2999 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003000 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003001 } else {
3002 mSearchKeyShortcutPending = false;
3003 if (mConsumeSearchKeyUp) {
3004 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003005 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003006 }
3007 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003008 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003009 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08003010 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07003011 if (down && repeatCount == 0) {
3012 preloadRecentApps();
3013 } else if (!down) {
3014 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08003015 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003016 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003017 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07003018 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
3019 if (down) {
3020 IStatusBarService service = getStatusBarService();
3021 if (service != null) {
3022 try {
3023 service.expandNotificationsPanel();
3024 } catch (RemoteException e) {
3025 // do nothing.
3026 }
3027 }
3028 }
Clara Bayarrif2debb12015-07-10 14:47:17 +01003029 } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) {
3030 if (down) {
3031 if (repeatCount == 0) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003032 toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01003033 }
3034 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003035 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
3036 if (down) {
3037 if (repeatCount == 0) {
3038 mAssistKeyLongPressed = false;
3039 } else if (repeatCount == 1) {
3040 mAssistKeyLongPressed = true;
3041 if (!keyguardOn) {
3042 launchAssistLongPressAction();
3043 }
3044 }
3045 } else {
3046 if (mAssistKeyLongPressed) {
3047 mAssistKeyLongPressed = false;
3048 } else {
3049 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003050 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003051 }
3052 }
3053 }
3054 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003055 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
3056 if (!down) {
3057 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07003058 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003059 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3060 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07003061 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
3062 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
3063 if (dic != null) {
3064 try {
3065 dic.exitIdle("voice-search");
3066 } catch (RemoteException e) {
3067 }
3068 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003069 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07003070 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003071 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003072 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003073 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003074 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
3075 if (down && repeatCount == 0) {
3076 mHandler.post(mScreenshotRunnable);
3077 }
3078 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08003079 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
3080 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
3081 if (down) {
3082 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
3083
3084 // Disable autobrightness if it's on
3085 int auto = Settings.System.getIntForUser(
3086 mContext.getContentResolver(),
3087 Settings.System.SCREEN_BRIGHTNESS_MODE,
3088 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3089 UserHandle.USER_CURRENT_OR_SELF);
3090 if (auto != 0) {
3091 Settings.System.putIntForUser(mContext.getContentResolver(),
3092 Settings.System.SCREEN_BRIGHTNESS_MODE,
3093 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3094 UserHandle.USER_CURRENT_OR_SELF);
3095 }
3096
3097 int min = mPowerManager.getMinimumScreenBrightnessSetting();
3098 int max = mPowerManager.getMaximumScreenBrightnessSetting();
3099 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
3100 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
3101 Settings.System.SCREEN_BRIGHTNESS,
3102 mPowerManager.getDefaultScreenBrightnessSetting(),
3103 UserHandle.USER_CURRENT_OR_SELF);
3104 brightness += step;
3105 // Make sure we don't go beyond the limits.
3106 brightness = Math.min(max, brightness);
3107 brightness = Math.max(min, brightness);
3108
3109 Settings.System.putIntForUser(mContext.getContentResolver(),
3110 Settings.System.SCREEN_BRIGHTNESS, brightness,
3111 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00003112 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07003113 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08003114 }
3115 return -1;
Jaewan Kim765487f2016-01-12 14:45:42 +09003116 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
3117 || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
3118 || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
3119 if (mUseTvRouting) {
3120 // On TVs volume keys never go to the foreground app.
3121 dispatchDirectAudioEvent(event);
3122 return -1;
3123 }
Muyuan Li94ce94e2016-02-24 16:20:54 -08003124 }
3125
3126 if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07003127 if (down) {
3128 mPendingMetaAction = true;
3129 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003130 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07003131 }
3132 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003133 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003134
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003135 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08003136 // Any printing key that is chorded with Search should be consumed
3137 // even if no shortcut was invoked. This prevents text from being
3138 // inadvertently inserted when using a keyboard that has built-in macro
3139 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003140 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08003141 final KeyCharacterMap kcm = event.getKeyCharacterMap();
3142 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003143 mConsumeSearchKeyUp = true;
3144 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08003145 if (down && repeatCount == 0 && !keyguardOn) {
3146 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
3147 if (shortcutIntent != null) {
3148 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003149 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003150 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003151 } catch (ActivityNotFoundException ex) {
3152 Slog.w(TAG, "Dropping shortcut key combination because "
3153 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003154 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003155 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003156 } else {
3157 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003158 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003159 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003160 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003161 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003162 }
3163 }
3164
Jeff Brown68b909d2011-12-07 16:36:01 -08003165 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07003166 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08003167 && (metaState & KeyEvent.META_META_ON) != 0) {
3168 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07003169 if (kcm.isPrintingKey(keyCode)) {
3170 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
3171 metaState & ~(KeyEvent.META_META_ON
3172 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
3173 if (shortcutIntent != null) {
3174 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3175 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003176 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07003177 } catch (ActivityNotFoundException ex) {
3178 Slog.w(TAG, "Dropping shortcut key combination because "
3179 + "the activity to which it is registered was not found: "
3180 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
3181 }
3182 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08003183 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003184 }
3185 }
3186
Jeff Brown6651a632011-11-28 12:59:11 -08003187 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07003188 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08003189 String category = sApplicationLaunchKeyCategories.get(keyCode);
3190 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08003191 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08003192 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3193 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003194 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08003195 } catch (ActivityNotFoundException ex) {
3196 Slog.w(TAG, "Dropping application launch key because "
3197 + "the activity to which it is registered was not found: "
3198 + "keyCode=" + keyCode + ", category=" + category, ex);
3199 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003200 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08003201 }
3202 }
3203
Michael Wright61c46752014-08-21 16:57:33 -07003204 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08003205 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Michael Wrightd847ad52015-10-24 13:24:15 +01003206 if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) {
Jeff Brown68b909d2011-12-07 16:36:01 -08003207 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07003208 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003209 mRecentAppsHeldModifiers = shiftlessModifiers;
3210 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08003211 return -1;
3212 }
3213 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07003214 } else if (!down && mRecentAppsHeldModifiers != 0
3215 && (metaState & mRecentAppsHeldModifiers) == 0) {
3216 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07003217 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003218 }
3219
Yohei Yukawaae61f712015-12-09 13:00:10 -08003220 // Handle input method switching.
Jeff Browncf39bdf2012-05-18 14:41:19 -07003221 if (down && repeatCount == 0
3222 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3223 || (keyCode == KeyEvent.KEYCODE_SPACE
Yohei Yukawaae61f712015-12-09 13:00:10 -08003224 && (metaState & KeyEvent.META_META_MASK) != 0))) {
3225 final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0;
3226 mWindowManagerFuncs.switchInputMethod(forwardDirection);
Jeff Browncf39bdf2012-05-18 14:41:19 -07003227 return -1;
3228 }
3229 if (mLanguageSwitchKeyPressed && !down
3230 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3231 || keyCode == KeyEvent.KEYCODE_SPACE)) {
3232 mLanguageSwitchKeyPressed = false;
3233 return -1;
3234 }
3235
Jeff Brown13f00f02014-10-31 14:45:50 -07003236 if (isValidGlobalKey(keyCode)
3237 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07003238 return -1;
3239 }
3240
Muyuan Li94ce94e2016-02-24 16:20:54 -08003241 if (down) {
3242 long shortcutCode = (long) keyCode;
3243 if (event.isCtrlPressed()) {
3244 shortcutCode |= ((long) KeyEvent.META_CTRL_ON) << Integer.SIZE;
3245 }
3246
3247 if (event.isAltPressed()) {
3248 shortcutCode |= ((long) KeyEvent.META_ALT_ON) << Integer.SIZE;
3249 }
3250
3251 if (event.isShiftPressed()) {
3252 shortcutCode |= ((long) KeyEvent.META_SHIFT_ON) << Integer.SIZE;
3253 }
3254
3255 if (event.isMetaPressed()) {
3256 shortcutCode |= ((long) KeyEvent.META_META_ON) << Integer.SIZE;
3257 }
3258
3259 IShortcutService shortcutService = mShortcutKeyServices.get(shortcutCode);
3260 if (shortcutService != null) {
3261 try {
3262 shortcutService.notifyShortcutKeyPressed(shortcutCode);
3263 } catch (RemoteException e) {
3264 mShortcutKeyServices.delete(shortcutCode);
3265 }
3266 return -1;
3267 }
3268 }
3269
Michael Wright6a62e552014-06-03 19:19:48 -07003270 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07003271 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07003272 return -1;
3273 }
3274
Jeff Brown68b909d2011-12-07 16:36:01 -08003275 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003276 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003277 }
3278
Jeff Brown3915bb82010-11-05 15:02:16 -07003279 /** {@inheritDoc} */
3280 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08003281 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07003282 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07003283 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08003284 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
3285 + ", flags=" + event.getFlags()
3286 + ", keyCode=" + event.getKeyCode()
3287 + ", scanCode=" + event.getScanCode()
3288 + ", metaState=" + event.getMetaState()
3289 + ", repeatCount=" + event.getRepeatCount()
3290 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07003291 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003292
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003293 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003294 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3295 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003296 final int keyCode = event.getKeyCode();
3297 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003298 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
3299 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003300
Jeff Brown54875002011-04-06 15:33:01 -07003301 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003302 final FallbackAction fallbackAction;
3303 if (initialDown) {
3304 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
3305 } else {
3306 fallbackAction = mFallbackActions.get(keyCode);
3307 }
3308
3309 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07003310 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003311 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
3312 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003313 }
3314
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003315 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
3316 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08003317 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003318 event.getAction(), fallbackAction.keyCode,
3319 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08003320 event.getDeviceId(), event.getScanCode(),
3321 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003322
3323 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
3324 fallbackEvent.recycle();
3325 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003326 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003327
3328 if (initialDown) {
3329 mFallbackActions.put(keyCode, fallbackAction);
3330 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3331 mFallbackActions.remove(keyCode);
3332 fallbackAction.recycle();
3333 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003334 }
3335 }
3336
Jeff Brown40013652012-05-16 21:22:36 -07003337 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003338 if (fallbackEvent == null) {
3339 Slog.d(TAG, "No fallback.");
3340 } else {
3341 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3342 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003343 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003344 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003345 }
3346
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003347 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003348 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003349 if ((actions & ACTION_PASS_TO_USER) != 0) {
3350 long delayMillis = interceptKeyBeforeDispatching(
3351 win, fallbackEvent, policyFlags);
3352 if (delayMillis == 0) {
3353 return true;
3354 }
3355 }
3356 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003357 }
3358
Muyuan Li94ce94e2016-02-24 16:20:54 -08003359 public void registerShortcutKey(long shortcutCode, IShortcutService shortcutService)
3360 throws RemoteException {
3361 synchronized (mLock) {
3362 IShortcutService service = mShortcutKeyServices.get(shortcutCode);
3363 if (service != null && service.asBinder().isBinderAlive()) {
3364 throw new RemoteException("Key already exists.");
3365 }
3366
3367 mShortcutKeyServices.put(shortcutCode, shortcutService);
3368 }
3369 }
3370
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003371 private void launchAssistLongPressAction() {
3372 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3373 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3374
3375 // launch the search activity
3376 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3377 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3378 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003379 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003380 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003381 SearchManager searchManager = getSearchManager();
3382 if (searchManager != null) {
3383 searchManager.stopSearch();
3384 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003385 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003386 } catch (ActivityNotFoundException e) {
3387 Slog.w(TAG, "No activity to handle assist long press action.", e);
3388 }
3389 }
3390
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003391 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003392 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Maurice Lam39d13812015-07-23 20:49:20 -07003393 if (!isUserSetupComplete()) {
3394 // Disable opening assist window during setup
3395 return;
3396 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003397 Bundle args = null;
3398 if (deviceId > Integer.MIN_VALUE) {
3399 args = new Bundle();
3400 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003401 }
Jorim Jaggi165ce062015-07-06 16:18:11 -07003402 if ((mContext.getResources().getConfiguration().uiMode
3403 & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
3404 // On TV, use legacy handling until assistants are implemented in the proper way.
3405 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3406 .launchLegacyAssist(hint, UserHandle.myUserId(), args);
3407 } else {
3408 try {
3409 if (hint != null) {
3410 if (args == null) {
3411 args = new Bundle();
3412 }
3413 args.putBoolean(hint, true);
3414 }
3415 IStatusBarService statusbar = getStatusBarService();
3416 if (statusbar != null) {
3417 statusbar.startAssist(args);
3418 }
3419 } catch (RemoteException e) {
3420 Slog.e(TAG, "RemoteException when starting assist", e);
3421 // re-acquire status bar service next time it is needed.
3422 mStatusBarService = null;
3423 }
3424 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003425 }
3426
Bart Sears8b1c27c2015-03-18 23:51:02 +00003427 private void startActivityAsUser(Intent intent, UserHandle handle) {
3428 if (isUserSetupComplete()) {
3429 mContext.startActivityAsUser(intent, handle);
3430 } else {
3431 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3432 }
3433 }
3434
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003435 private SearchManager getSearchManager() {
3436 if (mSearchManager == null) {
3437 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3438 }
3439 return mSearchManager;
3440 }
3441
Jeff Browncaca8812013-05-09 13:34:33 -07003442 private void preloadRecentApps() {
3443 mPreloadedRecentApps = true;
3444 try {
3445 IStatusBarService statusbar = getStatusBarService();
3446 if (statusbar != null) {
3447 statusbar.preloadRecentApps();
3448 }
3449 } catch (RemoteException e) {
3450 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3451 // re-acquire status bar service next time it is needed.
3452 mStatusBarService = null;
3453 }
3454 }
3455
3456 private void cancelPreloadRecentApps() {
3457 if (mPreloadedRecentApps) {
3458 mPreloadedRecentApps = false;
3459 try {
3460 IStatusBarService statusbar = getStatusBarService();
3461 if (statusbar != null) {
3462 statusbar.cancelPreloadRecentApps();
3463 }
3464 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003465 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003466 // re-acquire status bar service next time it is needed.
3467 mStatusBarService = null;
3468 }
3469 }
3470 }
3471
3472 private void toggleRecentApps() {
3473 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003474 try {
3475 IStatusBarService statusbar = getStatusBarService();
3476 if (statusbar != null) {
3477 statusbar.toggleRecentApps();
3478 }
3479 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003480 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3481 // re-acquire status bar service next time it is needed.
3482 mStatusBarService = null;
3483 }
3484 }
3485
Craig Mautner84984fa2014-06-19 11:19:20 -07003486 @Override
3487 public void showRecentApps() {
3488 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3489 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3490 }
3491
Winson Chung1e8d71b2014-05-16 17:05:22 -07003492 private void showRecentApps(boolean triggeredFromAltTab) {
3493 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3494 try {
3495 IStatusBarService statusbar = getStatusBarService();
3496 if (statusbar != null) {
3497 statusbar.showRecentApps(triggeredFromAltTab);
3498 }
3499 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003500 Slog.e(TAG, "RemoteException when showing recent apps", e);
3501 // re-acquire status bar service next time it is needed.
3502 mStatusBarService = null;
3503 }
3504 }
3505
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003506 private void toggleKeyboardShortcutsMenu() {
Clara Bayarrif2debb12015-07-10 14:47:17 +01003507 try {
3508 IStatusBarService statusbar = getStatusBarService();
3509 if (statusbar != null) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003510 statusbar.toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01003511 }
3512 } catch (RemoteException e) {
3513 Slog.e(TAG, "RemoteException when showing keyboard shortcuts menu", e);
3514 }
3515 }
3516
Winson Chungcdcd4872014-08-05 18:00:13 -07003517 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003518 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3519 try {
3520 IStatusBarService statusbar = getStatusBarService();
3521 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003522 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003523 }
3524 } catch (RemoteException e) {
3525 Slog.e(TAG, "RemoteException when closing recent apps", e);
3526 // re-acquire status bar service next time it is needed.
3527 mStatusBarService = null;
3528 }
3529 }
3530
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003531 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003532 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003533 }
3534
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003535 /**
3536 * A home key -> launch home action was detected. Take the appropriate action
3537 * given the situation with the keyguard.
3538 */
Bryce Lee662ed802015-04-10 20:11:39 +00003539 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3540 if (respectKeyguard) {
3541 if (isKeyguardShowingAndNotOccluded()) {
3542 // don't launch home if keyguard showing
3543 return;
3544 }
3545
3546 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3547 // when in keyguard restricted mode, must first verify unlock
3548 // before launching home
3549 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3550 @Override
3551 public void onKeyguardExitResult(boolean success) {
3552 if (success) {
3553 try {
3554 ActivityManagerNative.getDefault().stopAppSwitches();
3555 } catch (RemoteException e) {
3556 }
3557 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3558 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003559 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003560 }
Bryce Lee662ed802015-04-10 20:11:39 +00003561 });
3562 return;
3563 }
3564 }
3565
3566 // no keyguard stuff to worry about, just launch home!
3567 try {
3568 ActivityManagerNative.getDefault().stopAppSwitches();
3569 } catch (RemoteException e) {
3570 }
3571 if (mRecentsVisible) {
3572 // Hide Recents and notify it to launch Home
3573 if (awakenFromDreams) {
3574 awakenDreams();
3575 }
Bryce Lee662ed802015-04-10 20:11:39 +00003576 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003577 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003578 // Otherwise, just launch Home
3579 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3580 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003581 }
3582 }
3583
John Spurlock04db1762013-05-13 12:46:41 -04003584 private final Runnable mClearHideNavigationFlag = new Runnable() {
3585 @Override
3586 public void run() {
3587 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3588 // Clear flags.
3589 mForceClearedSystemUiFlags &=
3590 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3591 }
3592 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003593 }
3594 };
3595
3596 /**
3597 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3598 * to determine when the nav bar should be shown and prevent applications from
3599 * receiving those touches.
3600 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003601 final class HideNavInputEventReceiver extends InputEventReceiver {
3602 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3603 super(inputChannel, looper);
3604 }
3605
Dianne Hackborndf89e652011-10-06 22:35:11 -07003606 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003607 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003608 boolean handled = false;
3609 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003610 if (event instanceof MotionEvent
3611 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3612 final MotionEvent motionEvent = (MotionEvent)event;
3613 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003614 // When the user taps down, we re-show the nav bar.
3615 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003616 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003617 // Any user activity always causes us to show the
3618 // navigation controls, if they had been hidden.
3619 // We also clear the low profile and only content
3620 // flags so that tapping on the screen will atomically
3621 // restore all currently hidden screen decorations.
3622 int newVal = mResettingSystemUiFlags |
3623 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3624 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3625 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003626 if (mResettingSystemUiFlags != newVal) {
3627 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003628 changed = true;
3629 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003630 // We don't allow the system's nav bar to be hidden
3631 // again for 1 second, to prevent applications from
3632 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003633 newVal = mForceClearedSystemUiFlags |
3634 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003635 if (mForceClearedSystemUiFlags != newVal) {
3636 mForceClearedSystemUiFlags = newVal;
3637 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003638 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003639 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003640 }
3641 if (changed) {
3642 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3643 }
3644 }
3645 }
3646 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003647 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003648 }
3649 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003650 }
3651 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3652 new InputEventReceiver.Factory() {
3653 @Override
3654 public InputEventReceiver createInputEventReceiver(
3655 InputChannel inputChannel, Looper looper) {
3656 return new HideNavInputEventReceiver(inputChannel, looper);
3657 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003658 };
3659
3660 @Override
3661 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003662 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3663 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003664 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003665
Dianne Hackborndf89e652011-10-06 22:35:11 -07003666 // Reset any bits in mForceClearingStatusBarVisibility that
3667 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003668 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003669 // Clear any bits in the new visibility that are currently being
3670 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003671 return visibility & ~mResettingSystemUiFlags
3672 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003673 }
3674
Craig Mautner69b08182012-09-05 13:07:13 -07003675 @Override
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08003676 public boolean getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation,
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003677 Rect outContentInsets, Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003678 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003679 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3680 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003681
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003682 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
3683 if (useOutsets) {
3684 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
3685 if (outset > 0) {
3686 if (displayRotation == Surface.ROTATION_0) {
3687 outOutsets.bottom += outset;
3688 } else if (displayRotation == Surface.ROTATION_90) {
3689 outOutsets.right += outset;
3690 } else if (displayRotation == Surface.ROTATION_180) {
3691 outOutsets.top += outset;
3692 } else if (displayRotation == Surface.ROTATION_270) {
3693 outOutsets.left += outset;
3694 }
3695 }
3696 }
3697
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003698 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003699 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003700 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003701 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003702 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003703 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3704 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3705 } else {
3706 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3707 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3708 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003709 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3710 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003711 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003712 availRight - mStableFullscreenRight,
3713 availBottom - mStableFullscreenBottom);
3714 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003715 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003716 availRight - mStableRight, availBottom - mStableBottom);
3717 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003718 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003719 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003720 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003721 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003722 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003723 availRight - mCurRight, availBottom - mCurBottom);
3724 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003725 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003726 availRight - mCurRight, availBottom - mCurBottom);
3727 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003728
3729 outStableInsets.set(mStableLeft, mStableTop,
3730 availRight - mStableRight, availBottom - mStableBottom);
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08003731 return mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003732 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003733 outContentInsets.setEmpty();
3734 outStableInsets.setEmpty();
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08003735 return mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003736 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003737
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003738 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
3739 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
3740 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
3741 }
3742
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003743 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003744 @Override
3745 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003746 int displayRotation, int uiMode) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003747 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003748 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3749 if (isDefaultDisplay) {
3750 switch (displayRotation) {
3751 case Surface.ROTATION_90:
3752 overscanLeft = mOverscanTop;
3753 overscanTop = mOverscanRight;
3754 overscanRight = mOverscanBottom;
3755 overscanBottom = mOverscanLeft;
3756 break;
3757 case Surface.ROTATION_180:
3758 overscanLeft = mOverscanRight;
3759 overscanTop = mOverscanBottom;
3760 overscanRight = mOverscanLeft;
3761 overscanBottom = mOverscanTop;
3762 break;
3763 case Surface.ROTATION_270:
3764 overscanLeft = mOverscanBottom;
3765 overscanTop = mOverscanLeft;
3766 overscanRight = mOverscanTop;
3767 overscanBottom = mOverscanRight;
3768 break;
3769 default:
3770 overscanLeft = mOverscanLeft;
3771 overscanTop = mOverscanTop;
3772 overscanRight = mOverscanRight;
3773 overscanBottom = mOverscanBottom;
3774 break;
3775 }
3776 } else {
3777 overscanLeft = 0;
3778 overscanTop = 0;
3779 overscanRight = 0;
3780 overscanBottom = 0;
3781 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003782 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3783 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3784 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3785 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003786 mSystemLeft = 0;
3787 mSystemTop = 0;
3788 mSystemRight = displayWidth;
3789 mSystemBottom = displayHeight;
3790 mUnrestrictedScreenLeft = overscanLeft;
3791 mUnrestrictedScreenTop = overscanTop;
3792 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3793 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3794 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3795 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003796 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3797 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003798 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003799 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003800 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003801 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003802 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003803 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003804 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003805 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003806 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003807 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003808
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003809 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3810 final Rect pf = mTmpParentFrame;
3811 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003812 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003813 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003814 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003815 pf.left = df.left = of.left = vf.left = mDockLeft;
3816 pf.top = df.top = of.top = vf.top = mDockTop;
3817 pf.right = df.right = of.right = vf.right = mDockRight;
3818 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003819 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003820
Craig Mautner69b08182012-09-05 13:07:13 -07003821 if (isDefaultDisplay) {
3822 // For purposes of putting out fake window up to steal focus, we will
3823 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003824 final int sysui = mLastSystemUiFlags;
3825 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003826 boolean navTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003827 & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003828 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3829 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3830 boolean navAllowedHidden = immersive || immersiveSticky;
3831 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003832 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3833 if (!isKeyguardShowing) {
3834 navTranslucent &= areTranslucentBarsAllowed();
3835 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003836
Craig Mautner69b08182012-09-05 13:07:13 -07003837 // When the navigation bar isn't visible, we put up a fake
3838 // input window to catch all touch events. This way we can
3839 // detect when the user presses anywhere to bring back the nav
3840 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003841 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003842 if (mInputConsumer != null) {
3843 mInputConsumer.dismiss();
3844 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003845 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003846 } else if (mInputConsumer == null) {
3847 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3848 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003849 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003850
Craig Mautner69b08182012-09-05 13:07:13 -07003851 // For purposes of positioning and showing the nav bar, if we have
3852 // decided that it can't be hidden (because of the screen aspect ratio),
3853 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003854 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003855
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003856 boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003857 displayRotation, uiMode, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003858 navAllowedHidden);
Craig Mautnereda67292013-04-28 13:50:14 -07003859 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003860 mDockLeft, mDockTop, mDockRight, mDockBottom));
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003861 updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003862 if (updateSysUiVisibility) {
3863 updateSystemUiVisibilityLw();
3864 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003865 }
3866 }
3867
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003868 private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui,
3869 boolean isKeyguardShowing) {
3870 // decide where the status bar goes ahead of time
3871 if (mStatusBar != null) {
3872 // apply any navigation bar insets
3873 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3874 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3875 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3876 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3877 + mUnrestrictedScreenTop;
3878 vf.left = mStableLeft;
3879 vf.top = mStableTop;
3880 vf.right = mStableRight;
3881 vf.bottom = mStableBottom;
3882
3883 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3884
3885 // Let the status bar determine its size.
3886 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3887 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3888 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
3889
3890 // For layout, the status bar is always at the top with our fixed height.
3891 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3892
3893 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
3894 boolean statusBarTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003895 & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0;
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003896 if (!isKeyguardShowing) {
3897 statusBarTranslucent &= areTranslucentBarsAllowed();
3898 }
3899
3900 // If the status bar is hidden, we don't want to cause
3901 // windows behind it to scroll.
3902 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
3903 // Status bar may go away, so the screen area it occupies
3904 // is available to apps but just covering them when the
3905 // status bar is visible.
3906 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3907
3908 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3909 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3910 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3911 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3912
3913 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
3914 String.format(
3915 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3916 mDockLeft, mDockTop, mDockRight, mDockBottom,
3917 mContentLeft, mContentTop, mContentRight, mContentBottom,
3918 mCurLeft, mCurTop, mCurRight, mCurBottom));
3919 }
3920 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
3921 && !statusBarTransient && !statusBarTranslucent
3922 && !mStatusBarController.wasRecentlyTranslucent()) {
3923 // If the opaque status bar is currently requested to be visible,
3924 // and not in the process of animating on or off, then
3925 // we can tell the app that it is covered by it.
3926 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3927 }
3928 if (mStatusBarController.checkHiddenLw()) {
3929 return true;
3930 }
3931 }
3932 return false;
3933 }
3934
3935 private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003936 int uiMode, int overscanRight, int overscanBottom, Rect dcf, boolean navVisible,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003937 boolean navTranslucent, boolean navAllowedHidden) {
3938 if (mNavigationBar != null) {
3939 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
3940 // Force the navigation bar to its appropriate place and
3941 // size. We need to do this directly, instead of relying on
3942 // it to bubble up from the nav bar, because this needs to
3943 // change atomically with screen rotations.
Jorim Jaggi737af722015-12-31 10:42:27 +01003944 mNavigationBarOnBottom = isNavigationBarOnBottom(displayWidth, displayHeight);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003945 if (mNavigationBarOnBottom) {
3946 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
3947 int top = displayHeight - overscanBottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003948 - getNavigationBarHeight(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003949 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
3950 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
3951 if (transientNavBarShowing) {
3952 mNavigationBarController.setBarShowingLw(true);
3953 } else if (navVisible) {
3954 mNavigationBarController.setBarShowingLw(true);
3955 mDockBottom = mTmpNavigationFrame.top;
3956 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3957 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
3958 } else {
3959 // We currently want to hide the navigation UI.
3960 mNavigationBarController.setBarShowingLw(false);
3961 }
3962 if (navVisible && !navTranslucent && !navAllowedHidden
3963 && !mNavigationBar.isAnimatingLw()
3964 && !mNavigationBarController.wasRecentlyTranslucent()) {
3965 // If the opaque nav bar is currently requested to be visible,
3966 // and not in the process of animating on or off, then
3967 // we can tell the app that it is covered by it.
3968 mSystemBottom = mTmpNavigationFrame.top;
3969 }
3970 } else {
3971 // Landscape screen; nav bar goes to the right.
3972 int left = displayWidth - overscanRight
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003973 - getNavigationBarWidth(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003974 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
3975 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
3976 if (transientNavBarShowing) {
3977 mNavigationBarController.setBarShowingLw(true);
3978 } else if (navVisible) {
3979 mNavigationBarController.setBarShowingLw(true);
3980 mDockRight = mTmpNavigationFrame.left;
3981 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3982 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
3983 } else {
3984 // We currently want to hide the navigation UI.
3985 mNavigationBarController.setBarShowingLw(false);
3986 }
3987 if (navVisible && !navTranslucent && !navAllowedHidden
3988 && !mNavigationBar.isAnimatingLw()
3989 && !mNavigationBarController.wasRecentlyTranslucent()) {
3990 // If the nav bar is currently requested to be visible,
3991 // and not in the process of animating on or off, then
3992 // we can tell the app that it is covered by it.
3993 mSystemRight = mTmpNavigationFrame.left;
3994 }
3995 }
3996 // Make sure the content and current rectangles are updated to
3997 // account for the restrictions from the navigation bar.
3998 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3999 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
4000 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
4001 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
4002 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
4003 // And compute the final frame.
4004 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
4005 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
4006 mTmpNavigationFrame, mTmpNavigationFrame);
4007 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
4008 if (mNavigationBarController.checkHiddenLw()) {
4009 return true;
4010 }
4011 }
4012 return false;
4013 }
4014
Jorim Jaggi737af722015-12-31 10:42:27 +01004015 private boolean isNavigationBarOnBottom(int displayWidth, int displayHeight) {
4016 return !mNavigationBarCanMove || displayWidth < displayHeight;
4017 }
4018
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07004019 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07004020 @Override
John Spurlock46646232013-09-30 22:32:42 -04004021 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00004022 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
4023 return mStatusBar.getSurfaceLayer();
4024 }
4025
4026 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
4027 return mNavigationBar.getSurfaceLayer();
4028 }
4029
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07004030 return 0;
4031 }
4032
Craig Mautner967212c2013-04-13 21:10:58 -07004033 @Override
4034 public void getContentRectLw(Rect r) {
4035 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
4036 }
4037
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004038 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
4039 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004040 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
4041 // Here's a special case: if this attached window is a panel that is
4042 // above the dock window, and the window it is attached to is below
4043 // the dock window, then the frames we computed for the window it is
4044 // attached to can not be used because the dock is effectively part
4045 // of the underlying window and the attached window is floating on top
4046 // of the whole thing. So, we ignore the attached window and explicitly
4047 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004048 df.left = of.left = cf.left = vf.left = mDockLeft;
4049 df.top = of.top = cf.top = vf.top = mDockTop;
4050 df.right = of.right = cf.right = vf.right = mDockRight;
4051 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004052 } else {
4053 // The effective display frame of the attached window depends on
4054 // whether it is taking care of insetting its content. If not,
4055 // we need to use the parent's content frame so that the entire
4056 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07004057 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004058 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004059 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07004060 // Set the content frame of the attached window to the parent's decor frame
4061 // (same as content frame when IME isn't present) if specifically requested by
4062 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
4063 // Otherwise, use the overscan frame.
4064 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
4065 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004066 } else {
4067 // If the window is resizing, then we want to base the content
4068 // frame on our attached content frame to resize... however,
4069 // things can be tricky if the attached window is NOT in resize
4070 // mode, in which case its content frame will be larger.
4071 // Ungh. So to deal with that, make sure the content frame
4072 // we end up using is not covering the IM dock.
4073 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004074 if (attached.isVoiceInteraction()) {
4075 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
4076 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
4077 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
4078 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
4079 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004080 if (cf.left < mContentLeft) cf.left = mContentLeft;
4081 if (cf.top < mContentTop) cf.top = mContentTop;
4082 if (cf.right > mContentRight) cf.right = mContentRight;
4083 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
4084 }
4085 }
4086 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004087 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004088 vf.set(attached.getVisibleFrameLw());
4089 }
4090 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
4091 // window should be positioned relative to its parent or the entire
4092 // screen.
4093 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
4094 ? attached.getFrameLw() : df);
4095 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004096
4097 private void applyStableConstraints(int sysui, int fl, Rect r) {
4098 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
4099 // If app is requesting a stable layout, don't let the
4100 // content insets go below the stable values.
4101 if ((fl & FLAG_FULLSCREEN) != 0) {
4102 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
4103 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
4104 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
4105 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
4106 } else {
4107 if (r.left < mStableLeft) r.left = mStableLeft;
4108 if (r.top < mStableTop) r.top = mStableTop;
4109 if (r.right > mStableRight) r.right = mStableRight;
4110 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
4111 }
4112 }
4113 }
4114
Jorim Jaggiaa806142015-05-20 18:04:16 -07004115 private boolean canReceiveInput(WindowState win) {
4116 boolean notFocusable =
4117 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
4118 boolean altFocusableIm =
4119 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
4120 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
4121 return !notFocusableForIm;
4122 }
4123
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004124 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07004125 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004126 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07004127 // We've already done the navigation bar and status bar. If the status bar can receive
4128 // input, we need to layout it again to accomodate for the IME window.
4129 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004130 return;
4131 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07004132 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07004133 final boolean isDefaultDisplay = win.isDefaultDisplay();
4134 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09004135 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
4136 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07004137 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09004138 offsetInputMethodWindowLw(mLastInputMethodWindow);
4139 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004140
John Spurlockc6d1c602014-01-17 15:22:06 -05004141 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004142 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05004143 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004144
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004145 final Rect pf = mTmpParentFrame;
4146 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004147 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004148 final Rect cf = mTmpContentFrame;
4149 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04004150 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07004151 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004152 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04004153 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07004154
4155 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04004156 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004157
Craig Mautnerf683b562012-10-02 11:10:57 -07004158 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
4159
Adrian Roosfa104232014-06-20 16:10:14 -07004160 if (isDefaultDisplay) {
4161 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
4162 } else {
4163 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
4164 }
4165
Craig Mautner69b08182012-09-05 13:07:13 -07004166 if (!isDefaultDisplay) {
4167 if (attached != null) {
4168 // If this window is attached to another, our display
4169 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004170 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07004171 } else {
4172 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004173 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4174 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4175 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004176 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004177 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004178 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07004179 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004180 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004181 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
4182 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
4183 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04004184 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04004185 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04004186 // ...with content insets above the nav bar
4187 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004188 // IM dock windows always go to the bottom of the screen.
4189 attrs.gravity = Gravity.BOTTOM;
4190 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004191 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004192 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004193 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004194 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4195 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004196 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004197 // Note: In Phone landscape mode, the button bar should also be excluded.
4198 cf.right = vf.right = mStableRight;
4199 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004200 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07004201 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02004202 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4203 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4204 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
4205 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
4206 cf.left = vf.left = mStableLeft;
4207 cf.top = vf.top = mStableTop;
4208 cf.right = vf.right = mStableRight;
4209 vf.bottom = mStableBottom;
Adrian Roosdc5b4532016-01-06 20:49:41 +01004210
4211 if (adjust == SOFT_INPUT_ADJUST_RESIZE) {
4212 cf.bottom = mContentBottom;
4213 } else {
4214 cf.bottom = mDockBottom;
4215 vf.bottom = mContentBottom;
4216 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004217 } else {
John Spurlock46646232013-09-30 22:32:42 -04004218
4219 // Default policy decor for the default display
4220 dcf.left = mSystemLeft;
4221 dcf.top = mSystemTop;
4222 dcf.right = mSystemRight;
4223 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04004224 final boolean inheritTranslucentDecor = (attrs.privateFlags
4225 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04004226 final boolean isAppWindow =
4227 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
4228 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
4229 final boolean topAtRest =
4230 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
4231 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04004232 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
4233 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004234 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
4235 && (fl & WindowManager.LayoutParams.
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004236 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0
4237 && !mForceWindowDrawsStatusBarBackground) {
John Spurlock46646232013-09-30 22:32:42 -04004238 // Ensure policy decor includes status bar
4239 dcf.top = mStableTop;
4240 }
John Spurlockbd957402013-10-03 11:38:39 -04004241 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004242 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
4243 && (fl & WindowManager.LayoutParams.
4244 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004245 // Ensure policy decor includes navigation bar
4246 dcf.bottom = mStableBottom;
4247 dcf.right = mStableRight;
4248 }
4249 }
4250
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004251 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
4252 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07004253 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004254 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004255 // This is the case for a normal activity window: we want it
4256 // to cover all of the screen space, and it can take care of
4257 // moving its contents to account for screen decorations that
4258 // intrude into that space.
4259 if (attached != null) {
4260 // If this window is attached to another, our display
4261 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004262 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004263 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004264 if (attrs.type == TYPE_STATUS_BAR_PANEL
4265 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08004266 // Status bar panels are the only windows who can go on top of
4267 // the status bar. They are protected by the STATUS_BAR_SERVICE
4268 // permission, so they have the same privileges as the status
4269 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004270 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004271 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004272
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004273 pf.left = df.left = of.left = hasNavBar
4274 ? mDockLeft : mUnrestrictedScreenLeft;
4275 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4276 pf.right = df.right = of.right = hasNavBar
4277 ? mRestrictedScreenLeft+mRestrictedScreenWidth
4278 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4279 pf.bottom = df.bottom = of.bottom = hasNavBar
4280 ? mRestrictedScreenTop+mRestrictedScreenHeight
4281 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004282
Craig Mautnereda67292013-04-28 13:50:14 -07004283 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004284 "Laying out status bar window: (%d,%d - %d,%d)",
4285 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04004286 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004287 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4288 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4289 // Asking to layout into the overscan region, so give it that pure
4290 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004291 pf.left = df.left = of.left = mOverscanScreenLeft;
4292 pf.top = df.top = of.top = mOverscanScreenTop;
4293 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
4294 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
4295 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004296 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004297 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004298 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4299 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004300 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08004301 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004302 // only do this for application windows to ensure no window that
4303 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08004304 pf.left = df.left = mOverscanScreenLeft;
4305 pf.top = df.top = mOverscanScreenTop;
4306 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4307 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004308 // We need to tell the app about where the frame inside the overscan
4309 // is, so it can inset its content by that amount -- it didn't ask
4310 // to actually extend itself into the overscan region.
4311 of.left = mUnrestrictedScreenLeft;
4312 of.top = mUnrestrictedScreenTop;
4313 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4314 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004315 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08004316 pf.left = df.left = mRestrictedOverscanScreenLeft;
4317 pf.top = df.top = mRestrictedOverscanScreenTop;
4318 pf.right = df.right = mRestrictedOverscanScreenLeft
4319 + mRestrictedOverscanScreenWidth;
4320 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
4321 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004322 // We need to tell the app about where the frame inside the overscan
4323 // is, so it can inset its content by that amount -- it didn't ask
4324 // to actually extend itself into the overscan region.
4325 of.left = mUnrestrictedScreenLeft;
4326 of.top = mUnrestrictedScreenTop;
4327 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4328 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004329 }
Craig Mautner69b08182012-09-05 13:07:13 -07004330
John Spurlock46646232013-09-30 22:32:42 -04004331 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004332 if (win.isVoiceInteraction()) {
4333 cf.left = mVoiceContentLeft;
4334 cf.top = mVoiceContentTop;
4335 cf.right = mVoiceContentRight;
4336 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004337 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004338 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4339 cf.left = mDockLeft;
4340 cf.top = mDockTop;
4341 cf.right = mDockRight;
4342 cf.bottom = mDockBottom;
4343 } else {
4344 cf.left = mContentLeft;
4345 cf.top = mContentTop;
4346 cf.right = mContentRight;
4347 cf.bottom = mContentBottom;
4348 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004349 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004350 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004351 // Full screen windows are always given a layout that is as if the
4352 // status bar and other transient decors are gone. This is to avoid
4353 // bad states when moving from a window that is not hding the
4354 // status bar to one that is.
4355 cf.left = mRestrictedScreenLeft;
4356 cf.top = mRestrictedScreenTop;
4357 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4358 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004359 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004360 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004361 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4362 vf.left = mCurLeft;
4363 vf.top = mCurTop;
4364 vf.right = mCurRight;
4365 vf.bottom = mCurBottom;
4366 } else {
4367 vf.set(cf);
4368 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004369 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004370 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
4371 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
4372 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07004373 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4374 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004375 // A window that has requested to fill the entire screen just
4376 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004377 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04004378 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
4379 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004380 pf.left = df.left = of.left = cf.left = hasNavBar
4381 ? mDockLeft : mUnrestrictedScreenLeft;
4382 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4383 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004384 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08004385 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004386 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004387 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004388 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004389 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04004390 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
4391 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07004392 } else if (attrs.type == TYPE_NAVIGATION_BAR
4393 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004394 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004395 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4396 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4397 pf.right = df.right = of.right = mUnrestrictedScreenLeft
4398 + mUnrestrictedScreenWidth;
4399 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
4400 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004401 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004402 "Laying out navigation bar window: (%d,%d - %d,%d)",
4403 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08004404 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
4405 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07004406 && ((fl & FLAG_FULLSCREEN) != 0)) {
4407 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004408 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4409 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4410 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4411 + mOverscanScreenWidth;
4412 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4413 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08004414 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08004415 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004416 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4417 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4418 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4419 + mOverscanScreenWidth;
4420 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4421 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04004422 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004423 // The wallpaper also has Real Ultimate Power, but we want to tell
4424 // it about the overscan area.
4425 pf.left = df.left = mOverscanScreenLeft;
4426 pf.top = df.top = mOverscanScreenTop;
4427 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4428 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4429 of.left = cf.left = mUnrestrictedScreenLeft;
4430 of.top = cf.top = mUnrestrictedScreenTop;
4431 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4432 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004433 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004434 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4435 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4436 // Asking to layout into the overscan region, so give it that pure
4437 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004438 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4439 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4440 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004441 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004442 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004443 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004444 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004445 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004446 && (attrs.type == TYPE_STATUS_BAR
4447 || attrs.type == TYPE_TOAST
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01004448 || attrs.type == TYPE_DOCK_DIVIDER
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004449 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004450 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4451 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004452 // Asking for layout as if the nav bar is hidden, lets the
4453 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004454 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004455 // can be above the nav bar can do this.
4456 // XXX This assumes that an app asking for this will also
4457 // ask for layout in only content. We can't currently figure out
4458 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004459 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4460 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4461 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4462 + mUnrestrictedScreenWidth;
4463 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4464 + mUnrestrictedScreenHeight;
Jorim Jaggi9f6798a2016-02-10 22:16:06 -08004465 } else if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0) {
4466 pf.left = df.left = of.left = mRestrictedScreenLeft;
4467 pf.top = df.top = of.top = mRestrictedScreenTop;
4468 pf.right = df.right = of.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4469 pf.bottom = df.bottom = of.bottom = mRestrictedScreenTop
4470 + mRestrictedScreenHeight;
4471 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4472 cf.left = mDockLeft;
4473 cf.top = mDockTop;
4474 cf.right = mDockRight;
4475 cf.bottom = mDockBottom;
4476 } else {
4477 cf.left = mContentLeft;
4478 cf.top = mContentTop;
4479 cf.right = mContentRight;
4480 cf.bottom = mContentBottom;
4481 }
Joe Onorato29fc2c92010-11-24 10:26:50 -08004482 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004483 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4484 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4485 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4486 + mRestrictedScreenWidth;
4487 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4488 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004489 }
Craig Mautner69b08182012-09-05 13:07:13 -07004490
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004491 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004492
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004493 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4494 vf.left = mCurLeft;
4495 vf.top = mCurTop;
4496 vf.right = mCurRight;
4497 vf.bottom = mCurBottom;
4498 } else {
4499 vf.set(cf);
4500 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004501 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004502 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4503 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004504 // A child window should be placed inside of the same visible
4505 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004506 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004507 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004508 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4509 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004510 // Otherwise, a normal window must be placed inside the content
4511 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004512 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4513 // Status bar panels and the volume dialog are the only windows who can go on
4514 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004515 // permission, so they have the same privileges as the status
4516 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004517 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4518 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4519 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4520 + mRestrictedScreenWidth;
4521 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4522 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004523 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004524 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004525 pf.left = df.left = of.left = cf.left = mStableLeft;
4526 pf.top = df.top = of.top = cf.top = mStableTop;
4527 pf.right = df.right = of.right = cf.right = mStableRight;
4528 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004529 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004530 pf.left = mContentLeft;
4531 pf.top = mContentTop;
4532 pf.right = mContentRight;
4533 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004534 if (win.isVoiceInteraction()) {
4535 df.left = of.left = cf.left = mVoiceContentLeft;
4536 df.top = of.top = cf.top = mVoiceContentTop;
4537 df.right = of.right = cf.right = mVoiceContentRight;
4538 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4539 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004540 df.left = of.left = cf.left = mDockLeft;
4541 df.top = of.top = cf.top = mDockTop;
4542 df.right = of.right = cf.right = mDockRight;
4543 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004544 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004545 df.left = of.left = cf.left = mContentLeft;
4546 df.top = of.top = cf.top = mContentTop;
4547 df.right = of.right = cf.right = mContentRight;
4548 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004549 }
4550 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4551 vf.left = mCurLeft;
4552 vf.top = mCurTop;
4553 vf.right = mCurRight;
4554 vf.bottom = mCurBottom;
4555 } else {
4556 vf.set(cf);
4557 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004558 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004559 }
4560 }
Craig Mautner69b08182012-09-05 13:07:13 -07004561
Craig Mautnerb816bed2013-07-23 10:26:17 -07004562 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4563 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004564 df.left = df.top = -10000;
4565 df.right = df.bottom = 10000;
4566 if (attrs.type != TYPE_WALLPAPER) {
4567 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4568 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4569 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004570 }
4571
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004572 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4573 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004574 // We only want to apply outsets to certain types of windows. For example, we never want to
4575 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004576 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004577 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004578 osf = mTmpOutsetFrame;
4579 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4580 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4581 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004582 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004583 if (rotation == Surface.ROTATION_0) {
4584 osf.bottom += outset;
4585 } else if (rotation == Surface.ROTATION_90) {
4586 osf.right += outset;
4587 } else if (rotation == Surface.ROTATION_180) {
4588 osf.top -= outset;
4589 } else if (rotation == Surface.ROTATION_270) {
4590 osf.left -= outset;
4591 }
4592 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4593 + " with rotation " + rotation + ", result: " + osf);
4594 }
4595 }
4596
Craig Mautnereda67292013-04-28 13:50:14 -07004597 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004598 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004599 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004600 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004601 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004602 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004603 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004604 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004605 + " sf=" + sf.toShortString()
4606 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004607
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004608 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004609
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004610 // Dock windows carve out the bottom of the screen, so normal windows
4611 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004612 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4613 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004614 setLastInputMethodWindowLw(null, null);
4615 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004616 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004617 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4618 && !win.getGivenInsetsPendingLw()) {
4619 offsetVoiceInputWindowLw(win);
4620 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004621 }
4622
satok1bc0a492012-04-25 22:47:12 +09004623 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004624 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004625 top += win.getGivenContentInsetsLw().top;
4626 if (mContentBottom > top) {
4627 mContentBottom = top;
4628 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004629 if (mVoiceContentBottom > top) {
4630 mVoiceContentBottom = top;
4631 }
satok1bc0a492012-04-25 22:47:12 +09004632 top = win.getVisibleFrameLw().top;
4633 top += win.getGivenVisibleInsetsLw().top;
4634 if (mCurBottom > top) {
4635 mCurBottom = top;
4636 }
Craig Mautnereda67292013-04-28 13:50:14 -07004637 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004638 + mDockBottom + " mContentBottom="
4639 + mContentBottom + " mCurBottom=" + mCurBottom);
4640 }
4641
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004642 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004643 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004644 top += win.getGivenContentInsetsLw().top;
4645 if (mVoiceContentBottom > top) {
4646 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004647 }
4648 }
4649
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004650 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004651 @Override
4652 public void finishLayoutLw() {
4653 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004654 }
4655
4656 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004657 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004658 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004659 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004660 mTopFullscreenOpaqueOrDimmingWindowState = null;
Jorim Jaggi86905582016-02-09 21:36:09 -08004661 mTopDockedOpaqueWindowState = null;
4662 mTopDockedOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004663 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004664 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004665 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004666 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004667 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004668 mForcingShowNavBar = false;
4669 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004670
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004671 mHideLockScreen = false;
4672 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004673 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004674 mShowingLockscreen = false;
4675 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004676 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004677 mKeyguardSecure = isKeyguardSecure();
4678 mKeyguardSecureIncludingHidden = mKeyguardSecure
4679 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004680 }
4681
4682 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004683 @Override
Yohei Yukawad1a09222015-06-30 16:22:05 -07004684 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,
4685 WindowState attached) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004686 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4687 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004688 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004689 if (mTopFullscreenOpaqueWindowState == null
4690 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4691 mForcingShowNavBar = true;
4692 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004693 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004694 if (attrs.type == TYPE_STATUS_BAR) {
4695 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4696 mForceStatusBarFromKeyguard = true;
Jorim Jaggie1de9f62015-09-23 14:59:50 -07004697 mShowingLockscreen = true;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004698 }
4699 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4700 mForceStatusBarTransparent = true;
4701 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004702 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004703
4704 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4705 && attrs.type < FIRST_SYSTEM_WINDOW;
4706 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4707 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Jorim Jaggi86905582016-02-09 21:36:09 -08004708 final int stackId = win.getStackId();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004709 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004710 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004711 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004712 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004713 mForceStatusBarFromKeyguard = true;
4714 } else {
4715 mForceStatusBar = true;
4716 }
4717 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004718 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004719 // If the lockscreen was showing when the dream started then wait
4720 // for the dream to draw before hiding the lockscreen.
4721 if (!mDreamingLockscreen
4722 || (win.isVisibleLw() && win.hasDrawnLw())) {
4723 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004724 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004725 }
4726 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004727
Yohei Yukawad1a09222015-06-30 16:22:05 -07004728 final IApplicationToken appToken = win.getAppToken();
4729
4730 // For app windows that are not attached, we decide if all windows in the app they
4731 // represent should be hidden or if we should hide the lockscreen. For attached app
4732 // windows we defer the decision to the window it is attached to.
4733 if (appWindow && attached == null) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004734 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004735 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004736 mAppsToBeHidden.remove(appToken);
4737 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004738 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004739 if (dismissKeyguard && !mKeyguardSecure) {
4740 mAppsThatDismissKeyguard.add(appToken);
Selim Cinek90b5e072015-08-28 17:05:56 -07004741 } else if (win.isDrawnLw() || win.hasAppShownWindows()) {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004742 mWinShowWhenLocked = win;
4743 mHideLockScreen = true;
4744 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004745 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004746 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004747 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004748 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004749 mAppsToBeHidden.add(appToken);
4750 } else {
4751 mAppsToBeHidden.remove(appToken);
4752 }
4753 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004754 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004755 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004756 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004757 if (isFullscreen(attrs) && StackId.normallyFullscreenWindows(stackId)) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004758 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4759 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004760 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4761 mTopFullscreenOpaqueOrDimmingWindowState = win;
4762 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004763 if (!mAppsThatDismissKeyguard.isEmpty() &&
4764 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4765 if (DEBUG_LAYOUT) Slog.v(TAG,
4766 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004767 mDismissKeyguard = (mWinDismissingKeyguard == win
4768 && mSecureDismissingKeyguard == mKeyguardSecure)
4769 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004770 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004771 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004772 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Selim Cinek90b5e072015-08-28 17:05:56 -07004773 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked
4774 && (win.isDrawnLw() || win.hasAppShownWindows())) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004775 if (DEBUG_LAYOUT) Slog.v(TAG,
4776 "Setting mHideLockScreen to true by win " + win);
4777 mHideLockScreen = true;
4778 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004779 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004780 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004781 mAllowLockscreenWhenOn = true;
4782 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004783 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004784
4785 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004786 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4787 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004788 win.hideLw(false);
4789 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004790 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004791 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4792 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4793 // that is being hidden in an animation - keep the
4794 // keyguard hidden until the new window shows up and
4795 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004796 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004797 mHideLockScreen = true;
4798 mWinShowWhenLocked = win;
4799 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004800 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004801
4802 // Keep track of the window if it's dimming but not necessarily fullscreen.
4803 final boolean reallyVisible = win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw();
4804 if (mTopFullscreenOpaqueOrDimmingWindowState == null && reallyVisible
4805 && win.isDimming() && StackId.normallyFullscreenWindows(stackId)) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01004806 mTopFullscreenOpaqueOrDimmingWindowState = win;
4807 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004808
4809 // We need to keep track of the top "fullscreen" opaque window for the docked stack
4810 // separately, because both the "real fullscreen" opaque window and the one for the docked
4811 // stack can control View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.
4812 if (mTopDockedOpaqueWindowState == null && reallyVisible && appWindow && attached == null
4813 && isFullscreen(attrs) && stackId == DOCKED_STACK_ID) {
4814 mTopDockedOpaqueWindowState = win;
4815 if (mTopDockedOpaqueOrDimmingWindowState == null) {
4816 mTopDockedOpaqueOrDimmingWindowState = win;
4817 }
4818 }
4819
4820 // Also keep track of any windows that are dimming but not necessarily fullscreen in the
4821 // docked stack.
4822 if (mTopDockedOpaqueOrDimmingWindowState == null && reallyVisible && win.isDimming()
4823 && stackId == DOCKED_STACK_ID) {
4824 mTopDockedOpaqueOrDimmingWindowState = win;
4825 }
4826 }
4827
4828 private boolean isFullscreen(WindowManager.LayoutParams attrs) {
4829 return attrs.x == 0 && attrs.y == 0
4830 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4831 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004832 }
4833
4834 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004835 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004836 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004837 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4838 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4839 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004840 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4841 // fullscreen window.
4842 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4843 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4844 mTopFullscreenOpaqueWindowState.hideLw(false);
4845 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4846 }
4847
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004848 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004849 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004850
4851 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4852 ? mTopFullscreenOpaqueWindowState.getAttrs()
4853 : null;
4854
Jeff Brownc8018eb2012-10-29 21:33:27 -07004855 // If we are not currently showing a dream then remember the current
4856 // lockscreen state. We will use this to determine whether the dream
4857 // started while the lockscreen was showing and remember this state
4858 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004859 if (!mShowingDream) {
4860 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004861 if (mDreamingSleepTokenNeeded) {
4862 mDreamingSleepTokenNeeded = false;
4863 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4864 }
4865 } else {
4866 if (!mDreamingSleepTokenNeeded) {
4867 mDreamingSleepTokenNeeded = true;
4868 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4869 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004870 }
4871
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004872 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004873 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004874 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004875 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004876 boolean shouldBeTransparent = mForceStatusBarTransparent
4877 && !mForceStatusBar
4878 && !mForceStatusBarFromKeyguard;
4879 if (!shouldBeTransparent) {
4880 mStatusBarController.setShowTransparent(false /* transparent */);
4881 } else if (!mStatusBar.isVisibleLw()) {
4882 mStatusBarController.setShowTransparent(true /* transparent */);
4883 }
4884 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004885 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004886 if (mStatusBarController.setBarShowingLw(true)) {
4887 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4888 }
Craig Mautner81defc72013-10-29 11:10:42 -07004889 // Maintain fullscreen layout until incoming animation is complete.
4890 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004891 // Transient status bar on the lockscreen is not allowed
4892 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4893 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4894 mLastSystemUiFlags, mLastSystemUiFlags);
4895 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004896 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004897 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004898 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004899 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07004900 + " shown position: "
4901 + mTopFullscreenOpaqueWindowState.getShownPositionLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004902 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004903 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004904 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004905 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004906 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004907 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004908 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004909 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4910 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004911 if (mStatusBarController.isTransientShowing()) {
4912 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004913 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4914 }
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07004915 } else if (topIsFullscreen
4916 && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID)
4917 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) {
Craig Mautnereda67292013-04-28 13:50:14 -07004918 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004919 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004920 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004921 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004922 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004923 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004924 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004925 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004926 if (mStatusBarController.setBarShowingLw(true)) {
4927 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4928 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004929 }
4930 }
4931 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004932
Craig Mautner81defc72013-10-29 11:10:42 -07004933 if (mTopIsFullscreen != topIsFullscreen) {
4934 if (!topIsFullscreen) {
4935 // Force another layout when status bar becomes fully shown.
4936 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4937 }
4938 mTopIsFullscreen = topIsFullscreen;
4939 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004940
Craig Mautner39834192012-09-02 07:47:24 -07004941 // Hide the key guard if a visible window explicitly specifies that it wants to be
4942 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004943 if (mKeyguardDelegate != null && mStatusBar != null) {
4944 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4945 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004946 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004947 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004948 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004949 changes |= FINISH_LAYOUT_REDO_LAYOUT
4950 | FINISH_LAYOUT_REDO_CONFIG
4951 | FINISH_LAYOUT_REDO_WALLPAPER;
4952 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004953 if (mKeyguardDelegate.isShowing()) {
4954 mHandler.post(new Runnable() {
4955 @Override
4956 public void run() {
4957 mKeyguardDelegate.keyguardDone(false, false);
4958 }
4959 });
4960 }
4961 } else if (mHideLockScreen) {
4962 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004963 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004964 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004965 changes |= FINISH_LAYOUT_REDO_LAYOUT
4966 | FINISH_LAYOUT_REDO_CONFIG
4967 | FINISH_LAYOUT_REDO_WALLPAPER;
4968 }
4969 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004970 mKeyguardHidden = false;
4971 if (setKeyguardOccludedLw(false)) {
4972 changes |= FINISH_LAYOUT_REDO_LAYOUT
4973 | FINISH_LAYOUT_REDO_CONFIG
4974 | FINISH_LAYOUT_REDO_WALLPAPER;
4975 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004976 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4977 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004978 mHandler.post(new Runnable() {
4979 @Override
4980 public void run() {
4981 mKeyguardDelegate.dismiss();
4982 }
4983 });
4984 }
4985 } else {
4986 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004987 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004988 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004989 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004990 changes |= FINISH_LAYOUT_REDO_LAYOUT
4991 | FINISH_LAYOUT_REDO_CONFIG
4992 | FINISH_LAYOUT_REDO_WALLPAPER;
4993 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004994 }
4995 }
Joe Onorato664644d2011-01-23 17:53:23 -08004996
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004997 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004998 // If the navigation bar has been hidden or shown, we need to do another
4999 // layout pass to update that window.
5000 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5001 }
Joe Onorato664644d2011-01-23 17:53:23 -08005002
Mike Lockwood28569302010-01-28 11:54:40 -05005003 // update since mAllowLockscreenWhenOn might have changed
5004 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005005 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005006 }
5007
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005008 /**
Jim Millerab954542014-10-10 18:21:49 -07005009 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005010 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005011 * @return Whether the flags have changed and we have to redo the layout.
5012 */
Jim Millerab954542014-10-10 18:21:49 -07005013 private boolean setKeyguardOccludedLw(boolean isOccluded) {
5014 boolean wasOccluded = mKeyguardOccluded;
5015 boolean showing = mKeyguardDelegate.isShowing();
5016 if (wasOccluded && !isOccluded && showing) {
5017 mKeyguardOccluded = false;
5018 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005019 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
5020 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
5021 return true;
Jim Millerab954542014-10-10 18:21:49 -07005022 } else if (!wasOccluded && isOccluded && showing) {
5023 mKeyguardOccluded = true;
5024 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005025 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
5026 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
5027 return true;
5028 } else {
5029 return false;
5030 }
5031 }
5032
5033 private boolean isStatusBarKeyguard() {
5034 return mStatusBar != null
5035 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
5036 }
5037
Jose Lima9546b202014-07-02 17:21:51 -07005038 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08005039 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005040 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07005041 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08005042 return false;
5043 }
Dianne Hackborn08743722009-12-21 12:16:51 -08005044 return true;
5045 }
5046
Jose Lima9546b202014-07-02 17:21:51 -07005047 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005048 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08005049 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005050 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005051 // If the navigation bar has been hidden or shown, we need to do another
5052 // layout pass to update that window.
5053 return FINISH_LAYOUT_REDO_LAYOUT;
5054 }
5055 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08005056 }
5057
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07005058 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005059 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07005060 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5061 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07005062 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
5063 if (newLidState == mLidState) {
5064 return;
5065 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005066
Jeff Brownc458ce92012-04-30 14:58:40 -07005067 mLidState = newLidState;
5068 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005069 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07005070
5071 if (lidOpen) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005072 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch,
5073 "android.policy:LID");
Jeff Brownc458ce92012-04-30 14:58:40 -07005074 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07005075 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005076 }
5077 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005078
Michael Wright3818c922014-09-02 13:59:07 -07005079 @Override
5080 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
5081 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
5082 if (mCameraLensCoverState == lensCoverState) {
5083 return;
5084 }
5085 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
5086 lensCoverState == CAMERA_LENS_UNCOVERED) {
5087 Intent intent;
5088 final boolean keyguardActive = mKeyguardDelegate == null ? false :
5089 mKeyguardDelegate.isShowing();
5090 if (keyguardActive) {
5091 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
5092 } else {
5093 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
5094 }
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005095 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens,
5096 "android.policy:CAMERA_COVER");
Bart Sears8b1c27c2015-03-18 23:51:02 +00005097 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07005098 }
5099 mCameraLensCoverState = lensCoverState;
5100 }
5101
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005102 void setHdmiPlugged(boolean plugged) {
5103 if (mHdmiPlugged != plugged) {
5104 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005105 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005106 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08005107 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005108 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07005109 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005110 }
5111 }
5112
Joe Onoratoea495d42011-04-06 11:41:11 -07005113 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07005114 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07005115 // watch for HDMI plug messages if the hdmi switch exists
5116 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
5117 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
5118
Joe Onoratoea495d42011-04-06 11:41:11 -07005119 final String filename = "/sys/class/switch/hdmi/state";
5120 FileReader reader = null;
5121 try {
5122 reader = new FileReader(filename);
5123 char[] buf = new char[15];
5124 int n = reader.read(buf);
5125 if (n > 1) {
5126 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
5127 }
5128 } catch (IOException ex) {
5129 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5130 } catch (NumberFormatException ex) {
5131 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5132 } finally {
5133 if (reader != null) {
5134 try {
5135 reader.close();
5136 } catch (IOException ex) {
5137 }
Joe Onoratodc100302011-01-11 17:07:41 -08005138 }
5139 }
5140 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07005141 // This dance forces the code in setHdmiPlugged to run.
5142 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
5143 mHdmiPlugged = !plugged;
5144 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08005145 }
5146
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07005147 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005148 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005149
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005150 final Runnable mScreenshotTimeout = new Runnable() {
5151 @Override public void run() {
5152 synchronized (mScreenshotLock) {
5153 if (mScreenshotConnection != null) {
5154 mContext.unbindService(mScreenshotConnection);
5155 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005156 }
Winson Chung9112ec32011-06-27 13:15:32 -07005157 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005158 }
5159 };
5160
5161 // Assume this is called from the Handler thread.
5162 private void takeScreenshot() {
5163 synchronized (mScreenshotLock) {
5164 if (mScreenshotConnection != null) {
5165 return;
5166 }
5167 ComponentName cn = new ComponentName("com.android.systemui",
5168 "com.android.systemui.screenshot.TakeScreenshotService");
5169 Intent intent = new Intent();
5170 intent.setComponent(cn);
5171 ServiceConnection conn = new ServiceConnection() {
5172 @Override
5173 public void onServiceConnected(ComponentName name, IBinder service) {
5174 synchronized (mScreenshotLock) {
5175 if (mScreenshotConnection != this) {
5176 return;
5177 }
5178 Messenger messenger = new Messenger(service);
5179 Message msg = Message.obtain(null, 1);
5180 final ServiceConnection myConn = this;
5181 Handler h = new Handler(mHandler.getLooper()) {
5182 @Override
5183 public void handleMessage(Message msg) {
5184 synchronized (mScreenshotLock) {
5185 if (mScreenshotConnection == myConn) {
5186 mContext.unbindService(mScreenshotConnection);
5187 mScreenshotConnection = null;
5188 mHandler.removeCallbacks(mScreenshotTimeout);
5189 }
5190 }
5191 }
5192 };
5193 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07005194 msg.arg1 = msg.arg2 = 0;
5195 if (mStatusBar != null && mStatusBar.isVisibleLw())
5196 msg.arg1 = 1;
5197 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
5198 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005199 try {
5200 messenger.send(msg);
5201 } catch (RemoteException e) {
5202 }
5203 }
5204 }
5205 @Override
5206 public void onServiceDisconnected(ComponentName name) {}
5207 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08005208 if (mContext.bindServiceAsUser(
5209 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005210 mScreenshotConnection = conn;
5211 mHandler.postDelayed(mScreenshotTimeout, 10000);
5212 }
5213 }
Winson Chung9112ec32011-06-27 13:15:32 -07005214 }
5215
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005216 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005217 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07005218 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07005219 if (!mSystemBooted) {
5220 // If we have not yet booted, don't let key events do anything.
5221 return 0;
5222 }
5223
Jeff Brown037c33e2014-04-09 00:31:55 -07005224 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08005225 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
5226 final boolean canceled = event.isCanceled();
5227 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07005228
Jeff Brown3122e442010-10-11 23:32:49 -07005229 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07005230
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05005231 // If screen is off then we treat the case where the keyguard is open but hidden
5232 // the same as if it were open and in front.
5233 // This will prevent any keys other than the power button from waking the screen
5234 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08005235 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07005236 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07005237 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08005238 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005239
Jeff Brown40013652012-05-16 21:22:36 -07005240 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005241 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07005242 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08005243 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005244 }
5245
Jeff Brown037c33e2014-04-09 00:31:55 -07005246 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07005247 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07005248 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
5249 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07005250 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07005251 // When the device is interactive or the key is injected pass the
5252 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07005253 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005254 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07005255 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
5256 // If we're currently dozing with the screen on and the keyguard showing, pass the key
5257 // to the application but preserve its wake key status to make sure we still move
5258 // from dozing to fully interactive if we would normally go from off to fully
5259 // interactive.
5260 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07005261 } else {
5262 // When the screen is off and the key is not injected, determine whether
5263 // to wake the device but don't pass the key to the application.
5264 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08005265 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
5266 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005267 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005268 }
5269
Justin Kohd378ad72013-04-01 12:18:26 -07005270 // If the key would be handled globally, just return the result, don't worry about special
5271 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07005272 if (isValidGlobalKey(keyCode)
5273 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07005274 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005275 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Michael Wright85b1af62014-06-04 14:51:58 -07005276 }
Justin Kohd378ad72013-04-01 12:18:26 -07005277 return result;
5278 }
5279
Jeff Brownbae8e772014-06-12 19:59:45 -07005280 boolean useHapticFeedback = down
5281 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
5282 && event.getRepeatCount() == 0;
5283
Jeff Brown4d396052010-10-29 21:50:21 -07005284 // Handle special keys.
5285 switch (keyCode) {
5286 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07005287 case KeyEvent.KEYCODE_VOLUME_UP:
5288 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005289 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
5290 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005291 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005292 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005293 mScreenshotChordVolumeDownKeyTriggered = true;
5294 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
5295 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005296 cancelPendingPowerKeyAction();
5297 interceptScreenshotChord();
5298 }
5299 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005300 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005301 cancelPendingScreenshotChordAction();
5302 }
5303 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
5304 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005305 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005306 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005307 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005308 cancelPendingPowerKeyAction();
5309 cancelPendingScreenshotChordAction();
5310 }
5311 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005312 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005313 cancelPendingScreenshotChordAction();
5314 }
5315 }
Jeff Brown4d396052010-10-29 21:50:21 -07005316 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005317 TelecomManager telecomManager = getTelecommService();
5318 if (telecomManager != null) {
5319 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005320 // If an incoming call is ringing, either VOLUME key means
5321 // "silence ringer". We handle these keys here, rather than
5322 // in the InCallScreen, to make sure we'll respond to them
5323 // even if the InCallScreen hasn't come to the foreground yet.
5324 // Look for the DOWN event here, to agree with the "fallback"
5325 // behavior in the InCallScreen.
5326 Log.i(TAG, "interceptKeyBeforeQueueing:"
5327 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07005328
Santos Cordon6848f722014-05-21 15:22:12 -07005329 // Silence the ringer. (It's safe to call this
5330 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005331 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07005332
Santos Cordon6848f722014-05-21 15:22:12 -07005333 // And *don't* pass this key thru to the current activity
5334 // (which is probably the InCallScreen.)
5335 result &= ~ACTION_PASS_TO_USER;
5336 break;
5337 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005338 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07005339 && (result & ACTION_PASS_TO_USER) == 0) {
5340 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07005341 // the application, just pass it to the session service.
5342
5343 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07005344 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07005345 break;
Jeff Brown4d396052010-10-29 21:50:21 -07005346 }
5347 }
Jaewan Kim765487f2016-01-12 14:45:42 +09005348 }
5349 if (mUseTvRouting) {
5350 // On TVs, defer special key handlings to
5351 // {@link interceptKeyBeforeDispatching()}.
5352 result |= ACTION_PASS_TO_USER;
5353 } else if ((result & ACTION_PASS_TO_USER) == 0) {
5354 // If we aren't passing to the user and no one else
5355 // handled it send it to the session manager to
5356 // figure out.
5357 MediaSessionLegacyHelper.getHelper(mContext)
5358 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07005359 }
5360 break;
5361 }
5362
5363 case KeyEvent.KEYCODE_ENDCALL: {
5364 result &= ~ACTION_PASS_TO_USER;
5365 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005366 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07005367 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005368 if (telecomManager != null) {
5369 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07005370 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005371 if (interactive && !hungUp) {
5372 mEndCallKeyHandled = false;
5373 mHandler.postDelayed(mEndCallLongPress,
5374 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
5375 } else {
5376 mEndCallKeyHandled = true;
5377 }
Jeff Brown4d396052010-10-29 21:50:21 -07005378 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005379 if (!mEndCallKeyHandled) {
5380 mHandler.removeCallbacks(mEndCallLongPress);
5381 if (!canceled) {
5382 if ((mEndcallBehavior
5383 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
5384 if (goHome()) {
5385 break;
5386 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07005387 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005388 if ((mEndcallBehavior
5389 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
5390 mPowerManager.goToSleep(event.getEventTime(),
5391 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
5392 isWakeKey = false;
5393 }
Jeff Brown4d396052010-10-29 21:50:21 -07005394 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005395 }
Jeff Brown4d396052010-10-29 21:50:21 -07005396 }
5397 break;
5398 }
5399
5400 case KeyEvent.KEYCODE_POWER: {
5401 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07005402 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07005403 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005404 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005405 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005406 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07005407 }
5408 break;
5409 }
5410
Jeff Brown6212a492014-03-07 13:58:47 -08005411 case KeyEvent.KEYCODE_SLEEP: {
5412 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005413 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07005414 if (!mPowerManager.isInteractive()) {
5415 useHapticFeedback = false; // suppress feedback if already non-interactive
5416 }
Nick Vaccarob593a812015-05-15 11:23:05 -07005417 if (down) {
5418 sleepPress(event.getEventTime());
5419 } else {
5420 sleepRelease(event.getEventTime());
5421 }
Jeff Brown6212a492014-03-07 13:58:47 -08005422 break;
5423 }
5424
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -07005425 case KeyEvent.KEYCODE_SOFT_SLEEP: {
5426 result &= ~ACTION_PASS_TO_USER;
5427 isWakeKey = false;
5428 if (!down) {
5429 mPowerManagerInternal.setUserInactiveOverrideFromWindowManager();
5430 }
5431 break;
5432 }
5433
Jeff Brown6212a492014-03-07 13:58:47 -08005434 case KeyEvent.KEYCODE_WAKEUP: {
5435 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005436 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08005437 break;
5438 }
5439
Jeff Brown4d396052010-10-29 21:50:21 -07005440 case KeyEvent.KEYCODE_MEDIA_PLAY:
5441 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5442 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07005443 case KeyEvent.KEYCODE_HEADSETHOOK:
5444 case KeyEvent.KEYCODE_MUTE:
5445 case KeyEvent.KEYCODE_MEDIA_STOP:
5446 case KeyEvent.KEYCODE_MEDIA_NEXT:
5447 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5448 case KeyEvent.KEYCODE_MEDIA_REWIND:
5449 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005450 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
5451 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07005452 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
5453 // If the global session is active pass all media keys to it
5454 // instead of the active window.
5455 result &= ~ACTION_PASS_TO_USER;
5456 }
Jeff Brown4d396052010-10-29 21:50:21 -07005457 if ((result & ACTION_PASS_TO_USER) == 0) {
5458 // Only do this if we would otherwise not pass it to the user. In that
5459 // case, the PhoneWindow class will do the same thing, except it will
5460 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07005461 // Note that we need to make a copy of the key event here because the
5462 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07005463 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07005464 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
5465 new KeyEvent(event));
5466 msg.setAsynchronous(true);
5467 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005468 }
5469 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005470 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005471
Jeff Brown4d396052010-10-29 21:50:21 -07005472 case KeyEvent.KEYCODE_CALL: {
5473 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005474 TelecomManager telecomManager = getTelecommService();
5475 if (telecomManager != null) {
5476 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005477 Log.i(TAG, "interceptKeyBeforeQueueing:"
5478 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005479 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005480
Santos Cordon6848f722014-05-21 15:22:12 -07005481 // And *don't* pass this key thru to the current activity
5482 // (which is presumably the InCallScreen.)
5483 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005484 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005485 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005486 }
Jeff Brown4d396052010-10-29 21:50:21 -07005487 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005488 }
Michael Wright869a67c2014-08-26 19:33:06 -07005489 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5490 // Only do this if we would otherwise not pass it to the user. In that case,
5491 // interceptKeyBeforeDispatching would apply a similar but different policy in
5492 // order to invoke voice assist actions. Note that we need to make a copy of the
5493 // key event here because the original key event will be recycled when we return.
5494 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5495 mBroadcastWakeLock.acquire();
5496 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5497 keyguardActive ? 1 : 0, 0);
5498 msg.setAsynchronous(true);
5499 msg.sendToTarget();
5500 }
Jaewan Kim49117872016-01-19 17:24:08 +09005501 break;
5502 }
5503 case KeyEvent.KEYCODE_WINDOW: {
5504 if (mShortPressWindowBehavior == SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE) {
5505 if (!down) {
Jaewan Kimc552b042016-01-18 16:08:45 +09005506 requestTvPictureInPicture(event);
Jaewan Kim49117872016-01-19 17:24:08 +09005507 }
5508 result &= ~ACTION_PASS_TO_USER;
5509 }
5510 break;
Michael Wright869a67c2014-08-26 19:33:06 -07005511 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005512 }
Jeff Brown26875502014-01-30 21:47:47 -08005513
Jeff Brownbae8e772014-06-12 19:59:45 -07005514 if (useHapticFeedback) {
5515 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5516 }
5517
Jeff Brown26875502014-01-30 21:47:47 -08005518 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005519 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Jeff Brown26875502014-01-30 21:47:47 -08005520 }
Bryce Lee584a4452014-10-21 15:55:55 -07005521
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005522 return result;
5523 }
5524
Jeff Brown1c2e4942012-11-06 16:32:01 -08005525 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005526 * Returns true if the key can have global actions attached to it.
5527 * We reserve all power management keys for the system since they require
5528 * very careful handling.
5529 */
5530 private static boolean isValidGlobalKey(int keyCode) {
5531 switch (keyCode) {
5532 case KeyEvent.KEYCODE_POWER:
5533 case KeyEvent.KEYCODE_WAKEUP:
5534 case KeyEvent.KEYCODE_SLEEP:
5535 return false;
5536 default:
5537 return true;
5538 }
5539 }
5540
5541 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005542 * When the screen is off we ignore some keys that might otherwise typically
5543 * be considered wake keys. We filter them out here.
5544 *
5545 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5546 * is always considered a wake key.
5547 */
5548 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5549 switch (keyCode) {
5550 // ignore volume keys unless docked
5551 case KeyEvent.KEYCODE_VOLUME_UP:
5552 case KeyEvent.KEYCODE_VOLUME_DOWN:
5553 case KeyEvent.KEYCODE_VOLUME_MUTE:
5554 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5555
5556 // ignore media and camera keys
5557 case KeyEvent.KEYCODE_MUTE:
5558 case KeyEvent.KEYCODE_HEADSETHOOK:
5559 case KeyEvent.KEYCODE_MEDIA_PLAY:
5560 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5561 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5562 case KeyEvent.KEYCODE_MEDIA_STOP:
5563 case KeyEvent.KEYCODE_MEDIA_NEXT:
5564 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5565 case KeyEvent.KEYCODE_MEDIA_REWIND:
5566 case KeyEvent.KEYCODE_MEDIA_RECORD:
5567 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005568 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005569 case KeyEvent.KEYCODE_CAMERA:
5570 return false;
5571 }
5572 return true;
5573 }
5574
5575
Jeff Brown56194eb2011-03-02 19:23:13 -08005576 /** {@inheritDoc} */
5577 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005578 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5579 if ((policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005580 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion,
5581 "android.policy:MOTION")) {
Bryce Lee5c138322014-11-03 08:26:09 -08005582 return 0;
5583 }
Michael Wright70af00a2014-09-03 19:30:20 -07005584 }
Bryce Lee5c138322014-11-03 08:26:09 -08005585
Michael Wright70af00a2014-09-03 19:30:20 -07005586 if (shouldDispatchInputWhenNonInteractive()) {
5587 return ACTION_PASS_TO_USER;
5588 }
Bryce Lee5c138322014-11-03 08:26:09 -08005589
Bryce Lee812d7022014-11-10 13:33:28 -08005590 // If we have not passed the action up and we are in theater mode without dreaming,
5591 // there will be no dream to intercept the touch and wake into ambient. The device should
5592 // wake up in this case.
5593 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005594 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming,
5595 "android.policy:MOTION");
Bryce Lee812d7022014-11-10 13:33:28 -08005596 }
5597
Jeff Brown037c33e2014-04-09 00:31:55 -07005598 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005599 }
5600
Michael Wright70af00a2014-09-03 19:30:20 -07005601 private boolean shouldDispatchInputWhenNonInteractive() {
Joe LaPennaf2b9b2d2015-11-17 22:22:37 +00005602 // Send events to keyguard while the screen is on.
5603 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5604 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005605 return true;
5606 }
5607
5608 // Send events to a dozing dream even if the screen is off since the dream
5609 // is in control of the state of the screen.
5610 IDreamManager dreamManager = getDreamManager();
5611
5612 try {
5613 if (dreamManager != null && dreamManager.isDreaming()) {
5614 return true;
5615 }
5616 } catch (RemoteException e) {
5617 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5618 }
5619
5620 // Otherwise, consume events since the user can't see what is being
5621 // interacted with.
5622 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005623 }
5624
RoboErik001c59c2015-01-26 15:53:51 -08005625 private void dispatchDirectAudioEvent(KeyEvent event) {
5626 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5627 return;
5628 }
5629 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005630 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5631 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005632 String pkgName = mContext.getOpPackageName();
5633 switch (keyCode) {
5634 case KeyEvent.KEYCODE_VOLUME_UP:
5635 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005636 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005637 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005638 } catch (RemoteException e) {
5639 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5640 }
5641 break;
5642 case KeyEvent.KEYCODE_VOLUME_DOWN:
5643 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005644 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005645 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005646 } catch (RemoteException e) {
5647 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5648 }
5649 break;
5650 case KeyEvent.KEYCODE_VOLUME_MUTE:
5651 try {
5652 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005653 getAudioService().adjustSuggestedStreamVolume(
5654 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005655 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005656 }
5657 } catch (RemoteException e) {
5658 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5659 }
5660 break;
5661 }
5662 }
5663
Jeff Brown40013652012-05-16 21:22:36 -07005664 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5665 if (DEBUG_INPUT) {
5666 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005667 }
5668
Jeff Brown40013652012-05-16 21:22:36 -07005669 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5670 if (DEBUG_INPUT) {
5671 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5672 }
5673
5674 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5675 mHavePendingMediaKeyRepeatWithWakeLock = false;
5676 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5677 }
5678
5679 dispatchMediaKeyWithWakeLockToAudioService(event);
5680
5681 if (event.getAction() == KeyEvent.ACTION_DOWN
5682 && event.getRepeatCount() == 0) {
5683 mHavePendingMediaKeyRepeatWithWakeLock = true;
5684
5685 Message msg = mHandler.obtainMessage(
5686 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5687 msg.setAsynchronous(true);
5688 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5689 } else {
5690 mBroadcastWakeLock.release();
5691 }
5692 }
5693
5694 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5695 mHavePendingMediaKeyRepeatWithWakeLock = false;
5696
5697 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5698 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5699 if (DEBUG_INPUT) {
5700 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5701 }
5702
5703 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5704 mBroadcastWakeLock.release();
5705 }
5706
5707 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5708 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005709 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005710 }
5711 }
5712
Michael Wright869a67c2014-08-26 19:33:06 -07005713 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005714 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5715 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5716 if (dic != null) {
5717 try {
5718 dic.exitIdle("voice-search");
5719 } catch (RemoteException e) {
5720 }
5721 }
Michael Wright869a67c2014-08-26 19:33:06 -07005722 Intent voiceIntent =
5723 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5724 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005725 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005726 mBroadcastWakeLock.release();
5727 }
5728
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005729 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005730 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005731 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005732 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5733 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5734 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005735 } else {
5736 try {
5737 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5738 ServiceManager.getService(Context.UI_MODE_SERVICE));
5739 mUiMode = uiModeService.getCurrentModeType();
5740 } catch (RemoteException e) {
5741 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005742 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005743 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005744 synchronized (mLock) {
5745 updateOrientationListenerLp();
5746 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005747 }
5748 };
5749
Jeff Brown6aaf2952012-10-05 16:01:08 -07005750 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5751 @Override
5752 public void onReceive(Context context, Intent intent) {
5753 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005754 if (mKeyguardDelegate != null) {
5755 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005756 }
5757 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005758 if (mKeyguardDelegate != null) {
5759 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005760 }
5761 }
5762 }
5763 };
5764
Christopher Tate5e08af02012-09-21 17:17:22 -07005765 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5766 @Override
5767 public void onReceive(Context context, Intent intent) {
5768 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5769 // tickle the settings observer: this first ensures that we're
5770 // observing the relevant settings for the newly-active user,
5771 // and then updates our own bookkeeping based on the now-
5772 // current user.
5773 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005774
5775 // force a re-application of focused window sysui visibility.
5776 // the window may never have been shown for this user
5777 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005778 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005779 mLastSystemUiFlags = 0;
5780 updateSystemUiVisibilityLw();
5781 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005782 }
5783 }
5784 };
5785
Adrian Roosddc8b272015-05-21 16:28:27 -07005786 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005787 @Override
5788 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005789 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5790 if (!isUserSetupComplete()) {
5791 // Swipe-up for navigation bar is disabled during setup
5792 return;
5793 }
5794 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5795 mNavigationBarController.showTransient();
5796 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005797 }
5798 };
5799
John Spurlocke1f366f2013-08-05 12:22:40 -04005800 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005801 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005802 if (!isUserSetupComplete()) {
5803 // Swipe-up for navigation bar is disabled during setup
5804 return;
5805 }
John Spurlock27735a42013-08-14 17:57:38 -04005806 boolean sb = mStatusBarController.checkShowTransientBarLw();
5807 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005808 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005809 // Don't show status bar when swiping on already visible navigation bar
5810 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005811 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005812 return;
5813 }
John Spurlock27735a42013-08-14 17:57:38 -04005814 if (sb) mStatusBarController.showTransient();
5815 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005816 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005817 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005818 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005819 }
5820 }
5821
Jeff Brown3ee549c2014-09-22 20:14:39 -07005822 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005823 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005824 public void startedGoingToSleep(int why) {
5825 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005826 if (mKeyguardDelegate != null) {
5827 mKeyguardDelegate.onStartedGoingToSleep(why);
5828 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005829 }
5830
5831 // Called on the PowerManager's Notifier thread.
5832 @Override
5833 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005834 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005835 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04005836 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005837
5838 // We must get this work done here because the power manager will drop
5839 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005840 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005841 mAwake = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005842 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005843 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005844 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005845 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005846 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005847 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005848 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005849 }
5850
Jeff Brown3ee549c2014-09-22 20:14:39 -07005851 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005852 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005853 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005854 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005855 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005856
Jeff Brown3ee549c2014-09-22 20:14:39 -07005857 // Since goToSleep performs these functions synchronously, we must
5858 // do the same here. We cannot post this work to a handler because
5859 // that might cause it to become reordered with respect to what
5860 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005861 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005862 mAwake = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005863
Jeff Browna20dda42014-05-27 20:57:24 -07005864 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005865 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005866 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005867 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005868
Jim Miller5ecd8112013-01-09 18:50:26 -08005869 if (mKeyguardDelegate != null) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005870 mKeyguardDelegate.onStartedWakingUp();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005871 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005872 }
5873
Jeff Brown416c49c2015-05-26 19:50:18 -07005874 // Called on the PowerManager's Notifier thread.
5875 @Override
5876 public void finishedWakingUp() {
5877 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5878 }
5879
5880 private void wakeUpFromPowerKey(long eventTime) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005881 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER");
Jeff Brown416c49c2015-05-26 19:50:18 -07005882 }
5883
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005884 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) {
Bryce Leed3896842015-06-23 17:06:51 -07005885 final boolean theaterModeEnabled = isTheaterModeEnabled();
5886 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07005887 return false;
5888 }
5889
Bryce Leed3896842015-06-23 17:06:51 -07005890 if (theaterModeEnabled) {
5891 Settings.Global.putInt(mContext.getContentResolver(),
5892 Settings.Global.THEATER_MODE_ON, 0);
5893 }
5894
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005895 mPowerManager.wakeUp(wakeTime, reason);
Jeff Brown416c49c2015-05-26 19:50:18 -07005896 return true;
5897 }
5898
Jeff Brown36c4db82014-09-19 12:05:31 -07005899 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005900 synchronized (mLock) {
Jorim Jaggif3255482015-07-24 12:32:42 -07005901 if (!mScreenOnEarly || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005902 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005903 }
5904
Jeff Brown36c4db82014-09-19 12:05:31 -07005905 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005906 if (mKeyguardDelegate != null) {
5907 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5908 }
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005909 mWindowManagerDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005910 }
5911
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005912 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
5913 // as well as enabling the orientation change logic/sensor.
5914 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5915 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005916 }
5917
5918 // Called on the DisplayManager's DisplayPowerController thread.
5919 @Override
5920 public void screenTurnedOff() {
5921 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5922
Jeff Brown48d1b142015-06-10 16:36:03 -07005923 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005924 synchronized (mLock) {
5925 mScreenOnEarly = false;
5926 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005927 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005928 mWindowManagerDrawComplete = false;
5929 mScreenOnListener = null;
5930 updateOrientationListenerLp();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005931
5932 if (mKeyguardDelegate != null) {
5933 mKeyguardDelegate.onScreenTurnedOff();
5934 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005935 }
5936 }
5937
Jeff Brown3ee549c2014-09-22 20:14:39 -07005938 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005939 @Override
5940 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005941 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005942
Jeff Brown48d1b142015-06-10 16:36:03 -07005943 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005944 synchronized (mLock) {
5945 mScreenOnEarly = true;
5946 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005947 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005948 mWindowManagerDrawComplete = false;
5949 mScreenOnListener = screenOnListener;
Jeff Brown36c4db82014-09-19 12:05:31 -07005950
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005951 if (mKeyguardDelegate != null) {
Jorim Jaggia4b51bc2015-08-10 18:20:43 -07005952 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5953 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005954 mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback);
5955 } else {
5956 if (DEBUG_WAKEUP) Slog.d(TAG,
5957 "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
5958 finishKeyguardDrawn();
5959 }
5960 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005961 }
5962
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005963 // Called on the DisplayManager's DisplayPowerController thread.
5964 @Override
5965 public void screenTurnedOn() {
5966 synchronized (mLock) {
5967 if (mKeyguardDelegate != null) {
5968 mKeyguardDelegate.onScreenTurnedOn();
5969 }
5970 }
5971 }
5972
Jeff Brown36c4db82014-09-19 12:05:31 -07005973 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005974 synchronized (mLock) {
5975 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005976 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005977 }
5978
Jeff Brown36c4db82014-09-19 12:05:31 -07005979 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005980 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005981
5982 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005983 }
5984
Craig Mautner8a0da012014-05-31 15:13:37 -07005985 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005986 synchronized (mLock) {
5987 // We have just finished drawing screen content. Since the orientation listener
5988 // gets only installed when all windows are drawn, we try to install it again.
5989 updateOrientationListenerLp();
5990 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005991 final ScreenOnListener listener;
5992 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005993 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005994 if (DEBUG_WAKEUP) Slog.d(TAG,
5995 "finishScreenTurningOn: mAwake=" + mAwake
5996 + ", mScreenOnEarly=" + mScreenOnEarly
5997 + ", mScreenOnFully=" + mScreenOnFully
5998 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5999 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
6000
6001 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
6002 || (mAwake && !mKeyguardDrawComplete)) {
6003 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07006004 }
6005
Jeff Brown3ee549c2014-09-22 20:14:39 -07006006 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
6007 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07006008 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006009 mScreenOnFully = true;
6010
6011 // Remember the first time we draw the keyguard so we know when we're done with
6012 // the main part of booting and can enable the screen and hide boot messages.
6013 if (!mKeyguardDrawnOnce && mAwake) {
6014 mKeyguardDrawnOnce = true;
6015 enableScreen = true;
6016 if (mBootMessageNeedsHiding) {
6017 mBootMessageNeedsHiding = false;
6018 hideBootMessages();
6019 }
6020 } else {
6021 enableScreen = false;
6022 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006023 }
6024
Jeff Brown3ee549c2014-09-22 20:14:39 -07006025 if (listener != null) {
6026 listener.onScreenOn();
6027 }
Jeff Brown4fc45272012-10-10 18:28:14 -07006028
Jeff Brown3ee549c2014-09-22 20:14:39 -07006029 if (enableScreen) {
6030 try {
6031 mWindowManager.enableScreenIfNeeded();
6032 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07006033 }
Craig Mautnera631d492014-08-05 15:16:01 -07006034 }
6035 }
6036
6037 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006038 synchronized (mLock) {
6039 if (!mKeyguardDrawnOnce) {
6040 mBootMessageNeedsHiding = true;
6041 return; // keyguard hasn't drawn the first time yet, not done booting
6042 }
Craig Mautnera631d492014-08-05 15:16:01 -07006043 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006044
6045 if (mBootMsgDialog != null) {
6046 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
6047 mBootMsgDialog.dismiss();
6048 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07006049 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006050 }
6051
6052 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07006053 public boolean isScreenOn() {
6054 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08006055 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006056
Dianne Hackborn08743722009-12-21 12:16:51 -08006057 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006058 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006059 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006060 if (mKeyguardDelegate != null) {
6061 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006062 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006063 }
6064
6065 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006066 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006067 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006068 if (mKeyguardDelegate != null) {
6069 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006070 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006071 }
6072
Jim Millerab954542014-10-10 18:21:49 -07006073 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006074 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07006075 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006076 }
6077
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006078 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006079 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006080 public boolean isKeyguardLocked() {
6081 return keyguardOn();
6082 }
6083
6084 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006085 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006086 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006087 if (mKeyguardDelegate == null) return false;
6088 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006089 }
6090
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006091 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006092 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07006093 public boolean isKeyguardShowingOrOccluded() {
6094 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
6095 }
6096
6097 /** {@inheritDoc} */
6098 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006099 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006100 if (mKeyguardDelegate == null) return false;
6101 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006102 }
6103
Jose Lima9546b202014-07-02 17:21:51 -07006104 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006105 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07006106 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006107 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05006108 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07006109 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05006110 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02006111 // ask the keyguard to prompt the user to authenticate if necessary
6112 mKeyguardDelegate.dismiss();
6113 }
6114 });
6115 }
6116 }
6117
6118 public void notifyActivityDrawnForKeyguardLw() {
6119 if (mKeyguardDelegate != null) {
6120 mHandler.post(new Runnable() {
6121 @Override
6122 public void run() {
6123 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05006124 }
6125 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006126 }
6127 }
6128
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006129 @Override
6130 public boolean isKeyguardDrawnLw() {
6131 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006132 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006133 }
6134 }
6135
Jorim Jaggi0d674622014-05-21 01:34:15 +02006136 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006137 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02006138 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006139 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006140 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02006141 }
6142 }
6143
Jorim Jaggi737af722015-12-31 10:42:27 +01006144 @Override
6145 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6146 Rect outInsets) {
6147 outInsets.setEmpty();
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006148
6149 // Navigation bar and status bar.
6150 getNonDecorInsetsLw(displayRotation, displayWidth, displayHeight, outInsets);
Jorim Jaggi737af722015-12-31 10:42:27 +01006151 if (mStatusBar != null) {
6152 outInsets.top = mStatusBarHeight;
6153 }
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006154 }
6155
6156 @Override
6157 public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6158 Rect outInsets) {
6159 outInsets.setEmpty();
6160
6161 // Only navigation bar
Jorim Jaggi737af722015-12-31 10:42:27 +01006162 if (mNavigationBar != null) {
6163 if (isNavigationBarOnBottom(displayWidth, displayHeight)) {
6164 outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode);
6165 } else {
6166 outInsets.right = getNavigationBarWidth(displayRotation, mUiMode);
6167 }
6168 }
6169 }
6170
Jorim Jaggi5060bd82016-02-19 17:12:19 -08006171 @Override
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08006172 public boolean isNavBarForcedShownLw(WindowState windowState) {
6173 return mForceShowSystemBars
6174 && !windowState.getFrameLw().equals(windowState.getDisplayFrameLw());
6175 }
6176
6177 @Override
Jorim Jaggi5060bd82016-02-19 17:12:19 -08006178 public boolean isDockSideAllowed(int dockSide) {
6179
6180 // We do not allow all dock sides at which the navigation bar touches the docked stack.
6181 if (!mNavigationBarCanMove) {
6182 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT || dockSide == DOCKED_RIGHT;
6183 } else {
6184 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT;
6185 }
6186 }
6187
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006188 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006189 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006190 }
6191
6192 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006193 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006194 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07006195
Jeff Brown01a98dd2011-09-20 15:08:29 -07006196 @Override
6197 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006198 if (false) {
6199 Slog.v(TAG, "rotationForOrientationLw(orient="
6200 + orientation + ", last=" + lastRotation
6201 + "); user=" + mUserRotation + " "
6202 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
6203 ? "USER_ROTATION_LOCKED" : "")
6204 );
6205 }
6206
Craig Mautner46ac6fa2013-08-01 10:06:34 -07006207 if (mForceDefaultOrientation) {
6208 return Surface.ROTATION_0;
6209 }
6210
The Android Open Source Project0727d222009-03-11 12:11:58 -07006211 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07006212 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
6213 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07006214 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07006215 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006216
Jeff Browndec6cf42011-11-15 14:08:20 -08006217 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07006218 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006219 // Ignore sensor when lid switch is open and rotation is forced.
6220 preferredRotation = mLidOpenRotation;
6221 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07006222 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006223 // Ignore sensor when in car dock unless explicitly enabled.
6224 // This case can override the behavior of NOSENSOR, and can also
6225 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006226 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006227 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08006228 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6229 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
6230 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07006231 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006232 // Ignore sensor when in desk dock unless explicitly enabled.
6233 // This case can override the behavior of NOSENSOR, and can also
6234 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006235 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006236 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006237 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
6238 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08006239 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006240 preferredRotation = mDemoHdmiRotation;
6241 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
6242 && mUndockedHdmiRotation >= 0) {
6243 // Ignore sensor when plugged into HDMI and an undocked orientation has
6244 // been specified in the configuration (only for legacy devices without
6245 // full multi-display support).
6246 // Note that the dock orientation overrides the HDMI orientation.
6247 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08006248 } else if (mDemoRotationLock) {
6249 // Ignore sensor when demo rotation lock is enabled.
6250 // Note that the dock orientation and HDMI rotation lock override this.
6251 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006252 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
6253 // Application just wants to remain locked in the last rotation.
6254 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08006255 } else if (!mSupportAutoRotation) {
6256 // If we don't support auto-rotation then bail out here and ignore
6257 // the sensor and any rotation lock settings.
6258 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07006259 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07006260 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006261 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
6262 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
6263 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
6264 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07006265 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
6266 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6267 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
6268 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
6269 // Otherwise, use sensor only if requested by the application or enabled
6270 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07006271 if (mAllowAllRotations < 0) {
6272 // Can't read this during init() because the context doesn't
6273 // have display metrics at that time so we cannot determine
6274 // tablet vs. phone then.
6275 mAllowAllRotations = mContext.getResources().getBoolean(
6276 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
6277 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006278 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07006279 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006280 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6281 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006282 preferredRotation = sensorRotation;
6283 } else {
6284 preferredRotation = lastRotation;
6285 }
Jeff Brown207673cd2012-06-05 17:47:11 -07006286 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
6287 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
6288 // Apply rotation lock. Does not apply to NOSENSOR.
6289 // The idea is that the user rotation expresses a weak preference for the direction
6290 // of gravity and as NOSENSOR is never affected by gravity, then neither should
6291 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07006292 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08006293 } else {
6294 // No overriding preference.
6295 // We will do exactly what the application asked us to do.
6296 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07006297 }
6298
Dianne Hackborne5439f22010-10-02 16:53:50 -07006299 switch (orientation) {
6300 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006301 // Return portrait unless overridden.
6302 if (isAnyPortrait(preferredRotation)) {
6303 return preferredRotation;
6304 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07006305 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006306
Jeff Brown01a98dd2011-09-20 15:08:29 -07006307 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006308 // Return landscape unless overridden.
6309 if (isLandscapeOrSeascape(preferredRotation)) {
6310 return preferredRotation;
6311 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006312 return mLandscapeRotation;
6313
6314 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006315 // Return reverse portrait unless overridden.
6316 if (isAnyPortrait(preferredRotation)) {
6317 return preferredRotation;
6318 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006319 return mUpsideDownRotation;
6320
6321 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006322 // Return seascape unless overridden.
6323 if (isLandscapeOrSeascape(preferredRotation)) {
6324 return preferredRotation;
6325 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006326 return mSeascapeRotation;
6327
6328 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006329 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006330 // Return either landscape rotation.
6331 if (isLandscapeOrSeascape(preferredRotation)) {
6332 return preferredRotation;
6333 }
6334 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08006335 return lastRotation;
6336 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006337 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006338
Jeff Brown01a98dd2011-09-20 15:08:29 -07006339 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006340 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006341 // Return either portrait rotation.
6342 if (isAnyPortrait(preferredRotation)) {
6343 return preferredRotation;
6344 }
6345 if (isAnyPortrait(lastRotation)) {
6346 return lastRotation;
6347 }
6348 return mPortraitRotation;
6349
6350 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07006351 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
6352 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07006353 if (preferredRotation >= 0) {
6354 return preferredRotation;
6355 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07006356 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05006357 }
6358 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006359 }
6360
Jeff Brown01a98dd2011-09-20 15:08:29 -07006361 @Override
6362 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
6363 switch (orientation) {
6364 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
6365 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
6366 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
6367 return isAnyPortrait(rotation);
6368
6369 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
6370 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
6371 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
6372 return isLandscapeOrSeascape(rotation);
6373
6374 default:
6375 return true;
6376 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006377 }
6378
Jeff Brownc0347aa2011-09-23 17:26:09 -07006379 @Override
6380 public void setRotationLw(int rotation) {
6381 mOrientationListener.setCurrentRotation(rotation);
6382 }
6383
Jeff Brown01a98dd2011-09-20 15:08:29 -07006384 private boolean isLandscapeOrSeascape(int rotation) {
6385 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006386 }
6387
Jeff Brown01a98dd2011-09-20 15:08:29 -07006388 private boolean isAnyPortrait(int rotation) {
6389 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006390 }
6391
Jose Lima9546b202014-07-02 17:21:51 -07006392 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006393 public int getUserRotationMode() {
6394 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07006395 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
6396 WindowManagerPolicy.USER_ROTATION_FREE :
6397 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006398 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006399
6400 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07006401 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006402 public void setUserRotationMode(int mode, int rot) {
6403 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006404
6405 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006406 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07006407 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006408 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006409 rot,
6410 UserHandle.USER_CURRENT);
6411 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006412 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006413 0,
6414 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006415 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07006416 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006417 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006418 1,
6419 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006420 }
6421 }
6422
Jose Lima9546b202014-07-02 17:21:51 -07006423 @Override
Jeff Brownac143512012-04-05 18:57:33 -07006424 public void setSafeMode(boolean safeMode) {
6425 mSafeMode = safeMode;
6426 performHapticFeedbackLw(null, safeMode
6427 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
6428 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006429 }
Craig Mautnereda67292013-04-28 13:50:14 -07006430
Dianne Hackborn181ceb52009-08-27 22:16:40 -07006431 static long[] getLongIntArray(Resources r, int resid) {
6432 int[] ar = r.getIntArray(resid);
6433 if (ar == null) {
6434 return null;
6435 }
6436 long[] out = new long[ar.length];
6437 for (int i=0; i<ar.length; i++) {
6438 out[i] = ar[i];
6439 }
6440 return out;
6441 }
Craig Mautnereda67292013-04-28 13:50:14 -07006442
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006443 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006444 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006445 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07006446 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08006447 mKeyguardDelegate.onSystemReady();
6448
Michael Wright3818c922014-09-02 13:59:07 -07006449 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07006450 updateUiMode();
Adrian Roos3542f7d2015-07-13 15:57:53 -07006451 boolean bindKeyguardNow;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006452 synchronized (mLock) {
6453 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08006454 mSystemReady = true;
6455 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006456 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08006457 public void run() {
6458 updateSettings();
6459 }
6460 });
Adrian Roos3542f7d2015-07-13 15:57:53 -07006461
6462 bindKeyguardNow = mDeferBindKeyguard;
6463 if (bindKeyguardNow) {
6464 // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now.
6465 mDeferBindKeyguard = false;
6466 }
6467 }
6468
6469 if (bindKeyguardNow) {
6470 mKeyguardDelegate.bindService(mContext);
6471 mKeyguardDelegate.onBootCompleted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006472 }
Michael Wrighta4d22d72015-09-16 23:19:26 +01006473 mSystemGestures.systemReady();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006474 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006475
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006476 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006477 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006478 public void systemBooted() {
Adrian Roos3542f7d2015-07-13 15:57:53 -07006479 boolean bindKeyguardNow = false;
6480 synchronized (mLock) {
6481 // Time to bind Keyguard; take care to only bind it once, either here if ready or
6482 // in systemReady if not.
6483 if (mKeyguardDelegate != null) {
6484 bindKeyguardNow = true;
6485 } else {
6486 // Because mKeyguardDelegate is null, we know that the synchronized block in
6487 // systemReady didn't run yet and setting this will actually have an effect.
6488 mDeferBindKeyguard = true;
6489 }
6490 }
6491 if (bindKeyguardNow) {
Jason Monk5eeebf52014-09-26 12:36:51 -04006492 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07006493 mKeyguardDelegate.onBootCompleted();
6494 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006495 synchronized (mLock) {
6496 mSystemBooted = true;
6497 }
Jeff Brown416c49c2015-05-26 19:50:18 -07006498 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07006499 screenTurningOn(null);
Jorim Jaggic0496072015-08-19 15:14:52 -07006500 screenTurnedOn();
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006501 }
6502
Dianne Hackborn661cd522011-08-22 00:26:20 -07006503 ProgressDialog mBootMsgDialog = null;
6504
6505 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006506 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006507 public void showBootMessage(final CharSequence msg, final boolean always) {
6508 mHandler.post(new Runnable() {
6509 @Override public void run() {
6510 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006511 int theme;
Jaewan Kim49117872016-01-19 17:24:08 +09006512 if (mContext.getPackageManager().hasSystemFeature(FEATURE_WATCH)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006513 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
Jaewan Kim49117872016-01-19 17:24:08 +09006514 } else if (mContext.getPackageManager().hasSystemFeature(FEATURE_TELEVISION)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006515 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
6516 } else {
6517 theme = 0;
6518 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07006519
6520 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07006521 // This dialog will consume all events coming in to
6522 // it, to avoid it trying to do things too early in boot.
6523 @Override public boolean dispatchKeyEvent(KeyEvent event) {
6524 return true;
6525 }
6526 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
6527 return true;
6528 }
6529 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
6530 return true;
6531 }
6532 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
6533 return true;
6534 }
6535 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
6536 return true;
6537 }
6538 @Override public boolean dispatchPopulateAccessibilityEvent(
6539 AccessibilityEvent event) {
6540 return true;
6541 }
6542 };
Jeff Hao9f60c082014-10-28 18:51:07 -07006543 if (mContext.getPackageManager().isUpgrade()) {
6544 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
6545 } else {
6546 mBootMsgDialog.setTitle(R.string.android_start_title);
6547 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006548 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
6549 mBootMsgDialog.setIndeterminate(true);
6550 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07006551 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006552 mBootMsgDialog.getWindow().addFlags(
6553 WindowManager.LayoutParams.FLAG_DIM_BEHIND
6554 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
6555 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08006556 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
6557 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
6558 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006559 mBootMsgDialog.setCancelable(false);
6560 mBootMsgDialog.show();
6561 }
6562 mBootMsgDialog.setMessage(msg);
6563 }
6564 });
6565 }
6566
6567 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006568 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006569 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07006570 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006571 }
6572
Mike Lockwood28569302010-01-28 11:54:40 -05006573 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006574 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006575 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006576 // ***************************************
6577 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
6578 // ***************************************
6579 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
6580 // WITH ITS LOCKS HELD.
6581 //
6582 // This code must be VERY careful about the locks
6583 // it acquires.
6584 // In fact, the current code acquires way too many,
6585 // and probably has lurking deadlocks.
6586
Mike Lockwood28569302010-01-28 11:54:40 -05006587 synchronized (mScreenLockTimeout) {
6588 if (mLockScreenTimerActive) {
6589 // reset the timer
6590 mHandler.removeCallbacks(mScreenLockTimeout);
6591 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6592 }
6593 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006594 }
6595
Adam Cohenf7522022012-10-03 20:03:18 -07006596 class ScreenLockTimeout implements Runnable {
6597 Bundle options;
6598
6599 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006600 public void run() {
6601 synchronized (this) {
6602 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006603 if (mKeyguardDelegate != null) {
6604 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006605 }
Mike Lockwood28569302010-01-28 11:54:40 -05006606 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006607 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006608 }
6609 }
Mike Lockwood28569302010-01-28 11:54:40 -05006610
Adam Cohenf7522022012-10-03 20:03:18 -07006611 public void setLockOptions(Bundle options) {
6612 this.options = options;
6613 }
6614 }
6615
6616 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6617
Jose Lima9546b202014-07-02 17:21:51 -07006618 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006619 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006620 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6621 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006622 if (options != null) {
6623 // In case multiple calls are made to lockNow, we don't wipe out the options
6624 // until the runnable actually executes.
6625 mScreenLockTimeout.setLockOptions(options);
6626 }
Jim Miller93c518e2012-01-17 15:55:31 -08006627 mHandler.post(mScreenLockTimeout);
6628 }
6629
Mike Lockwood28569302010-01-28 11:54:40 -05006630 private void updateLockScreenTimeout() {
6631 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006632 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006633 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006634 if (mLockScreenTimerActive != enable) {
6635 if (enable) {
6636 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
Jim Miller2967f482016-01-07 15:05:32 -08006637 mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests
Mike Lockwood28569302010-01-28 11:54:40 -05006638 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6639 } else {
6640 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6641 mHandler.removeCallbacks(mScreenLockTimeout);
6642 }
6643 mLockScreenTimerActive = enable;
6644 }
6645 }
6646 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006647
Jeff Brown061ea992015-04-17 19:55:47 -07006648 private void updateDreamingSleepToken(boolean acquire) {
6649 if (acquire) {
6650 if (mDreamingSleepToken == null) {
6651 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6652 }
6653 } else {
6654 if (mDreamingSleepToken != null) {
6655 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006656 mDreamingSleepToken = null;
6657 }
6658 }
6659 }
6660
6661 private void updateScreenOffSleepToken(boolean acquire) {
6662 if (acquire) {
6663 if (mScreenOffSleepToken == null) {
6664 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6665 }
6666 } else {
6667 if (mScreenOffSleepToken != null) {
6668 mScreenOffSleepToken.release();
6669 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006670 }
6671 }
6672 }
6673
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006674 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006675 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006676 public void enableScreenAfterBoot() {
6677 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006678 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006679 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006680 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006681
Jeff Brownc458ce92012-04-30 14:58:40 -07006682 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006683 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006684 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006685 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006686 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01006687 } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) {
6688 mWindowManagerFuncs.lockDeviceNow();
Jeff Brownc458ce92012-04-30 14:58:40 -07006689 }
Jeff Browna20dda42014-05-27 20:57:24 -07006690
6691 synchronized (mLock) {
6692 updateWakeGestureListenerLp();
6693 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006694 }
6695
Jeff Brown4f5fa282014-06-12 19:19:15 -07006696 void updateUiMode() {
6697 if (mUiModeManager == null) {
6698 mUiModeManager = IUiModeManager.Stub.asInterface(
6699 ServiceManager.getService(Context.UI_MODE_SERVICE));
6700 }
6701 try {
6702 mUiMode = mUiModeManager.getCurrentModeType();
6703 } catch (RemoteException e) {
6704 }
6705 }
6706
Jeff Brown01a98dd2011-09-20 15:08:29 -07006707 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006708 try {
6709 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006710 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6711 } catch (RemoteException e) {
6712 // Ignore
6713 }
6714 }
6715
6716 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6717 try {
6718 //set orientation on WindowManager
6719 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006720 } catch (RemoteException e) {
6721 // Ignore
6722 }
6723 }
6724
Daniel Sandler6396c722013-04-16 20:19:09 -04006725 /**
6726 * Return an Intent to launch the currently active dock app as home. Returns
6727 * null if the standard home should be launched, which is the case if any of the following is
6728 * true:
6729 * <ul>
6730 * <li>The device is not in either car mode or desk mode
keunyounga7710492015-09-23 11:33:58 -07006731 * <li>The device is in car mode but mEnableCarDockHomeCapture is false
Daniel Sandler6396c722013-04-16 20:19:09 -04006732 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6733 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6734 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6735 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006736 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006737 */
6738 Intent createHomeDockIntent() {
6739 Intent intent = null;
6740
6741 // What home does is based on the mode, not the dock state. That
6742 // is, when in car mode you should be taken to car home regardless
6743 // of whether we are actually in a car dock.
6744 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
keunyounga7710492015-09-23 11:33:58 -07006745 if (mEnableCarDockHomeCapture) {
Daniel Sandler6396c722013-04-16 20:19:09 -04006746 intent = mCarDockIntent;
6747 }
6748 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6749 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6750 intent = mDeskDockIntent;
6751 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006752 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6753 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6754 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6755 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6756 // Always launch dock home from home when watch is docked, if it exists.
6757 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006758 }
6759
6760 if (intent == null) {
6761 return null;
6762 }
6763
6764 ActivityInfo ai = null;
6765 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6766 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006767 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006768 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006769 if (info != null) {
6770 ai = info.activityInfo;
6771 }
6772 if (ai != null
6773 && ai.metaData != null
6774 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6775 intent = new Intent(intent);
6776 intent.setClassName(ai.packageName, ai.name);
6777 return intent;
6778 }
6779
6780 return null;
6781 }
6782
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006783 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6784 if (awakenFromDreams) {
6785 awakenDreams();
6786 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006787
6788 Intent dock = createHomeDockIntent();
6789 if (dock != null) {
6790 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006791 if (fromHomeKey) {
6792 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6793 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006794 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006795 return;
6796 } catch (ActivityNotFoundException e) {
6797 }
6798 }
6799
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006800 Intent intent;
6801
6802 if (fromHomeKey) {
6803 intent = new Intent(mHomeIntent);
6804 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6805 } else {
6806 intent = mHomeIntent;
6807 }
6808
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006809 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006810 }
Craig Mautnereda67292013-04-28 13:50:14 -07006811
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006812 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006813 * goes to the home screen
6814 * @return whether it did anything
6815 */
6816 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006817 if (!isUserSetupComplete()) {
6818 Slog.i(TAG, "Not going home because user setup is in progress.");
6819 return false;
6820 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006821 if (false) {
6822 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006823 try {
6824 ActivityManagerNative.getDefault().stopAppSwitches();
6825 } catch (RemoteException e) {
6826 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006827 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006828 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006829 } else {
6830 // This code brings home to the front or, if it is already
6831 // at the front, puts the device to sleep.
6832 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006833 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6834 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6835 Log.d(TAG, "UTS-TEST-MODE");
6836 } else {
6837 ActivityManagerNative.getDefault().stopAppSwitches();
6838 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006839 Intent dock = createHomeDockIntent();
6840 if (dock != null) {
6841 int result = ActivityManagerNative.getDefault()
6842 .startActivityAsUser(null, null, dock,
6843 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6844 null, null, 0,
6845 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006846 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006847 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6848 return false;
6849 }
6850 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006851 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006852 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006853 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006854 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006855 null, null, 0,
6856 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006857 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006858 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006859 return false;
6860 }
6861 } catch (RemoteException ex) {
6862 // bummer, the activity manager, which is in this process, is dead
6863 }
6864 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006865 return true;
6866 }
Craig Mautnereda67292013-04-28 13:50:14 -07006867
6868 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006869 public void setCurrentOrientationLw(int newOrientation) {
6870 synchronized (mLock) {
6871 if (newOrientation != mCurrentAppOrientation) {
6872 mCurrentAppOrientation = newOrientation;
6873 updateOrientationListenerLp();
6874 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006875 }
6876 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006877
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006878 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6879 if (!isGlobalAccessibilityGestureEnabled()) {
6880 return;
6881 }
6882 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6883 Context.AUDIO_SERVICE);
6884 if (audioManager.isSilentMode()) {
6885 return;
6886 }
6887 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6888 Settings.System.DEFAULT_NOTIFICATION_URI);
6889 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6890 ringTone.play();
6891 }
Craig Mautnereda67292013-04-28 13:50:14 -07006892
Bryce Lee584a4452014-10-21 15:55:55 -07006893 private boolean isTheaterModeEnabled() {
6894 return Settings.Global.getInt(mContext.getContentResolver(),
6895 Settings.Global.THEATER_MODE_ON, 0) == 1;
6896 }
6897
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006898 private boolean isGlobalAccessibilityGestureEnabled() {
6899 return Settings.Global.getInt(mContext.getContentResolver(),
6900 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6901 }
6902
Craig Mautnereda67292013-04-28 13:50:14 -07006903 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006904 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006905 if (!mVibrator.hasVibrator()) {
6906 return false;
6907 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006908 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6909 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006910 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006911 return false;
6912 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006913 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006914 switch (effectId) {
6915 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006916 pattern = mLongPressVibePattern;
6917 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006918 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006919 pattern = mVirtualKeyVibePattern;
6920 break;
6921 case HapticFeedbackConstants.KEYBOARD_TAP:
6922 pattern = mKeyboardTapVibePattern;
6923 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006924 case HapticFeedbackConstants.CLOCK_TICK:
6925 pattern = mClockTickVibePattern;
6926 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006927 case HapticFeedbackConstants.CALENDAR_DATE:
6928 pattern = mCalendarDateVibePattern;
6929 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006930 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006931 pattern = mSafeModeDisabledVibePattern;
6932 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006933 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006934 pattern = mSafeModeEnabledVibePattern;
6935 break;
Mady Mellore8608912015-06-05 09:02:55 -07006936 case HapticFeedbackConstants.CONTEXT_CLICK:
6937 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006938 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006939 default:
6940 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006941 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006942 int owningUid;
6943 String owningPackage;
6944 if (win != null) {
6945 owningUid = win.getOwningUid();
6946 owningPackage = win.getOwningPackage();
6947 } else {
6948 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006949 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006950 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006951 if (pattern.length == 1) {
6952 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006953 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006954 } else {
6955 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006956 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006957 }
6958 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006959 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006960
6961 @Override
6962 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006963 }
6964
Jeff Brownc38c9be2012-10-04 13:16:19 -07006965 @Override
6966 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006967 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006968 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006969 }
6970 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006971
Dianne Hackborndf89e652011-10-06 22:35:11 -07006972 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006973 // If there is no window focused, there will be nobody to handle the events
6974 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006975 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6976 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006977 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006978 return 0;
6979 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006980 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006981 // We are updating at a point where the keyguard has gotten
6982 // focus, but we were last in a state where the top window is
6983 // hiding it. This is probably because the keyguard as been
6984 // shown while the top window was displayed, so we want to ignore
6985 // it here because this is just a very transient change and it
6986 // will quickly lose focus once it correctly gets hidden.
6987 return 0;
6988 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006989
John Spurlock1db8b682014-02-18 11:18:59 -05006990 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006991 & ~mResettingSystemUiFlags
6992 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006993 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006994 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006995 }
Thanh Hai Mai6c009f52015-09-01 16:27:32 -07006996
6997 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6998 tmpVisibility |= StatusBarManager.DISABLE_RECENT;
6999 }
7000
Jorim Jaggi86905582016-02-09 21:36:09 -08007001 final int fullscreenVisibility = updateLightStatusBarLw(0 /* vis */,
7002 mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState);
7003 final int dockedVisibility = updateLightStatusBarLw(0 /* vis */,
7004 mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState);
7005 mWindowManagerFuncs.getStackBounds(HOME_STACK_ID, mNonDockedStackBounds);
7006 mWindowManagerFuncs.getStackBounds(DOCKED_STACK_ID, mDockedStackBounds);
John Spurlock79da8332013-09-20 12:04:47 -04007007 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04007008 final int diff = visibility ^ mLastSystemUiFlags;
Jorim Jaggi86905582016-02-09 21:36:09 -08007009 final int fullscreenDiff = fullscreenVisibility ^ mLastFullscreenStackSysUiFlags;
7010 final int dockedDiff = dockedVisibility ^ mLastDockedStackSysUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04007011 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Jorim Jaggi86905582016-02-09 21:36:09 -08007012 if (diff == 0 && fullscreenDiff == 0 && dockedDiff == 0 && mLastFocusNeedsMenu == needsMenu
7013 && mFocusedApp == win.getAppToken()
7014 && mLastNonDockedStackBounds.equals(mNonDockedStackBounds)
7015 && mLastDockedStackBounds.equals(mDockedStackBounds)) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07007016 return 0;
7017 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07007018 mLastSystemUiFlags = visibility;
Jorim Jaggi86905582016-02-09 21:36:09 -08007019 mLastFullscreenStackSysUiFlags = fullscreenVisibility;
7020 mLastDockedStackSysUiFlags = dockedVisibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007021 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04007022 mFocusedApp = win.getAppToken();
Jorim Jaggi86905582016-02-09 21:36:09 -08007023 final Rect fullscreenStackBounds = new Rect(mNonDockedStackBounds);
7024 final Rect dockedStackBounds = new Rect(mDockedStackBounds);
Dianne Hackborndf89e652011-10-06 22:35:11 -07007025 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07007026 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07007027 public void run() {
Jorim Jaggi86905582016-02-09 21:36:09 -08007028 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
7029 if (statusbar != null) {
7030 statusbar.setSystemUiVisibility(visibility, fullscreenVisibility,
7031 dockedVisibility, 0xffffffff, fullscreenStackBounds,
7032 dockedStackBounds, win.toString());
7033 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08007034 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07007035 }
7036 });
7037 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08007038 }
7039
Jorim Jaggi86905582016-02-09 21:36:09 -08007040 private int updateLightStatusBarLw(int vis, WindowState opaque, WindowState opaqueOrDimming) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01007041 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
7042 ? mStatusBar
Jorim Jaggi86905582016-02-09 21:36:09 -08007043 : opaqueOrDimming;
Adrian Rooscd3884d2015-02-18 17:25:23 +01007044
7045 if (statusColorWin != null) {
Jorim Jaggi86905582016-02-09 21:36:09 -08007046 if (statusColorWin == opaque) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01007047 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
7048 // its light flag.
7049 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7050 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
7051 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7052 } else if (statusColorWin != null && statusColorWin.isDimming()) {
7053 // Otherwise if it's dimming, clear the light flag.
7054 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7055 }
7056 }
7057 return vis;
7058 }
7059
John Spurlock79da8332013-09-20 12:04:47 -04007060 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007061 final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
7062 final boolean freeformStackVisible =
7063 mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID);
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08007064 final boolean resizing = mWindowManagerInternal.isDockedDividerResizing();
7065
7066 // We need to force system bars when the docked stack is visible, when the freeform stack
7067 // is visible but also when we are resizing for the transitions when docked stack
7068 // visibility changes.
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007069 mForceShowSystemBars = dockedStackVisible || freeformStackVisible || resizing;
7070 final boolean forceOpaqueSystemBars = mForceShowSystemBars && !mForceStatusBarFromKeyguard;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007071
John Spurlockbd957402013-10-03 11:38:39 -04007072 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01007073 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
7074 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04007075 : mTopFullscreenOpaqueWindowState;
7076 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
7077 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
7078
John Spurlock27735a42013-08-14 17:57:38 -04007079 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07007080 int type = win.getAttrs().type;
7081 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04007082 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04007083 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
7084 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04007085 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01007086 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
7087 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04007088 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01007089 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
7090 }
John Spurlockbd957402013-10-03 11:38:39 -04007091 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04007092 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04007093
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007094 if ((!areTranslucentBarsAllowed() && transWin != mStatusBar)
7095 || forceOpaqueSystemBars) {
Adrian Roosea562512014-05-05 13:33:03 +02007096 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
7097 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007098 }
7099
Yorke Lee2e4b7322016-03-02 17:33:06 -08007100 if (mForceNavBarOpaque) {
7101 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT);
7102 }
7103
Jorim Jaggi4fa78922015-11-30 17:13:56 -08007104 if (mForceWindowDrawsStatusBarBackground) {
7105 vis |= View.STATUS_BAR_TRANSPARENT;
7106 vis &= ~View.STATUS_BAR_TRANSLUCENT;
7107 }
7108
John Spurlock27735a42013-08-14 17:57:38 -04007109 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04007110 boolean immersiveSticky =
7111 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007112 final boolean hideStatusBarWM =
7113 mTopFullscreenOpaqueWindowState != null
7114 && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04007115 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007116 final boolean hideStatusBarSysui =
John Spurlock27735a42013-08-14 17:57:38 -04007117 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007118 final boolean hideNavBarSysui =
John Spurlockf1a36642013-10-12 17:50:42 -04007119 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007120
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007121 final boolean transientStatusBarAllowed = mStatusBar != null
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007122 && (statusBarHasFocus || (!mForceShowSystemBars
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007123 && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky))));
John Spurlock27735a42013-08-14 17:57:38 -04007124
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007125 final boolean transientNavBarAllowed = mNavigationBar != null
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007126 && !mForceShowSystemBars && hideNavBarSysui && immersiveSticky;
John Spurlockf1a36642013-10-12 17:50:42 -04007127
Adrian Roosddc8b272015-05-21 16:28:27 -07007128 final long now = SystemClock.uptimeMillis();
7129 final boolean pendingPanic = mPendingPanicGestureUptime != 0
7130 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
7131 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
7132 // The user performed the panic gesture recently, we're about to hide the bars,
7133 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
7134 mPendingPanicGestureUptime = 0;
7135 mStatusBarController.showTransient();
7136 mNavigationBarController.showTransient();
7137 }
7138
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007139 final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007140 && !transientStatusBarAllowed && hideStatusBarSysui;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007141 final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007142 && !transientNavBarAllowed;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007143 if (denyTransientStatus || denyTransientNav || mForceShowSystemBars) {
John Spurlock27735a42013-08-14 17:57:38 -04007144 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04007145 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08007146 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007147 }
John Spurlock27735a42013-08-14 17:57:38 -04007148
Selim Cinekf98702e2015-05-20 22:48:40 -07007149 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
7150 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
7151 final boolean navAllowedHidden = immersive || immersiveSticky;
7152
Selim Cinekd6623612015-05-22 18:56:22 -07007153 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
7154 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07007155 // We can't hide the navbar from this window otherwise the input consumer would not get
7156 // the input events.
7157 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
7158 }
7159
John Spurlock27735a42013-08-14 17:57:38 -04007160 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
7161
7162 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04007163 boolean oldImmersiveMode = isImmersiveMode(oldVis);
7164 boolean newImmersiveMode = isImmersiveMode(vis);
7165 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04007166 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07007167 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
7168 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04007169 }
John Spurlock27735a42013-08-14 17:57:38 -04007170
John Spurlockf1a36642013-10-12 17:50:42 -04007171 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
7172
John Spurlocke1f366f2013-08-05 12:22:40 -04007173 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007174 }
7175
John Spurlockf1a36642013-10-12 17:50:42 -04007176 private void clearClearableFlagsLw() {
7177 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
7178 if (newVal != mResettingSystemUiFlags) {
7179 mResettingSystemUiFlags = newVal;
7180 mWindowManagerFuncs.reevaluateStatusBarVisibility();
7181 }
7182 }
7183
7184 private boolean isImmersiveMode(int vis) {
7185 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04007186 return mNavigationBar != null
7187 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04007188 && (vis & flags) != 0
7189 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04007190 }
7191
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007192 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007193 * @return whether the navigation or status bar can be made translucent
7194 *
7195 * This should return true unless touch exploration is not enabled or
7196 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007197 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007198 private boolean areTranslucentBarsAllowed() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04007199 return mTranslucentDecorEnabled;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007200 }
7201
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007202 // Use this instead of checking config_showNavigationBar so that it can be consistently
7203 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07007204 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007205 public boolean hasNavigationBar() {
7206 return mHasNavigationBar;
7207 }
7208
satok1bc0a492012-04-25 22:47:12 +09007209 @Override
7210 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
7211 mLastInputMethodWindow = ime;
7212 mLastInputMethodTargetWindow = target;
7213 }
7214
Craig Mautnerf1b67412012-09-19 13:18:29 -07007215 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09007216 public int getInputMethodWindowVisibleHeightLw() {
7217 return mDockBottom - mCurBottom;
7218 }
7219
7220 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07007221 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07007222 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08007223 if (mKeyguardDelegate != null) {
7224 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007225 }
John Spurlock13451a22012-09-28 14:40:41 -04007226 if (mStatusBarService != null) {
7227 try {
7228 mStatusBarService.setCurrentUser(newUserId);
7229 } catch (RemoteException e) {
7230 // oh well
7231 }
7232 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007233 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007234 }
7235
7236 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08007237 public boolean canMagnifyWindow(int windowType) {
7238 switch (windowType) {
7239 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
7240 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
7241 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
7242 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
7243 return false;
7244 }
7245 }
7246 return true;
7247 }
7248
7249 @Override
7250 public boolean isTopLevelWindow(int windowType) {
7251 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
7252 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
7253 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
7254 }
7255 return true;
7256 }
7257
Jim Miller4eeb4f62012-11-08 00:04:29 -08007258 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07007259 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007260 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007261 pw.print(" mSystemReady="); pw.print(mSystemReady);
7262 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07007263 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007264 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07007265 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007266 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07007267 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
7268 || mForceClearedSystemUiFlags != 0) {
7269 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
7270 pw.print(Integer.toHexString(mLastSystemUiFlags));
7271 pw.print(" mResettingSystemUiFlags=0x");
7272 pw.print(Integer.toHexString(mResettingSystemUiFlags));
7273 pw.print(" mForceClearedSystemUiFlags=0x");
7274 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07007275 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007276 if (mLastFocusNeedsMenu) {
7277 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
7278 pw.println(mLastFocusNeedsMenu);
7279 }
Jeff Browna20dda42014-05-27 20:57:24 -07007280 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
7281 pw.println(mWakeGestureEnabledSetting);
7282
Jeff Brownbcdfc622014-03-06 19:13:04 -08007283 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04007284 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
7285 pw.print(" mDockMode="); pw.print(mDockMode);
keunyounga7710492015-09-23 11:33:58 -07007286 pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007287 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
7288 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
7289 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
7290 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05007291 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007292 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007293 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
7294 pw.print(mCarDockEnablesAccelerometer);
7295 pw.print(" mDeskDockEnablesAccelerometer=");
7296 pw.println(mDeskDockEnablesAccelerometer);
7297 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
7298 pw.print(mLidKeyboardAccessibility);
7299 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01007300 pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007301 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007302 pw.print(prefix);
7303 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
7304 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07007305 pw.print(prefix);
7306 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
7307 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007308 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07007309 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
7310 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
7311 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
7312 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
7313 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
7314 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
7315 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08007316 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
7317 pw.print(","); pw.print(mOverscanScreenTop);
7318 pw.print(") "); pw.print(mOverscanScreenWidth);
7319 pw.print("x"); pw.println(mOverscanScreenHeight);
7320 if (mOverscanLeft != 0 || mOverscanTop != 0
7321 || mOverscanRight != 0 || mOverscanBottom != 0) {
7322 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
7323 pw.print(" top="); pw.print(mOverscanTop);
7324 pw.print(" right="); pw.print(mOverscanRight);
7325 pw.print(" bottom="); pw.println(mOverscanBottom);
7326 }
Dianne Hackborn313440842013-02-19 19:22:59 -08007327 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
7328 pw.print(mRestrictedOverscanScreenLeft);
7329 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
7330 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
7331 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007332 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
7333 pw.print(","); pw.print(mUnrestrictedScreenTop);
7334 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
7335 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
7336 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
7337 pw.print(","); pw.print(mRestrictedScreenTop);
7338 pw.print(") "); pw.print(mRestrictedScreenWidth);
7339 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07007340 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
7341 pw.print(","); pw.print(mStableFullscreenTop);
7342 pw.print(")-("); pw.print(mStableFullscreenRight);
7343 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07007344 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
7345 pw.print(","); pw.print(mStableTop);
7346 pw.print(")-("); pw.print(mStableRight);
7347 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007348 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
7349 pw.print(","); pw.print(mSystemTop);
7350 pw.print(")-("); pw.print(mSystemRight);
7351 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007352 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
7353 pw.print(","); pw.print(mCurTop);
7354 pw.print(")-("); pw.print(mCurRight);
7355 pw.print(","); pw.print(mCurBottom); pw.println(")");
7356 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
7357 pw.print(","); pw.print(mContentTop);
7358 pw.print(")-("); pw.print(mContentRight);
7359 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07007360 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
7361 pw.print(","); pw.print(mVoiceContentTop);
7362 pw.print(")-("); pw.print(mVoiceContentRight);
7363 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007364 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
7365 pw.print(","); pw.print(mDockTop);
7366 pw.print(")-("); pw.print(mDockRight);
7367 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007368 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
7369 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007370 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
7371 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07007372 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
7373 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007374 if (mLastInputMethodWindow != null) {
7375 pw.print(prefix); pw.print("mLastInputMethodWindow=");
7376 pw.println(mLastInputMethodWindow);
7377 }
7378 if (mLastInputMethodTargetWindow != null) {
7379 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
7380 pw.println(mLastInputMethodTargetWindow);
7381 }
7382 if (mStatusBar != null) {
7383 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08007384 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
7385 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007386 }
7387 if (mNavigationBar != null) {
7388 pw.print(prefix); pw.print("mNavigationBar=");
7389 pw.println(mNavigationBar);
7390 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007391 if (mFocusedWindow != null) {
7392 pw.print(prefix); pw.print("mFocusedWindow=");
7393 pw.println(mFocusedWindow);
7394 }
7395 if (mFocusedApp != null) {
7396 pw.print(prefix); pw.print("mFocusedApp=");
7397 pw.println(mFocusedApp);
7398 }
7399 if (mWinDismissingKeyguard != null) {
7400 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
7401 pw.println(mWinDismissingKeyguard);
7402 }
7403 if (mTopFullscreenOpaqueWindowState != null) {
7404 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
7405 pw.println(mTopFullscreenOpaqueWindowState);
7406 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01007407 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
7408 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
7409 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
7410 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007411 if (mForcingShowNavBar) {
7412 pw.print(prefix); pw.print("mForcingShowNavBar=");
7413 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
7414 pw.println(mForcingShowNavBarLayer);
7415 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007416 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007417 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007418 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
7419 pw.print(" mForceStatusBarFromKeyguard=");
7420 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007421 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07007422 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007423 pw.print(" mHomePressed="); pw.println(mHomePressed);
7424 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
7425 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
7426 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
7427 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
7428 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
7429 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
7430 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
7431 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
7432 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
7433 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07007434 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
7435 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
7436 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07007437
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07007438 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04007439 mStatusBarController.dump(pw, prefix);
7440 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05007441 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07007442
Jeff Browna20dda42014-05-27 20:57:24 -07007443 if (mWakeGestureListener != null) {
7444 mWakeGestureListener.dump(pw, prefix);
7445 }
Jeff Brown600f0032014-05-22 17:06:00 -07007446 if (mOrientationListener != null) {
7447 mOrientationListener.dump(pw, prefix);
7448 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00007449 if (mBurnInProtectionHelper != null) {
7450 mBurnInProtectionHelper.dump(prefix, pw);
7451 }
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07007452 if (mKeyguardDelegate != null) {
7453 mKeyguardDelegate.dump(prefix, pw);
7454 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007455 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007456}