blob: 1603f1c12cd096a9017a2817cbb22219c6f36976 [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;
Muyuan Li6ca619f2016-03-08 13:30:42 -080031import static android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN;
32import static android.view.WindowManager.TAKE_SCREENSHOT_SELECTED_REGION;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070033import static android.view.WindowManager.LayoutParams.*;
Jaewan Kim49117872016-01-19 17:24:08 +090034import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070035import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
36import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
Jaewan Kim49117872016-01-19 17:24:08 +090037import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
38import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
39import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070040
Svet Ganov9cea80cd2016-02-16 11:47:00 -080041import android.Manifest;
Dianne Hackborna4972e92012-03-14 10:38:05 -070042import android.app.ActivityManager;
Jorim Jaggi86905582016-02-09 21:36:09 -080043import android.app.ActivityManager.StackId;
Jeff Brown061ea992015-04-17 19:55:47 -070044import android.app.ActivityManagerInternal;
45import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080046import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080047import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040048import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070049import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070050import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040051import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080052import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070053import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080054import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040055import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080056import android.content.ContentResolver;
57import android.content.Context;
58import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070059import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070060import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080061import android.content.pm.ActivityInfo;
Svet Ganov03f2afc2016-03-04 16:13:03 -080062import android.content.pm.ApplicationInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080063import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040064import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070065import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080066import android.content.res.Configuration;
67import android.content.res.Resources;
68import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080069import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080070import android.graphics.Rect;
Jinsuk Kime601b712015-07-07 08:01:02 +090071import android.hardware.hdmi.HdmiControlManager;
72import android.hardware.hdmi.HdmiPlaybackClient;
73import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback;
John Spurlock7b414672014-07-18 13:02:39 -040074import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080075import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050076import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080077import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070078import android.media.Ringtone;
79import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070080import android.media.session.MediaSessionLegacyHelper;
Billy Laucbe540f2015-06-25 01:51:44 +010081import android.os.Binder;
Svet Ganov03f2afc2016-03-04 16:13:03 -080082import android.os.Build;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070083import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080084import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070085import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080086import android.os.Handler;
87import android.os.IBinder;
Dianne Hackbornb6683c42015-06-18 17:40:33 -070088import android.os.IDeviceIdleController;
Jeff Brown32cbc38552011-12-01 14:01:49 -080089import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070090import android.os.Message;
91import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080092import android.os.PowerManager;
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -070093import android.os.PowerManagerInternal;
Billy Laucbe540f2015-06-25 01:51:44 +010094import android.os.Process;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080095import android.os.RemoteException;
96import android.os.ServiceManager;
97import android.os.SystemClock;
98import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080099import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700100import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800101import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -0700102import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800103import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -0700104import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -0400105import android.service.dreams.DreamService;
106import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -0700107import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700108import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700109import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800110import android.util.EventLog;
111import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -0700112import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -0800113import android.util.SparseArray;
Muyuan Li94ce94e2016-02-24 16:20:54 -0800114import android.util.LongSparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700115import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800116import android.view.Gravity;
117import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800118import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800119import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -0700120import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -0700121import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -0800122import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800123import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -0800124import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -0800125import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800126import android.view.KeyEvent;
127import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800128import android.view.Surface;
129import android.view.View;
130import android.view.ViewConfiguration;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800131import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800132import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700133import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800134import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800135import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800136import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800137import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200138import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800139import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800140import com.android.internal.R;
Jason Monk8f7f3182015-11-18 16:35:14 -0500141import com.android.internal.logging.MetricsLogger;
142import com.android.internal.policy.PhoneWindow;
Muyuan Li94ce94e2016-02-24 16:20:54 -0800143import com.android.internal.policy.IShortcutService;
Craig Mautnerae446592012-12-06 19:05:05 -0800144import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700145import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800146import com.android.internal.widget.PointerLocationView;
Adrian Roos5941c982015-09-03 15:59:49 -0700147import com.android.server.GestureLauncherService;
Craig Mautner8a0da012014-05-31 15:13:37 -0700148import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100149import com.android.server.policy.keyguard.KeyguardServiceDelegate;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700150import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
Jorim Jaggi86905582016-02-09 21:36:09 -0800151import com.android.server.statusbar.StatusBarManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800152
153import java.io.File;
154import java.io.FileReader;
155import java.io.IOException;
156import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700157import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800158import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800159
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800160/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700161 * WindowManagerPolicy implementation for the Android phone UI. This
162 * introduces a new method suffix, Lp, for an internal lock of the
163 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400164 * 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 -0700165 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800166 */
167public class PhoneWindowManager implements WindowManagerPolicy {
168 static final String TAG = "WindowManager";
169 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700170 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700171 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700172 static final boolean DEBUG_KEYGUARD = false;
173 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700174 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700175 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800176 static final boolean SHOW_STARTING_ANIMATIONS = true;
177 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400178
Daniel Sandler6396c722013-04-16 20:19:09 -0400179 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
keunyounga7710492015-09-23 11:33:58 -0700180 // No longer recommended for desk docks;
Daniel Sandler6396c722013-04-16 20:19:09 -0400181 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
182
Jeff Brown6d8fd272014-05-20 21:24:38 -0700183 static final int SHORT_PRESS_POWER_NOTHING = 0;
184 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
185 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
186 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800187 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700188
Joe Onoratod208e702010-10-08 16:22:43 -0400189 static final int LONG_PRESS_POWER_NOTHING = 0;
190 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
191 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700192 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700193
Jeff Brown13f00f02014-10-31 14:45:50 -0700194 static final int MULTI_PRESS_POWER_NOTHING = 0;
195 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
196 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
197
Michael Jurka3b1fc472011-06-13 10:54:40 -0700198 // These need to match the documentation/constant in
199 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800200 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800201 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700202 static final int LONG_PRESS_HOME_ASSIST = 2;
Jaewan Kim76b7d0d2016-02-12 19:01:02 +0900203 static final int LAST_LONG_PRESS_HOME_BEHAVIOR = LONG_PRESS_HOME_ASSIST;
Jeff Browncaca8812013-05-09 13:34:33 -0700204
205 static final int DOUBLE_TAP_HOME_NOTHING = 0;
206 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800207
Jaewan Kim49117872016-01-19 17:24:08 +0900208 static final int SHORT_PRESS_WINDOW_NOTHING = 0;
209 static final int SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE = 1;
210
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000211 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
212 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
213
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700214 static final int APPLICATION_MEDIA_SUBLAYER = -2;
215 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800216 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800217 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700218 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700219
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800220 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
221 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
222 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500223 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700224 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800225
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700226 /**
227 * These are the system UI flags that, when changing, can cause the layout
228 * of the screen to change.
229 */
230 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400231 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400232 | View.SYSTEM_UI_FLAG_FULLSCREEN
233 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200234 | View.NAVIGATION_BAR_TRANSLUCENT
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800235 | View.STATUS_BAR_TRANSPARENT
236 | View.NAVIGATION_BAR_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700237
John Spurlock7b414672014-07-18 13:02:39 -0400238 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
239 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
240 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
241 .build();
242
Adrian Roosddc8b272015-05-21 16:28:27 -0700243 // The panic gesture may become active only after the keyguard is dismissed and the immersive
244 // app shows again. If that doesn't happen for 30s we drop the gesture.
245 private static final long PANIC_GESTURE_EXPIRATION = 30000;
246
Jim Miller5ecd8112013-01-09 18:50:26 -0800247 /**
248 * Keyguard stuff
249 */
250 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100251 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700252 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800253
Jeff Brown6651a632011-11-28 12:59:11 -0800254 /* Table of Application Launch keys. Maps from key codes to intent categories.
255 *
256 * These are special keys that are used to launch particular kinds of applications,
257 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
258 * usage page. We don't support quite that many yet...
259 */
260 static SparseArray<String> sApplicationLaunchKeyCategories;
261 static {
262 sApplicationLaunchKeyCategories = new SparseArray<String>();
263 sApplicationLaunchKeyCategories.append(
264 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
265 sApplicationLaunchKeyCategories.append(
266 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
267 sApplicationLaunchKeyCategories.append(
268 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
269 sApplicationLaunchKeyCategories.append(
270 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
271 sApplicationLaunchKeyCategories.append(
272 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
273 sApplicationLaunchKeyCategories.append(
274 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
275 }
276
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700277 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700278 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700279
Dianne Hackborndf89e652011-10-06 22:35:11 -0700280 /**
281 * Lock protecting internal state. Must not call out into window
282 * manager with lock held. (This lock will be acquired in places
283 * where the window manager is calling in with its own lock held.)
284 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800285 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700286
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800287 Context mContext;
288 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700289 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700290 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700291 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700292 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700293 DreamManagerInternal mDreamManagerInternal;
Michael Wrighta4d22d72015-09-16 23:19:26 +0100294 PowerManagerInternal mPowerManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400295 IStatusBarService mStatusBarService;
Jorim Jaggi86905582016-02-09 21:36:09 -0800296 StatusBarManagerInternal mStatusBarManagerInternal;
Jeff Browncaca8812013-05-09 13:34:33 -0700297 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700298 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800299 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700300 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800301 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000302 BurnInProtectionHelper mBurnInProtectionHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100303 AppOpsManager mAppOpsManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800304
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700305 // Vibrator pattern for haptic feedback of a long press.
306 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700307
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700308 // Vibrator pattern for haptic feedback of virtual key press.
309 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700310
Amith Yamasanic33cb712010-02-10 15:21:49 -0800311 // Vibrator pattern for a short vibration.
312 long[] mKeyboardTapVibePattern;
313
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700314 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
315 long[] mClockTickVibePattern;
316
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700317 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
318 long[] mCalendarDateVibePattern;
319
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700320 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
321 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700322
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700323 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
324 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700325
Mady Mellore8608912015-06-05 09:02:55 -0700326 // Vibrator pattern for haptic feedback of a context click.
327 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700328
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800329 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
330 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400331
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800332 boolean mSafeMode;
333 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700334 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400335 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400336 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700337 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400338 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
339 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -0800340 int[] mNavigationBarHeightForRotationDefault = new int[4];
341 int[] mNavigationBarWidthForRotationDefault = new int[4];
342 int[] mNavigationBarHeightForRotationInCarMode = new int[4];
343 int[] mNavigationBarWidthForRotationInCarMode = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400344
Muyuan Li94ce94e2016-02-24 16:20:54 -0800345 private LongSparseArray<IShortcutService> mShortcutKeyServices = new LongSparseArray<>();
346
keunyounga7710492015-09-23 11:33:58 -0700347 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
348 // This is for car dock and this is updated from resource.
349 private boolean mEnableCarDockHomeCapture = true;
350
Craig Mautnera631d492014-08-05 15:16:01 -0700351 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800352 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700353 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700354 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700355 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700356 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
357 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
358 }
359 };
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700360 final DrawnListener mKeyguardDrawnCallback = new DrawnListener() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700361 @Override
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700362 public void onDrawn() {
363 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn.");
Craig Mautner8a0da012014-05-31 15:13:37 -0700364 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
365 }
366 };
367
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800368 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800369 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900370 WindowState mLastInputMethodWindow = null;
371 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800372
Jeff Brown13f00f02014-10-31 14:45:50 -0700373 // FIXME This state is shared between the input reader and handler thread.
374 // Technically it's broken and buggy but it has been like this for many years
375 // and we have not yet seen any problems. Someday we'll rewrite this logic
376 // so that only one thread is involved in handling input policy. Unfortunately
377 // it's on a critical path for power management so we can't just post the work to the
378 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
379 // to hold wakelocks during dispatch and eliminating the critical path.
380 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800381 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700382 volatile int mPowerKeyPressCounter;
383 volatile boolean mEndCallKeyHandled;
384
Winson Chungd42a6cf2014-06-03 16:24:04 -0700385 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700386 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700387 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800388
Jeff Brown2e7760e2012-04-11 15:14:55 -0700389 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700390 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700391 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800392
Dianne Hackbornc777e072010-02-12 13:07:59 -0800393 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700394 boolean mSystemBooted;
Adrian Roos3542f7d2015-07-13 15:57:53 -0700395 private boolean mDeferBindKeyguard;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800396 boolean mHdmiPlugged;
Jinsuk Kime601b712015-07-07 08:01:02 +0900397 HdmiControl mHdmiControl;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700398 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400399 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700400 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700401 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400402 int mCarDockRotation;
403 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700404 int mUndockedHdmiRotation;
405 int mDemoHdmiRotation;
406 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800407 int mDemoRotation;
408 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400409
Jeff Browna20dda42014-05-27 20:57:24 -0700410 boolean mWakeGestureEnabledSetting;
411 MyWakeGestureListener mWakeGestureListener;
412
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700413 // Default display does not rotate, apps that require non-default orientation will have to
414 // have the orientation emulated.
415 private boolean mForceDefaultOrientation = false;
416
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400417 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
418 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700419 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400420
Jeff Brownbcdfc622014-03-06 19:13:04 -0800421 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700422 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400423 boolean mCarDockEnablesAccelerometer;
424 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700425 int mLidKeyboardAccessibility;
426 int mLidNavigationAccessibility;
Edward Savage-Jones7def60d2015-11-13 13:27:03 +0100427 boolean mLidControlsScreenLock;
Jeff Brownc458ce92012-04-30 14:58:40 -0700428 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700429 int mShortPressOnPowerBehavior;
430 int mLongPressOnPowerBehavior;
431 int mDoublePressOnPowerBehavior;
432 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000433 int mShortPressOnSleepBehavior;
Jaewan Kim49117872016-01-19 17:24:08 +0900434 int mShortPressWindowBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700435 boolean mAwake;
436 boolean mScreenOnEarly;
437 boolean mScreenOnFully;
438 ScreenOnListener mScreenOnListener;
439 boolean mKeyguardDrawComplete;
440 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800441 boolean mOrientationSensorEnabled = false;
442 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800443 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400444 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800445 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700446
Jeff Brown70825162012-03-28 17:27:48 -0700447 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800448
449 // The last window we were told about in focusChanged.
450 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800451 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800452
Jeff Brown70825162012-03-28 17:27:48 -0700453 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800454
Dianne Hackbornc652de82013-02-15 16:32:56 -0800455 // The current size of the screen; really; extends into the overscan area of
456 // the screen and doesn't account for any system elements like the status bar.
457 int mOverscanScreenLeft, mOverscanScreenTop;
458 int mOverscanScreenWidth, mOverscanScreenHeight;
459 // The current visible size of the screen; really; (ir)regardless of whether the status
460 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800461 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
462 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800463 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
464 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
465 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700466 // The current size of the screen; these may be different than (0,0)-(dw,dh)
467 // if the status bar can't be hidden; in that case it effectively carves out
468 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800469 int mRestrictedScreenLeft, mRestrictedScreenTop;
470 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700471 // During layout, the current screen borders accounting for any currently
472 // visible system UI elements.
473 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700474 // For applications requesting stable content insets, these are them.
475 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700476 // For applications requesting stable content insets but have also set the
477 // fullscreen window flag, these are the stable dimensions without the status bar.
478 int mStableFullscreenLeft, mStableFullscreenTop;
479 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800480 // During layout, the current screen borders with all outer decoration
481 // (status bar, input method dock) accounted for.
482 int mCurLeft, mCurTop, mCurRight, mCurBottom;
483 // During layout, the frame in which content should be displayed
484 // to the user, accounting for all screen decoration except for any
485 // space they deem as available for other content. This is usually
486 // the same as mCur*, but may be larger if the screen decor has supplied
487 // content insets.
488 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700489 // During layout, the frame in which voice content should be displayed
490 // to the user, accounting for all screen decoration except for any
491 // space they deem as available for other content.
492 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800493 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800494 // windows are placed.
495 int mDockLeft, mDockTop, mDockRight, mDockBottom;
496 // During layout, the layer at which the doc window is placed.
497 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700498 // During layout, this is the layer of the status bar.
499 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700500 int mLastSystemUiFlags;
501 // Bits that we are in the process of clearing, so we want to prevent
502 // them from being set by applications until everything has been updated
503 // to have them clear.
504 int mResettingSystemUiFlags = 0;
505 // Bits that we are currently always keeping cleared.
506 int mForceClearedSystemUiFlags = 0;
Jorim Jaggi86905582016-02-09 21:36:09 -0800507 int mLastFullscreenStackSysUiFlags;
508 int mLastDockedStackSysUiFlags;
509 final Rect mNonDockedStackBounds = new Rect();
510 final Rect mDockedStackBounds = new Rect();
511 final Rect mLastNonDockedStackBounds = new Rect();
512 final Rect mLastDockedStackBounds = new Rect();
513
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800514 // What we last reported to system UI about whether the compatibility
515 // menu needs to be displayed.
516 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700517 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
518 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700519
Selim Cinekf83e8242015-05-19 18:08:14 -0700520 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700521
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800522 static final Rect mTmpParentFrame = new Rect();
523 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800524 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800525 static final Rect mTmpContentFrame = new Rect();
526 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400527 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700528 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700529 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700530 static final Rect mTmpOutsetFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700531
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800532 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100533 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Jorim Jaggi86905582016-02-09 21:36:09 -0800534 WindowState mTopDockedOpaqueWindowState;
535 WindowState mTopDockedOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700536 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200537 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400538 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800539 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700540 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700541 private boolean mForceStatusBarTransparent;
Yorke Lee2e4b7322016-03-02 17:33:06 -0800542 boolean mForceNavBarOpaque;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700543 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800544 boolean mForcingShowNavBar;
545 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700546
547 // States of keyguard dismiss.
548 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
549 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
550 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
551 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
552
553 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
554 * be done once per window. */
555 private WindowState mWinDismissingKeyguard;
556
tingna_sunge785ffa2015-05-12 13:23:15 +0800557 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
558 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
559 * lock SIM card. This variable is used to record the previous keyguard secure state for
560 * monitoring secure state change on window dismissing keyguard. */
561 private boolean mSecureDismissingKeyguard;
562
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700563 /** The window that is currently showing "over" the keyguard. If there is an app window
564 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
565 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
566 * the wallpaper. */
567 private WindowState mWinShowWhenLocked;
568
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700569 boolean mShowingLockscreen;
570 boolean mShowingDream;
571 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700572 boolean mDreamingSleepTokenNeeded;
573 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700574 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700575 boolean mKeyguardSecure;
576 boolean mKeyguardSecureIncludingHidden;
577 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800578 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700579 boolean mHomeConsumed;
580 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800581 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700582 Intent mCarDockIntent;
583 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700584 boolean mSearchKeyShortcutPending;
585 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700586 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700587 boolean mPendingMetaAction;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -0800588 boolean mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800589
Mike Lockwood28569302010-01-28 11:54:40 -0500590 // support for activating the lock screen while the screen is on
591 boolean mAllowLockscreenWhenOn;
592 int mLockScreenTimeout;
593 boolean mLockScreenTimerActive;
594
David Brownbaf8d092010-03-08 21:52:59 -0800595 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800596 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800597
598 // Behavior of POWER button while in-call and screen on.
599 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
600 int mIncallPowerBehavior;
601
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700602 Display mDisplay;
603
Filip Gruszczynski2987f612015-06-30 15:03:30 -0700604 private int mDisplayRotation;
605
Dianne Hackborn9d132642011-04-21 17:26:39 -0700606 int mLandscapeRotation = 0; // default landscape rotation
607 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
608 int mPortraitRotation = 0; // default portrait rotation
609 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700610
Dianne Hackbornc652de82013-02-15 16:32:56 -0800611 int mOverscanLeft = 0;
612 int mOverscanTop = 0;
613 int mOverscanRight = 0;
614 int mOverscanBottom = 0;
615
Joe Onorato46b0d682010-11-22 17:37:27 -0800616 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700617 private int mLongPressOnHomeBehavior;
618
619 // What we do when the user double-taps on home
620 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800621
Bryce Lee584a4452014-10-21 15:55:55 -0700622 // Allowed theater mode wake actions
623 private boolean mAllowTheaterModeWakeFromKey;
624 private boolean mAllowTheaterModeWakeFromPowerKey;
625 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800626 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700627 private boolean mAllowTheaterModeWakeFromCameraLens;
628 private boolean mAllowTheaterModeWakeFromLidSwitch;
629 private boolean mAllowTheaterModeWakeFromWakeGesture;
630
Bryce Leed3b28402015-03-09 15:49:13 +0000631 // Whether to support long press from power button in non-interactive mode
632 private boolean mSupportLongPressPowerWhenNonInteractive;
633
Bryce Lee55e846d2014-11-04 12:43:44 -0800634 // Whether to go to sleep entering theater mode from power button
635 private boolean mGoToSleepOnButtonPressTheaterMode;
636
Winson Chung9112ec32011-06-27 13:15:32 -0700637 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700638 // Time to volume and power must be pressed within this interval of each other.
639 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700640 // Increase the chord delay when taking a screenshot from the keyguard
641 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800642 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700643 private boolean mScreenshotChordVolumeDownKeyTriggered;
644 private long mScreenshotChordVolumeDownKeyTime;
645 private boolean mScreenshotChordVolumeDownKeyConsumed;
646 private boolean mScreenshotChordVolumeUpKeyTriggered;
647 private boolean mScreenshotChordPowerKeyTriggered;
648 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700649
Michael Wrightb854e242013-02-05 17:54:02 -0800650 /* The number of steps between min and max brightness */
651 private static final int BRIGHTNESS_STEPS = 10;
652
Christopher Tate5e08af02012-09-21 17:17:22 -0700653 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800654 ShortcutManager mShortcutManager;
655 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700656 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700657 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800658
Craig Mautnerd625ab22013-09-06 13:40:31 -0700659 private int mCurrentUserId;
660
Justin Kohd378ad72013-04-01 12:18:26 -0700661 // Maps global key codes to the components that will handle them.
662 private GlobalKeyManager mGlobalKeyManager;
663
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700664 // Fallback actions by key code.
665 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
666 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800667
Jorim Jaggi76a16232014-08-08 17:00:47 +0200668 private final LogDecelerateInterpolator mLogDecelerateInterpolator
669 = new LogDecelerateInterpolator(100, 0);
670
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800671 private boolean mForceWindowDrawsStatusBarBackground;
672
Jeff Brown70825162012-03-28 17:27:48 -0700673 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
674 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700675 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
676 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700677 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
678 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
679 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700680 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700681 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700682 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700683 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700684 private static final int MSG_POWER_DELAYED_PRESS = 13;
685 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700686 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700687 private static final int MSG_REQUEST_TRANSIENT_BARS = 16;
Jaewan Kimc552b042016-01-18 16:08:45 +0900688 private static final int MSG_REQUEST_TV_PICTURE_IN_PICTURE = 17;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700689
690 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
691 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
Jeff Brown70825162012-03-28 17:27:48 -0700692
693 private class PolicyHandler extends Handler {
694 @Override
695 public void handleMessage(Message msg) {
696 switch (msg.what) {
697 case MSG_ENABLE_POINTER_LOCATION:
698 enablePointerLocation();
699 break;
700 case MSG_DISABLE_POINTER_LOCATION:
701 disablePointerLocation();
702 break;
Jeff Brown40013652012-05-16 21:22:36 -0700703 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
704 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
705 break;
706 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
707 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
708 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700709 case MSG_DISPATCH_SHOW_RECENTS:
710 showRecentApps(false);
711 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700712 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
713 showGlobalActionsInternal();
714 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700715 case MSG_KEYGUARD_DRAWN_COMPLETE:
716 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700717 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700718 break;
719 case MSG_KEYGUARD_DRAWN_TIMEOUT:
720 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700721 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700722 break;
723 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
724 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700725 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700726 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700727 case MSG_HIDE_BOOT_MESSAGE:
728 handleHideBootMessage();
729 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700730 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
731 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
732 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700733 case MSG_POWER_DELAYED_PRESS:
734 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
735 finishPowerKeyPress();
736 break;
737 case MSG_POWER_LONG_PRESS:
738 powerLongPress();
739 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700740 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
741 updateDreamingSleepToken(msg.arg1 != 0);
742 break;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700743 case MSG_REQUEST_TRANSIENT_BARS:
744 WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ?
745 mStatusBar : mNavigationBar;
746 if (targetBar != null) {
747 requestTransientBars(targetBar);
748 }
749 break;
Jaewan Kimc552b042016-01-18 16:08:45 +0900750 case MSG_REQUEST_TV_PICTURE_IN_PICTURE:
751 requestTvPictureInPictureInternal();
752 break;
Jeff Brown70825162012-03-28 17:27:48 -0700753 }
754 }
755 }
756
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800757 private UEventObserver mHDMIObserver = new UEventObserver() {
758 @Override
759 public void onUEvent(UEventObserver.UEvent event) {
760 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
761 }
762 };
763
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800764 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800765 SettingsObserver(Handler handler) {
766 super(handler);
767 }
David Brownbaf8d092010-03-08 21:52:59 -0800768
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800769 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700770 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800771 ContentResolver resolver = mContext.getContentResolver();
772 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700773 Settings.System.END_BUTTON_BEHAVIOR), false, this,
774 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800775 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700776 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
777 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700778 resolver.registerContentObserver(Settings.Secure.getUriFor(
779 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
780 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800781 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700782 Settings.System.ACCELEROMETER_ROTATION), false, this,
783 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500784 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700785 Settings.System.USER_ROTATION), false, this,
786 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400787 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700788 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
789 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800790 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700791 Settings.System.POINTER_LOCATION), false, this,
792 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800793 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700794 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
795 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500796 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400797 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700798 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500799 resolver.registerContentObserver(Settings.Global.getUriFor(
800 Settings.Global.POLICY_CONTROL), false, this,
801 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800802 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800803 }
804
805 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800806 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700807 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800808 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800809 }
Craig Mautner967212c2013-04-13 21:10:58 -0700810
Jeff Browna20dda42014-05-27 20:57:24 -0700811 class MyWakeGestureListener extends WakeGestureListener {
812 MyWakeGestureListener(Context context, Handler handler) {
813 super(context, handler);
814 }
815
816 @Override
817 public void onWakeUp() {
818 synchronized (mLock) {
819 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700820 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700821 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture,
822 "android.policy:GESTURE");
Jeff Browna20dda42014-05-27 20:57:24 -0700823 }
824 }
825 }
826 }
827
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800828 class MyOrientationListener extends WindowOrientationListener {
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700829 private final Runnable mUpdateRotationRunnable = new Runnable() {
830 @Override
831 public void run() {
Tim Murray1f407642015-10-01 17:07:12 -0700832 // send interaction hint to improve redraw performance
833 mPowerManagerInternal.powerHint(PowerManagerInternal.POWER_HINT_INTERACTION, 0);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700834 updateRotation(false);
835 }
836 };
837
Craig Mautnereee29c42013-01-17 14:44:34 -0800838 MyOrientationListener(Context context, Handler handler) {
839 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800840 }
Craig Mautner967212c2013-04-13 21:10:58 -0700841
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800842 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700843 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700844 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700845 mHandler.post(mUpdateRotationRunnable);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700846 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800847 }
848 MyOrientationListener mOrientationListener;
849
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100850 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400851
John Spurlock27735a42013-08-14 17:57:38 -0400852 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400853 View.NAVIGATION_BAR_TRANSIENT,
854 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400855 View.NAVIGATION_BAR_TRANSLUCENT,
856 StatusBarManager.WINDOW_NAVIGATION_BAR,
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800857 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
858 View.NAVIGATION_BAR_TRANSPARENT);
John Spurlock5b9145b2013-08-20 15:13:47 -0400859
John Spurlockf1a36642013-10-12 17:50:42 -0400860 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400861
Craig Mautner037aa8d2013-06-07 10:35:44 -0700862 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400863
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700864 IStatusBarService getStatusBarService() {
865 synchronized (mServiceAquireLock) {
866 if (mStatusBarService == null) {
867 mStatusBarService = IStatusBarService.Stub.asInterface(
868 ServiceManager.getService("statusbar"));
869 }
870 return mStatusBarService;
871 }
872 }
873
Jorim Jaggi86905582016-02-09 21:36:09 -0800874 StatusBarManagerInternal getStatusBarManagerInternal() {
875 synchronized (mServiceAquireLock) {
876 if (mStatusBarManagerInternal == null) {
877 mStatusBarManagerInternal =
878 LocalServices.getService(StatusBarManagerInternal.class);
879 }
880 return mStatusBarManagerInternal;
881 }
882 }
883
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700884 /*
885 * We always let the sensor be switched on by default except when
886 * the user has explicitly disabled sensor based rotation or when the
887 * screen is switched off.
888 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700889 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800890 if (mSupportAutoRotation) {
891 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
892 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
893 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
894 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
895 // If the application has explicitly requested to follow the
896 // orientation, then we need to turn the sensor on.
897 return true;
898 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800899 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700900 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800901 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
902 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
903 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400904 // enable accelerometer if we are docked in a dock that enables accelerometer
905 // orientation management,
906 return true;
907 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700908 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800909 // If the setting for using the sensor by default is enabled, then
910 // we will always leave it on. Note that the user could go to
911 // a window that forces an orientation that does not use the
912 // sensor and in theory we could turn it off... however, when next
913 // turning it on we won't have a good value for the current
914 // orientation for a little bit, which can cause orientation
915 // changes to lag, so we'd like to keep it always on. (It will
916 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700917 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800918 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800919 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800920 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700921
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800922 /*
923 * Various use cases for invoking this function
924 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700925 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800926 * if not already enabled
927 * screen turned on and current app does not have sensor orientation, disable listeners if
928 * already enabled
929 * screen turning on and current app has sensor based orientation, enable listeners if needed
930 * screen turning on and current app has nosensor based orientation, do nothing
931 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700932 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800933 if (!mOrientationListener.canDetectOrientation()) {
934 // If sensor is turned off or nonexistent for some reason
935 return;
936 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000937 // Could have been invoked due to screen turning on or off or
938 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -0700939 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
940 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000941 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
942 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
943 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800944 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000945 // Note: We postpone the rotating of the screen until the keyguard as well as the
946 // window manager have reported a draw complete.
947 if (mScreenOnEarly && mAwake &&
948 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700949 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800950 disable = false;
951 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700952 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800953 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700954 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800955 mOrientationSensorEnabled = true;
956 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700957 }
958 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800959 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700960 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800961 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700962 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800963 mOrientationSensorEnabled = false;
964 }
965 }
966
Jeff Brown13f00f02014-10-31 14:45:50 -0700967 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
968 // Hold a wake lock until the power key is released.
969 if (!mPowerKeyWakeLock.isHeld()) {
970 mPowerKeyWakeLock.acquire();
971 }
972
973 // Cancel multi-press detection timeout.
974 if (mPowerKeyPressCounter != 0) {
975 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
976 }
977
978 // Detect user pressing the power button in panic when an application has
979 // taken over the whole screen.
980 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800981 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700982 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700983 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700984 }
985
986 // Latch power key state to detect screenshot chord.
987 if (interactive && !mScreenshotChordPowerKeyTriggered
988 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
989 mScreenshotChordPowerKeyTriggered = true;
990 mScreenshotChordPowerKeyTime = event.getDownTime();
991 interceptScreenshotChord();
992 }
993
994 // Stop ringing or end call if configured to do so when power is pressed.
995 TelecomManager telecomManager = getTelecommService();
996 boolean hungUp = false;
997 if (telecomManager != null) {
998 if (telecomManager.isRinging()) {
999 // Pressing Power while there's a ringing incoming
1000 // call should silence the ringer.
1001 telecomManager.silenceRinger();
1002 } else if ((mIncallPowerBehavior
1003 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
1004 && telecomManager.isInCall() && interactive) {
1005 // Otherwise, if "Power button ends call" is enabled,
1006 // the Power button will hang up any current active call.
1007 hungUp = telecomManager.endCall();
1008 }
1009 }
1010
Adrian Roos5941c982015-09-03 15:59:49 -07001011 GestureLauncherService gestureService = LocalServices.getService(
1012 GestureLauncherService.class);
1013 boolean gesturedServiceIntercepted = false;
1014 if (gestureService != null) {
1015 gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive);
1016 }
1017
Jeff Brown13f00f02014-10-31 14:45:50 -07001018 // If the power key has still not yet been handled, then detect short
1019 // press, long press, or multi press and decide what to do.
1020 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
Adrian Roos5941c982015-09-03 15:59:49 -07001021 || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted;
Jeff Brown13f00f02014-10-31 14:45:50 -07001022 if (!mPowerKeyHandled) {
1023 if (interactive) {
1024 // When interactive, we're already awake.
1025 // Wait for a long press or for the button to be released to decide what to do.
1026 if (hasLongPressOnPowerBehavior()) {
1027 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1028 msg.setAsynchronous(true);
1029 mHandler.sendMessageDelayed(msg,
1030 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
1031 }
1032 } else {
Bryce Leed9268e32014-11-17 17:40:59 -08001033 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -08001034
Bryce Leed3b28402015-03-09 15:49:13 +00001035 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
1036 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1037 msg.setAsynchronous(true);
1038 mHandler.sendMessageDelayed(msg,
1039 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -08001040 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +00001041 } else {
1042 final int maxCount = getMaxMultiPressPowerCount();
1043
1044 if (maxCount <= 1) {
1045 mPowerKeyHandled = true;
1046 } else {
1047 mBeganFromNonInteractive = true;
1048 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001049 }
1050 }
Jeff Brown4d396052010-10-29 21:50:21 -07001051 }
1052 }
1053
Jeff Brown13f00f02014-10-31 14:45:50 -07001054 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
1055 final boolean handled = canceled || mPowerKeyHandled;
1056 mScreenshotChordPowerKeyTriggered = false;
1057 cancelPendingScreenshotChordAction();
1058 cancelPendingPowerKeyAction();
1059
1060 if (!handled) {
1061 // Figure out how to handle the key now that it has been released.
1062 mPowerKeyPressCounter += 1;
1063
1064 final int maxCount = getMaxMultiPressPowerCount();
1065 final long eventTime = event.getDownTime();
1066 if (mPowerKeyPressCounter < maxCount) {
1067 // This could be a multi-press. Wait a little bit longer to confirm.
1068 // Continue holding the wake lock.
1069 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
1070 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
1071 msg.setAsynchronous(true);
1072 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
1073 return;
1074 }
1075
1076 // No other actions. Handle it immediately.
1077 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -07001078 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001079
1080 // Done. Reset our state.
1081 finishPowerKeyPress();
1082 }
1083
1084 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -08001085 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001086 mPowerKeyPressCounter = 0;
1087 if (mPowerKeyWakeLock.isHeld()) {
1088 mPowerKeyWakeLock.release();
1089 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001090 }
1091
1092 private void cancelPendingPowerKeyAction() {
1093 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001094 mPowerKeyHandled = true;
1095 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001096 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001097 }
1098
1099 private void powerPress(long eventTime, boolean interactive, int count) {
1100 if (mScreenOnEarly && !mScreenOnFully) {
1101 Slog.i(TAG, "Suppressed redundant power key press while "
1102 + "already in the process of turning the screen on.");
1103 return;
Jeff Brownff204712011-10-25 21:27:54 -07001104 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001105
1106 if (count == 2) {
1107 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1108 } else if (count == 3) {
1109 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001110 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001111 switch (mShortPressOnPowerBehavior) {
1112 case SHORT_PRESS_POWER_NOTHING:
1113 break;
1114 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1115 mPowerManager.goToSleep(eventTime,
1116 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1117 break;
1118 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1119 mPowerManager.goToSleep(eventTime,
1120 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1121 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1122 break;
1123 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1124 mPowerManager.goToSleep(eventTime,
1125 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1126 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1127 launchHomeFromHotKey();
1128 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001129 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001130 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001131 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001132 }
1133 }
1134 }
1135
1136 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1137 switch (behavior) {
1138 case MULTI_PRESS_POWER_NOTHING:
1139 break;
1140 case MULTI_PRESS_POWER_THEATER_MODE:
Bryce Lee3ae447e2015-06-30 12:31:41 -07001141 if (!isUserSetupComplete()) {
1142 Slog.i(TAG, "Ignoring toggling theater mode - device not setup.");
1143 break;
1144 }
1145
Jeff Brown13f00f02014-10-31 14:45:50 -07001146 if (isTheaterModeEnabled()) {
1147 Slog.i(TAG, "Toggling theater mode off.");
1148 Settings.Global.putInt(mContext.getContentResolver(),
1149 Settings.Global.THEATER_MODE_ON, 0);
1150 if (!interactive) {
1151 wakeUpFromPowerKey(eventTime);
1152 }
1153 } else {
1154 Slog.i(TAG, "Toggling theater mode on.");
1155 Settings.Global.putInt(mContext.getContentResolver(),
1156 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001157
1158 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001159 mPowerManager.goToSleep(eventTime,
1160 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1161 }
1162 }
1163 break;
1164 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001165 Slog.i(TAG, "Starting brightness boost.");
1166 if (!interactive) {
1167 wakeUpFromPowerKey(eventTime);
1168 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001169 mPowerManager.boostScreenBrightness(eventTime);
1170 break;
1171 }
1172 }
1173
1174 private int getMaxMultiPressPowerCount() {
1175 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1176 return 3;
1177 }
1178 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1179 return 2;
1180 }
1181 return 1;
1182 }
1183
1184 private void powerLongPress() {
1185 final int behavior = getResolvedLongPressOnPowerBehavior();
1186 switch (behavior) {
1187 case LONG_PRESS_POWER_NOTHING:
1188 break;
1189 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1190 mPowerKeyHandled = true;
1191 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1192 performAuditoryFeedbackForAccessibilityIfNeed();
1193 }
1194 showGlobalActionsInternal();
1195 break;
1196 case LONG_PRESS_POWER_SHUT_OFF:
1197 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1198 mPowerKeyHandled = true;
1199 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1200 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1201 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1202 break;
1203 }
1204 }
1205
Nick Vaccarob593a812015-05-15 11:23:05 -07001206 private void sleepPress(long eventTime) {
1207 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1208 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1209 }
1210 }
1211
1212 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001213 switch (mShortPressOnSleepBehavior) {
1214 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001215 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001216 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1217 mPowerManager.goToSleep(eventTime,
1218 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001219 break;
1220 }
1221 }
1222
Jeff Brown13f00f02014-10-31 14:45:50 -07001223 private int getResolvedLongPressOnPowerBehavior() {
1224 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1225 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1226 }
1227 return mLongPressOnPowerBehavior;
1228 }
1229
1230 private boolean hasLongPressOnPowerBehavior() {
1231 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001232 }
1233
1234 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001235 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001236 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1237 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001238 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001239 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1240 && now <= mScreenshotChordPowerKeyTime
1241 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1242 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001243 cancelPendingPowerKeyAction();
Muyuan Li6ca619f2016-03-08 13:30:42 -08001244 mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN);
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001245 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001246 }
1247 }
1248 }
1249
Winson Chung1cea2f32012-10-08 20:42:01 -07001250 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001251 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001252 // Double the time it takes to take a screenshot from the keyguard
1253 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001254 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001255 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001256 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001257 }
1258
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001259 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001260 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001261 }
1262
Jeff Brown13f00f02014-10-31 14:45:50 -07001263 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001264 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001265 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001266 mEndCallKeyHandled = true;
1267 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1268 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001269 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001270 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001271 }
1272 };
1273
Muyuan Li6ca619f2016-03-08 13:30:42 -08001274 private class ScreenshotRunnable implements Runnable {
1275 private int mScreenshotType = TAKE_SCREENSHOT_FULLSCREEN;
1276
1277 public void setScreenshotType(int screenshotType) {
1278 mScreenshotType = screenshotType;
1279 }
1280
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001281 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001282 public void run() {
Muyuan Li6ca619f2016-03-08 13:30:42 -08001283 takeScreenshot(mScreenshotType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001284 }
Muyuan Li6ca619f2016-03-08 13:30:42 -08001285 }
1286
1287 private final ScreenshotRunnable mScreenshotRunnable = new ScreenshotRunnable();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001288
Alan Viverettee34560b22014-07-10 14:50:06 -07001289 @Override
1290 public void showGlobalActions() {
1291 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1292 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1293 }
1294
1295 void showGlobalActionsInternal() {
1296 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001297 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001298 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001299 }
Jim Millerab954542014-10-10 18:21:49 -07001300 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001301 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1302 if (keyguardShowing) {
1303 // since it took two seconds of long press to bring this up,
1304 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001305 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001306 }
1307 }
1308
1309 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001310 return Settings.Global.getInt(
1311 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001312 }
1313
Maurice Lam99c6e072014-04-28 18:24:28 -07001314 boolean isUserSetupComplete() {
1315 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1316 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1317 }
1318
Jeff Brown13f00f02014-10-31 14:45:50 -07001319 private void handleShortPressOnHome() {
Jinsuk Kime601b712015-07-07 08:01:02 +09001320 // Turn on the connected TV and switch HDMI input if we're a HDMI playback device.
1321 getHdmiControl().turnOnTv();
1322
Jeff Brown13f00f02014-10-31 14:45:50 -07001323 // If there's a dream running then use home to escape the dream
1324 // but don't actually go home.
1325 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1326 mDreamManagerInternal.stopDream(false /*immediate*/);
1327 return;
1328 }
1329
1330 // Go home!
1331 launchHomeFromHotKey();
1332 }
1333
Jinsuk Kime601b712015-07-07 08:01:02 +09001334 /**
1335 * Creates an accessor to HDMI control service that performs the operation of
1336 * turning on TV (optional) and switching input to us. If HDMI control service
1337 * is not available or we're not a HDMI playback device, the operation is no-op.
1338 */
1339 private HdmiControl getHdmiControl() {
1340 if (null == mHdmiControl) {
1341 HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService(
1342 Context.HDMI_CONTROL_SERVICE);
1343 HdmiPlaybackClient client = null;
1344 if (manager != null) {
1345 client = manager.getPlaybackClient();
1346 }
1347 mHdmiControl = new HdmiControl(client);
1348 }
1349 return mHdmiControl;
1350 }
1351
1352 private static class HdmiControl {
1353 private final HdmiPlaybackClient mClient;
1354
1355 private HdmiControl(HdmiPlaybackClient client) {
1356 mClient = client;
1357 }
1358
1359 public void turnOnTv() {
1360 if (mClient == null) {
1361 return;
1362 }
1363 mClient.oneTouchPlay(new OneTouchPlayCallback() {
1364 @Override
1365 public void onComplete(int result) {
1366 if (result != HdmiControlManager.RESULT_SUCCESS) {
1367 Log.w(TAG, "One touch play failed: " + result);
1368 }
1369 }
1370 });
1371 }
1372 }
1373
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001374 private void handleLongPressOnHome(int deviceId) {
Jaewan Kim52632e22016-01-14 18:01:52 +09001375 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) {
1376 return;
1377 }
1378 mHomeConsumed = true;
1379 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001380
Jaewan Kim52632e22016-01-14 18:01:52 +09001381 switch (mLongPressOnHomeBehavior) {
1382 case LONG_PRESS_HOME_RECENT_SYSTEM_UI:
Jeff Browncaca8812013-05-09 13:34:33 -07001383 toggleRecentApps();
Jaewan Kim52632e22016-01-14 18:01:52 +09001384 break;
1385 case LONG_PRESS_HOME_ASSIST:
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001386 launchAssistAction(null, deviceId);
Jaewan Kim52632e22016-01-14 18:01:52 +09001387 break;
Jaewan Kim52632e22016-01-14 18:01:52 +09001388 default:
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001389 Log.w(TAG, "Undefined home long press behavior: " + mLongPressOnHomeBehavior);
Jaewan Kim52632e22016-01-14 18:01:52 +09001390 break;
Jim Millere6ad1a82010-08-20 19:25:39 -07001391 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001392 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001393
Jeff Browncaca8812013-05-09 13:34:33 -07001394 private void handleDoubleTapOnHome() {
1395 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1396 mHomeConsumed = true;
1397 toggleRecentApps();
1398 }
1399 }
1400
Jaewan Kimc552b042016-01-18 16:08:45 +09001401 private void requestTvPictureInPicture(KeyEvent event) {
1402 if (DEBUG_INPUT) Log.d(TAG, "requestTvPictureInPicture event=" + event);
1403 mHandler.removeMessages(MSG_REQUEST_TV_PICTURE_IN_PICTURE);
1404 Message msg = mHandler.obtainMessage(MSG_REQUEST_TV_PICTURE_IN_PICTURE);
1405 msg.setAsynchronous(true);
1406 msg.sendToTarget();
1407 }
1408
1409 private void requestTvPictureInPictureInternal() {
1410 try {
1411 IStatusBarService statusbar = getStatusBarService();
1412 if (statusbar != null) {
1413 statusbar.requestTvPictureInPicture();
1414 }
1415 } catch (RemoteException|IllegalArgumentException e) {
1416 Slog.e(TAG, "Cannot handle picture-in-picture key", e);
1417 // re-acquire status bar service next time it is needed.
1418 mStatusBarService = null;
1419 }
Jaewan Kim52632e22016-01-14 18:01:52 +09001420 }
1421
Jeff Browncaca8812013-05-09 13:34:33 -07001422 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1423 @Override
1424 public void run() {
1425 if (mHomeDoubleTapPending) {
1426 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001427 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001428 }
1429 }
1430 };
1431
Mark Renoufc1256912015-03-11 14:38:23 -04001432 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001433 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001434 }
1435
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001436 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001437 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001438 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001439 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001440 mContext = context;
1441 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001442 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001443 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001444 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001445 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Michael Wrighta4d22d72015-09-16 23:19:26 +01001446 mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001447 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Mark Renoufc1256912015-03-11 14:38:23 -04001448
1449 // Init display burn-in protection
1450 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1451 com.android.internal.R.bool.config_enableBurnInProtection);
1452 // Allow a system property to override this. Used by developer settings.
1453 boolean burnInProtectionDevMode =
1454 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1455 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1456 final int minHorizontal;
1457 final int maxHorizontal;
1458 final int minVertical;
1459 final int maxVertical;
1460 final int maxRadius;
1461 if (burnInProtectionDevMode) {
1462 minHorizontal = -8;
1463 maxHorizontal = 8;
1464 minVertical = -8;
1465 maxVertical = -4;
1466 maxRadius = (isRoundWindow()) ? 6 : -1;
1467 } else {
1468 Resources resources = context.getResources();
1469 minHorizontal = resources.getInteger(
1470 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1471 maxHorizontal = resources.getInteger(
1472 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1473 minVertical = resources.getInteger(
1474 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1475 maxVertical = resources.getInteger(
1476 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1477 maxRadius = resources.getInteger(
1478 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1479 }
1480 mBurnInProtectionHelper = new BurnInProtectionHelper(
1481 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001482 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001483
Jeff Brown70825162012-03-28 17:27:48 -07001484 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001485 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001486 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001487 try {
1488 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1489 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001490 mSettingsObserver = new SettingsObserver(mHandler);
1491 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001492 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001493 mUiMode = context.getResources().getInteger(
1494 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001495 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1496 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1497 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1498 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
keunyounga7710492015-09-23 11:33:58 -07001499 mEnableCarDockHomeCapture = context.getResources().getBoolean(
1500 com.android.internal.R.bool.config_enableCarDockHomeLaunch);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001501 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1502 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1503 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1504 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1505 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1506 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1507 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1508 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001509
Jeff Brown96307042012-07-27 15:51:34 -07001510 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1511 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001512 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001513 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1514 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001515 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001516 mSupportAutoRotation = mContext.getResources().getBoolean(
1517 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001518 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001519 com.android.internal.R.integer.config_lidOpenRotation);
1520 mCarDockRotation = readRotation(
1521 com.android.internal.R.integer.config_carDockRotation);
1522 mDeskDockRotation = readRotation(
1523 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001524 mUndockedHdmiRotation = readRotation(
1525 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001526 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1527 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1528 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1529 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001530 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1531 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1532 mLidNavigationAccessibility = mContext.getResources().getInteger(
1533 com.android.internal.R.integer.config_lidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01001534 mLidControlsScreenLock = mContext.getResources().getBoolean(
1535 com.android.internal.R.bool.config_lidControlsScreenLock);
Jeff Brownc458ce92012-04-30 14:58:40 -07001536 mLidControlsSleep = mContext.getResources().getBoolean(
1537 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001538 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1539 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001540
1541 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1542 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1543 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1544 || mContext.getResources().getBoolean(
1545 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1546 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1547 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001548 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1549 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001550 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1551 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1552 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1553 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1554 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1555 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1556
Bryce Lee55e846d2014-11-04 12:43:44 -08001557 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1558 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1559
Bryce Leed3b28402015-03-09 15:49:13 +00001560 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1561 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1562
Jeff Brown13f00f02014-10-31 14:45:50 -07001563 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1564 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1565 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1566 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1567 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1568 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1569 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1570 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001571 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1572 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001573
John Spurlock61560172015-02-06 19:46:04 -05001574 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001575
Jeff Brownf71343d2013-05-31 17:59:11 -07001576 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001577
Svetoslav8e3feb12014-02-24 13:46:47 -08001578 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1579 Context.ACCESSIBILITY_SERVICE);
1580
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001581 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001582 IntentFilter filter = new IntentFilter();
1583 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1584 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1585 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1586 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001587 filter.addAction(Intent.ACTION_DOCK_EVENT);
1588 Intent intent = context.registerReceiver(mDockReceiver, filter);
1589 if (intent != null) {
1590 // Retrieve current sticky dock event broadcast.
1591 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1592 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1593 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001594
Jeff Brown6aaf2952012-10-05 16:01:08 -07001595 // register for dream-related broadcasts
1596 filter = new IntentFilter();
1597 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1598 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1599 context.registerReceiver(mDreamReceiver, filter);
1600
Christopher Tate5e08af02012-09-21 17:17:22 -07001601 // register for multiuser-relevant broadcasts
1602 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1603 context.registerReceiver(mMultiuserReceiver, filter);
1604
John Spurlock57306e62013-04-22 09:48:49 -04001605 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001606 mSystemGestures = new SystemGesturesPointerEventListener(context,
1607 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001608 @Override
1609 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001610 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001611 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001612 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001613 }
1614 @Override
1615 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001616 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001617 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001618 }
1619 }
1620 @Override
1621 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001622 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001623 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001624 }
1625 }
1626 @Override
Michael Wrighta4d22d72015-09-16 23:19:26 +01001627 public void onFling(int duration) {
1628 if (mPowerManagerInternal != null) {
1629 mPowerManagerInternal.powerHint(
1630 PowerManagerInternal.POWER_HINT_INTERACTION, duration);
1631 }
1632 }
1633 @Override
John Spurlockad3e6cb2013-04-30 08:47:43 -04001634 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001635 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001636 }
Adrian Roos3595be42015-03-05 16:31:15 +01001637 @Override
1638 public void onDown() {
1639 mOrientationListener.onTouchStart();
1640 }
1641 @Override
1642 public void onUpOrCancel() {
1643 mOrientationListener.onTouchEnd();
1644 }
Jun Mukaid2e7e352015-07-22 17:14:02 -07001645 @Override
1646 public void onMouseHoverAtTop() {
1647 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1648 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1649 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS;
1650 mHandler.sendMessageDelayed(msg, 500);
1651 }
1652 @Override
1653 public void onMouseHoverAtBottom() {
1654 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1655 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1656 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION;
1657 mHandler.sendMessageDelayed(msg, 500);
1658 }
1659 @Override
1660 public void onMouseLeaveFromEdge() {
1661 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1662 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001663 });
John Spurlockf1a36642013-10-12 17:50:42 -04001664 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001665 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001666
Jeff Brownc2346132012-04-13 01:55:38 -07001667 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001668 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1669 com.android.internal.R.array.config_longPressVibePattern);
1670 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1671 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001672 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1673 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001674 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1675 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001676 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1677 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001678 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1679 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1680 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1681 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001682 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1683 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001684
Christopher Tatee90585f2012-03-05 18:56:25 -08001685 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1686 com.android.internal.R.bool.config_enableScreenshotChord);
Jorim Jaggi406585a2015-12-21 10:58:56 +01001687 mForceWindowDrawsStatusBarBackground = mContext.getResources().getBoolean(
1688 R.bool.config_forceWindowDrawsStatusBarBackground);
Christopher Tatee90585f2012-03-05 18:56:25 -08001689
Justin Kohd378ad72013-04-01 12:18:26 -07001690 mGlobalKeyManager = new GlobalKeyManager(mContext);
1691
Joe Onoratoea495d42011-04-06 11:41:11 -07001692 // Controls rotation and the like.
1693 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001694
1695 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001696 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001697 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1698 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001699 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001700
1701 mWindowManagerInternal.registerAppTransitionListener(
1702 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001703 }
1704
Jeff Brownf71343d2013-05-31 17:59:11 -07001705 /**
1706 * Read values from config.xml that may be overridden depending on
1707 * the configuration of the device.
1708 * eg. Disable long press on home goes to recents on sw600dp.
1709 */
1710 private void readConfigurationDependentBehaviors() {
Jaewan Kimc552b042016-01-18 16:08:45 +09001711 final Resources res = mContext.getResources();
1712
1713 mLongPressOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001714 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1715 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
Jaewan Kim52632e22016-01-14 18:01:52 +09001716 mLongPressOnHomeBehavior > LAST_LONG_PRESS_HOME_BEHAVIOR) {
Jeff Brownf71343d2013-05-31 17:59:11 -07001717 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1718 }
1719
Jaewan Kimc552b042016-01-18 16:08:45 +09001720 mDoubleTapOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001721 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1722 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1723 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1724 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1725 }
Jaewan Kim49117872016-01-19 17:24:08 +09001726
1727 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_NOTHING;
1728 if (mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)) {
1729 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE;
1730 }
Yorke Lee2e4b7322016-03-02 17:33:06 -08001731
1732 mForceNavBarOpaque = res.getBoolean(
1733 com.android.internal.R.bool.config_forceNavBarAlwaysOpaque);
Jeff Brownf71343d2013-05-31 17:59:11 -07001734 }
1735
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001736 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001737 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001738 // This method might be called before the policy has been fully initialized
1739 // or for other displays we don't care about.
1740 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1741 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001742 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001743 mDisplay = display;
1744
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001745 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001746 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001747 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001748 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001749 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001750 mLandscapeRotation = Surface.ROTATION_0;
1751 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001752 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001753 mPortraitRotation = Surface.ROTATION_90;
1754 mUpsideDownRotation = Surface.ROTATION_270;
1755 } else {
1756 mPortraitRotation = Surface.ROTATION_270;
1757 mUpsideDownRotation = Surface.ROTATION_90;
1758 }
1759 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001760 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001761 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001762 mPortraitRotation = Surface.ROTATION_0;
1763 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001764 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001765 mLandscapeRotation = Surface.ROTATION_270;
1766 mSeascapeRotation = Surface.ROTATION_90;
1767 } else {
1768 mLandscapeRotation = Surface.ROTATION_90;
1769 mSeascapeRotation = Surface.ROTATION_270;
1770 }
1771 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001772
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001773 mStatusBarHeight =
1774 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001775
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001776 // Height of the navigation bar when presented horizontally at bottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001777 mNavigationBarHeightForRotationDefault[mPortraitRotation] =
1778 mNavigationBarHeightForRotationDefault[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001779 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001780 mNavigationBarHeightForRotationDefault[mLandscapeRotation] =
1781 mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize(
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001782 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001783
1784 // Width of the navigation bar when presented vertically along one side
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001785 mNavigationBarWidthForRotationDefault[mPortraitRotation] =
1786 mNavigationBarWidthForRotationDefault[mUpsideDownRotation] =
1787 mNavigationBarWidthForRotationDefault[mLandscapeRotation] =
1788 mNavigationBarWidthForRotationDefault[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001789 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001790
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001791 // Height of the navigation bar when presented horizontally at bottom
1792 mNavigationBarHeightForRotationInCarMode[mPortraitRotation] =
1793 mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] =
1794 res.getDimensionPixelSize(
1795 com.android.internal.R.dimen.navigation_bar_height_car_mode);
1796 mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] =
1797 mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize(
1798 com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode);
1799
1800 // Width of the navigation bar when presented vertically along one side
1801 mNavigationBarWidthForRotationInCarMode[mPortraitRotation] =
1802 mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] =
1803 mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] =
1804 mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] =
1805 res.getDimensionPixelSize(
1806 com.android.internal.R.dimen.navigation_bar_width_car_mode);
1807
Daniel Sandler4a066c52012-04-20 14:49:13 -04001808 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001809 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001810 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001811
Devin Kimd7b12b42014-05-05 14:34:58 -07001812 // Allow the navigation bar to move on non-square small devices (phones).
1813 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001814
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001815 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001816 // Allow a system property to override this. Used by the emulator.
1817 // See also hasNavigationBar().
1818 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1819 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001820 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001821 } else if ("0".equals(navBarOverride)) {
1822 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001823 }
1824
Jeff Brown27f1d672012-10-17 18:32:34 -07001825 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1826 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001827 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001828 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001829 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001830 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001831 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001832 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001833
Chong Zhangae6119ff2014-11-11 18:54:39 -08001834 // For demo purposes, allow the rotation of the remote display to be controlled.
1835 // By default, remote display locks rotation to landscape.
1836 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1837 mDemoRotation = mPortraitRotation;
1838 } else {
1839 mDemoRotation = mLandscapeRotation;
1840 }
1841 mDemoRotationLock = SystemProperties.getBoolean(
1842 "persist.demo.rotationlock", false);
1843
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001844 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1845 // http://developer.android.com/guide/practices/screens_support.html#range
1846 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1847 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1848 // For debug purposes the next line turns this feature off with:
1849 // $ adb shell setprop config.override_forced_orient true
1850 // $ adb shell wm size reset
1851 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1852 }
1853
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001854 /**
1855 * @return whether the navigation bar can be hidden, e.g. the device has a
1856 * navigation bar and touch exploration is not enabled
1857 */
1858 private boolean canHideNavigationBar() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04001859 return mHasNavigationBar;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001860 }
1861
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001862 @Override
1863 public boolean isDefaultOrientationForced() {
1864 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001865 }
1866
Dianne Hackbornc652de82013-02-15 16:32:56 -08001867 @Override
1868 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1869 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1870 mOverscanLeft = left;
1871 mOverscanTop = top;
1872 mOverscanRight = right;
1873 mOverscanBottom = bottom;
1874 }
1875 }
1876
Dianne Hackbornc777e072010-02-12 13:07:59 -08001877 public void updateSettings() {
1878 ContentResolver resolver = mContext.getContentResolver();
1879 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001880 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001881 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001882 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001883 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1884 UserHandle.USER_CURRENT);
1885 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001886 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001887 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1888 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001889
Jeff Browna20dda42014-05-27 20:57:24 -07001890 // Configure wake gesture.
1891 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1892 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1893 UserHandle.USER_CURRENT) != 0;
1894 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1895 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1896 updateWakeGestureListenerLp();
1897 }
1898
Jeff Brown207673cd2012-06-05 17:47:11 -07001899 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001900 int userRotation = Settings.System.getIntForUser(resolver,
1901 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1902 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001903 if (mUserRotation != userRotation) {
1904 mUserRotation = userRotation;
1905 updateRotation = true;
1906 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001907 int userRotationMode = Settings.System.getIntForUser(resolver,
1908 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001909 WindowManagerPolicy.USER_ROTATION_FREE :
1910 WindowManagerPolicy.USER_ROTATION_LOCKED;
1911 if (mUserRotationMode != userRotationMode) {
1912 mUserRotationMode = userRotationMode;
1913 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001914 updateOrientationListenerLp();
1915 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001916
Dianne Hackbornc777e072010-02-12 13:07:59 -08001917 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001918 int pointerLocation = Settings.System.getIntForUser(resolver,
1919 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001920 if (mPointerLocationMode != pointerLocation) {
1921 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001922 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1923 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001924 }
1925 }
1926 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001927 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1928 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1929 String imId = Settings.Secure.getStringForUser(resolver,
1930 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001931 boolean hasSoftInput = imId != null && imId.length() > 0;
1932 if (mHasSoftInput != hasSoftInput) {
1933 mHasSoftInput = hasSoftInput;
1934 updateRotation = true;
1935 }
John Spurlockf1a36642013-10-12 17:50:42 -04001936 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001937 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001938 }
tiger_huangcc6366d2015-06-29 17:17:30 +08001939 }
1940 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05001941 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001942 }
1943 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001944 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001945 }
Jeff Brown70825162012-03-28 17:27:48 -07001946 }
1947
Jeff Browna20dda42014-05-27 20:57:24 -07001948 private void updateWakeGestureListenerLp() {
1949 if (shouldEnableWakeGestureLp()) {
1950 mWakeGestureListener.requestWakeUpTrigger();
1951 } else {
1952 mWakeGestureListener.cancelWakeUpTrigger();
1953 }
1954 }
1955
1956 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001957 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001958 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1959 && mWakeGestureListener.isSupported();
1960 }
1961
Jeff Brown70825162012-03-28 17:27:48 -07001962 private void enablePointerLocation() {
1963 if (mPointerLocationView == null) {
1964 mPointerLocationView = new PointerLocationView(mContext);
1965 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001966 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1967 WindowManager.LayoutParams.MATCH_PARENT,
1968 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001969 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001970 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1971 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1972 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1973 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001974 if (ActivityManager.isHighEndGfx()) {
1975 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1976 lp.privateFlags |=
1977 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1978 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001979 lp.format = PixelFormat.TRANSLUCENT;
1980 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001981 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001982 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001983 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001984 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001985 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001986 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001987 }
Jeff Brown70825162012-03-28 17:27:48 -07001988
1989 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001990 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001991 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1992 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001993 wm.removeView(mPointerLocationView);
1994 mPointerLocationView = null;
1995 }
1996 }
1997
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001998 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001999 try {
2000 int rotation = mContext.getResources().getInteger(resID);
2001 switch (rotation) {
2002 case 0:
2003 return Surface.ROTATION_0;
2004 case 90:
2005 return Surface.ROTATION_90;
2006 case 180:
2007 return Surface.ROTATION_180;
2008 case 270:
2009 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002010 }
2011 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002012 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002013 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002014 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002015 }
2016
2017 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07002018 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08002019 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002020 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08002021
2022 outAppOp[0] = AppOpsManager.OP_NONE;
2023
Wale Ogunwale74bf0652015-01-12 10:24:36 -08002024 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
2025 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
2026 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
2027 return WindowManagerGlobal.ADD_INVALID_TYPE;
2028 }
2029
2030 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
2031 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07002032 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002033 }
2034 String permission = null;
2035 switch (type) {
2036 case TYPE_TOAST:
2037 // XXX right now the app process has complete control over
2038 // this... should introduce a token to let the system
2039 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04002040 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002041 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05002042 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002043 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07002044 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07002045 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002046 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07002047 case TYPE_ACCESSIBILITY_OVERLAY:
Jason Monk8f7f3182015-11-18 16:35:14 -05002048 case TYPE_QS_DIALOG:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07002049 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002050 break;
2051 case TYPE_PHONE:
2052 case TYPE_PRIORITY_PHONE:
2053 case TYPE_SYSTEM_ALERT:
2054 case TYPE_SYSTEM_ERROR:
2055 case TYPE_SYSTEM_OVERLAY:
2056 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08002057 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002058 break;
2059 default:
2060 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
2061 }
2062 if (permission != null) {
Svet Ganov9cea80cd2016-02-16 11:47:00 -08002063 if (android.Manifest.permission.SYSTEM_ALERT_WINDOW.equals(permission)) {
Billy Laucbe540f2015-06-25 01:51:44 +01002064 final int callingUid = Binder.getCallingUid();
Billy Lau060275f2015-07-15 22:29:19 +01002065 // system processes will be automatically allowed privilege to draw
Billy Laucbe540f2015-06-25 01:51:44 +01002066 if (callingUid == Process.SYSTEM_UID) {
2067 return WindowManagerGlobal.ADD_OKAY;
2068 }
2069
Billy Lau060275f2015-07-15 22:29:19 +01002070 // check if user has enabled this operation. SecurityException will be thrown if
2071 // this app has not been allowed by the user
Svet Ganov03f2afc2016-03-04 16:13:03 -08002072 final int mode = mAppOpsManager.checkOpNoThrow(outAppOp[0], callingUid,
Billy Laucbe540f2015-06-25 01:51:44 +01002073 attrs.packageName);
Billy Lau060275f2015-07-15 22:29:19 +01002074 switch (mode) {
2075 case AppOpsManager.MODE_ALLOWED:
2076 case AppOpsManager.MODE_IGNORED:
2077 // although we return ADD_OKAY for MODE_IGNORED, the added window will
2078 // actually be hidden in WindowManagerService
2079 return WindowManagerGlobal.ADD_OKAY;
2080 case AppOpsManager.MODE_ERRORED:
Svet Ganov03f2afc2016-03-04 16:13:03 -08002081 try {
2082 ApplicationInfo appInfo = mContext.getPackageManager()
2083 .getApplicationInfo(attrs.packageName,
2084 UserHandle.getUserId(callingUid));
2085 // Don't crash legacy apps
2086 if (appInfo.targetSdkVersion < Build.VERSION_CODES.M) {
2087 return WindowManagerGlobal.ADD_OKAY;
2088 }
2089 } catch (PackageManager.NameNotFoundException e) {
2090 /* ignore */
2091 }
Billy Laucbe540f2015-06-25 01:51:44 +01002092 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
Billy Lau060275f2015-07-15 22:29:19 +01002093 default:
2094 // in the default mode, we will make a decision here based on
2095 // checkCallingPermission()
2096 if (mContext.checkCallingPermission(permission) !=
2097 PackageManager.PERMISSION_GRANTED) {
2098 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
2099 } else {
2100 return WindowManagerGlobal.ADD_OKAY;
2101 }
Billy Laucbe540f2015-06-25 01:51:44 +01002102 }
Billy Laucbe540f2015-06-25 01:51:44 +01002103 }
2104
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002105 if (mContext.checkCallingOrSelfPermission(permission)
2106 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07002107 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002108 }
2109 }
Jeff Brown98365d72012-08-19 20:30:52 -07002110 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002111 }
Craig Mautner88400d32012-09-30 12:35:45 -07002112
2113 @Override
2114 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
2115
2116 // If this switch statement is modified, modify the comment in the declarations of
2117 // the type in {@link WindowManager.LayoutParams} as well.
2118 switch (attrs.type) {
2119 default:
2120 // These are the windows that by default are shown only to the user that created
2121 // them. If this needs to be overridden, set
2122 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
2123 // {@link WindowManager.LayoutParams}. Note that permission
2124 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
2125 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
2126 return true;
2127 }
2128 break;
2129
2130 // These are the windows that by default are shown to all users. However, to
2131 // protect against spoofing, check permissions below.
2132 case TYPE_APPLICATION_STARTING:
2133 case TYPE_BOOT_PROGRESS:
2134 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07002135 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08002136 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07002137 case TYPE_KEYGUARD_DIALOG:
2138 case TYPE_MAGNIFICATION_OVERLAY:
2139 case TYPE_NAVIGATION_BAR:
2140 case TYPE_NAVIGATION_BAR_PANEL:
2141 case TYPE_PHONE:
2142 case TYPE_POINTER:
2143 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07002144 case TYPE_SEARCH_BAR:
2145 case TYPE_STATUS_BAR:
2146 case TYPE_STATUS_BAR_PANEL:
2147 case TYPE_STATUS_BAR_SUB_PANEL:
2148 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07002149 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07002150 case TYPE_PRIVATE_PRESENTATION:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002151 case TYPE_DOCK_DIVIDER:
Craig Mautner88400d32012-09-30 12:35:45 -07002152 break;
2153 }
2154
2155 // Check if third party app has set window to system window type.
2156 return mContext.checkCallingOrSelfPermission(
2157 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
2158 != PackageManager.PERMISSION_GRANTED;
2159 }
2160
Craig Mautner967212c2013-04-13 21:10:58 -07002161 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002162 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
2163 switch (attrs.type) {
2164 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07002165 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002166 // These types of windows can't receive input events.
2167 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2168 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002169 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002170 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002171 case TYPE_STATUS_BAR:
2172
2173 // If the Keyguard is in a hidden state (occluded by another window), we force to
2174 // remove the wallpaper and keyguard flag so that any change in-flight after setting
2175 // the keyguard as occluded wouldn't set these flags again.
2176 // See {@link #processKeyguardSetHiddenResultLw}.
2177 if (mKeyguardHidden) {
2178 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2179 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2180 }
2181 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002182 }
Adrian Roos38502112014-04-09 21:04:11 +02002183
2184 if (attrs.type != TYPE_STATUS_BAR) {
2185 // The status bar is the only window allowed to exhibit keyguard behavior.
2186 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2187 }
Adrian Roosea562512014-05-05 13:33:03 +02002188
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002189 if (ActivityManager.isHighEndGfx()) {
2190 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
2191 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
2192 }
2193 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0
Jorim Jaggi406585a2015-12-21 10:58:56 +01002194 || (mForceWindowDrawsStatusBarBackground
2195 && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT)) {
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002196 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
2197 }
Adrian Roosea562512014-05-05 13:33:03 +02002198 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002199 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002200
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002201 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07002202 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002203 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002204
Michael Wright3818c922014-09-02 13:59:07 -07002205 private void readCameraLensCoverState() {
2206 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
2207 }
2208
Jeff Browndaa37532012-05-01 15:54:03 -07002209 private boolean isHidden(int accessibilityMode) {
2210 switch (accessibilityMode) {
2211 case 1:
2212 return mLidState == LID_CLOSED;
2213 case 2:
2214 return mLidState == LID_OPEN;
2215 default:
2216 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002217 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002218 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002219
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002220 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002221 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07002222 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
2223 int navigationPresence) {
2224 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
2225
Jeff Brownf71343d2013-05-31 17:59:11 -07002226 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002227 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07002228 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08002229
Jeff Browndaa37532012-05-01 15:54:03 -07002230 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
2231 || (keyboardPresence == PRESENCE_INTERNAL
2232 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002233 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07002234 if (!mHasSoftInput) {
2235 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
2236 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002237 }
2238
Jeff Browndaa37532012-05-01 15:54:03 -07002239 if (config.navigation == Configuration.NAVIGATION_NONAV
2240 || (navigationPresence == PRESENCE_INTERNAL
2241 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002242 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08002243 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002244 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002245
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002246 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002247 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002248 public int windowTypeToLayerLw(int type) {
2249 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002250 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002251 }
2252 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07002253 case TYPE_PRIVATE_PRESENTATION:
2254 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002255 case TYPE_WALLPAPER:
2256 // wallpaper is at the bottom, though the window manager may move it.
2257 return 2;
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002258 case TYPE_DOCK_DIVIDER:
2259 return 2;
Jason Monk8f7f3182015-11-18 16:35:14 -05002260 case TYPE_QS_DIALOG:
2261 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002262 case TYPE_PHONE:
2263 return 3;
2264 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002265 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002266 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002267 case TYPE_VOICE_INTERACTION:
2268 // voice interaction layer is almost immediately above apps.
2269 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07002270 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002271 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07002272 case TYPE_SYSTEM_DIALOG:
2273 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002274 case TYPE_TOAST:
2275 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07002276 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002277 case TYPE_PRIORITY_PHONE:
2278 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07002279 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002280 case TYPE_DREAM:
2281 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07002282 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002283 case TYPE_SYSTEM_ALERT:
2284 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002285 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002286 case TYPE_INPUT_METHOD:
2287 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002288 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002289 case TYPE_INPUT_METHOD_DIALOG:
2290 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002291 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08002292 case TYPE_KEYGUARD_SCRIM:
2293 // the safety window that shows behind keyguard while keyguard is starting
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002294 return 14;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002295 case TYPE_STATUS_BAR_SUB_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002296 return 15;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002297 case TYPE_STATUS_BAR:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002298 return 16;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002299 case TYPE_STATUS_BAR_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002300 return 17;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002301 case TYPE_KEYGUARD_DIALOG:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002302 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002303 case TYPE_VOLUME_OVERLAY:
2304 // the on-screen volume indicator and controller shown when the user
2305 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002306 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002307 case TYPE_SYSTEM_OVERLAY:
2308 // the on-screen volume indicator and controller shown when the user
2309 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002310 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002311 case TYPE_NAVIGATION_BAR:
2312 // the navigation bar, if available, shows atop most things
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002313 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002314 case TYPE_NAVIGATION_BAR_PANEL:
2315 // some panels (e.g. search) need to show on top of the navigation bar
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002316 return 22;
Muyuan Li6ca619f2016-03-08 13:30:42 -08002317 case TYPE_SCREENSHOT:
2318 // screenshot selection layer shouldn't go above system error, but it should cover
2319 // navigation bars at the very least.
2320 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002321 case TYPE_SYSTEM_ERROR:
2322 // system-level error dialogs
Muyuan Li6ca619f2016-03-08 13:30:42 -08002323 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002324 case TYPE_MAGNIFICATION_OVERLAY:
2325 // used to highlight the magnified portion of a display
Muyuan Li6ca619f2016-03-08 13:30:42 -08002326 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002327 case TYPE_DISPLAY_OVERLAY:
2328 // used to simulate secondary display devices
Muyuan Li6ca619f2016-03-08 13:30:42 -08002329 return 26;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002330 case TYPE_DRAG:
2331 // the drag layer: input for drag-and-drop is associated with this window,
2332 // which sits above all other focusable windows
Muyuan Li6ca619f2016-03-08 13:30:42 -08002333 return 27;
Svetoslav3a5c7212014-10-14 09:54:26 -07002334 case TYPE_ACCESSIBILITY_OVERLAY:
2335 // overlay put by accessibility services to intercept user interaction
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002336 return 28;
Muyuan Li6ca619f2016-03-08 13:30:42 -08002337 case TYPE_SECURE_SYSTEM_OVERLAY:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002338 return 29;
Muyuan Li6ca619f2016-03-08 13:30:42 -08002339 case TYPE_BOOT_PROGRESS:
2340 return 30;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002341 case TYPE_POINTER:
2342 // the (mouse) pointer layer
Muyuan Li6ca619f2016-03-08 13:30:42 -08002343 return 31;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002344 }
2345 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002346 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002347 }
2348
2349 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002350 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002351 public int subWindowTypeToLayerLw(int type) {
2352 switch (type) {
2353 case TYPE_APPLICATION_PANEL:
2354 case TYPE_APPLICATION_ATTACHED_DIALOG:
2355 return APPLICATION_PANEL_SUBLAYER;
2356 case TYPE_APPLICATION_MEDIA:
2357 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002358 case TYPE_APPLICATION_MEDIA_OVERLAY:
2359 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002360 case TYPE_APPLICATION_SUB_PANEL:
2361 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002362 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2363 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002364 }
2365 Log.e(TAG, "Unknown sub-window type: " + type);
2366 return 0;
2367 }
2368
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002369 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002370 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002371 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002372 }
2373
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002374 private int getNavigationBarWidth(int rotation, int uiMode) {
2375 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2376 return mNavigationBarWidthForRotationInCarMode[rotation];
2377 } else {
2378 return mNavigationBarWidthForRotationDefault[rotation];
2379 }
2380 }
2381
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002382 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002383 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation,
2384 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002385 if (mHasNavigationBar) {
2386 // For a basic navigation bar, when we are in landscape mode we place
2387 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002388 if (mNavigationBarCanMove && fullWidth > fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002389 return fullWidth - getNavigationBarWidth(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002390 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002391 }
2392 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002393 }
2394
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002395 private int getNavigationBarHeight(int rotation, int uiMode) {
2396 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2397 return mNavigationBarHeightForRotationInCarMode[rotation];
2398 } else {
2399 return mNavigationBarHeightForRotationDefault[rotation];
2400 }
2401 }
2402
Jose Lima9546b202014-07-02 17:21:51 -07002403 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002404 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation,
2405 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002406 if (mHasNavigationBar) {
2407 // For a basic navigation bar, when we are in portrait mode we place
2408 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002409 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002410 return fullHeight - getNavigationBarHeight(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002411 }
2412 }
2413 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002414 }
2415
Jose Lima9546b202014-07-02 17:21:51 -07002416 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002417 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode) {
2418 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002419 }
2420
Jose Lima9546b202014-07-02 17:21:51 -07002421 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002422 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode) {
John Spurlock80f00c12013-06-13 11:10:51 -04002423 // There is a separate status bar at the top of the display. We don't count that as part
2424 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002425 // we do want to exclude it since applications can't generally use that part
2426 // of the screen.
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002427 return getNonDecorDisplayHeight(
2428 fullWidth, fullHeight, rotation, uiMode) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002429 }
2430
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002431 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002432 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2433 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002434 (isKeyguardHostWindow(attrs) &&
2435 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002436 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002437 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002438
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002439 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002440 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2441 return attrs.type == TYPE_STATUS_BAR;
2442 }
2443
2444 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002445 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002446 switch (attrs.type) {
2447 case TYPE_STATUS_BAR:
2448 case TYPE_NAVIGATION_BAR:
2449 case TYPE_WALLPAPER:
2450 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002451 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002452 return false;
2453 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002454 // Hide only windows below the keyguard host window.
2455 return windowTypeToLayerLw(win.getBaseType())
2456 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002457 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002458 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002459
Craig Mautner7d7808f2014-09-11 18:02:38 -07002460 @Override
2461 public WindowState getWinShowWhenLockedLw() {
2462 return mWinShowWhenLocked;
2463 }
2464
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002465 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002466 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002467 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2468 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002469 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002470 if (!SHOW_STARTING_ANIMATIONS) {
2471 return null;
2472 }
2473 if (packageName == null) {
2474 return null;
2475 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002476
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002477 WindowManager wm = null;
2478 View view = null;
2479
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002480 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002481 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002482 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2483 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2484 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002485 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002486 try {
2487 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002488 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002489 } catch (PackageManager.NameNotFoundException e) {
2490 // Ignore
2491 }
2492 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002493
Jorim Jaggia16cc152015-06-01 16:55:05 -07002494 PhoneWindow win = new PhoneWindow(context);
2495 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002496
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002497 Resources r = context.getResources();
2498 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002499
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002500 win.setType(
2501 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002502
2503 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2504 // Assumes it's safe to show starting windows of launched apps while
2505 // the keyguard is being hidden. This is okay because starting windows never show
2506 // secret information.
2507 if (mKeyguardHidden) {
2508 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2509 }
2510 }
2511
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002512 // Force the window flags: this is a fake window, so it is not really
2513 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2514 // flag because we do know that the next window will take input
2515 // focus, so we want to get the IME window up on top of us right away.
2516 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002517 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002518 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2519 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2520 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002521 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002522 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2523 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2524 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002525
Adam Powell04fe6eb2013-05-31 14:39:48 -07002526 win.setDefaultIcon(icon);
2527 win.setDefaultLogo(logo);
2528
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002529 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002530 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002531
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002532 final WindowManager.LayoutParams params = win.getAttributes();
2533 params.token = appToken;
2534 params.packageName = packageName;
2535 params.windowAnimations = win.getWindowStyle().getResourceId(
2536 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002537 params.privateFlags |=
2538 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002539 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002540
2541 if (!compatInfo.supportsScreen()) {
2542 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2543 }
2544
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002545 params.setTitle("Starting " + packageName);
2546
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002547 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2548 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002549
Craig Mautner6fbda632012-07-03 09:26:39 -07002550 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002551 TAG, "Adding starting window for " + packageName
2552 + " / " + appToken + ": "
2553 + (view.getParent() != null ? view : null));
2554
2555 wm.addView(view, params);
2556
2557 // Only return the view if it was successfully added to the
2558 // window manager... which we can tell by it having a parent.
2559 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002560 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002561 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002562 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2563 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002564 } catch (RuntimeException e) {
2565 // don't crash if something else bad happens, for example a
2566 // failure loading resources because we are loading from an app
2567 // on external storage that has been unmounted.
2568 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002569 } finally {
2570 if (view != null && view.getParent() == null) {
2571 Log.w(TAG, "view not successfully added to wm, removing view");
2572 wm.removeViewImmediate(view);
2573 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002574 }
2575
2576 return null;
2577 }
2578
2579 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002580 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002581 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002582 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2583 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002584
2585 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002586 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002587 wm.removeView(window);
2588 }
2589 }
2590
2591 /**
2592 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002593 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002594 * Currently enforces that three window types are singletons:
2595 * <ul>
2596 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002597 * <li>KEYGUARD_TYPE</li>
2598 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002599 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002600 * @param win The window to be added
2601 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002602 *
Jeff Brown98365d72012-08-19 20:30:52 -07002603 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2604 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002605 */
Jose Lima9546b202014-07-02 17:21:51 -07002606 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002607 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2608 switch (attrs.type) {
2609 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002610 mContext.enforceCallingOrSelfPermission(
2611 android.Manifest.permission.STATUS_BAR_SERVICE,
2612 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002613 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002614 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002615 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002616 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002617 }
2618 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002619 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002620 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002621 case TYPE_NAVIGATION_BAR:
2622 mContext.enforceCallingOrSelfPermission(
2623 android.Manifest.permission.STATUS_BAR_SERVICE,
2624 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002625 if (mNavigationBar != null) {
2626 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002627 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002628 }
2629 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002630 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002631 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002632 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002633 break;
Jim Millere898ac52012-04-06 17:10:57 -07002634 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002635 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002636 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002637 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002638 mContext.enforceCallingOrSelfPermission(
2639 android.Manifest.permission.STATUS_BAR_SERVICE,
2640 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002641 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002642 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002643 if (mKeyguardScrim != null) {
2644 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2645 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002646 mKeyguardScrim = win;
2647 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002648 }
Jeff Brown98365d72012-08-19 20:30:52 -07002649 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002650 }
2651
2652 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002653 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002654 public void removeWindowLw(WindowState win) {
2655 if (mStatusBar == win) {
2656 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002657 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002658 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002659 } else if (mKeyguardScrim == win) {
2660 Log.v(TAG, "Removing keyguard scrim");
2661 mKeyguardScrim = null;
2662 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002663 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002664 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002665 }
2666 }
2667
2668 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002669
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002670 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002671 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002672 public int selectAnimationLw(WindowState win, int transit) {
2673 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2674 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002675 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002676 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002677 if (transit == TRANSIT_EXIT
2678 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002679 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002680 } else if (transit == TRANSIT_ENTER
2681 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002682 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002683 }
2684 } else if (win == mNavigationBar) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002685 if (win.getAttrs().windowAnimations != 0) {
2686 return 0;
2687 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002688 // This can be on either the bottom or the right.
2689 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002690 if (transit == TRANSIT_EXIT
2691 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002692 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002693 } else if (transit == TRANSIT_ENTER
2694 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002695 return R.anim.dock_bottom_enter;
2696 }
2697 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002698 if (transit == TRANSIT_EXIT
2699 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002700 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002701 } else if (transit == TRANSIT_ENTER
2702 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002703 return R.anim.dock_right_enter;
2704 }
2705 }
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08002706 } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08002707 return selectDockedDividerAnimationLw(win, transit);
Craig Mautner4b71aa12012-12-27 17:20:01 -08002708 }
2709
2710 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002711 if (win.hasAppShownWindows()) {
2712 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2713 return com.android.internal.R.anim.app_starting_exit;
2714 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002715 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002716 && transit == TRANSIT_ENTER) {
2717 // Special case: we are animating in a dream, while the keyguard
2718 // is shown. We don't want an animation on the dream, because
2719 // we need it shown immediately with the keyguard animating away
2720 // to reveal it.
2721 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002722 }
2723
2724 return 0;
2725 }
2726
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08002727 private int selectDockedDividerAnimationLw(WindowState win, int transit) {
2728 int insets = mWindowManagerFuncs.getDockedDividerInsetsLw();
2729
2730 // If the divider is behind the navigation bar, don't animate.
2731 if (mNavigationBar != null
2732 && (win.getFrameLw().top + insets >= mNavigationBar.getFrameLw().top
2733 || win.getFrameLw().left + insets >= mNavigationBar.getFrameLw().left)) {
2734 return 0;
2735 }
2736 if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
2737 return R.anim.fade_in;
2738 } else if (transit == TRANSIT_EXIT) {
2739 return R.anim.fade_out;
2740 } else {
2741 return 0;
2742 }
2743 }
2744
Craig Mautner3c174372013-02-21 17:54:37 -08002745 @Override
2746 public void selectRotationAnimationLw(int anim[]) {
2747 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2748 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2749 + (mTopFullscreenOpaqueWindowState == null ?
2750 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2751 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2752 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2753 case ROTATION_ANIMATION_CROSSFADE:
2754 anim[0] = R.anim.rotation_animation_xfade_exit;
2755 anim[1] = R.anim.rotation_animation_enter;
2756 break;
2757 case ROTATION_ANIMATION_JUMPCUT:
2758 anim[0] = R.anim.rotation_animation_jump_exit;
2759 anim[1] = R.anim.rotation_animation_enter;
2760 break;
2761 case ROTATION_ANIMATION_ROTATE:
2762 default:
2763 anim[0] = anim[1] = 0;
2764 break;
2765 }
2766 } else {
2767 anim[0] = anim[1] = 0;
2768 }
2769 }
2770
2771 @Override
2772 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2773 boolean forceDefault) {
2774 switch (exitAnimId) {
2775 case R.anim.rotation_animation_xfade_exit:
2776 case R.anim.rotation_animation_jump_exit:
2777 // These are the only cases that matter.
2778 if (forceDefault) {
2779 return false;
2780 }
2781 int anim[] = new int[2];
2782 selectRotationAnimationLw(anim);
2783 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2784 default:
2785 return true;
2786 }
2787 }
2788
2789 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002790 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2791 boolean goingToNotificationShade) {
2792 if (goingToNotificationShade) {
2793 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002794 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002795
2796 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2797 R.anim.lock_screen_behind_enter_wallpaper :
2798 R.anim.lock_screen_behind_enter);
2799
2800 // TODO: Use XML interpolators when we have log interpolators available in XML.
2801 final List<Animation> animations = set.getAnimations();
2802 for (int i = animations.size() - 1; i >= 0; --i) {
2803 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2804 }
2805
2806 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002807 }
2808
2809
2810 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002811 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2812 if (goingToNotificationShade) {
2813 return null;
2814 } else {
2815 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2816 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002817 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002818
2819 private static void awakenDreams() {
2820 IDreamManager dreamManager = getDreamManager();
2821 if (dreamManager != null) {
2822 try {
2823 dreamManager.awaken();
2824 } catch (RemoteException e) {
2825 // fine, stay asleep then
2826 }
2827 }
2828 }
2829
2830 static IDreamManager getDreamManager() {
2831 return IDreamManager.Stub.asInterface(
2832 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2833 }
2834
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002835 TelecomManager getTelecommService() {
2836 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002837 }
2838
Jeff Brown4d396052010-10-29 21:50:21 -07002839 static IAudioService getAudioService() {
2840 IAudioService audioService = IAudioService.Stub.asInterface(
2841 ServiceManager.checkService(Context.AUDIO_SERVICE));
2842 if (audioService == null) {
2843 Log.w(TAG, "Unable to find IAudioService interface.");
2844 }
2845 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002846 }
2847
2848 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002849 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002850 }
2851
2852 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2853 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2854 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2855 };
2856
2857 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002858 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002859 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002860 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002861 final int keyCode = event.getKeyCode();
2862 final int repeatCount = event.getRepeatCount();
2863 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002864 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002865 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2866 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002867
Jeff Brown40013652012-05-16 21:22:36 -07002868 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002869 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002870 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2871 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002872 }
2873
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002874 // If we think we might have a volume down & power key chord on the way
2875 // but we're not sure, then tell the dispatcher to wait a little while and
2876 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002877 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002878 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002879 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002880 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2881 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002882 if (now < timeoutTime) {
2883 return timeoutTime - now;
2884 }
2885 }
2886 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002887 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002888 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002889 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002890 }
2891 return -1;
2892 }
2893 }
2894
Michael Wright6a62e552014-06-03 19:19:48 -07002895 // Cancel any pending meta actions if we see any other keys being pressed between the down
2896 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002897 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002898 mPendingMetaAction = false;
2899 }
2900
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002901 // First we always handle the home key here, so applications
2902 // can never break it, although if keyguard is on, we do let
2903 // it handle it, because that gives us the correct 5 second
2904 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002905 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002906
Jeff Brown49ed71d2010-12-06 17:13:33 -08002907 // If we have released the home key, and didn't do anything else
2908 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002909 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002910 cancelPreloadRecentApps();
2911
Jeff Brown49ed71d2010-12-06 17:13:33 -08002912 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002913 if (mHomeConsumed) {
2914 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002915 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002916 }
Jeff Browncaca8812013-05-09 13:34:33 -07002917
2918 if (canceled) {
2919 Log.i(TAG, "Ignoring HOME; event canceled.");
2920 return -1;
2921 }
2922
Yorke Lee4f803242014-12-15 23:22:06 +00002923 // If an incoming call is ringing, HOME is totally disabled.
2924 // (The user is already on the InCallUI at this point,
2925 // and his ONLY options are to answer or reject the call.)
2926 TelecomManager telecomManager = getTelecommService();
2927 if (telecomManager != null && telecomManager.isRinging()) {
2928 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2929 return -1;
2930 }
2931
Jeff Browncaca8812013-05-09 13:34:33 -07002932 // Delay handling home if a double-tap is possible.
2933 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2934 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2935 mHomeDoubleTapPending = true;
2936 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2937 ViewConfiguration.getDoubleTapTimeout());
2938 return -1;
2939 }
2940
Jeff Brown13f00f02014-10-31 14:45:50 -07002941 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002942 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002943 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002944
2945 // If a system window has focus, then it doesn't make sense
2946 // right now to interact with applications.
2947 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2948 if (attrs != null) {
2949 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002950 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2951 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2952 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002953 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002954 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002955 }
2956 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2957 for (int i=0; i<typeCount; i++) {
2958 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2959 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002960 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002961 }
2962 }
2963 }
Jeff Browncaca8812013-05-09 13:34:33 -07002964
2965 // Remember that home is pressed and handle special actions.
2966 if (repeatCount == 0) {
2967 mHomePressed = true;
2968 if (mHomeDoubleTapPending) {
2969 mHomeDoubleTapPending = false;
2970 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2971 handleDoubleTapOnHome();
2972 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2973 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2974 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002975 }
Jeff Browncaca8812013-05-09 13:34:33 -07002976 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2977 if (!keyguardOn) {
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09002978 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002979 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002980 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002981 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002982 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002983 // Hijack modified menu keys for debugging features
2984 final int chordBug = KeyEvent.META_SHIFT_ON;
2985
2986 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002987 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002988 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002989 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2990 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002991 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002992 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002993 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002994 Intent service = new Intent();
2995 service.setClassName(mContext, "com.android.server.LoadAverageService");
2996 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002997 boolean shown = Settings.Global.getInt(
2998 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002999 if (!shown) {
3000 mContext.startService(service);
3001 } else {
3002 mContext.stopService(service);
3003 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07003004 Settings.Global.putInt(
3005 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003006 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003007 }
3008 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003009 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003010 if (down) {
3011 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003012 mSearchKeyShortcutPending = true;
3013 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003014 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003015 } else {
3016 mSearchKeyShortcutPending = false;
3017 if (mConsumeSearchKeyUp) {
3018 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003019 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003020 }
3021 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003022 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003023 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08003024 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07003025 if (down && repeatCount == 0) {
3026 preloadRecentApps();
3027 } else if (!down) {
3028 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08003029 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003030 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003031 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07003032 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
3033 if (down) {
3034 IStatusBarService service = getStatusBarService();
3035 if (service != null) {
3036 try {
3037 service.expandNotificationsPanel();
3038 } catch (RemoteException e) {
3039 // do nothing.
3040 }
3041 }
3042 }
Muyuan Li6ca619f2016-03-08 13:30:42 -08003043 } else if (keyCode == KeyEvent.KEYCODE_S && event.isMetaPressed()
3044 && event.isCtrlPressed()) {
3045 if (down && repeatCount == 0) {
3046 int type = event.isShiftPressed() ? TAKE_SCREENSHOT_SELECTED_REGION
3047 : TAKE_SCREENSHOT_FULLSCREEN;
3048 mScreenshotRunnable.setScreenshotType(type);
3049 mHandler.post(mScreenshotRunnable);
3050 return -1;
3051 }
Clara Bayarrif2debb12015-07-10 14:47:17 +01003052 } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) {
3053 if (down) {
3054 if (repeatCount == 0) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003055 toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01003056 }
3057 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003058 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
3059 if (down) {
3060 if (repeatCount == 0) {
3061 mAssistKeyLongPressed = false;
3062 } else if (repeatCount == 1) {
3063 mAssistKeyLongPressed = true;
3064 if (!keyguardOn) {
3065 launchAssistLongPressAction();
3066 }
3067 }
3068 } else {
3069 if (mAssistKeyLongPressed) {
3070 mAssistKeyLongPressed = false;
3071 } else {
3072 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003073 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003074 }
3075 }
3076 }
3077 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003078 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
3079 if (!down) {
3080 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07003081 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003082 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3083 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07003084 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
3085 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
3086 if (dic != null) {
3087 try {
3088 dic.exitIdle("voice-search");
3089 } catch (RemoteException e) {
3090 }
3091 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003092 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07003093 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003094 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003095 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003096 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003097 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
3098 if (down && repeatCount == 0) {
Muyuan Li6ca619f2016-03-08 13:30:42 -08003099 mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN);
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003100 mHandler.post(mScreenshotRunnable);
3101 }
3102 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08003103 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
3104 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
3105 if (down) {
3106 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
3107
3108 // Disable autobrightness if it's on
3109 int auto = Settings.System.getIntForUser(
3110 mContext.getContentResolver(),
3111 Settings.System.SCREEN_BRIGHTNESS_MODE,
3112 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3113 UserHandle.USER_CURRENT_OR_SELF);
3114 if (auto != 0) {
3115 Settings.System.putIntForUser(mContext.getContentResolver(),
3116 Settings.System.SCREEN_BRIGHTNESS_MODE,
3117 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3118 UserHandle.USER_CURRENT_OR_SELF);
3119 }
3120
3121 int min = mPowerManager.getMinimumScreenBrightnessSetting();
3122 int max = mPowerManager.getMaximumScreenBrightnessSetting();
3123 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
3124 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
3125 Settings.System.SCREEN_BRIGHTNESS,
3126 mPowerManager.getDefaultScreenBrightnessSetting(),
3127 UserHandle.USER_CURRENT_OR_SELF);
3128 brightness += step;
3129 // Make sure we don't go beyond the limits.
3130 brightness = Math.min(max, brightness);
3131 brightness = Math.max(min, brightness);
3132
3133 Settings.System.putIntForUser(mContext.getContentResolver(),
3134 Settings.System.SCREEN_BRIGHTNESS, brightness,
3135 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00003136 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07003137 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08003138 }
3139 return -1;
Jaewan Kim765487f2016-01-12 14:45:42 +09003140 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
3141 || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
3142 || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
3143 if (mUseTvRouting) {
3144 // On TVs volume keys never go to the foreground app.
3145 dispatchDirectAudioEvent(event);
3146 return -1;
3147 }
Muyuan Li94ce94e2016-02-24 16:20:54 -08003148 }
3149
3150 if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07003151 if (down) {
3152 mPendingMetaAction = true;
3153 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003154 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07003155 }
3156 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003157 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003158
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003159 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08003160 // Any printing key that is chorded with Search should be consumed
3161 // even if no shortcut was invoked. This prevents text from being
3162 // inadvertently inserted when using a keyboard that has built-in macro
3163 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003164 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08003165 final KeyCharacterMap kcm = event.getKeyCharacterMap();
3166 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003167 mConsumeSearchKeyUp = true;
3168 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08003169 if (down && repeatCount == 0 && !keyguardOn) {
3170 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
3171 if (shortcutIntent != null) {
3172 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003173 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003174 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003175 } catch (ActivityNotFoundException ex) {
3176 Slog.w(TAG, "Dropping shortcut key combination because "
3177 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003178 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003179 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003180 } else {
3181 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003182 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003183 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003184 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003185 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003186 }
3187 }
3188
Jeff Brown68b909d2011-12-07 16:36:01 -08003189 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07003190 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08003191 && (metaState & KeyEvent.META_META_ON) != 0) {
3192 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07003193 if (kcm.isPrintingKey(keyCode)) {
3194 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
3195 metaState & ~(KeyEvent.META_META_ON
3196 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
3197 if (shortcutIntent != null) {
3198 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3199 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003200 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07003201 } catch (ActivityNotFoundException ex) {
3202 Slog.w(TAG, "Dropping shortcut key combination because "
3203 + "the activity to which it is registered was not found: "
3204 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
3205 }
3206 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08003207 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003208 }
3209 }
3210
Jeff Brown6651a632011-11-28 12:59:11 -08003211 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07003212 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08003213 String category = sApplicationLaunchKeyCategories.get(keyCode);
3214 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08003215 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08003216 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3217 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003218 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08003219 } catch (ActivityNotFoundException ex) {
3220 Slog.w(TAG, "Dropping application launch key because "
3221 + "the activity to which it is registered was not found: "
3222 + "keyCode=" + keyCode + ", category=" + category, ex);
3223 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003224 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08003225 }
3226 }
3227
Michael Wright61c46752014-08-21 16:57:33 -07003228 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08003229 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Michael Wrightd847ad52015-10-24 13:24:15 +01003230 if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) {
Jeff Brown68b909d2011-12-07 16:36:01 -08003231 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07003232 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003233 mRecentAppsHeldModifiers = shiftlessModifiers;
3234 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08003235 return -1;
3236 }
3237 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07003238 } else if (!down && mRecentAppsHeldModifiers != 0
3239 && (metaState & mRecentAppsHeldModifiers) == 0) {
3240 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07003241 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003242 }
3243
Yohei Yukawaae61f712015-12-09 13:00:10 -08003244 // Handle input method switching.
Jeff Browncf39bdf2012-05-18 14:41:19 -07003245 if (down && repeatCount == 0
3246 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3247 || (keyCode == KeyEvent.KEYCODE_SPACE
Yohei Yukawaae61f712015-12-09 13:00:10 -08003248 && (metaState & KeyEvent.META_META_MASK) != 0))) {
3249 final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0;
3250 mWindowManagerFuncs.switchInputMethod(forwardDirection);
Jeff Browncf39bdf2012-05-18 14:41:19 -07003251 return -1;
3252 }
3253 if (mLanguageSwitchKeyPressed && !down
3254 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3255 || keyCode == KeyEvent.KEYCODE_SPACE)) {
3256 mLanguageSwitchKeyPressed = false;
3257 return -1;
3258 }
3259
Jeff Brown13f00f02014-10-31 14:45:50 -07003260 if (isValidGlobalKey(keyCode)
3261 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07003262 return -1;
3263 }
3264
Muyuan Li94ce94e2016-02-24 16:20:54 -08003265 if (down) {
3266 long shortcutCode = (long) keyCode;
3267 if (event.isCtrlPressed()) {
3268 shortcutCode |= ((long) KeyEvent.META_CTRL_ON) << Integer.SIZE;
3269 }
3270
3271 if (event.isAltPressed()) {
3272 shortcutCode |= ((long) KeyEvent.META_ALT_ON) << Integer.SIZE;
3273 }
3274
3275 if (event.isShiftPressed()) {
3276 shortcutCode |= ((long) KeyEvent.META_SHIFT_ON) << Integer.SIZE;
3277 }
3278
3279 if (event.isMetaPressed()) {
3280 shortcutCode |= ((long) KeyEvent.META_META_ON) << Integer.SIZE;
3281 }
3282
3283 IShortcutService shortcutService = mShortcutKeyServices.get(shortcutCode);
3284 if (shortcutService != null) {
3285 try {
3286 shortcutService.notifyShortcutKeyPressed(shortcutCode);
3287 } catch (RemoteException e) {
3288 mShortcutKeyServices.delete(shortcutCode);
3289 }
3290 return -1;
3291 }
3292 }
3293
Michael Wright6a62e552014-06-03 19:19:48 -07003294 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07003295 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07003296 return -1;
3297 }
3298
Jeff Brown68b909d2011-12-07 16:36:01 -08003299 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003300 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003301 }
3302
Jeff Brown3915bb82010-11-05 15:02:16 -07003303 /** {@inheritDoc} */
3304 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08003305 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07003306 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07003307 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08003308 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
3309 + ", flags=" + event.getFlags()
3310 + ", keyCode=" + event.getKeyCode()
3311 + ", scanCode=" + event.getScanCode()
3312 + ", metaState=" + event.getMetaState()
3313 + ", repeatCount=" + event.getRepeatCount()
3314 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07003315 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003316
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003317 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003318 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3319 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003320 final int keyCode = event.getKeyCode();
3321 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003322 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
3323 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003324
Jeff Brown54875002011-04-06 15:33:01 -07003325 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003326 final FallbackAction fallbackAction;
3327 if (initialDown) {
3328 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
3329 } else {
3330 fallbackAction = mFallbackActions.get(keyCode);
3331 }
3332
3333 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07003334 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003335 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
3336 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003337 }
3338
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003339 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
3340 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08003341 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003342 event.getAction(), fallbackAction.keyCode,
3343 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08003344 event.getDeviceId(), event.getScanCode(),
3345 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003346
3347 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
3348 fallbackEvent.recycle();
3349 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003350 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003351
3352 if (initialDown) {
3353 mFallbackActions.put(keyCode, fallbackAction);
3354 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3355 mFallbackActions.remove(keyCode);
3356 fallbackAction.recycle();
3357 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003358 }
3359 }
3360
Jeff Brown40013652012-05-16 21:22:36 -07003361 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003362 if (fallbackEvent == null) {
3363 Slog.d(TAG, "No fallback.");
3364 } else {
3365 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3366 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003367 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003368 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003369 }
3370
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003371 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003372 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003373 if ((actions & ACTION_PASS_TO_USER) != 0) {
3374 long delayMillis = interceptKeyBeforeDispatching(
3375 win, fallbackEvent, policyFlags);
3376 if (delayMillis == 0) {
3377 return true;
3378 }
3379 }
3380 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003381 }
3382
Muyuan Li94ce94e2016-02-24 16:20:54 -08003383 public void registerShortcutKey(long shortcutCode, IShortcutService shortcutService)
3384 throws RemoteException {
3385 synchronized (mLock) {
3386 IShortcutService service = mShortcutKeyServices.get(shortcutCode);
Muyuan Li24d24ac2016-03-03 21:15:02 -08003387 if (service != null && service.asBinder().pingBinder()) {
3388 throw new RemoteException("Key already exists.");
Muyuan Li94ce94e2016-02-24 16:20:54 -08003389 }
3390
3391 mShortcutKeyServices.put(shortcutCode, shortcutService);
3392 }
3393 }
3394
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003395 private void launchAssistLongPressAction() {
3396 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3397 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3398
3399 // launch the search activity
3400 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3401 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3402 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003403 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003404 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003405 SearchManager searchManager = getSearchManager();
3406 if (searchManager != null) {
3407 searchManager.stopSearch();
3408 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003409 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003410 } catch (ActivityNotFoundException e) {
3411 Slog.w(TAG, "No activity to handle assist long press action.", e);
3412 }
3413 }
3414
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003415 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003416 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Maurice Lam39d13812015-07-23 20:49:20 -07003417 if (!isUserSetupComplete()) {
3418 // Disable opening assist window during setup
3419 return;
3420 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003421 Bundle args = null;
3422 if (deviceId > Integer.MIN_VALUE) {
3423 args = new Bundle();
3424 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003425 }
Jorim Jaggi165ce062015-07-06 16:18:11 -07003426 if ((mContext.getResources().getConfiguration().uiMode
3427 & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
3428 // On TV, use legacy handling until assistants are implemented in the proper way.
3429 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3430 .launchLegacyAssist(hint, UserHandle.myUserId(), args);
3431 } else {
3432 try {
3433 if (hint != null) {
3434 if (args == null) {
3435 args = new Bundle();
3436 }
3437 args.putBoolean(hint, true);
3438 }
3439 IStatusBarService statusbar = getStatusBarService();
3440 if (statusbar != null) {
3441 statusbar.startAssist(args);
3442 }
3443 } catch (RemoteException e) {
3444 Slog.e(TAG, "RemoteException when starting assist", e);
3445 // re-acquire status bar service next time it is needed.
3446 mStatusBarService = null;
3447 }
3448 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003449 }
3450
Bart Sears8b1c27c2015-03-18 23:51:02 +00003451 private void startActivityAsUser(Intent intent, UserHandle handle) {
3452 if (isUserSetupComplete()) {
3453 mContext.startActivityAsUser(intent, handle);
3454 } else {
3455 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3456 }
3457 }
3458
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003459 private SearchManager getSearchManager() {
3460 if (mSearchManager == null) {
3461 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3462 }
3463 return mSearchManager;
3464 }
3465
Jeff Browncaca8812013-05-09 13:34:33 -07003466 private void preloadRecentApps() {
3467 mPreloadedRecentApps = true;
3468 try {
3469 IStatusBarService statusbar = getStatusBarService();
3470 if (statusbar != null) {
3471 statusbar.preloadRecentApps();
3472 }
3473 } catch (RemoteException e) {
3474 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3475 // re-acquire status bar service next time it is needed.
3476 mStatusBarService = null;
3477 }
3478 }
3479
3480 private void cancelPreloadRecentApps() {
3481 if (mPreloadedRecentApps) {
3482 mPreloadedRecentApps = false;
3483 try {
3484 IStatusBarService statusbar = getStatusBarService();
3485 if (statusbar != null) {
3486 statusbar.cancelPreloadRecentApps();
3487 }
3488 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003489 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003490 // re-acquire status bar service next time it is needed.
3491 mStatusBarService = null;
3492 }
3493 }
3494 }
3495
3496 private void toggleRecentApps() {
3497 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003498 try {
3499 IStatusBarService statusbar = getStatusBarService();
3500 if (statusbar != null) {
3501 statusbar.toggleRecentApps();
3502 }
3503 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003504 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3505 // re-acquire status bar service next time it is needed.
3506 mStatusBarService = null;
3507 }
3508 }
3509
Craig Mautner84984fa2014-06-19 11:19:20 -07003510 @Override
3511 public void showRecentApps() {
3512 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3513 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3514 }
3515
Winson Chung1e8d71b2014-05-16 17:05:22 -07003516 private void showRecentApps(boolean triggeredFromAltTab) {
3517 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3518 try {
3519 IStatusBarService statusbar = getStatusBarService();
3520 if (statusbar != null) {
3521 statusbar.showRecentApps(triggeredFromAltTab);
3522 }
3523 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003524 Slog.e(TAG, "RemoteException when showing recent apps", e);
3525 // re-acquire status bar service next time it is needed.
3526 mStatusBarService = null;
3527 }
3528 }
3529
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003530 private void toggleKeyboardShortcutsMenu() {
Clara Bayarrif2debb12015-07-10 14:47:17 +01003531 try {
3532 IStatusBarService statusbar = getStatusBarService();
3533 if (statusbar != null) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003534 statusbar.toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01003535 }
3536 } catch (RemoteException e) {
3537 Slog.e(TAG, "RemoteException when showing keyboard shortcuts menu", e);
3538 }
3539 }
3540
Winson Chungcdcd4872014-08-05 18:00:13 -07003541 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003542 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3543 try {
3544 IStatusBarService statusbar = getStatusBarService();
3545 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003546 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003547 }
3548 } catch (RemoteException e) {
3549 Slog.e(TAG, "RemoteException when closing recent apps", e);
3550 // re-acquire status bar service next time it is needed.
3551 mStatusBarService = null;
3552 }
3553 }
3554
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003555 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003556 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003557 }
3558
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003559 /**
3560 * A home key -> launch home action was detected. Take the appropriate action
3561 * given the situation with the keyguard.
3562 */
Bryce Lee662ed802015-04-10 20:11:39 +00003563 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3564 if (respectKeyguard) {
3565 if (isKeyguardShowingAndNotOccluded()) {
3566 // don't launch home if keyguard showing
3567 return;
3568 }
3569
3570 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3571 // when in keyguard restricted mode, must first verify unlock
3572 // before launching home
3573 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3574 @Override
3575 public void onKeyguardExitResult(boolean success) {
3576 if (success) {
3577 try {
3578 ActivityManagerNative.getDefault().stopAppSwitches();
3579 } catch (RemoteException e) {
3580 }
3581 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3582 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003583 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003584 }
Bryce Lee662ed802015-04-10 20:11:39 +00003585 });
3586 return;
3587 }
3588 }
3589
3590 // no keyguard stuff to worry about, just launch home!
3591 try {
3592 ActivityManagerNative.getDefault().stopAppSwitches();
3593 } catch (RemoteException e) {
3594 }
3595 if (mRecentsVisible) {
3596 // Hide Recents and notify it to launch Home
3597 if (awakenFromDreams) {
3598 awakenDreams();
3599 }
Bryce Lee662ed802015-04-10 20:11:39 +00003600 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003601 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003602 // Otherwise, just launch Home
3603 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3604 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003605 }
3606 }
3607
John Spurlock04db1762013-05-13 12:46:41 -04003608 private final Runnable mClearHideNavigationFlag = new Runnable() {
3609 @Override
3610 public void run() {
3611 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3612 // Clear flags.
3613 mForceClearedSystemUiFlags &=
3614 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3615 }
3616 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003617 }
3618 };
3619
3620 /**
3621 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3622 * to determine when the nav bar should be shown and prevent applications from
3623 * receiving those touches.
3624 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003625 final class HideNavInputEventReceiver extends InputEventReceiver {
3626 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3627 super(inputChannel, looper);
3628 }
3629
Dianne Hackborndf89e652011-10-06 22:35:11 -07003630 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003631 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003632 boolean handled = false;
3633 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003634 if (event instanceof MotionEvent
3635 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3636 final MotionEvent motionEvent = (MotionEvent)event;
3637 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003638 // When the user taps down, we re-show the nav bar.
3639 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003640 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003641 // Any user activity always causes us to show the
3642 // navigation controls, if they had been hidden.
3643 // We also clear the low profile and only content
3644 // flags so that tapping on the screen will atomically
3645 // restore all currently hidden screen decorations.
3646 int newVal = mResettingSystemUiFlags |
3647 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3648 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3649 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003650 if (mResettingSystemUiFlags != newVal) {
3651 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003652 changed = true;
3653 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003654 // We don't allow the system's nav bar to be hidden
3655 // again for 1 second, to prevent applications from
3656 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003657 newVal = mForceClearedSystemUiFlags |
3658 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003659 if (mForceClearedSystemUiFlags != newVal) {
3660 mForceClearedSystemUiFlags = newVal;
3661 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003662 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003663 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003664 }
3665 if (changed) {
3666 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3667 }
3668 }
3669 }
3670 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003671 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003672 }
3673 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003674 }
3675 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3676 new InputEventReceiver.Factory() {
3677 @Override
3678 public InputEventReceiver createInputEventReceiver(
3679 InputChannel inputChannel, Looper looper) {
3680 return new HideNavInputEventReceiver(inputChannel, looper);
3681 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003682 };
3683
3684 @Override
3685 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003686 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3687 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003688 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003689
Dianne Hackborndf89e652011-10-06 22:35:11 -07003690 // Reset any bits in mForceClearingStatusBarVisibility that
3691 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003692 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003693 // Clear any bits in the new visibility that are currently being
3694 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003695 return visibility & ~mResettingSystemUiFlags
3696 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003697 }
3698
Craig Mautner69b08182012-09-05 13:07:13 -07003699 @Override
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08003700 public boolean getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation,
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003701 Rect outContentInsets, Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003702 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003703 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3704 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003705
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003706 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
3707 if (useOutsets) {
3708 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
3709 if (outset > 0) {
3710 if (displayRotation == Surface.ROTATION_0) {
3711 outOutsets.bottom += outset;
3712 } else if (displayRotation == Surface.ROTATION_90) {
3713 outOutsets.right += outset;
3714 } else if (displayRotation == Surface.ROTATION_180) {
3715 outOutsets.top += outset;
3716 } else if (displayRotation == Surface.ROTATION_270) {
3717 outOutsets.left += outset;
3718 }
3719 }
3720 }
3721
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003722 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003723 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003724 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003725 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003726 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003727 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3728 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3729 } else {
3730 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3731 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3732 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003733 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3734 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003735 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003736 availRight - mStableFullscreenRight,
3737 availBottom - mStableFullscreenBottom);
3738 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003739 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003740 availRight - mStableRight, availBottom - mStableBottom);
3741 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003742 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003743 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003744 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003745 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003746 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003747 availRight - mCurRight, availBottom - mCurBottom);
3748 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003749 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003750 availRight - mCurRight, availBottom - mCurBottom);
3751 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003752
3753 outStableInsets.set(mStableLeft, mStableTop,
3754 availRight - mStableRight, availBottom - mStableBottom);
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08003755 return mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003756 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003757 outContentInsets.setEmpty();
3758 outStableInsets.setEmpty();
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08003759 return mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003760 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003761
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003762 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
3763 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
3764 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
3765 }
3766
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003767 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003768 @Override
3769 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003770 int displayRotation, int uiMode) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003771 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003772 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3773 if (isDefaultDisplay) {
3774 switch (displayRotation) {
3775 case Surface.ROTATION_90:
3776 overscanLeft = mOverscanTop;
3777 overscanTop = mOverscanRight;
3778 overscanRight = mOverscanBottom;
3779 overscanBottom = mOverscanLeft;
3780 break;
3781 case Surface.ROTATION_180:
3782 overscanLeft = mOverscanRight;
3783 overscanTop = mOverscanBottom;
3784 overscanRight = mOverscanLeft;
3785 overscanBottom = mOverscanTop;
3786 break;
3787 case Surface.ROTATION_270:
3788 overscanLeft = mOverscanBottom;
3789 overscanTop = mOverscanLeft;
3790 overscanRight = mOverscanTop;
3791 overscanBottom = mOverscanRight;
3792 break;
3793 default:
3794 overscanLeft = mOverscanLeft;
3795 overscanTop = mOverscanTop;
3796 overscanRight = mOverscanRight;
3797 overscanBottom = mOverscanBottom;
3798 break;
3799 }
3800 } else {
3801 overscanLeft = 0;
3802 overscanTop = 0;
3803 overscanRight = 0;
3804 overscanBottom = 0;
3805 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003806 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3807 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3808 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3809 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003810 mSystemLeft = 0;
3811 mSystemTop = 0;
3812 mSystemRight = displayWidth;
3813 mSystemBottom = displayHeight;
3814 mUnrestrictedScreenLeft = overscanLeft;
3815 mUnrestrictedScreenTop = overscanTop;
3816 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3817 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3818 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3819 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003820 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3821 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003822 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003823 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003824 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003825 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003826 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003827 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003828 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003829 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003830 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003831 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003832
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003833 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3834 final Rect pf = mTmpParentFrame;
3835 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003836 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003837 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003838 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003839 pf.left = df.left = of.left = vf.left = mDockLeft;
3840 pf.top = df.top = of.top = vf.top = mDockTop;
3841 pf.right = df.right = of.right = vf.right = mDockRight;
3842 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003843 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003844
Craig Mautner69b08182012-09-05 13:07:13 -07003845 if (isDefaultDisplay) {
3846 // For purposes of putting out fake window up to steal focus, we will
3847 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003848 final int sysui = mLastSystemUiFlags;
3849 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003850 boolean navTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003851 & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003852 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3853 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3854 boolean navAllowedHidden = immersive || immersiveSticky;
3855 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003856 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3857 if (!isKeyguardShowing) {
3858 navTranslucent &= areTranslucentBarsAllowed();
3859 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003860
Craig Mautner69b08182012-09-05 13:07:13 -07003861 // When the navigation bar isn't visible, we put up a fake
3862 // input window to catch all touch events. This way we can
3863 // detect when the user presses anywhere to bring back the nav
3864 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003865 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003866 if (mInputConsumer != null) {
3867 mInputConsumer.dismiss();
3868 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003869 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003870 } else if (mInputConsumer == null) {
3871 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3872 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003873 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003874
Craig Mautner69b08182012-09-05 13:07:13 -07003875 // For purposes of positioning and showing the nav bar, if we have
3876 // decided that it can't be hidden (because of the screen aspect ratio),
3877 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003878 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003879
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003880 boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003881 displayRotation, uiMode, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003882 navAllowedHidden);
Craig Mautnereda67292013-04-28 13:50:14 -07003883 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003884 mDockLeft, mDockTop, mDockRight, mDockBottom));
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003885 updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003886 if (updateSysUiVisibility) {
3887 updateSystemUiVisibilityLw();
3888 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003889 }
3890 }
3891
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003892 private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui,
3893 boolean isKeyguardShowing) {
3894 // decide where the status bar goes ahead of time
3895 if (mStatusBar != null) {
3896 // apply any navigation bar insets
3897 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3898 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3899 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3900 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3901 + mUnrestrictedScreenTop;
3902 vf.left = mStableLeft;
3903 vf.top = mStableTop;
3904 vf.right = mStableRight;
3905 vf.bottom = mStableBottom;
3906
3907 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3908
3909 // Let the status bar determine its size.
3910 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3911 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3912 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
3913
3914 // For layout, the status bar is always at the top with our fixed height.
3915 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3916
3917 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
3918 boolean statusBarTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003919 & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0;
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003920 if (!isKeyguardShowing) {
3921 statusBarTranslucent &= areTranslucentBarsAllowed();
3922 }
3923
3924 // If the status bar is hidden, we don't want to cause
3925 // windows behind it to scroll.
3926 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
3927 // Status bar may go away, so the screen area it occupies
3928 // is available to apps but just covering them when the
3929 // status bar is visible.
3930 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3931
3932 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3933 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3934 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3935 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3936
3937 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
3938 String.format(
3939 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3940 mDockLeft, mDockTop, mDockRight, mDockBottom,
3941 mContentLeft, mContentTop, mContentRight, mContentBottom,
3942 mCurLeft, mCurTop, mCurRight, mCurBottom));
3943 }
3944 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
3945 && !statusBarTransient && !statusBarTranslucent
3946 && !mStatusBarController.wasRecentlyTranslucent()) {
3947 // If the opaque status bar is currently requested to be visible,
3948 // and not in the process of animating on or off, then
3949 // we can tell the app that it is covered by it.
3950 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3951 }
3952 if (mStatusBarController.checkHiddenLw()) {
3953 return true;
3954 }
3955 }
3956 return false;
3957 }
3958
3959 private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003960 int uiMode, int overscanRight, int overscanBottom, Rect dcf, boolean navVisible,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003961 boolean navTranslucent, boolean navAllowedHidden) {
3962 if (mNavigationBar != null) {
3963 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
3964 // Force the navigation bar to its appropriate place and
3965 // size. We need to do this directly, instead of relying on
3966 // it to bubble up from the nav bar, because this needs to
3967 // change atomically with screen rotations.
Jorim Jaggi737af722015-12-31 10:42:27 +01003968 mNavigationBarOnBottom = isNavigationBarOnBottom(displayWidth, displayHeight);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003969 if (mNavigationBarOnBottom) {
3970 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
3971 int top = displayHeight - overscanBottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003972 - getNavigationBarHeight(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003973 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
3974 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
3975 if (transientNavBarShowing) {
3976 mNavigationBarController.setBarShowingLw(true);
3977 } else if (navVisible) {
3978 mNavigationBarController.setBarShowingLw(true);
3979 mDockBottom = mTmpNavigationFrame.top;
3980 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3981 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
3982 } else {
3983 // We currently want to hide the navigation UI.
3984 mNavigationBarController.setBarShowingLw(false);
3985 }
3986 if (navVisible && !navTranslucent && !navAllowedHidden
3987 && !mNavigationBar.isAnimatingLw()
3988 && !mNavigationBarController.wasRecentlyTranslucent()) {
3989 // If the opaque nav bar is currently requested to be visible,
3990 // and not in the process of animating on or off, then
3991 // we can tell the app that it is covered by it.
3992 mSystemBottom = mTmpNavigationFrame.top;
3993 }
3994 } else {
3995 // Landscape screen; nav bar goes to the right.
3996 int left = displayWidth - overscanRight
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003997 - getNavigationBarWidth(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003998 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
3999 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
4000 if (transientNavBarShowing) {
4001 mNavigationBarController.setBarShowingLw(true);
4002 } else if (navVisible) {
4003 mNavigationBarController.setBarShowingLw(true);
4004 mDockRight = mTmpNavigationFrame.left;
4005 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
4006 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
4007 } else {
4008 // We currently want to hide the navigation UI.
4009 mNavigationBarController.setBarShowingLw(false);
4010 }
4011 if (navVisible && !navTranslucent && !navAllowedHidden
4012 && !mNavigationBar.isAnimatingLw()
4013 && !mNavigationBarController.wasRecentlyTranslucent()) {
4014 // If the nav bar is currently requested to be visible,
4015 // and not in the process of animating on or off, then
4016 // we can tell the app that it is covered by it.
4017 mSystemRight = mTmpNavigationFrame.left;
4018 }
4019 }
4020 // Make sure the content and current rectangles are updated to
4021 // account for the restrictions from the navigation bar.
4022 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
4023 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
4024 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
4025 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
4026 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
4027 // And compute the final frame.
4028 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
4029 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
4030 mTmpNavigationFrame, mTmpNavigationFrame);
4031 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
4032 if (mNavigationBarController.checkHiddenLw()) {
4033 return true;
4034 }
4035 }
4036 return false;
4037 }
4038
Jorim Jaggi737af722015-12-31 10:42:27 +01004039 private boolean isNavigationBarOnBottom(int displayWidth, int displayHeight) {
4040 return !mNavigationBarCanMove || displayWidth < displayHeight;
4041 }
4042
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07004043 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07004044 @Override
John Spurlock46646232013-09-30 22:32:42 -04004045 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00004046 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
4047 return mStatusBar.getSurfaceLayer();
4048 }
4049
4050 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
4051 return mNavigationBar.getSurfaceLayer();
4052 }
4053
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07004054 return 0;
4055 }
4056
Craig Mautner967212c2013-04-13 21:10:58 -07004057 @Override
4058 public void getContentRectLw(Rect r) {
4059 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
4060 }
4061
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004062 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
4063 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004064 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
4065 // Here's a special case: if this attached window is a panel that is
4066 // above the dock window, and the window it is attached to is below
4067 // the dock window, then the frames we computed for the window it is
4068 // attached to can not be used because the dock is effectively part
4069 // of the underlying window and the attached window is floating on top
4070 // of the whole thing. So, we ignore the attached window and explicitly
4071 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004072 df.left = of.left = cf.left = vf.left = mDockLeft;
4073 df.top = of.top = cf.top = vf.top = mDockTop;
4074 df.right = of.right = cf.right = vf.right = mDockRight;
4075 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004076 } else {
4077 // The effective display frame of the attached window depends on
4078 // whether it is taking care of insetting its content. If not,
4079 // we need to use the parent's content frame so that the entire
4080 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07004081 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004082 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004083 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07004084 // Set the content frame of the attached window to the parent's decor frame
4085 // (same as content frame when IME isn't present) if specifically requested by
4086 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
4087 // Otherwise, use the overscan frame.
4088 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
4089 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004090 } else {
4091 // If the window is resizing, then we want to base the content
4092 // frame on our attached content frame to resize... however,
4093 // things can be tricky if the attached window is NOT in resize
4094 // mode, in which case its content frame will be larger.
4095 // Ungh. So to deal with that, make sure the content frame
4096 // we end up using is not covering the IM dock.
4097 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004098 if (attached.isVoiceInteraction()) {
4099 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
4100 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
4101 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
4102 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
4103 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004104 if (cf.left < mContentLeft) cf.left = mContentLeft;
4105 if (cf.top < mContentTop) cf.top = mContentTop;
4106 if (cf.right > mContentRight) cf.right = mContentRight;
4107 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
4108 }
4109 }
4110 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004111 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004112 vf.set(attached.getVisibleFrameLw());
4113 }
4114 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
4115 // window should be positioned relative to its parent or the entire
4116 // screen.
4117 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
4118 ? attached.getFrameLw() : df);
4119 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004120
4121 private void applyStableConstraints(int sysui, int fl, Rect r) {
4122 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
4123 // If app is requesting a stable layout, don't let the
4124 // content insets go below the stable values.
4125 if ((fl & FLAG_FULLSCREEN) != 0) {
4126 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
4127 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
4128 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
4129 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
4130 } else {
4131 if (r.left < mStableLeft) r.left = mStableLeft;
4132 if (r.top < mStableTop) r.top = mStableTop;
4133 if (r.right > mStableRight) r.right = mStableRight;
4134 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
4135 }
4136 }
4137 }
4138
Jorim Jaggiaa806142015-05-20 18:04:16 -07004139 private boolean canReceiveInput(WindowState win) {
4140 boolean notFocusable =
4141 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
4142 boolean altFocusableIm =
4143 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
4144 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
4145 return !notFocusableForIm;
4146 }
4147
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004148 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07004149 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004150 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07004151 // We've already done the navigation bar and status bar. If the status bar can receive
4152 // input, we need to layout it again to accomodate for the IME window.
4153 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004154 return;
4155 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07004156 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07004157 final boolean isDefaultDisplay = win.isDefaultDisplay();
4158 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09004159 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
4160 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07004161 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09004162 offsetInputMethodWindowLw(mLastInputMethodWindow);
4163 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004164
John Spurlockc6d1c602014-01-17 15:22:06 -05004165 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004166 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05004167 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004168
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004169 final Rect pf = mTmpParentFrame;
4170 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004171 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004172 final Rect cf = mTmpContentFrame;
4173 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04004174 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07004175 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004176 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04004177 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07004178
4179 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04004180 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004181
Craig Mautnerf683b562012-10-02 11:10:57 -07004182 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
4183
Adrian Roosfa104232014-06-20 16:10:14 -07004184 if (isDefaultDisplay) {
4185 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
4186 } else {
4187 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
4188 }
4189
Craig Mautner69b08182012-09-05 13:07:13 -07004190 if (!isDefaultDisplay) {
4191 if (attached != null) {
4192 // If this window is attached to another, our display
4193 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004194 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07004195 } else {
4196 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004197 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4198 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4199 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004200 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004201 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004202 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07004203 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004204 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004205 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
4206 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
4207 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04004208 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04004209 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04004210 // ...with content insets above the nav bar
4211 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004212 // IM dock windows always go to the bottom of the screen.
4213 attrs.gravity = Gravity.BOTTOM;
4214 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004215 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004216 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004217 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004218 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4219 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004220 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004221 // Note: In Phone landscape mode, the button bar should also be excluded.
4222 cf.right = vf.right = mStableRight;
4223 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004224 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07004225 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02004226 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4227 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4228 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
4229 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
4230 cf.left = vf.left = mStableLeft;
4231 cf.top = vf.top = mStableTop;
4232 cf.right = vf.right = mStableRight;
4233 vf.bottom = mStableBottom;
Adrian Roosdc5b4532016-01-06 20:49:41 +01004234
4235 if (adjust == SOFT_INPUT_ADJUST_RESIZE) {
4236 cf.bottom = mContentBottom;
4237 } else {
4238 cf.bottom = mDockBottom;
4239 vf.bottom = mContentBottom;
4240 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004241 } else {
John Spurlock46646232013-09-30 22:32:42 -04004242
4243 // Default policy decor for the default display
4244 dcf.left = mSystemLeft;
4245 dcf.top = mSystemTop;
4246 dcf.right = mSystemRight;
4247 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04004248 final boolean inheritTranslucentDecor = (attrs.privateFlags
4249 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04004250 final boolean isAppWindow =
4251 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
4252 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
4253 final boolean topAtRest =
4254 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
4255 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04004256 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
4257 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004258 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
4259 && (fl & WindowManager.LayoutParams.
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004260 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0
4261 && !mForceWindowDrawsStatusBarBackground) {
John Spurlock46646232013-09-30 22:32:42 -04004262 // Ensure policy decor includes status bar
4263 dcf.top = mStableTop;
4264 }
John Spurlockbd957402013-10-03 11:38:39 -04004265 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004266 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
4267 && (fl & WindowManager.LayoutParams.
4268 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004269 // Ensure policy decor includes navigation bar
4270 dcf.bottom = mStableBottom;
4271 dcf.right = mStableRight;
4272 }
4273 }
4274
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004275 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
4276 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07004277 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004278 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004279 // This is the case for a normal activity window: we want it
4280 // to cover all of the screen space, and it can take care of
4281 // moving its contents to account for screen decorations that
4282 // intrude into that space.
4283 if (attached != null) {
4284 // If this window is attached to another, our display
4285 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004286 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004287 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004288 if (attrs.type == TYPE_STATUS_BAR_PANEL
4289 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08004290 // Status bar panels are the only windows who can go on top of
4291 // the status bar. They are protected by the STATUS_BAR_SERVICE
4292 // permission, so they have the same privileges as the status
4293 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004294 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004295 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004296
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004297 pf.left = df.left = of.left = hasNavBar
4298 ? mDockLeft : mUnrestrictedScreenLeft;
4299 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4300 pf.right = df.right = of.right = hasNavBar
4301 ? mRestrictedScreenLeft+mRestrictedScreenWidth
4302 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4303 pf.bottom = df.bottom = of.bottom = hasNavBar
4304 ? mRestrictedScreenTop+mRestrictedScreenHeight
4305 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004306
Craig Mautnereda67292013-04-28 13:50:14 -07004307 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004308 "Laying out status bar window: (%d,%d - %d,%d)",
4309 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04004310 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004311 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4312 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4313 // Asking to layout into the overscan region, so give it that pure
4314 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004315 pf.left = df.left = of.left = mOverscanScreenLeft;
4316 pf.top = df.top = of.top = mOverscanScreenTop;
4317 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
4318 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
4319 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004320 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004321 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004322 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4323 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004324 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08004325 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004326 // only do this for application windows to ensure no window that
4327 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08004328 pf.left = df.left = mOverscanScreenLeft;
4329 pf.top = df.top = mOverscanScreenTop;
4330 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4331 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004332 // We need to tell the app about where the frame inside the overscan
4333 // is, so it can inset its content by that amount -- it didn't ask
4334 // to actually extend itself into the overscan region.
4335 of.left = mUnrestrictedScreenLeft;
4336 of.top = mUnrestrictedScreenTop;
4337 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4338 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004339 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08004340 pf.left = df.left = mRestrictedOverscanScreenLeft;
4341 pf.top = df.top = mRestrictedOverscanScreenTop;
4342 pf.right = df.right = mRestrictedOverscanScreenLeft
4343 + mRestrictedOverscanScreenWidth;
4344 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
4345 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004346 // We need to tell the app about where the frame inside the overscan
4347 // is, so it can inset its content by that amount -- it didn't ask
4348 // to actually extend itself into the overscan region.
4349 of.left = mUnrestrictedScreenLeft;
4350 of.top = mUnrestrictedScreenTop;
4351 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4352 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004353 }
Craig Mautner69b08182012-09-05 13:07:13 -07004354
John Spurlock46646232013-09-30 22:32:42 -04004355 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004356 if (win.isVoiceInteraction()) {
4357 cf.left = mVoiceContentLeft;
4358 cf.top = mVoiceContentTop;
4359 cf.right = mVoiceContentRight;
4360 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004361 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004362 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4363 cf.left = mDockLeft;
4364 cf.top = mDockTop;
4365 cf.right = mDockRight;
4366 cf.bottom = mDockBottom;
4367 } else {
4368 cf.left = mContentLeft;
4369 cf.top = mContentTop;
4370 cf.right = mContentRight;
4371 cf.bottom = mContentBottom;
4372 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004373 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004374 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004375 // Full screen windows are always given a layout that is as if the
4376 // status bar and other transient decors are gone. This is to avoid
4377 // bad states when moving from a window that is not hding the
4378 // status bar to one that is.
4379 cf.left = mRestrictedScreenLeft;
4380 cf.top = mRestrictedScreenTop;
4381 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4382 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004383 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004384 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004385 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4386 vf.left = mCurLeft;
4387 vf.top = mCurTop;
4388 vf.right = mCurRight;
4389 vf.bottom = mCurBottom;
4390 } else {
4391 vf.set(cf);
4392 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004393 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004394 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
4395 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
4396 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07004397 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4398 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004399 // A window that has requested to fill the entire screen just
4400 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004401 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04004402 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
4403 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004404 pf.left = df.left = of.left = cf.left = hasNavBar
4405 ? mDockLeft : mUnrestrictedScreenLeft;
4406 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4407 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004408 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08004409 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004410 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004411 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004412 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004413 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04004414 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
4415 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07004416 } else if (attrs.type == TYPE_NAVIGATION_BAR
4417 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004418 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004419 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4420 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4421 pf.right = df.right = of.right = mUnrestrictedScreenLeft
4422 + mUnrestrictedScreenWidth;
4423 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
4424 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004425 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004426 "Laying out navigation bar window: (%d,%d - %d,%d)",
4427 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08004428 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
Muyuan Li6ca619f2016-03-08 13:30:42 -08004429 || attrs.type == TYPE_BOOT_PROGRESS
4430 || attrs.type == TYPE_SCREENSHOT)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07004431 && ((fl & FLAG_FULLSCREEN) != 0)) {
Muyuan Li6ca619f2016-03-08 13:30:42 -08004432 // Fullscreen secure system overlays get what they ask for. Screenshot region
4433 // selection overlay should also expand to full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004434 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4435 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4436 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4437 + mOverscanScreenWidth;
4438 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4439 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08004440 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08004441 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004442 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4443 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4444 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4445 + mOverscanScreenWidth;
4446 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4447 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04004448 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004449 // The wallpaper also has Real Ultimate Power, but we want to tell
4450 // it about the overscan area.
4451 pf.left = df.left = mOverscanScreenLeft;
4452 pf.top = df.top = mOverscanScreenTop;
4453 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4454 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4455 of.left = cf.left = mUnrestrictedScreenLeft;
4456 of.top = cf.top = mUnrestrictedScreenTop;
4457 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4458 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004459 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004460 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4461 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4462 // Asking to layout into the overscan region, so give it that pure
4463 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004464 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4465 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4466 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004467 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004468 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004469 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004470 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004471 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004472 && (attrs.type == TYPE_STATUS_BAR
4473 || attrs.type == TYPE_TOAST
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01004474 || attrs.type == TYPE_DOCK_DIVIDER
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004475 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004476 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4477 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004478 // Asking for layout as if the nav bar is hidden, lets the
4479 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004480 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004481 // can be above the nav bar can do this.
4482 // XXX This assumes that an app asking for this will also
4483 // ask for layout in only content. We can't currently figure out
4484 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004485 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4486 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4487 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4488 + mUnrestrictedScreenWidth;
4489 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4490 + mUnrestrictedScreenHeight;
Jorim Jaggi9f6798a2016-02-10 22:16:06 -08004491 } else if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0) {
4492 pf.left = df.left = of.left = mRestrictedScreenLeft;
4493 pf.top = df.top = of.top = mRestrictedScreenTop;
4494 pf.right = df.right = of.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4495 pf.bottom = df.bottom = of.bottom = mRestrictedScreenTop
4496 + mRestrictedScreenHeight;
4497 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4498 cf.left = mDockLeft;
4499 cf.top = mDockTop;
4500 cf.right = mDockRight;
4501 cf.bottom = mDockBottom;
4502 } else {
4503 cf.left = mContentLeft;
4504 cf.top = mContentTop;
4505 cf.right = mContentRight;
4506 cf.bottom = mContentBottom;
4507 }
Joe Onorato29fc2c92010-11-24 10:26:50 -08004508 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004509 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4510 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4511 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4512 + mRestrictedScreenWidth;
4513 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4514 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004515 }
Craig Mautner69b08182012-09-05 13:07:13 -07004516
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004517 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004518
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004519 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4520 vf.left = mCurLeft;
4521 vf.top = mCurTop;
4522 vf.right = mCurRight;
4523 vf.bottom = mCurBottom;
4524 } else {
4525 vf.set(cf);
4526 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004527 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004528 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4529 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004530 // A child window should be placed inside of the same visible
4531 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004532 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004533 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004534 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4535 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004536 // Otherwise, a normal window must be placed inside the content
4537 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004538 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4539 // Status bar panels and the volume dialog are the only windows who can go on
4540 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004541 // permission, so they have the same privileges as the status
4542 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004543 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4544 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4545 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4546 + mRestrictedScreenWidth;
4547 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4548 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004549 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004550 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004551 pf.left = df.left = of.left = cf.left = mStableLeft;
4552 pf.top = df.top = of.top = cf.top = mStableTop;
4553 pf.right = df.right = of.right = cf.right = mStableRight;
4554 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004555 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004556 pf.left = mContentLeft;
4557 pf.top = mContentTop;
4558 pf.right = mContentRight;
4559 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004560 if (win.isVoiceInteraction()) {
4561 df.left = of.left = cf.left = mVoiceContentLeft;
4562 df.top = of.top = cf.top = mVoiceContentTop;
4563 df.right = of.right = cf.right = mVoiceContentRight;
4564 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4565 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004566 df.left = of.left = cf.left = mDockLeft;
4567 df.top = of.top = cf.top = mDockTop;
4568 df.right = of.right = cf.right = mDockRight;
4569 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004570 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004571 df.left = of.left = cf.left = mContentLeft;
4572 df.top = of.top = cf.top = mContentTop;
4573 df.right = of.right = cf.right = mContentRight;
4574 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004575 }
4576 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4577 vf.left = mCurLeft;
4578 vf.top = mCurTop;
4579 vf.right = mCurRight;
4580 vf.bottom = mCurBottom;
4581 } else {
4582 vf.set(cf);
4583 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004584 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004585 }
4586 }
Craig Mautner69b08182012-09-05 13:07:13 -07004587
Craig Mautnerb816bed2013-07-23 10:26:17 -07004588 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4589 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004590 df.left = df.top = -10000;
4591 df.right = df.bottom = 10000;
4592 if (attrs.type != TYPE_WALLPAPER) {
4593 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4594 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4595 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004596 }
4597
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004598 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4599 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004600 // We only want to apply outsets to certain types of windows. For example, we never want to
4601 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004602 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004603 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004604 osf = mTmpOutsetFrame;
4605 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4606 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4607 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004608 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004609 if (rotation == Surface.ROTATION_0) {
4610 osf.bottom += outset;
4611 } else if (rotation == Surface.ROTATION_90) {
4612 osf.right += outset;
4613 } else if (rotation == Surface.ROTATION_180) {
4614 osf.top -= outset;
4615 } else if (rotation == Surface.ROTATION_270) {
4616 osf.left -= outset;
4617 }
4618 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4619 + " with rotation " + rotation + ", result: " + osf);
4620 }
4621 }
4622
Craig Mautnereda67292013-04-28 13:50:14 -07004623 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004624 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004625 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004626 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004627 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004628 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004629 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004630 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004631 + " sf=" + sf.toShortString()
4632 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004633
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004634 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004635
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004636 // Dock windows carve out the bottom of the screen, so normal windows
4637 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004638 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4639 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004640 setLastInputMethodWindowLw(null, null);
4641 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004642 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004643 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4644 && !win.getGivenInsetsPendingLw()) {
4645 offsetVoiceInputWindowLw(win);
4646 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004647 }
4648
satok1bc0a492012-04-25 22:47:12 +09004649 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004650 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004651 top += win.getGivenContentInsetsLw().top;
4652 if (mContentBottom > top) {
4653 mContentBottom = top;
4654 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004655 if (mVoiceContentBottom > top) {
4656 mVoiceContentBottom = top;
4657 }
satok1bc0a492012-04-25 22:47:12 +09004658 top = win.getVisibleFrameLw().top;
4659 top += win.getGivenVisibleInsetsLw().top;
4660 if (mCurBottom > top) {
4661 mCurBottom = top;
4662 }
Craig Mautnereda67292013-04-28 13:50:14 -07004663 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004664 + mDockBottom + " mContentBottom="
4665 + mContentBottom + " mCurBottom=" + mCurBottom);
4666 }
4667
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004668 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004669 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004670 top += win.getGivenContentInsetsLw().top;
4671 if (mVoiceContentBottom > top) {
4672 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004673 }
4674 }
4675
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004676 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004677 @Override
4678 public void finishLayoutLw() {
4679 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004680 }
4681
4682 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004683 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004684 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004685 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004686 mTopFullscreenOpaqueOrDimmingWindowState = null;
Jorim Jaggi86905582016-02-09 21:36:09 -08004687 mTopDockedOpaqueWindowState = null;
4688 mTopDockedOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004689 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004690 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004691 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004692 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004693 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004694 mForcingShowNavBar = false;
4695 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004696
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004697 mHideLockScreen = false;
4698 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004699 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004700 mShowingLockscreen = false;
4701 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004702 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004703 mKeyguardSecure = isKeyguardSecure();
4704 mKeyguardSecureIncludingHidden = mKeyguardSecure
4705 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004706 }
4707
4708 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004709 @Override
Yohei Yukawad1a09222015-06-30 16:22:05 -07004710 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,
4711 WindowState attached) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004712 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4713 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004714 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004715 if (mTopFullscreenOpaqueWindowState == null
4716 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4717 mForcingShowNavBar = true;
4718 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004719 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004720 if (attrs.type == TYPE_STATUS_BAR) {
4721 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4722 mForceStatusBarFromKeyguard = true;
Jorim Jaggie1de9f62015-09-23 14:59:50 -07004723 mShowingLockscreen = true;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004724 }
4725 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4726 mForceStatusBarTransparent = true;
4727 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004728 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004729
4730 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4731 && attrs.type < FIRST_SYSTEM_WINDOW;
4732 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4733 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Jorim Jaggi86905582016-02-09 21:36:09 -08004734 final int stackId = win.getStackId();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004735 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004736 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004737 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004738 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004739 mForceStatusBarFromKeyguard = true;
4740 } else {
4741 mForceStatusBar = true;
4742 }
4743 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004744 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004745 // If the lockscreen was showing when the dream started then wait
4746 // for the dream to draw before hiding the lockscreen.
4747 if (!mDreamingLockscreen
4748 || (win.isVisibleLw() && win.hasDrawnLw())) {
4749 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004750 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004751 }
4752 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004753
Yohei Yukawad1a09222015-06-30 16:22:05 -07004754 final IApplicationToken appToken = win.getAppToken();
4755
4756 // For app windows that are not attached, we decide if all windows in the app they
4757 // represent should be hidden or if we should hide the lockscreen. For attached app
4758 // windows we defer the decision to the window it is attached to.
4759 if (appWindow && attached == null) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004760 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004761 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004762 mAppsToBeHidden.remove(appToken);
4763 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004764 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004765 if (dismissKeyguard && !mKeyguardSecure) {
4766 mAppsThatDismissKeyguard.add(appToken);
Selim Cinek90b5e072015-08-28 17:05:56 -07004767 } else if (win.isDrawnLw() || win.hasAppShownWindows()) {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004768 mWinShowWhenLocked = win;
4769 mHideLockScreen = true;
4770 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004771 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004772 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004773 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004774 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004775 mAppsToBeHidden.add(appToken);
4776 } else {
4777 mAppsToBeHidden.remove(appToken);
4778 }
4779 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004780 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004781 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004782 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004783 if (isFullscreen(attrs) && StackId.normallyFullscreenWindows(stackId)) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004784 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4785 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004786 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4787 mTopFullscreenOpaqueOrDimmingWindowState = win;
4788 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004789 if (!mAppsThatDismissKeyguard.isEmpty() &&
4790 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4791 if (DEBUG_LAYOUT) Slog.v(TAG,
4792 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004793 mDismissKeyguard = (mWinDismissingKeyguard == win
4794 && mSecureDismissingKeyguard == mKeyguardSecure)
4795 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004796 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004797 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004798 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Selim Cinek90b5e072015-08-28 17:05:56 -07004799 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked
4800 && (win.isDrawnLw() || win.hasAppShownWindows())) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004801 if (DEBUG_LAYOUT) Slog.v(TAG,
4802 "Setting mHideLockScreen to true by win " + win);
4803 mHideLockScreen = true;
4804 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004805 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004806 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004807 mAllowLockscreenWhenOn = true;
4808 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004809 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004810
4811 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004812 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4813 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004814 win.hideLw(false);
4815 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004816 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004817 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4818 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4819 // that is being hidden in an animation - keep the
4820 // keyguard hidden until the new window shows up and
4821 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004822 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004823 mHideLockScreen = true;
4824 mWinShowWhenLocked = win;
4825 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004826 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004827
4828 // Keep track of the window if it's dimming but not necessarily fullscreen.
4829 final boolean reallyVisible = win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw();
4830 if (mTopFullscreenOpaqueOrDimmingWindowState == null && reallyVisible
4831 && win.isDimming() && StackId.normallyFullscreenWindows(stackId)) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01004832 mTopFullscreenOpaqueOrDimmingWindowState = win;
4833 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004834
4835 // We need to keep track of the top "fullscreen" opaque window for the docked stack
4836 // separately, because both the "real fullscreen" opaque window and the one for the docked
4837 // stack can control View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.
4838 if (mTopDockedOpaqueWindowState == null && reallyVisible && appWindow && attached == null
4839 && isFullscreen(attrs) && stackId == DOCKED_STACK_ID) {
4840 mTopDockedOpaqueWindowState = win;
4841 if (mTopDockedOpaqueOrDimmingWindowState == null) {
4842 mTopDockedOpaqueOrDimmingWindowState = win;
4843 }
4844 }
4845
4846 // Also keep track of any windows that are dimming but not necessarily fullscreen in the
4847 // docked stack.
4848 if (mTopDockedOpaqueOrDimmingWindowState == null && reallyVisible && win.isDimming()
4849 && stackId == DOCKED_STACK_ID) {
4850 mTopDockedOpaqueOrDimmingWindowState = win;
4851 }
4852 }
4853
4854 private boolean isFullscreen(WindowManager.LayoutParams attrs) {
4855 return attrs.x == 0 && attrs.y == 0
4856 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4857 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004858 }
4859
4860 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004861 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004862 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004863 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4864 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4865 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004866 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4867 // fullscreen window.
4868 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4869 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4870 mTopFullscreenOpaqueWindowState.hideLw(false);
4871 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4872 }
4873
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004874 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004875 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004876
4877 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4878 ? mTopFullscreenOpaqueWindowState.getAttrs()
4879 : null;
4880
Jeff Brownc8018eb2012-10-29 21:33:27 -07004881 // If we are not currently showing a dream then remember the current
4882 // lockscreen state. We will use this to determine whether the dream
4883 // started while the lockscreen was showing and remember this state
4884 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004885 if (!mShowingDream) {
4886 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004887 if (mDreamingSleepTokenNeeded) {
4888 mDreamingSleepTokenNeeded = false;
4889 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4890 }
4891 } else {
4892 if (!mDreamingSleepTokenNeeded) {
4893 mDreamingSleepTokenNeeded = true;
4894 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4895 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004896 }
4897
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004898 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004899 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004900 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004901 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004902 boolean shouldBeTransparent = mForceStatusBarTransparent
4903 && !mForceStatusBar
4904 && !mForceStatusBarFromKeyguard;
4905 if (!shouldBeTransparent) {
4906 mStatusBarController.setShowTransparent(false /* transparent */);
4907 } else if (!mStatusBar.isVisibleLw()) {
4908 mStatusBarController.setShowTransparent(true /* transparent */);
4909 }
4910 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004911 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004912 if (mStatusBarController.setBarShowingLw(true)) {
4913 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4914 }
Craig Mautner81defc72013-10-29 11:10:42 -07004915 // Maintain fullscreen layout until incoming animation is complete.
4916 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004917 // Transient status bar on the lockscreen is not allowed
4918 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4919 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4920 mLastSystemUiFlags, mLastSystemUiFlags);
4921 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004922 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004923 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004924 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004925 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07004926 + " shown position: "
4927 + mTopFullscreenOpaqueWindowState.getShownPositionLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004928 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004929 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004930 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004931 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004932 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004933 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004934 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004935 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4936 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004937 if (mStatusBarController.isTransientShowing()) {
4938 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004939 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4940 }
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07004941 } else if (topIsFullscreen
4942 && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID)
4943 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) {
Craig Mautnereda67292013-04-28 13:50:14 -07004944 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004945 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004946 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004947 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004948 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004949 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004950 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004951 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004952 if (mStatusBarController.setBarShowingLw(true)) {
4953 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4954 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004955 }
4956 }
4957 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004958
Craig Mautner81defc72013-10-29 11:10:42 -07004959 if (mTopIsFullscreen != topIsFullscreen) {
4960 if (!topIsFullscreen) {
4961 // Force another layout when status bar becomes fully shown.
4962 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4963 }
4964 mTopIsFullscreen = topIsFullscreen;
4965 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004966
Craig Mautner39834192012-09-02 07:47:24 -07004967 // Hide the key guard if a visible window explicitly specifies that it wants to be
4968 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004969 if (mKeyguardDelegate != null && mStatusBar != null) {
4970 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4971 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004972 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004973 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004974 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004975 changes |= FINISH_LAYOUT_REDO_LAYOUT
4976 | FINISH_LAYOUT_REDO_CONFIG
4977 | FINISH_LAYOUT_REDO_WALLPAPER;
4978 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004979 if (mKeyguardDelegate.isShowing()) {
4980 mHandler.post(new Runnable() {
4981 @Override
4982 public void run() {
4983 mKeyguardDelegate.keyguardDone(false, false);
4984 }
4985 });
4986 }
4987 } else if (mHideLockScreen) {
4988 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004989 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004990 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004991 changes |= FINISH_LAYOUT_REDO_LAYOUT
4992 | FINISH_LAYOUT_REDO_CONFIG
4993 | FINISH_LAYOUT_REDO_WALLPAPER;
4994 }
4995 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004996 mKeyguardHidden = false;
4997 if (setKeyguardOccludedLw(false)) {
4998 changes |= FINISH_LAYOUT_REDO_LAYOUT
4999 | FINISH_LAYOUT_REDO_CONFIG
5000 | FINISH_LAYOUT_REDO_WALLPAPER;
5001 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005002 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
5003 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005004 mHandler.post(new Runnable() {
5005 @Override
5006 public void run() {
5007 mKeyguardDelegate.dismiss();
5008 }
5009 });
5010 }
5011 } else {
5012 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08005013 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005014 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07005015 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005016 changes |= FINISH_LAYOUT_REDO_LAYOUT
5017 | FINISH_LAYOUT_REDO_CONFIG
5018 | FINISH_LAYOUT_REDO_WALLPAPER;
5019 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07005020 }
5021 }
Joe Onorato664644d2011-01-23 17:53:23 -08005022
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005023 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005024 // If the navigation bar has been hidden or shown, we need to do another
5025 // layout pass to update that window.
5026 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5027 }
Joe Onorato664644d2011-01-23 17:53:23 -08005028
Mike Lockwood28569302010-01-28 11:54:40 -05005029 // update since mAllowLockscreenWhenOn might have changed
5030 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005031 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005032 }
5033
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005034 /**
Jim Millerab954542014-10-10 18:21:49 -07005035 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005036 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005037 * @return Whether the flags have changed and we have to redo the layout.
5038 */
Jim Millerab954542014-10-10 18:21:49 -07005039 private boolean setKeyguardOccludedLw(boolean isOccluded) {
5040 boolean wasOccluded = mKeyguardOccluded;
5041 boolean showing = mKeyguardDelegate.isShowing();
5042 if (wasOccluded && !isOccluded && showing) {
5043 mKeyguardOccluded = false;
5044 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005045 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
5046 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
5047 return true;
Jim Millerab954542014-10-10 18:21:49 -07005048 } else if (!wasOccluded && isOccluded && showing) {
5049 mKeyguardOccluded = true;
5050 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005051 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
5052 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
5053 return true;
5054 } else {
5055 return false;
5056 }
5057 }
5058
5059 private boolean isStatusBarKeyguard() {
5060 return mStatusBar != null
5061 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
5062 }
5063
Jose Lima9546b202014-07-02 17:21:51 -07005064 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08005065 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005066 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07005067 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08005068 return false;
5069 }
Dianne Hackborn08743722009-12-21 12:16:51 -08005070 return true;
5071 }
5072
Jose Lima9546b202014-07-02 17:21:51 -07005073 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005074 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08005075 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005076 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005077 // If the navigation bar has been hidden or shown, we need to do another
5078 // layout pass to update that window.
5079 return FINISH_LAYOUT_REDO_LAYOUT;
5080 }
5081 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08005082 }
5083
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07005084 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005085 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07005086 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5087 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07005088 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
5089 if (newLidState == mLidState) {
5090 return;
5091 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005092
Jeff Brownc458ce92012-04-30 14:58:40 -07005093 mLidState = newLidState;
5094 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005095 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07005096
5097 if (lidOpen) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005098 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch,
5099 "android.policy:LID");
Jeff Brownc458ce92012-04-30 14:58:40 -07005100 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07005101 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005102 }
5103 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005104
Michael Wright3818c922014-09-02 13:59:07 -07005105 @Override
5106 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
5107 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
5108 if (mCameraLensCoverState == lensCoverState) {
5109 return;
5110 }
5111 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
5112 lensCoverState == CAMERA_LENS_UNCOVERED) {
5113 Intent intent;
5114 final boolean keyguardActive = mKeyguardDelegate == null ? false :
5115 mKeyguardDelegate.isShowing();
5116 if (keyguardActive) {
5117 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
5118 } else {
5119 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
5120 }
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005121 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens,
5122 "android.policy:CAMERA_COVER");
Bart Sears8b1c27c2015-03-18 23:51:02 +00005123 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07005124 }
5125 mCameraLensCoverState = lensCoverState;
5126 }
5127
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005128 void setHdmiPlugged(boolean plugged) {
5129 if (mHdmiPlugged != plugged) {
5130 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005131 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005132 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08005133 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005134 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07005135 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005136 }
5137 }
5138
Joe Onoratoea495d42011-04-06 11:41:11 -07005139 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07005140 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07005141 // watch for HDMI plug messages if the hdmi switch exists
5142 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
5143 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
5144
Joe Onoratoea495d42011-04-06 11:41:11 -07005145 final String filename = "/sys/class/switch/hdmi/state";
5146 FileReader reader = null;
5147 try {
5148 reader = new FileReader(filename);
5149 char[] buf = new char[15];
5150 int n = reader.read(buf);
5151 if (n > 1) {
5152 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
5153 }
5154 } catch (IOException ex) {
5155 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5156 } catch (NumberFormatException ex) {
5157 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5158 } finally {
5159 if (reader != null) {
5160 try {
5161 reader.close();
5162 } catch (IOException ex) {
5163 }
Joe Onoratodc100302011-01-11 17:07:41 -08005164 }
5165 }
5166 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07005167 // This dance forces the code in setHdmiPlugged to run.
5168 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
5169 mHdmiPlugged = !plugged;
5170 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08005171 }
5172
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07005173 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005174 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005175
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005176 final Runnable mScreenshotTimeout = new Runnable() {
5177 @Override public void run() {
5178 synchronized (mScreenshotLock) {
5179 if (mScreenshotConnection != null) {
5180 mContext.unbindService(mScreenshotConnection);
5181 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005182 }
Winson Chung9112ec32011-06-27 13:15:32 -07005183 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005184 }
5185 };
5186
5187 // Assume this is called from the Handler thread.
Muyuan Li6ca619f2016-03-08 13:30:42 -08005188 private void takeScreenshot(final int screenshotType) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005189 synchronized (mScreenshotLock) {
5190 if (mScreenshotConnection != null) {
5191 return;
5192 }
5193 ComponentName cn = new ComponentName("com.android.systemui",
5194 "com.android.systemui.screenshot.TakeScreenshotService");
5195 Intent intent = new Intent();
5196 intent.setComponent(cn);
5197 ServiceConnection conn = new ServiceConnection() {
5198 @Override
5199 public void onServiceConnected(ComponentName name, IBinder service) {
5200 synchronized (mScreenshotLock) {
5201 if (mScreenshotConnection != this) {
5202 return;
5203 }
5204 Messenger messenger = new Messenger(service);
Muyuan Li6ca619f2016-03-08 13:30:42 -08005205 Message msg = Message.obtain(null, screenshotType);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005206 final ServiceConnection myConn = this;
5207 Handler h = new Handler(mHandler.getLooper()) {
5208 @Override
5209 public void handleMessage(Message msg) {
5210 synchronized (mScreenshotLock) {
5211 if (mScreenshotConnection == myConn) {
5212 mContext.unbindService(mScreenshotConnection);
5213 mScreenshotConnection = null;
5214 mHandler.removeCallbacks(mScreenshotTimeout);
5215 }
5216 }
5217 }
5218 };
5219 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07005220 msg.arg1 = msg.arg2 = 0;
5221 if (mStatusBar != null && mStatusBar.isVisibleLw())
5222 msg.arg1 = 1;
5223 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
5224 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005225 try {
5226 messenger.send(msg);
5227 } catch (RemoteException e) {
5228 }
5229 }
5230 }
5231 @Override
5232 public void onServiceDisconnected(ComponentName name) {}
5233 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08005234 if (mContext.bindServiceAsUser(
5235 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005236 mScreenshotConnection = conn;
5237 mHandler.postDelayed(mScreenshotTimeout, 10000);
5238 }
5239 }
Winson Chung9112ec32011-06-27 13:15:32 -07005240 }
5241
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005242 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005243 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07005244 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07005245 if (!mSystemBooted) {
5246 // If we have not yet booted, don't let key events do anything.
5247 return 0;
5248 }
5249
Jeff Brown037c33e2014-04-09 00:31:55 -07005250 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08005251 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
5252 final boolean canceled = event.isCanceled();
5253 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07005254
Jeff Brown3122e442010-10-11 23:32:49 -07005255 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07005256
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05005257 // If screen is off then we treat the case where the keyguard is open but hidden
5258 // the same as if it were open and in front.
5259 // This will prevent any keys other than the power button from waking the screen
5260 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08005261 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07005262 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07005263 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08005264 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005265
Jeff Brown40013652012-05-16 21:22:36 -07005266 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005267 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07005268 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08005269 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005270 }
5271
Jeff Brown037c33e2014-04-09 00:31:55 -07005272 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07005273 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07005274 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
5275 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07005276 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07005277 // When the device is interactive or the key is injected pass the
5278 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07005279 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005280 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07005281 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
5282 // If we're currently dozing with the screen on and the keyguard showing, pass the key
5283 // to the application but preserve its wake key status to make sure we still move
5284 // from dozing to fully interactive if we would normally go from off to fully
5285 // interactive.
5286 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07005287 } else {
5288 // When the screen is off and the key is not injected, determine whether
5289 // to wake the device but don't pass the key to the application.
5290 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08005291 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
5292 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005293 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005294 }
5295
Justin Kohd378ad72013-04-01 12:18:26 -07005296 // If the key would be handled globally, just return the result, don't worry about special
5297 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07005298 if (isValidGlobalKey(keyCode)
5299 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07005300 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005301 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Michael Wright85b1af62014-06-04 14:51:58 -07005302 }
Justin Kohd378ad72013-04-01 12:18:26 -07005303 return result;
5304 }
5305
Jeff Brownbae8e772014-06-12 19:59:45 -07005306 boolean useHapticFeedback = down
5307 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
5308 && event.getRepeatCount() == 0;
5309
Jeff Brown4d396052010-10-29 21:50:21 -07005310 // Handle special keys.
5311 switch (keyCode) {
5312 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07005313 case KeyEvent.KEYCODE_VOLUME_UP:
5314 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005315 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
5316 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005317 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005318 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005319 mScreenshotChordVolumeDownKeyTriggered = true;
5320 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
5321 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005322 cancelPendingPowerKeyAction();
5323 interceptScreenshotChord();
5324 }
5325 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005326 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005327 cancelPendingScreenshotChordAction();
5328 }
5329 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
5330 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005331 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005332 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005333 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005334 cancelPendingPowerKeyAction();
5335 cancelPendingScreenshotChordAction();
5336 }
5337 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005338 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005339 cancelPendingScreenshotChordAction();
5340 }
5341 }
Jeff Brown4d396052010-10-29 21:50:21 -07005342 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005343 TelecomManager telecomManager = getTelecommService();
5344 if (telecomManager != null) {
5345 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005346 // If an incoming call is ringing, either VOLUME key means
5347 // "silence ringer". We handle these keys here, rather than
5348 // in the InCallScreen, to make sure we'll respond to them
5349 // even if the InCallScreen hasn't come to the foreground yet.
5350 // Look for the DOWN event here, to agree with the "fallback"
5351 // behavior in the InCallScreen.
5352 Log.i(TAG, "interceptKeyBeforeQueueing:"
5353 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07005354
Santos Cordon6848f722014-05-21 15:22:12 -07005355 // Silence the ringer. (It's safe to call this
5356 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005357 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07005358
Santos Cordon6848f722014-05-21 15:22:12 -07005359 // And *don't* pass this key thru to the current activity
5360 // (which is probably the InCallScreen.)
5361 result &= ~ACTION_PASS_TO_USER;
5362 break;
5363 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005364 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07005365 && (result & ACTION_PASS_TO_USER) == 0) {
5366 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07005367 // the application, just pass it to the session service.
5368
5369 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07005370 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07005371 break;
Jeff Brown4d396052010-10-29 21:50:21 -07005372 }
5373 }
Jaewan Kim765487f2016-01-12 14:45:42 +09005374 }
5375 if (mUseTvRouting) {
5376 // On TVs, defer special key handlings to
5377 // {@link interceptKeyBeforeDispatching()}.
5378 result |= ACTION_PASS_TO_USER;
5379 } else if ((result & ACTION_PASS_TO_USER) == 0) {
5380 // If we aren't passing to the user and no one else
5381 // handled it send it to the session manager to
5382 // figure out.
5383 MediaSessionLegacyHelper.getHelper(mContext)
5384 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07005385 }
5386 break;
5387 }
5388
5389 case KeyEvent.KEYCODE_ENDCALL: {
5390 result &= ~ACTION_PASS_TO_USER;
5391 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005392 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07005393 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005394 if (telecomManager != null) {
5395 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07005396 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005397 if (interactive && !hungUp) {
5398 mEndCallKeyHandled = false;
5399 mHandler.postDelayed(mEndCallLongPress,
5400 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
5401 } else {
5402 mEndCallKeyHandled = true;
5403 }
Jeff Brown4d396052010-10-29 21:50:21 -07005404 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005405 if (!mEndCallKeyHandled) {
5406 mHandler.removeCallbacks(mEndCallLongPress);
5407 if (!canceled) {
5408 if ((mEndcallBehavior
5409 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
5410 if (goHome()) {
5411 break;
5412 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07005413 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005414 if ((mEndcallBehavior
5415 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
5416 mPowerManager.goToSleep(event.getEventTime(),
5417 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
5418 isWakeKey = false;
5419 }
Jeff Brown4d396052010-10-29 21:50:21 -07005420 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005421 }
Jeff Brown4d396052010-10-29 21:50:21 -07005422 }
5423 break;
5424 }
5425
5426 case KeyEvent.KEYCODE_POWER: {
5427 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07005428 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07005429 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005430 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005431 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005432 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07005433 }
5434 break;
5435 }
5436
Jeff Brown6212a492014-03-07 13:58:47 -08005437 case KeyEvent.KEYCODE_SLEEP: {
5438 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005439 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07005440 if (!mPowerManager.isInteractive()) {
5441 useHapticFeedback = false; // suppress feedback if already non-interactive
5442 }
Nick Vaccarob593a812015-05-15 11:23:05 -07005443 if (down) {
5444 sleepPress(event.getEventTime());
5445 } else {
5446 sleepRelease(event.getEventTime());
5447 }
Jeff Brown6212a492014-03-07 13:58:47 -08005448 break;
5449 }
5450
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -07005451 case KeyEvent.KEYCODE_SOFT_SLEEP: {
5452 result &= ~ACTION_PASS_TO_USER;
5453 isWakeKey = false;
5454 if (!down) {
5455 mPowerManagerInternal.setUserInactiveOverrideFromWindowManager();
5456 }
5457 break;
5458 }
5459
Jeff Brown6212a492014-03-07 13:58:47 -08005460 case KeyEvent.KEYCODE_WAKEUP: {
5461 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005462 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08005463 break;
5464 }
5465
Jeff Brown4d396052010-10-29 21:50:21 -07005466 case KeyEvent.KEYCODE_MEDIA_PLAY:
5467 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5468 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07005469 case KeyEvent.KEYCODE_HEADSETHOOK:
5470 case KeyEvent.KEYCODE_MUTE:
5471 case KeyEvent.KEYCODE_MEDIA_STOP:
5472 case KeyEvent.KEYCODE_MEDIA_NEXT:
5473 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5474 case KeyEvent.KEYCODE_MEDIA_REWIND:
5475 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005476 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
5477 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07005478 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
5479 // If the global session is active pass all media keys to it
5480 // instead of the active window.
5481 result &= ~ACTION_PASS_TO_USER;
5482 }
Jeff Brown4d396052010-10-29 21:50:21 -07005483 if ((result & ACTION_PASS_TO_USER) == 0) {
5484 // Only do this if we would otherwise not pass it to the user. In that
5485 // case, the PhoneWindow class will do the same thing, except it will
5486 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07005487 // Note that we need to make a copy of the key event here because the
5488 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07005489 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07005490 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
5491 new KeyEvent(event));
5492 msg.setAsynchronous(true);
5493 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005494 }
5495 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005496 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005497
Jeff Brown4d396052010-10-29 21:50:21 -07005498 case KeyEvent.KEYCODE_CALL: {
5499 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005500 TelecomManager telecomManager = getTelecommService();
5501 if (telecomManager != null) {
5502 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005503 Log.i(TAG, "interceptKeyBeforeQueueing:"
5504 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005505 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005506
Santos Cordon6848f722014-05-21 15:22:12 -07005507 // And *don't* pass this key thru to the current activity
5508 // (which is presumably the InCallScreen.)
5509 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005510 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005511 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005512 }
Jeff Brown4d396052010-10-29 21:50:21 -07005513 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005514 }
Michael Wright869a67c2014-08-26 19:33:06 -07005515 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5516 // Only do this if we would otherwise not pass it to the user. In that case,
5517 // interceptKeyBeforeDispatching would apply a similar but different policy in
5518 // order to invoke voice assist actions. Note that we need to make a copy of the
5519 // key event here because the original key event will be recycled when we return.
5520 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5521 mBroadcastWakeLock.acquire();
5522 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5523 keyguardActive ? 1 : 0, 0);
5524 msg.setAsynchronous(true);
5525 msg.sendToTarget();
5526 }
Jaewan Kim49117872016-01-19 17:24:08 +09005527 break;
5528 }
5529 case KeyEvent.KEYCODE_WINDOW: {
5530 if (mShortPressWindowBehavior == SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE) {
5531 if (!down) {
Jaewan Kimc552b042016-01-18 16:08:45 +09005532 requestTvPictureInPicture(event);
Jaewan Kim49117872016-01-19 17:24:08 +09005533 }
5534 result &= ~ACTION_PASS_TO_USER;
5535 }
5536 break;
Michael Wright869a67c2014-08-26 19:33:06 -07005537 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005538 }
Jeff Brown26875502014-01-30 21:47:47 -08005539
Jeff Brownbae8e772014-06-12 19:59:45 -07005540 if (useHapticFeedback) {
5541 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5542 }
5543
Jeff Brown26875502014-01-30 21:47:47 -08005544 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005545 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Jeff Brown26875502014-01-30 21:47:47 -08005546 }
Bryce Lee584a4452014-10-21 15:55:55 -07005547
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005548 return result;
5549 }
5550
Jeff Brown1c2e4942012-11-06 16:32:01 -08005551 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005552 * Returns true if the key can have global actions attached to it.
5553 * We reserve all power management keys for the system since they require
5554 * very careful handling.
5555 */
5556 private static boolean isValidGlobalKey(int keyCode) {
5557 switch (keyCode) {
5558 case KeyEvent.KEYCODE_POWER:
5559 case KeyEvent.KEYCODE_WAKEUP:
5560 case KeyEvent.KEYCODE_SLEEP:
5561 return false;
5562 default:
5563 return true;
5564 }
5565 }
5566
5567 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005568 * When the screen is off we ignore some keys that might otherwise typically
5569 * be considered wake keys. We filter them out here.
5570 *
5571 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5572 * is always considered a wake key.
5573 */
5574 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5575 switch (keyCode) {
5576 // ignore volume keys unless docked
5577 case KeyEvent.KEYCODE_VOLUME_UP:
5578 case KeyEvent.KEYCODE_VOLUME_DOWN:
5579 case KeyEvent.KEYCODE_VOLUME_MUTE:
5580 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5581
5582 // ignore media and camera keys
5583 case KeyEvent.KEYCODE_MUTE:
5584 case KeyEvent.KEYCODE_HEADSETHOOK:
5585 case KeyEvent.KEYCODE_MEDIA_PLAY:
5586 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5587 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5588 case KeyEvent.KEYCODE_MEDIA_STOP:
5589 case KeyEvent.KEYCODE_MEDIA_NEXT:
5590 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5591 case KeyEvent.KEYCODE_MEDIA_REWIND:
5592 case KeyEvent.KEYCODE_MEDIA_RECORD:
5593 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005594 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005595 case KeyEvent.KEYCODE_CAMERA:
5596 return false;
5597 }
5598 return true;
5599 }
5600
5601
Jeff Brown56194eb2011-03-02 19:23:13 -08005602 /** {@inheritDoc} */
5603 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005604 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5605 if ((policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005606 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion,
5607 "android.policy:MOTION")) {
Bryce Lee5c138322014-11-03 08:26:09 -08005608 return 0;
5609 }
Michael Wright70af00a2014-09-03 19:30:20 -07005610 }
Bryce Lee5c138322014-11-03 08:26:09 -08005611
Michael Wright70af00a2014-09-03 19:30:20 -07005612 if (shouldDispatchInputWhenNonInteractive()) {
5613 return ACTION_PASS_TO_USER;
5614 }
Bryce Lee5c138322014-11-03 08:26:09 -08005615
Bryce Lee812d7022014-11-10 13:33:28 -08005616 // If we have not passed the action up and we are in theater mode without dreaming,
5617 // there will be no dream to intercept the touch and wake into ambient. The device should
5618 // wake up in this case.
5619 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005620 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming,
5621 "android.policy:MOTION");
Bryce Lee812d7022014-11-10 13:33:28 -08005622 }
5623
Jeff Brown037c33e2014-04-09 00:31:55 -07005624 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005625 }
5626
Michael Wright70af00a2014-09-03 19:30:20 -07005627 private boolean shouldDispatchInputWhenNonInteractive() {
Joe LaPennaf2b9b2d2015-11-17 22:22:37 +00005628 // Send events to keyguard while the screen is on.
5629 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5630 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005631 return true;
5632 }
5633
5634 // Send events to a dozing dream even if the screen is off since the dream
5635 // is in control of the state of the screen.
5636 IDreamManager dreamManager = getDreamManager();
5637
5638 try {
5639 if (dreamManager != null && dreamManager.isDreaming()) {
5640 return true;
5641 }
5642 } catch (RemoteException e) {
5643 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5644 }
5645
5646 // Otherwise, consume events since the user can't see what is being
5647 // interacted with.
5648 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005649 }
5650
RoboErik001c59c2015-01-26 15:53:51 -08005651 private void dispatchDirectAudioEvent(KeyEvent event) {
5652 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5653 return;
5654 }
5655 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005656 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5657 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005658 String pkgName = mContext.getOpPackageName();
5659 switch (keyCode) {
5660 case KeyEvent.KEYCODE_VOLUME_UP:
5661 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005662 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005663 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005664 } catch (RemoteException e) {
5665 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5666 }
5667 break;
5668 case KeyEvent.KEYCODE_VOLUME_DOWN:
5669 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005670 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005671 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005672 } catch (RemoteException e) {
5673 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5674 }
5675 break;
5676 case KeyEvent.KEYCODE_VOLUME_MUTE:
5677 try {
5678 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005679 getAudioService().adjustSuggestedStreamVolume(
5680 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005681 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005682 }
5683 } catch (RemoteException e) {
5684 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5685 }
5686 break;
5687 }
5688 }
5689
Jeff Brown40013652012-05-16 21:22:36 -07005690 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5691 if (DEBUG_INPUT) {
5692 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005693 }
5694
Jeff Brown40013652012-05-16 21:22:36 -07005695 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5696 if (DEBUG_INPUT) {
5697 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5698 }
5699
5700 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5701 mHavePendingMediaKeyRepeatWithWakeLock = false;
5702 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5703 }
5704
5705 dispatchMediaKeyWithWakeLockToAudioService(event);
5706
5707 if (event.getAction() == KeyEvent.ACTION_DOWN
5708 && event.getRepeatCount() == 0) {
5709 mHavePendingMediaKeyRepeatWithWakeLock = true;
5710
5711 Message msg = mHandler.obtainMessage(
5712 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5713 msg.setAsynchronous(true);
5714 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5715 } else {
5716 mBroadcastWakeLock.release();
5717 }
5718 }
5719
5720 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5721 mHavePendingMediaKeyRepeatWithWakeLock = false;
5722
5723 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5724 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5725 if (DEBUG_INPUT) {
5726 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5727 }
5728
5729 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5730 mBroadcastWakeLock.release();
5731 }
5732
5733 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5734 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005735 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005736 }
5737 }
5738
Michael Wright869a67c2014-08-26 19:33:06 -07005739 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005740 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5741 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5742 if (dic != null) {
5743 try {
5744 dic.exitIdle("voice-search");
5745 } catch (RemoteException e) {
5746 }
5747 }
Michael Wright869a67c2014-08-26 19:33:06 -07005748 Intent voiceIntent =
5749 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5750 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005751 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005752 mBroadcastWakeLock.release();
5753 }
5754
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005755 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005756 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005757 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005758 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5759 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5760 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005761 } else {
5762 try {
5763 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5764 ServiceManager.getService(Context.UI_MODE_SERVICE));
5765 mUiMode = uiModeService.getCurrentModeType();
5766 } catch (RemoteException e) {
5767 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005768 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005769 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005770 synchronized (mLock) {
5771 updateOrientationListenerLp();
5772 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005773 }
5774 };
5775
Jeff Brown6aaf2952012-10-05 16:01:08 -07005776 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5777 @Override
5778 public void onReceive(Context context, Intent intent) {
5779 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005780 if (mKeyguardDelegate != null) {
5781 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005782 }
5783 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005784 if (mKeyguardDelegate != null) {
5785 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005786 }
5787 }
5788 }
5789 };
5790
Christopher Tate5e08af02012-09-21 17:17:22 -07005791 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5792 @Override
5793 public void onReceive(Context context, Intent intent) {
5794 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5795 // tickle the settings observer: this first ensures that we're
5796 // observing the relevant settings for the newly-active user,
5797 // and then updates our own bookkeeping based on the now-
5798 // current user.
5799 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005800
5801 // force a re-application of focused window sysui visibility.
5802 // the window may never have been shown for this user
5803 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005804 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005805 mLastSystemUiFlags = 0;
5806 updateSystemUiVisibilityLw();
5807 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005808 }
5809 }
5810 };
5811
Adrian Roosddc8b272015-05-21 16:28:27 -07005812 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005813 @Override
5814 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005815 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5816 if (!isUserSetupComplete()) {
5817 // Swipe-up for navigation bar is disabled during setup
5818 return;
5819 }
5820 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5821 mNavigationBarController.showTransient();
5822 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005823 }
5824 };
5825
John Spurlocke1f366f2013-08-05 12:22:40 -04005826 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005827 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005828 if (!isUserSetupComplete()) {
5829 // Swipe-up for navigation bar is disabled during setup
5830 return;
5831 }
John Spurlock27735a42013-08-14 17:57:38 -04005832 boolean sb = mStatusBarController.checkShowTransientBarLw();
5833 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005834 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005835 // Don't show status bar when swiping on already visible navigation bar
5836 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005837 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005838 return;
5839 }
John Spurlock27735a42013-08-14 17:57:38 -04005840 if (sb) mStatusBarController.showTransient();
5841 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005842 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005843 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005844 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005845 }
5846 }
5847
Jeff Brown3ee549c2014-09-22 20:14:39 -07005848 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005849 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005850 public void startedGoingToSleep(int why) {
5851 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005852 if (mKeyguardDelegate != null) {
5853 mKeyguardDelegate.onStartedGoingToSleep(why);
5854 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005855 }
5856
5857 // Called on the PowerManager's Notifier thread.
5858 @Override
5859 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005860 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005861 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04005862 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005863
5864 // We must get this work done here because the power manager will drop
5865 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005866 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005867 mAwake = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005868 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005869 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005870 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005871 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005872 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005873 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005874 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005875 }
5876
Jeff Brown3ee549c2014-09-22 20:14:39 -07005877 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005878 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005879 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005880 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005881 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005882
Jeff Brown3ee549c2014-09-22 20:14:39 -07005883 // Since goToSleep performs these functions synchronously, we must
5884 // do the same here. We cannot post this work to a handler because
5885 // that might cause it to become reordered with respect to what
5886 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005887 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005888 mAwake = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005889
Jeff Browna20dda42014-05-27 20:57:24 -07005890 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005891 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005892 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005893 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005894
Jim Miller5ecd8112013-01-09 18:50:26 -08005895 if (mKeyguardDelegate != null) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005896 mKeyguardDelegate.onStartedWakingUp();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005897 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005898 }
5899
Jeff Brown416c49c2015-05-26 19:50:18 -07005900 // Called on the PowerManager's Notifier thread.
5901 @Override
5902 public void finishedWakingUp() {
5903 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5904 }
5905
5906 private void wakeUpFromPowerKey(long eventTime) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005907 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER");
Jeff Brown416c49c2015-05-26 19:50:18 -07005908 }
5909
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005910 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) {
Bryce Leed3896842015-06-23 17:06:51 -07005911 final boolean theaterModeEnabled = isTheaterModeEnabled();
5912 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07005913 return false;
5914 }
5915
Bryce Leed3896842015-06-23 17:06:51 -07005916 if (theaterModeEnabled) {
5917 Settings.Global.putInt(mContext.getContentResolver(),
5918 Settings.Global.THEATER_MODE_ON, 0);
5919 }
5920
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005921 mPowerManager.wakeUp(wakeTime, reason);
Jeff Brown416c49c2015-05-26 19:50:18 -07005922 return true;
5923 }
5924
Jeff Brown36c4db82014-09-19 12:05:31 -07005925 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005926 synchronized (mLock) {
Jorim Jaggif3255482015-07-24 12:32:42 -07005927 if (!mScreenOnEarly || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005928 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005929 }
5930
Jeff Brown36c4db82014-09-19 12:05:31 -07005931 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005932 if (mKeyguardDelegate != null) {
5933 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5934 }
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005935 mWindowManagerDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005936 }
5937
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005938 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
5939 // as well as enabling the orientation change logic/sensor.
5940 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5941 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005942 }
5943
5944 // Called on the DisplayManager's DisplayPowerController thread.
5945 @Override
5946 public void screenTurnedOff() {
5947 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5948
Jeff Brown48d1b142015-06-10 16:36:03 -07005949 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005950 synchronized (mLock) {
5951 mScreenOnEarly = false;
5952 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005953 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005954 mWindowManagerDrawComplete = false;
5955 mScreenOnListener = null;
5956 updateOrientationListenerLp();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005957
5958 if (mKeyguardDelegate != null) {
5959 mKeyguardDelegate.onScreenTurnedOff();
5960 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005961 }
5962 }
5963
Jeff Brown3ee549c2014-09-22 20:14:39 -07005964 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005965 @Override
5966 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005967 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005968
Jeff Brown48d1b142015-06-10 16:36:03 -07005969 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005970 synchronized (mLock) {
5971 mScreenOnEarly = true;
5972 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005973 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005974 mWindowManagerDrawComplete = false;
5975 mScreenOnListener = screenOnListener;
Jeff Brown36c4db82014-09-19 12:05:31 -07005976
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005977 if (mKeyguardDelegate != null) {
Jorim Jaggia4b51bc2015-08-10 18:20:43 -07005978 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5979 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005980 mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback);
5981 } else {
5982 if (DEBUG_WAKEUP) Slog.d(TAG,
5983 "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
5984 finishKeyguardDrawn();
5985 }
5986 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005987 }
5988
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005989 // Called on the DisplayManager's DisplayPowerController thread.
5990 @Override
5991 public void screenTurnedOn() {
5992 synchronized (mLock) {
5993 if (mKeyguardDelegate != null) {
5994 mKeyguardDelegate.onScreenTurnedOn();
5995 }
5996 }
5997 }
5998
Jeff Brown36c4db82014-09-19 12:05:31 -07005999 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006000 synchronized (mLock) {
6001 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10006002 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07006003 }
6004
Jeff Brown36c4db82014-09-19 12:05:31 -07006005 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07006006 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006007
6008 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07006009 }
6010
Craig Mautner8a0da012014-05-31 15:13:37 -07006011 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10006012 synchronized (mLock) {
6013 // We have just finished drawing screen content. Since the orientation listener
6014 // gets only installed when all windows are drawn, we try to install it again.
6015 updateOrientationListenerLp();
6016 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006017 final ScreenOnListener listener;
6018 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07006019 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006020 if (DEBUG_WAKEUP) Slog.d(TAG,
6021 "finishScreenTurningOn: mAwake=" + mAwake
6022 + ", mScreenOnEarly=" + mScreenOnEarly
6023 + ", mScreenOnFully=" + mScreenOnFully
6024 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
6025 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
6026
6027 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
6028 || (mAwake && !mKeyguardDrawComplete)) {
6029 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07006030 }
6031
Jeff Brown3ee549c2014-09-22 20:14:39 -07006032 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
6033 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07006034 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006035 mScreenOnFully = true;
6036
6037 // Remember the first time we draw the keyguard so we know when we're done with
6038 // the main part of booting and can enable the screen and hide boot messages.
6039 if (!mKeyguardDrawnOnce && mAwake) {
6040 mKeyguardDrawnOnce = true;
6041 enableScreen = true;
6042 if (mBootMessageNeedsHiding) {
6043 mBootMessageNeedsHiding = false;
6044 hideBootMessages();
6045 }
6046 } else {
6047 enableScreen = false;
6048 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006049 }
6050
Jeff Brown3ee549c2014-09-22 20:14:39 -07006051 if (listener != null) {
6052 listener.onScreenOn();
6053 }
Jeff Brown4fc45272012-10-10 18:28:14 -07006054
Jeff Brown3ee549c2014-09-22 20:14:39 -07006055 if (enableScreen) {
6056 try {
6057 mWindowManager.enableScreenIfNeeded();
6058 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07006059 }
Craig Mautnera631d492014-08-05 15:16:01 -07006060 }
6061 }
6062
6063 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006064 synchronized (mLock) {
6065 if (!mKeyguardDrawnOnce) {
6066 mBootMessageNeedsHiding = true;
6067 return; // keyguard hasn't drawn the first time yet, not done booting
6068 }
Craig Mautnera631d492014-08-05 15:16:01 -07006069 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006070
6071 if (mBootMsgDialog != null) {
6072 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
6073 mBootMsgDialog.dismiss();
6074 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07006075 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006076 }
6077
6078 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07006079 public boolean isScreenOn() {
6080 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08006081 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006082
Dianne Hackborn08743722009-12-21 12:16:51 -08006083 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006084 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006085 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006086 if (mKeyguardDelegate != null) {
6087 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006088 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006089 }
6090
6091 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006092 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006093 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006094 if (mKeyguardDelegate != null) {
6095 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006096 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006097 }
6098
Jim Millerab954542014-10-10 18:21:49 -07006099 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006100 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07006101 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006102 }
6103
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006104 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006105 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006106 public boolean isKeyguardLocked() {
6107 return keyguardOn();
6108 }
6109
6110 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006111 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006112 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006113 if (mKeyguardDelegate == null) return false;
6114 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006115 }
6116
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006117 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006118 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07006119 public boolean isKeyguardShowingOrOccluded() {
6120 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
6121 }
6122
6123 /** {@inheritDoc} */
6124 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006125 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006126 if (mKeyguardDelegate == null) return false;
6127 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006128 }
6129
Jose Lima9546b202014-07-02 17:21:51 -07006130 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006131 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07006132 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006133 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05006134 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07006135 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05006136 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02006137 // ask the keyguard to prompt the user to authenticate if necessary
6138 mKeyguardDelegate.dismiss();
6139 }
6140 });
6141 }
6142 }
6143
6144 public void notifyActivityDrawnForKeyguardLw() {
6145 if (mKeyguardDelegate != null) {
6146 mHandler.post(new Runnable() {
6147 @Override
6148 public void run() {
6149 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05006150 }
6151 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006152 }
6153 }
6154
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006155 @Override
6156 public boolean isKeyguardDrawnLw() {
6157 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006158 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006159 }
6160 }
6161
Jorim Jaggi0d674622014-05-21 01:34:15 +02006162 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006163 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02006164 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006165 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006166 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02006167 }
6168 }
6169
Jorim Jaggi737af722015-12-31 10:42:27 +01006170 @Override
6171 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6172 Rect outInsets) {
6173 outInsets.setEmpty();
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006174
6175 // Navigation bar and status bar.
6176 getNonDecorInsetsLw(displayRotation, displayWidth, displayHeight, outInsets);
Jorim Jaggi737af722015-12-31 10:42:27 +01006177 if (mStatusBar != null) {
6178 outInsets.top = mStatusBarHeight;
6179 }
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006180 }
6181
6182 @Override
6183 public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6184 Rect outInsets) {
6185 outInsets.setEmpty();
6186
6187 // Only navigation bar
Jorim Jaggi737af722015-12-31 10:42:27 +01006188 if (mNavigationBar != null) {
6189 if (isNavigationBarOnBottom(displayWidth, displayHeight)) {
6190 outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode);
6191 } else {
6192 outInsets.right = getNavigationBarWidth(displayRotation, mUiMode);
6193 }
6194 }
6195 }
6196
Jorim Jaggi5060bd82016-02-19 17:12:19 -08006197 @Override
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08006198 public boolean isNavBarForcedShownLw(WindowState windowState) {
6199 return mForceShowSystemBars
6200 && !windowState.getFrameLw().equals(windowState.getDisplayFrameLw());
6201 }
6202
6203 @Override
Jorim Jaggi5060bd82016-02-19 17:12:19 -08006204 public boolean isDockSideAllowed(int dockSide) {
6205
6206 // We do not allow all dock sides at which the navigation bar touches the docked stack.
6207 if (!mNavigationBarCanMove) {
6208 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT || dockSide == DOCKED_RIGHT;
6209 } else {
6210 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT;
6211 }
6212 }
6213
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006214 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006215 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006216 }
6217
6218 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006219 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006220 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07006221
Jeff Brown01a98dd2011-09-20 15:08:29 -07006222 @Override
6223 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006224 if (false) {
6225 Slog.v(TAG, "rotationForOrientationLw(orient="
6226 + orientation + ", last=" + lastRotation
6227 + "); user=" + mUserRotation + " "
6228 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
6229 ? "USER_ROTATION_LOCKED" : "")
6230 );
6231 }
6232
Craig Mautner46ac6fa2013-08-01 10:06:34 -07006233 if (mForceDefaultOrientation) {
6234 return Surface.ROTATION_0;
6235 }
6236
The Android Open Source Project0727d222009-03-11 12:11:58 -07006237 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07006238 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
6239 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07006240 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07006241 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006242
Jeff Browndec6cf42011-11-15 14:08:20 -08006243 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07006244 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006245 // Ignore sensor when lid switch is open and rotation is forced.
6246 preferredRotation = mLidOpenRotation;
6247 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07006248 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006249 // Ignore sensor when in car dock unless explicitly enabled.
6250 // This case can override the behavior of NOSENSOR, and can also
6251 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006252 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006253 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08006254 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6255 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
6256 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07006257 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006258 // Ignore sensor when in desk dock unless explicitly enabled.
6259 // This case can override the behavior of NOSENSOR, and can also
6260 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006261 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006262 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006263 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
6264 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08006265 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006266 preferredRotation = mDemoHdmiRotation;
6267 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
6268 && mUndockedHdmiRotation >= 0) {
6269 // Ignore sensor when plugged into HDMI and an undocked orientation has
6270 // been specified in the configuration (only for legacy devices without
6271 // full multi-display support).
6272 // Note that the dock orientation overrides the HDMI orientation.
6273 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08006274 } else if (mDemoRotationLock) {
6275 // Ignore sensor when demo rotation lock is enabled.
6276 // Note that the dock orientation and HDMI rotation lock override this.
6277 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006278 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
6279 // Application just wants to remain locked in the last rotation.
6280 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08006281 } else if (!mSupportAutoRotation) {
6282 // If we don't support auto-rotation then bail out here and ignore
6283 // the sensor and any rotation lock settings.
6284 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07006285 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07006286 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006287 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
6288 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
6289 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
6290 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07006291 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
6292 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6293 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
6294 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
6295 // Otherwise, use sensor only if requested by the application or enabled
6296 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07006297 if (mAllowAllRotations < 0) {
6298 // Can't read this during init() because the context doesn't
6299 // have display metrics at that time so we cannot determine
6300 // tablet vs. phone then.
6301 mAllowAllRotations = mContext.getResources().getBoolean(
6302 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
6303 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006304 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07006305 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006306 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6307 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006308 preferredRotation = sensorRotation;
6309 } else {
6310 preferredRotation = lastRotation;
6311 }
Jeff Brown207673cd2012-06-05 17:47:11 -07006312 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
6313 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
6314 // Apply rotation lock. Does not apply to NOSENSOR.
6315 // The idea is that the user rotation expresses a weak preference for the direction
6316 // of gravity and as NOSENSOR is never affected by gravity, then neither should
6317 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07006318 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08006319 } else {
6320 // No overriding preference.
6321 // We will do exactly what the application asked us to do.
6322 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07006323 }
6324
Dianne Hackborne5439f22010-10-02 16:53:50 -07006325 switch (orientation) {
6326 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006327 // Return portrait unless overridden.
6328 if (isAnyPortrait(preferredRotation)) {
6329 return preferredRotation;
6330 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07006331 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006332
Jeff Brown01a98dd2011-09-20 15:08:29 -07006333 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006334 // Return landscape unless overridden.
6335 if (isLandscapeOrSeascape(preferredRotation)) {
6336 return preferredRotation;
6337 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006338 return mLandscapeRotation;
6339
6340 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006341 // Return reverse portrait unless overridden.
6342 if (isAnyPortrait(preferredRotation)) {
6343 return preferredRotation;
6344 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006345 return mUpsideDownRotation;
6346
6347 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006348 // Return seascape unless overridden.
6349 if (isLandscapeOrSeascape(preferredRotation)) {
6350 return preferredRotation;
6351 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006352 return mSeascapeRotation;
6353
6354 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006355 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006356 // Return either landscape rotation.
6357 if (isLandscapeOrSeascape(preferredRotation)) {
6358 return preferredRotation;
6359 }
6360 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08006361 return lastRotation;
6362 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006363 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006364
Jeff Brown01a98dd2011-09-20 15:08:29 -07006365 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006366 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006367 // Return either portrait rotation.
6368 if (isAnyPortrait(preferredRotation)) {
6369 return preferredRotation;
6370 }
6371 if (isAnyPortrait(lastRotation)) {
6372 return lastRotation;
6373 }
6374 return mPortraitRotation;
6375
6376 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07006377 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
6378 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07006379 if (preferredRotation >= 0) {
6380 return preferredRotation;
6381 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07006382 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05006383 }
6384 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006385 }
6386
Jeff Brown01a98dd2011-09-20 15:08:29 -07006387 @Override
6388 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
6389 switch (orientation) {
6390 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
6391 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
6392 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
6393 return isAnyPortrait(rotation);
6394
6395 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
6396 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
6397 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
6398 return isLandscapeOrSeascape(rotation);
6399
6400 default:
6401 return true;
6402 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006403 }
6404
Jeff Brownc0347aa2011-09-23 17:26:09 -07006405 @Override
6406 public void setRotationLw(int rotation) {
6407 mOrientationListener.setCurrentRotation(rotation);
6408 }
6409
Jeff Brown01a98dd2011-09-20 15:08:29 -07006410 private boolean isLandscapeOrSeascape(int rotation) {
6411 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006412 }
6413
Jeff Brown01a98dd2011-09-20 15:08:29 -07006414 private boolean isAnyPortrait(int rotation) {
6415 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006416 }
6417
Jose Lima9546b202014-07-02 17:21:51 -07006418 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006419 public int getUserRotationMode() {
6420 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07006421 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
6422 WindowManagerPolicy.USER_ROTATION_FREE :
6423 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006424 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006425
6426 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07006427 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006428 public void setUserRotationMode(int mode, int rot) {
6429 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006430
6431 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006432 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07006433 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006434 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006435 rot,
6436 UserHandle.USER_CURRENT);
6437 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006438 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006439 0,
6440 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006441 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07006442 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006443 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006444 1,
6445 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006446 }
6447 }
6448
Jose Lima9546b202014-07-02 17:21:51 -07006449 @Override
Jeff Brownac143512012-04-05 18:57:33 -07006450 public void setSafeMode(boolean safeMode) {
6451 mSafeMode = safeMode;
6452 performHapticFeedbackLw(null, safeMode
6453 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
6454 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006455 }
Craig Mautnereda67292013-04-28 13:50:14 -07006456
Dianne Hackborn181ceb52009-08-27 22:16:40 -07006457 static long[] getLongIntArray(Resources r, int resid) {
6458 int[] ar = r.getIntArray(resid);
6459 if (ar == null) {
6460 return null;
6461 }
6462 long[] out = new long[ar.length];
6463 for (int i=0; i<ar.length; i++) {
6464 out[i] = ar[i];
6465 }
6466 return out;
6467 }
Craig Mautnereda67292013-04-28 13:50:14 -07006468
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006469 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006470 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006471 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07006472 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08006473 mKeyguardDelegate.onSystemReady();
6474
Michael Wright3818c922014-09-02 13:59:07 -07006475 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07006476 updateUiMode();
Adrian Roos3542f7d2015-07-13 15:57:53 -07006477 boolean bindKeyguardNow;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006478 synchronized (mLock) {
6479 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08006480 mSystemReady = true;
6481 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006482 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08006483 public void run() {
6484 updateSettings();
6485 }
6486 });
Adrian Roos3542f7d2015-07-13 15:57:53 -07006487
6488 bindKeyguardNow = mDeferBindKeyguard;
6489 if (bindKeyguardNow) {
6490 // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now.
6491 mDeferBindKeyguard = false;
6492 }
6493 }
6494
6495 if (bindKeyguardNow) {
6496 mKeyguardDelegate.bindService(mContext);
6497 mKeyguardDelegate.onBootCompleted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006498 }
Michael Wrighta4d22d72015-09-16 23:19:26 +01006499 mSystemGestures.systemReady();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006500 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006501
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006502 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006503 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006504 public void systemBooted() {
Adrian Roos3542f7d2015-07-13 15:57:53 -07006505 boolean bindKeyguardNow = false;
6506 synchronized (mLock) {
6507 // Time to bind Keyguard; take care to only bind it once, either here if ready or
6508 // in systemReady if not.
6509 if (mKeyguardDelegate != null) {
6510 bindKeyguardNow = true;
6511 } else {
6512 // Because mKeyguardDelegate is null, we know that the synchronized block in
6513 // systemReady didn't run yet and setting this will actually have an effect.
6514 mDeferBindKeyguard = true;
6515 }
6516 }
6517 if (bindKeyguardNow) {
Jason Monk5eeebf52014-09-26 12:36:51 -04006518 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07006519 mKeyguardDelegate.onBootCompleted();
6520 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006521 synchronized (mLock) {
6522 mSystemBooted = true;
6523 }
Jeff Brown416c49c2015-05-26 19:50:18 -07006524 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07006525 screenTurningOn(null);
Jorim Jaggic0496072015-08-19 15:14:52 -07006526 screenTurnedOn();
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006527 }
6528
Dianne Hackborn661cd522011-08-22 00:26:20 -07006529 ProgressDialog mBootMsgDialog = null;
6530
6531 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006532 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006533 public void showBootMessage(final CharSequence msg, final boolean always) {
6534 mHandler.post(new Runnable() {
6535 @Override public void run() {
6536 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006537 int theme;
Jaewan Kim49117872016-01-19 17:24:08 +09006538 if (mContext.getPackageManager().hasSystemFeature(FEATURE_WATCH)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006539 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
Jaewan Kim49117872016-01-19 17:24:08 +09006540 } else if (mContext.getPackageManager().hasSystemFeature(FEATURE_TELEVISION)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006541 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
6542 } else {
6543 theme = 0;
6544 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07006545
6546 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07006547 // This dialog will consume all events coming in to
6548 // it, to avoid it trying to do things too early in boot.
6549 @Override public boolean dispatchKeyEvent(KeyEvent event) {
6550 return true;
6551 }
6552 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
6553 return true;
6554 }
6555 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
6556 return true;
6557 }
6558 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
6559 return true;
6560 }
6561 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
6562 return true;
6563 }
6564 @Override public boolean dispatchPopulateAccessibilityEvent(
6565 AccessibilityEvent event) {
6566 return true;
6567 }
6568 };
Jeff Hao9f60c082014-10-28 18:51:07 -07006569 if (mContext.getPackageManager().isUpgrade()) {
6570 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
6571 } else {
6572 mBootMsgDialog.setTitle(R.string.android_start_title);
6573 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006574 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
6575 mBootMsgDialog.setIndeterminate(true);
6576 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07006577 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006578 mBootMsgDialog.getWindow().addFlags(
6579 WindowManager.LayoutParams.FLAG_DIM_BEHIND
6580 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
6581 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08006582 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
6583 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
6584 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006585 mBootMsgDialog.setCancelable(false);
6586 mBootMsgDialog.show();
6587 }
6588 mBootMsgDialog.setMessage(msg);
6589 }
6590 });
6591 }
6592
6593 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006594 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006595 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07006596 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006597 }
6598
Mike Lockwood28569302010-01-28 11:54:40 -05006599 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006600 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006601 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006602 // ***************************************
6603 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
6604 // ***************************************
6605 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
6606 // WITH ITS LOCKS HELD.
6607 //
6608 // This code must be VERY careful about the locks
6609 // it acquires.
6610 // In fact, the current code acquires way too many,
6611 // and probably has lurking deadlocks.
6612
Mike Lockwood28569302010-01-28 11:54:40 -05006613 synchronized (mScreenLockTimeout) {
6614 if (mLockScreenTimerActive) {
6615 // reset the timer
6616 mHandler.removeCallbacks(mScreenLockTimeout);
6617 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6618 }
6619 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006620 }
6621
Adam Cohenf7522022012-10-03 20:03:18 -07006622 class ScreenLockTimeout implements Runnable {
6623 Bundle options;
6624
6625 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006626 public void run() {
6627 synchronized (this) {
6628 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006629 if (mKeyguardDelegate != null) {
6630 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006631 }
Mike Lockwood28569302010-01-28 11:54:40 -05006632 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006633 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006634 }
6635 }
Mike Lockwood28569302010-01-28 11:54:40 -05006636
Adam Cohenf7522022012-10-03 20:03:18 -07006637 public void setLockOptions(Bundle options) {
6638 this.options = options;
6639 }
6640 }
6641
6642 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6643
Jose Lima9546b202014-07-02 17:21:51 -07006644 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006645 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006646 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6647 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006648 if (options != null) {
6649 // In case multiple calls are made to lockNow, we don't wipe out the options
6650 // until the runnable actually executes.
6651 mScreenLockTimeout.setLockOptions(options);
6652 }
Jim Miller93c518e2012-01-17 15:55:31 -08006653 mHandler.post(mScreenLockTimeout);
6654 }
6655
Mike Lockwood28569302010-01-28 11:54:40 -05006656 private void updateLockScreenTimeout() {
6657 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006658 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006659 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006660 if (mLockScreenTimerActive != enable) {
6661 if (enable) {
6662 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
Jim Miller2967f482016-01-07 15:05:32 -08006663 mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests
Mike Lockwood28569302010-01-28 11:54:40 -05006664 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6665 } else {
6666 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6667 mHandler.removeCallbacks(mScreenLockTimeout);
6668 }
6669 mLockScreenTimerActive = enable;
6670 }
6671 }
6672 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006673
Jeff Brown061ea992015-04-17 19:55:47 -07006674 private void updateDreamingSleepToken(boolean acquire) {
6675 if (acquire) {
6676 if (mDreamingSleepToken == null) {
6677 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6678 }
6679 } else {
6680 if (mDreamingSleepToken != null) {
6681 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006682 mDreamingSleepToken = null;
6683 }
6684 }
6685 }
6686
6687 private void updateScreenOffSleepToken(boolean acquire) {
6688 if (acquire) {
6689 if (mScreenOffSleepToken == null) {
6690 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6691 }
6692 } else {
6693 if (mScreenOffSleepToken != null) {
6694 mScreenOffSleepToken.release();
6695 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006696 }
6697 }
6698 }
6699
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006700 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006701 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006702 public void enableScreenAfterBoot() {
6703 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006704 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006705 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006706 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006707
Jeff Brownc458ce92012-04-30 14:58:40 -07006708 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006709 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006710 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006711 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006712 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01006713 } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) {
6714 mWindowManagerFuncs.lockDeviceNow();
Jeff Brownc458ce92012-04-30 14:58:40 -07006715 }
Jeff Browna20dda42014-05-27 20:57:24 -07006716
6717 synchronized (mLock) {
6718 updateWakeGestureListenerLp();
6719 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006720 }
6721
Jeff Brown4f5fa282014-06-12 19:19:15 -07006722 void updateUiMode() {
6723 if (mUiModeManager == null) {
6724 mUiModeManager = IUiModeManager.Stub.asInterface(
6725 ServiceManager.getService(Context.UI_MODE_SERVICE));
6726 }
6727 try {
6728 mUiMode = mUiModeManager.getCurrentModeType();
6729 } catch (RemoteException e) {
6730 }
6731 }
6732
Jeff Brown01a98dd2011-09-20 15:08:29 -07006733 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006734 try {
6735 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006736 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6737 } catch (RemoteException e) {
6738 // Ignore
6739 }
6740 }
6741
6742 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6743 try {
6744 //set orientation on WindowManager
6745 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006746 } catch (RemoteException e) {
6747 // Ignore
6748 }
6749 }
6750
Daniel Sandler6396c722013-04-16 20:19:09 -04006751 /**
6752 * Return an Intent to launch the currently active dock app as home. Returns
6753 * null if the standard home should be launched, which is the case if any of the following is
6754 * true:
6755 * <ul>
6756 * <li>The device is not in either car mode or desk mode
keunyounga7710492015-09-23 11:33:58 -07006757 * <li>The device is in car mode but mEnableCarDockHomeCapture is false
Daniel Sandler6396c722013-04-16 20:19:09 -04006758 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6759 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6760 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6761 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006762 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006763 */
6764 Intent createHomeDockIntent() {
6765 Intent intent = null;
6766
6767 // What home does is based on the mode, not the dock state. That
6768 // is, when in car mode you should be taken to car home regardless
6769 // of whether we are actually in a car dock.
6770 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
keunyounga7710492015-09-23 11:33:58 -07006771 if (mEnableCarDockHomeCapture) {
Daniel Sandler6396c722013-04-16 20:19:09 -04006772 intent = mCarDockIntent;
6773 }
6774 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6775 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6776 intent = mDeskDockIntent;
6777 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006778 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6779 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6780 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6781 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6782 // Always launch dock home from home when watch is docked, if it exists.
6783 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006784 }
6785
6786 if (intent == null) {
6787 return null;
6788 }
6789
6790 ActivityInfo ai = null;
6791 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6792 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006793 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006794 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006795 if (info != null) {
6796 ai = info.activityInfo;
6797 }
6798 if (ai != null
6799 && ai.metaData != null
6800 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6801 intent = new Intent(intent);
6802 intent.setClassName(ai.packageName, ai.name);
6803 return intent;
6804 }
6805
6806 return null;
6807 }
6808
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006809 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6810 if (awakenFromDreams) {
6811 awakenDreams();
6812 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006813
6814 Intent dock = createHomeDockIntent();
6815 if (dock != null) {
6816 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006817 if (fromHomeKey) {
6818 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6819 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006820 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006821 return;
6822 } catch (ActivityNotFoundException e) {
6823 }
6824 }
6825
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006826 Intent intent;
6827
6828 if (fromHomeKey) {
6829 intent = new Intent(mHomeIntent);
6830 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6831 } else {
6832 intent = mHomeIntent;
6833 }
6834
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006835 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006836 }
Craig Mautnereda67292013-04-28 13:50:14 -07006837
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006838 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006839 * goes to the home screen
6840 * @return whether it did anything
6841 */
6842 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006843 if (!isUserSetupComplete()) {
6844 Slog.i(TAG, "Not going home because user setup is in progress.");
6845 return false;
6846 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006847 if (false) {
6848 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006849 try {
6850 ActivityManagerNative.getDefault().stopAppSwitches();
6851 } catch (RemoteException e) {
6852 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006853 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006854 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006855 } else {
6856 // This code brings home to the front or, if it is already
6857 // at the front, puts the device to sleep.
6858 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006859 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6860 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6861 Log.d(TAG, "UTS-TEST-MODE");
6862 } else {
6863 ActivityManagerNative.getDefault().stopAppSwitches();
6864 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006865 Intent dock = createHomeDockIntent();
6866 if (dock != null) {
6867 int result = ActivityManagerNative.getDefault()
6868 .startActivityAsUser(null, null, dock,
6869 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6870 null, null, 0,
6871 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006872 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006873 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6874 return false;
6875 }
6876 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006877 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006878 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006879 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006880 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006881 null, null, 0,
6882 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006883 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006884 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006885 return false;
6886 }
6887 } catch (RemoteException ex) {
6888 // bummer, the activity manager, which is in this process, is dead
6889 }
6890 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006891 return true;
6892 }
Craig Mautnereda67292013-04-28 13:50:14 -07006893
6894 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006895 public void setCurrentOrientationLw(int newOrientation) {
6896 synchronized (mLock) {
6897 if (newOrientation != mCurrentAppOrientation) {
6898 mCurrentAppOrientation = newOrientation;
6899 updateOrientationListenerLp();
6900 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006901 }
6902 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006903
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006904 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6905 if (!isGlobalAccessibilityGestureEnabled()) {
6906 return;
6907 }
6908 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6909 Context.AUDIO_SERVICE);
6910 if (audioManager.isSilentMode()) {
6911 return;
6912 }
6913 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6914 Settings.System.DEFAULT_NOTIFICATION_URI);
6915 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6916 ringTone.play();
6917 }
Craig Mautnereda67292013-04-28 13:50:14 -07006918
Bryce Lee584a4452014-10-21 15:55:55 -07006919 private boolean isTheaterModeEnabled() {
6920 return Settings.Global.getInt(mContext.getContentResolver(),
6921 Settings.Global.THEATER_MODE_ON, 0) == 1;
6922 }
6923
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006924 private boolean isGlobalAccessibilityGestureEnabled() {
6925 return Settings.Global.getInt(mContext.getContentResolver(),
6926 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6927 }
6928
Craig Mautnereda67292013-04-28 13:50:14 -07006929 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006930 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006931 if (!mVibrator.hasVibrator()) {
6932 return false;
6933 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006934 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6935 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006936 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006937 return false;
6938 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006939 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006940 switch (effectId) {
6941 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006942 pattern = mLongPressVibePattern;
6943 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006944 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006945 pattern = mVirtualKeyVibePattern;
6946 break;
6947 case HapticFeedbackConstants.KEYBOARD_TAP:
6948 pattern = mKeyboardTapVibePattern;
6949 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006950 case HapticFeedbackConstants.CLOCK_TICK:
6951 pattern = mClockTickVibePattern;
6952 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006953 case HapticFeedbackConstants.CALENDAR_DATE:
6954 pattern = mCalendarDateVibePattern;
6955 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006956 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006957 pattern = mSafeModeDisabledVibePattern;
6958 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006959 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006960 pattern = mSafeModeEnabledVibePattern;
6961 break;
Mady Mellore8608912015-06-05 09:02:55 -07006962 case HapticFeedbackConstants.CONTEXT_CLICK:
6963 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006964 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006965 default:
6966 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006967 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006968 int owningUid;
6969 String owningPackage;
6970 if (win != null) {
6971 owningUid = win.getOwningUid();
6972 owningPackage = win.getOwningPackage();
6973 } else {
6974 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006975 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006976 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006977 if (pattern.length == 1) {
6978 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006979 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006980 } else {
6981 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006982 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006983 }
6984 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006985 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006986
6987 @Override
6988 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006989 }
6990
Jeff Brownc38c9be2012-10-04 13:16:19 -07006991 @Override
6992 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006993 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006994 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006995 }
6996 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006997
Dianne Hackborndf89e652011-10-06 22:35:11 -07006998 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006999 // If there is no window focused, there will be nobody to handle the events
7000 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01007001 final WindowState win = mFocusedWindow != null ? mFocusedWindow
7002 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04007003 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07007004 return 0;
7005 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01007006 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007007 // We are updating at a point where the keyguard has gotten
7008 // focus, but we were last in a state where the top window is
7009 // hiding it. This is probably because the keyguard as been
7010 // shown while the top window was displayed, so we want to ignore
7011 // it here because this is just a very transient change and it
7012 // will quickly lose focus once it correctly gets hidden.
7013 return 0;
7014 }
John Spurlock32beb2c2013-03-11 10:16:47 -04007015
John Spurlock1db8b682014-02-18 11:18:59 -05007016 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07007017 & ~mResettingSystemUiFlags
7018 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04007019 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05007020 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007021 }
Thanh Hai Mai6c009f52015-09-01 16:27:32 -07007022
7023 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
7024 tmpVisibility |= StatusBarManager.DISABLE_RECENT;
7025 }
7026
Jorim Jaggi86905582016-02-09 21:36:09 -08007027 final int fullscreenVisibility = updateLightStatusBarLw(0 /* vis */,
7028 mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState);
7029 final int dockedVisibility = updateLightStatusBarLw(0 /* vis */,
7030 mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState);
7031 mWindowManagerFuncs.getStackBounds(HOME_STACK_ID, mNonDockedStackBounds);
7032 mWindowManagerFuncs.getStackBounds(DOCKED_STACK_ID, mDockedStackBounds);
John Spurlock79da8332013-09-20 12:04:47 -04007033 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04007034 final int diff = visibility ^ mLastSystemUiFlags;
Jorim Jaggi86905582016-02-09 21:36:09 -08007035 final int fullscreenDiff = fullscreenVisibility ^ mLastFullscreenStackSysUiFlags;
7036 final int dockedDiff = dockedVisibility ^ mLastDockedStackSysUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04007037 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Jorim Jaggi86905582016-02-09 21:36:09 -08007038 if (diff == 0 && fullscreenDiff == 0 && dockedDiff == 0 && mLastFocusNeedsMenu == needsMenu
7039 && mFocusedApp == win.getAppToken()
7040 && mLastNonDockedStackBounds.equals(mNonDockedStackBounds)
7041 && mLastDockedStackBounds.equals(mDockedStackBounds)) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07007042 return 0;
7043 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07007044 mLastSystemUiFlags = visibility;
Jorim Jaggi86905582016-02-09 21:36:09 -08007045 mLastFullscreenStackSysUiFlags = fullscreenVisibility;
7046 mLastDockedStackSysUiFlags = dockedVisibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007047 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04007048 mFocusedApp = win.getAppToken();
Jorim Jaggi86905582016-02-09 21:36:09 -08007049 final Rect fullscreenStackBounds = new Rect(mNonDockedStackBounds);
7050 final Rect dockedStackBounds = new Rect(mDockedStackBounds);
Dianne Hackborndf89e652011-10-06 22:35:11 -07007051 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07007052 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07007053 public void run() {
Jorim Jaggi86905582016-02-09 21:36:09 -08007054 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
7055 if (statusbar != null) {
7056 statusbar.setSystemUiVisibility(visibility, fullscreenVisibility,
7057 dockedVisibility, 0xffffffff, fullscreenStackBounds,
7058 dockedStackBounds, win.toString());
7059 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08007060 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07007061 }
7062 });
7063 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08007064 }
7065
Jorim Jaggi86905582016-02-09 21:36:09 -08007066 private int updateLightStatusBarLw(int vis, WindowState opaque, WindowState opaqueOrDimming) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01007067 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
7068 ? mStatusBar
Jorim Jaggi86905582016-02-09 21:36:09 -08007069 : opaqueOrDimming;
Adrian Rooscd3884d2015-02-18 17:25:23 +01007070
7071 if (statusColorWin != null) {
Jorim Jaggi86905582016-02-09 21:36:09 -08007072 if (statusColorWin == opaque) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01007073 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
7074 // its light flag.
7075 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7076 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
7077 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7078 } else if (statusColorWin != null && statusColorWin.isDimming()) {
7079 // Otherwise if it's dimming, clear the light flag.
7080 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7081 }
7082 }
7083 return vis;
7084 }
7085
John Spurlock79da8332013-09-20 12:04:47 -04007086 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007087 final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
7088 final boolean freeformStackVisible =
7089 mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID);
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08007090 final boolean resizing = mWindowManagerInternal.isDockedDividerResizing();
7091
7092 // We need to force system bars when the docked stack is visible, when the freeform stack
7093 // is visible but also when we are resizing for the transitions when docked stack
7094 // visibility changes.
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007095 mForceShowSystemBars = dockedStackVisible || freeformStackVisible || resizing;
7096 final boolean forceOpaqueSystemBars = mForceShowSystemBars && !mForceStatusBarFromKeyguard;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007097
John Spurlockbd957402013-10-03 11:38:39 -04007098 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01007099 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
7100 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04007101 : mTopFullscreenOpaqueWindowState;
7102 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
7103 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
7104
John Spurlock27735a42013-08-14 17:57:38 -04007105 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07007106 int type = win.getAttrs().type;
7107 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04007108 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04007109 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
7110 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04007111 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01007112 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
7113 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04007114 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01007115 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
7116 }
John Spurlockbd957402013-10-03 11:38:39 -04007117 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04007118 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04007119
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007120 if ((!areTranslucentBarsAllowed() && transWin != mStatusBar)
7121 || forceOpaqueSystemBars) {
Adrian Roosea562512014-05-05 13:33:03 +02007122 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
7123 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007124 }
7125
Yorke Lee2e4b7322016-03-02 17:33:06 -08007126 if (mForceNavBarOpaque) {
7127 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT);
7128 }
7129
Jorim Jaggi4fa78922015-11-30 17:13:56 -08007130 if (mForceWindowDrawsStatusBarBackground) {
7131 vis |= View.STATUS_BAR_TRANSPARENT;
7132 vis &= ~View.STATUS_BAR_TRANSLUCENT;
7133 }
7134
John Spurlock27735a42013-08-14 17:57:38 -04007135 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04007136 boolean immersiveSticky =
7137 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007138 final boolean hideStatusBarWM =
7139 mTopFullscreenOpaqueWindowState != null
7140 && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04007141 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007142 final boolean hideStatusBarSysui =
John Spurlock27735a42013-08-14 17:57:38 -04007143 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007144 final boolean hideNavBarSysui =
John Spurlockf1a36642013-10-12 17:50:42 -04007145 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007146
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007147 final boolean transientStatusBarAllowed = mStatusBar != null
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007148 && (statusBarHasFocus || (!mForceShowSystemBars
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007149 && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky))));
John Spurlock27735a42013-08-14 17:57:38 -04007150
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007151 final boolean transientNavBarAllowed = mNavigationBar != null
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007152 && !mForceShowSystemBars && hideNavBarSysui && immersiveSticky;
John Spurlockf1a36642013-10-12 17:50:42 -04007153
Adrian Roosddc8b272015-05-21 16:28:27 -07007154 final long now = SystemClock.uptimeMillis();
7155 final boolean pendingPanic = mPendingPanicGestureUptime != 0
7156 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
7157 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
7158 // The user performed the panic gesture recently, we're about to hide the bars,
7159 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
7160 mPendingPanicGestureUptime = 0;
7161 mStatusBarController.showTransient();
7162 mNavigationBarController.showTransient();
7163 }
7164
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007165 final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007166 && !transientStatusBarAllowed && hideStatusBarSysui;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007167 final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007168 && !transientNavBarAllowed;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007169 if (denyTransientStatus || denyTransientNav || mForceShowSystemBars) {
John Spurlock27735a42013-08-14 17:57:38 -04007170 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04007171 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08007172 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007173 }
John Spurlock27735a42013-08-14 17:57:38 -04007174
Selim Cinekf98702e2015-05-20 22:48:40 -07007175 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
7176 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
7177 final boolean navAllowedHidden = immersive || immersiveSticky;
7178
Selim Cinekd6623612015-05-22 18:56:22 -07007179 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
7180 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07007181 // We can't hide the navbar from this window otherwise the input consumer would not get
7182 // the input events.
7183 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
7184 }
7185
John Spurlock27735a42013-08-14 17:57:38 -04007186 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
7187
7188 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04007189 boolean oldImmersiveMode = isImmersiveMode(oldVis);
7190 boolean newImmersiveMode = isImmersiveMode(vis);
7191 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04007192 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07007193 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
7194 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04007195 }
John Spurlock27735a42013-08-14 17:57:38 -04007196
John Spurlockf1a36642013-10-12 17:50:42 -04007197 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
7198
John Spurlocke1f366f2013-08-05 12:22:40 -04007199 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007200 }
7201
John Spurlockf1a36642013-10-12 17:50:42 -04007202 private void clearClearableFlagsLw() {
7203 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
7204 if (newVal != mResettingSystemUiFlags) {
7205 mResettingSystemUiFlags = newVal;
7206 mWindowManagerFuncs.reevaluateStatusBarVisibility();
7207 }
7208 }
7209
7210 private boolean isImmersiveMode(int vis) {
7211 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04007212 return mNavigationBar != null
7213 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04007214 && (vis & flags) != 0
7215 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04007216 }
7217
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007218 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007219 * @return whether the navigation or status bar can be made translucent
7220 *
7221 * This should return true unless touch exploration is not enabled or
7222 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007223 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007224 private boolean areTranslucentBarsAllowed() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04007225 return mTranslucentDecorEnabled;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007226 }
7227
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007228 // Use this instead of checking config_showNavigationBar so that it can be consistently
7229 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07007230 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007231 public boolean hasNavigationBar() {
7232 return mHasNavigationBar;
7233 }
7234
satok1bc0a492012-04-25 22:47:12 +09007235 @Override
7236 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
7237 mLastInputMethodWindow = ime;
7238 mLastInputMethodTargetWindow = target;
7239 }
7240
Craig Mautnerf1b67412012-09-19 13:18:29 -07007241 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09007242 public int getInputMethodWindowVisibleHeightLw() {
7243 return mDockBottom - mCurBottom;
7244 }
7245
7246 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07007247 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07007248 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08007249 if (mKeyguardDelegate != null) {
7250 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007251 }
John Spurlock13451a22012-09-28 14:40:41 -04007252 if (mStatusBarService != null) {
7253 try {
7254 mStatusBarService.setCurrentUser(newUserId);
7255 } catch (RemoteException e) {
7256 // oh well
7257 }
7258 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007259 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007260 }
7261
7262 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08007263 public boolean canMagnifyWindow(int windowType) {
7264 switch (windowType) {
7265 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
7266 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
7267 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
7268 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
7269 return false;
7270 }
7271 }
7272 return true;
7273 }
7274
7275 @Override
7276 public boolean isTopLevelWindow(int windowType) {
7277 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
7278 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
7279 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
7280 }
7281 return true;
7282 }
7283
Jim Miller4eeb4f62012-11-08 00:04:29 -08007284 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07007285 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007286 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007287 pw.print(" mSystemReady="); pw.print(mSystemReady);
7288 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07007289 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007290 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07007291 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007292 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07007293 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
7294 || mForceClearedSystemUiFlags != 0) {
7295 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
7296 pw.print(Integer.toHexString(mLastSystemUiFlags));
7297 pw.print(" mResettingSystemUiFlags=0x");
7298 pw.print(Integer.toHexString(mResettingSystemUiFlags));
7299 pw.print(" mForceClearedSystemUiFlags=0x");
7300 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07007301 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007302 if (mLastFocusNeedsMenu) {
7303 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
7304 pw.println(mLastFocusNeedsMenu);
7305 }
Jeff Browna20dda42014-05-27 20:57:24 -07007306 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
7307 pw.println(mWakeGestureEnabledSetting);
7308
Jeff Brownbcdfc622014-03-06 19:13:04 -08007309 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04007310 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
7311 pw.print(" mDockMode="); pw.print(mDockMode);
keunyounga7710492015-09-23 11:33:58 -07007312 pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007313 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
7314 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
7315 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
7316 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05007317 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007318 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007319 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
7320 pw.print(mCarDockEnablesAccelerometer);
7321 pw.print(" mDeskDockEnablesAccelerometer=");
7322 pw.println(mDeskDockEnablesAccelerometer);
7323 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
7324 pw.print(mLidKeyboardAccessibility);
7325 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01007326 pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007327 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007328 pw.print(prefix);
7329 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
7330 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07007331 pw.print(prefix);
7332 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
7333 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007334 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07007335 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
7336 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
7337 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
7338 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
7339 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
7340 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
7341 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08007342 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
7343 pw.print(","); pw.print(mOverscanScreenTop);
7344 pw.print(") "); pw.print(mOverscanScreenWidth);
7345 pw.print("x"); pw.println(mOverscanScreenHeight);
7346 if (mOverscanLeft != 0 || mOverscanTop != 0
7347 || mOverscanRight != 0 || mOverscanBottom != 0) {
7348 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
7349 pw.print(" top="); pw.print(mOverscanTop);
7350 pw.print(" right="); pw.print(mOverscanRight);
7351 pw.print(" bottom="); pw.println(mOverscanBottom);
7352 }
Dianne Hackborn313440842013-02-19 19:22:59 -08007353 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
7354 pw.print(mRestrictedOverscanScreenLeft);
7355 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
7356 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
7357 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007358 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
7359 pw.print(","); pw.print(mUnrestrictedScreenTop);
7360 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
7361 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
7362 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
7363 pw.print(","); pw.print(mRestrictedScreenTop);
7364 pw.print(") "); pw.print(mRestrictedScreenWidth);
7365 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07007366 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
7367 pw.print(","); pw.print(mStableFullscreenTop);
7368 pw.print(")-("); pw.print(mStableFullscreenRight);
7369 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07007370 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
7371 pw.print(","); pw.print(mStableTop);
7372 pw.print(")-("); pw.print(mStableRight);
7373 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007374 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
7375 pw.print(","); pw.print(mSystemTop);
7376 pw.print(")-("); pw.print(mSystemRight);
7377 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007378 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
7379 pw.print(","); pw.print(mCurTop);
7380 pw.print(")-("); pw.print(mCurRight);
7381 pw.print(","); pw.print(mCurBottom); pw.println(")");
7382 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
7383 pw.print(","); pw.print(mContentTop);
7384 pw.print(")-("); pw.print(mContentRight);
7385 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07007386 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
7387 pw.print(","); pw.print(mVoiceContentTop);
7388 pw.print(")-("); pw.print(mVoiceContentRight);
7389 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007390 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
7391 pw.print(","); pw.print(mDockTop);
7392 pw.print(")-("); pw.print(mDockRight);
7393 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007394 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
7395 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007396 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
7397 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07007398 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
7399 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007400 if (mLastInputMethodWindow != null) {
7401 pw.print(prefix); pw.print("mLastInputMethodWindow=");
7402 pw.println(mLastInputMethodWindow);
7403 }
7404 if (mLastInputMethodTargetWindow != null) {
7405 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
7406 pw.println(mLastInputMethodTargetWindow);
7407 }
7408 if (mStatusBar != null) {
7409 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08007410 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
7411 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007412 }
7413 if (mNavigationBar != null) {
7414 pw.print(prefix); pw.print("mNavigationBar=");
7415 pw.println(mNavigationBar);
7416 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007417 if (mFocusedWindow != null) {
7418 pw.print(prefix); pw.print("mFocusedWindow=");
7419 pw.println(mFocusedWindow);
7420 }
7421 if (mFocusedApp != null) {
7422 pw.print(prefix); pw.print("mFocusedApp=");
7423 pw.println(mFocusedApp);
7424 }
7425 if (mWinDismissingKeyguard != null) {
7426 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
7427 pw.println(mWinDismissingKeyguard);
7428 }
7429 if (mTopFullscreenOpaqueWindowState != null) {
7430 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
7431 pw.println(mTopFullscreenOpaqueWindowState);
7432 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01007433 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
7434 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
7435 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
7436 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007437 if (mForcingShowNavBar) {
7438 pw.print(prefix); pw.print("mForcingShowNavBar=");
7439 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
7440 pw.println(mForcingShowNavBarLayer);
7441 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007442 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007443 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007444 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
7445 pw.print(" mForceStatusBarFromKeyguard=");
7446 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007447 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07007448 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007449 pw.print(" mHomePressed="); pw.println(mHomePressed);
7450 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
7451 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
7452 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
7453 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
7454 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
7455 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
7456 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
7457 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
7458 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
7459 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07007460 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
7461 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
7462 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07007463
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07007464 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04007465 mStatusBarController.dump(pw, prefix);
7466 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05007467 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07007468
Jeff Browna20dda42014-05-27 20:57:24 -07007469 if (mWakeGestureListener != null) {
7470 mWakeGestureListener.dump(pw, prefix);
7471 }
Jeff Brown600f0032014-05-22 17:06:00 -07007472 if (mOrientationListener != null) {
7473 mOrientationListener.dump(pw, prefix);
7474 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00007475 if (mBurnInProtectionHelper != null) {
7476 mBurnInProtectionHelper.dump(prefix, pw);
7477 }
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07007478 if (mKeyguardDelegate != null) {
7479 mKeyguardDelegate.dump(prefix, pw);
7480 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007481 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007482}