blob: c046ba610b3ad9ba4a938f90a49194f48c89dac6 [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;
Jaewan Kim49117872016-01-19 17:24:08 +090021import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE;
22import static android.content.pm.PackageManager.FEATURE_TELEVISION;
23import static android.content.pm.PackageManager.FEATURE_WATCH;
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -080024import static android.content.res.Configuration.UI_MODE_TYPE_CAR;
25import static android.content.res.Configuration.UI_MODE_TYPE_MASK;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070026import static android.view.WindowManager.LayoutParams.*;
Jaewan Kim49117872016-01-19 17:24:08 +090027import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070028import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
29import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
Jaewan Kim49117872016-01-19 17:24:08 +090030import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
31import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
32import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070033
Dianne Hackborna4972e92012-03-14 10:38:05 -070034import android.app.ActivityManager;
Jeff Brown061ea992015-04-17 19:55:47 -070035import android.app.ActivityManagerInternal;
36import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080037import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080038import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040039import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070040import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070041import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040042import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080043import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070044import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080045import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040046import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080047import android.content.ContentResolver;
48import android.content.Context;
49import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070050import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070051import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080052import android.content.pm.ActivityInfo;
53import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040054import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070055import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080056import android.content.res.Configuration;
57import android.content.res.Resources;
58import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080059import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080060import android.graphics.Rect;
Jinsuk Kime601b712015-07-07 08:01:02 +090061import android.hardware.hdmi.HdmiControlManager;
62import android.hardware.hdmi.HdmiPlaybackClient;
63import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback;
John Spurlock7b414672014-07-18 13:02:39 -040064import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080065import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050066import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080067import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070068import android.media.Ringtone;
69import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070070import android.media.session.MediaSessionLegacyHelper;
Billy Laucbe540f2015-06-25 01:51:44 +010071import android.os.Binder;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070072import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080073import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070074import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080075import android.os.Handler;
76import android.os.IBinder;
Dianne Hackbornb6683c42015-06-18 17:40:33 -070077import android.os.IDeviceIdleController;
Jeff Brown32cbc38552011-12-01 14:01:49 -080078import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070079import android.os.Message;
80import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080081import android.os.PowerManager;
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -070082import android.os.PowerManagerInternal;
Billy Laucbe540f2015-06-25 01:51:44 +010083import android.os.Process;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080084import android.os.RemoteException;
85import android.os.ServiceManager;
86import android.os.SystemClock;
87import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080088import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070089import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080090import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070091import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080092import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070093import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040094import android.service.dreams.DreamService;
95import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070096import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070097import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070098import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080099import android.util.EventLog;
100import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -0700101import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -0800102import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700103import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800104import android.view.Gravity;
105import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800106import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800107import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -0700108import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -0700109import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -0800110import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800111import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -0800112import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -0800113import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800114import android.view.KeyEvent;
115import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800116import android.view.Surface;
117import android.view.View;
118import android.view.ViewConfiguration;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800119import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800120import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700121import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800122import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800123import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800124import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800125import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200126import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800127import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800128import com.android.internal.R;
Jason Monk8f7f3182015-11-18 16:35:14 -0500129import com.android.internal.logging.MetricsLogger;
130import com.android.internal.policy.PhoneWindow;
Craig Mautnerae446592012-12-06 19:05:05 -0800131import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700132import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800133import com.android.internal.widget.PointerLocationView;
Adrian Roos5941c982015-09-03 15:59:49 -0700134import com.android.server.GestureLauncherService;
Craig Mautner8a0da012014-05-31 15:13:37 -0700135import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100136import com.android.server.policy.keyguard.KeyguardServiceDelegate;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700137import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800138
139import java.io.File;
140import java.io.FileReader;
141import java.io.IOException;
142import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700143import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800144import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800145
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800146/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700147 * WindowManagerPolicy implementation for the Android phone UI. This
148 * introduces a new method suffix, Lp, for an internal lock of the
149 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400150 * 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 -0700151 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800152 */
153public class PhoneWindowManager implements WindowManagerPolicy {
154 static final String TAG = "WindowManager";
155 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700156 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700157 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700158 static final boolean DEBUG_KEYGUARD = false;
159 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700160 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700161 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800162 static final boolean SHOW_STARTING_ANIMATIONS = true;
163 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400164
Daniel Sandler6396c722013-04-16 20:19:09 -0400165 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
keunyounga7710492015-09-23 11:33:58 -0700166 // No longer recommended for desk docks;
Daniel Sandler6396c722013-04-16 20:19:09 -0400167 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
168
Jeff Brown6d8fd272014-05-20 21:24:38 -0700169 static final int SHORT_PRESS_POWER_NOTHING = 0;
170 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
171 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
172 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800173 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700174
Joe Onoratod208e702010-10-08 16:22:43 -0400175 static final int LONG_PRESS_POWER_NOTHING = 0;
176 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
177 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700178 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700179
Jeff Brown13f00f02014-10-31 14:45:50 -0700180 static final int MULTI_PRESS_POWER_NOTHING = 0;
181 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
182 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
183
Michael Jurka3b1fc472011-06-13 10:54:40 -0700184 // These need to match the documentation/constant in
185 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800186 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800187 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700188 static final int LONG_PRESS_HOME_ASSIST = 2;
Jaewan Kim52632e22016-01-14 18:01:52 +0900189 static final int LONG_PRESS_HOME_PICTURE_IN_PICTURE = 3;
190 static final int LAST_LONG_PRESS_HOME_BEHAVIOR = LONG_PRESS_HOME_PICTURE_IN_PICTURE;
Jeff Browncaca8812013-05-09 13:34:33 -0700191
192 static final int DOUBLE_TAP_HOME_NOTHING = 0;
193 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800194
Jaewan Kim49117872016-01-19 17:24:08 +0900195 static final int SHORT_PRESS_WINDOW_NOTHING = 0;
196 static final int SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE = 1;
197
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000198 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
199 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
200
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700201 static final int APPLICATION_MEDIA_SUBLAYER = -2;
202 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800203 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800204 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700205 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700206
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800207 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
208 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
209 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500210 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700211 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800212
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700213 /**
214 * These are the system UI flags that, when changing, can cause the layout
215 * of the screen to change.
216 */
217 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400218 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400219 | View.SYSTEM_UI_FLAG_FULLSCREEN
220 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200221 | View.NAVIGATION_BAR_TRANSLUCENT
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800222 | View.STATUS_BAR_TRANSPARENT
223 | View.NAVIGATION_BAR_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700224
John Spurlock7b414672014-07-18 13:02:39 -0400225 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
226 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
227 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
228 .build();
229
Adrian Roosddc8b272015-05-21 16:28:27 -0700230 // The panic gesture may become active only after the keyguard is dismissed and the immersive
231 // app shows again. If that doesn't happen for 30s we drop the gesture.
232 private static final long PANIC_GESTURE_EXPIRATION = 30000;
233
Jim Miller5ecd8112013-01-09 18:50:26 -0800234 /**
235 * Keyguard stuff
236 */
237 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100238 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700239 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800240
Jeff Brown6651a632011-11-28 12:59:11 -0800241 /* Table of Application Launch keys. Maps from key codes to intent categories.
242 *
243 * These are special keys that are used to launch particular kinds of applications,
244 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
245 * usage page. We don't support quite that many yet...
246 */
247 static SparseArray<String> sApplicationLaunchKeyCategories;
248 static {
249 sApplicationLaunchKeyCategories = new SparseArray<String>();
250 sApplicationLaunchKeyCategories.append(
251 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
252 sApplicationLaunchKeyCategories.append(
253 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
254 sApplicationLaunchKeyCategories.append(
255 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
256 sApplicationLaunchKeyCategories.append(
257 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
258 sApplicationLaunchKeyCategories.append(
259 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
260 sApplicationLaunchKeyCategories.append(
261 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
262 }
263
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700264 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700265 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700266
Dianne Hackborndf89e652011-10-06 22:35:11 -0700267 /**
268 * Lock protecting internal state. Must not call out into window
269 * manager with lock held. (This lock will be acquired in places
270 * where the window manager is calling in with its own lock held.)
271 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800272 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700273
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800274 Context mContext;
275 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700276 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700277 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700278 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700279 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700280 DreamManagerInternal mDreamManagerInternal;
Michael Wrighta4d22d72015-09-16 23:19:26 +0100281 PowerManagerInternal mPowerManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400282 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700283 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700284 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800285 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700286 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800287 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000288 BurnInProtectionHelper mBurnInProtectionHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100289 AppOpsManager mAppOpsManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800290
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700291 // Vibrator pattern for haptic feedback of a long press.
292 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700293
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700294 // Vibrator pattern for haptic feedback of virtual key press.
295 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700296
Amith Yamasanic33cb712010-02-10 15:21:49 -0800297 // Vibrator pattern for a short vibration.
298 long[] mKeyboardTapVibePattern;
299
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700300 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
301 long[] mClockTickVibePattern;
302
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700303 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
304 long[] mCalendarDateVibePattern;
305
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700306 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
307 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700308
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700309 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
310 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700311
Mady Mellore8608912015-06-05 09:02:55 -0700312 // Vibrator pattern for haptic feedback of a context click.
313 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700314
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800315 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
316 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400317
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800318 boolean mSafeMode;
319 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700320 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400321 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400322 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700323 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400324 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
325 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -0800326 int[] mNavigationBarHeightForRotationDefault = new int[4];
327 int[] mNavigationBarWidthForRotationDefault = new int[4];
328 int[] mNavigationBarHeightForRotationInCarMode = new int[4];
329 int[] mNavigationBarWidthForRotationInCarMode = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400330
keunyounga7710492015-09-23 11:33:58 -0700331 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
332 // This is for car dock and this is updated from resource.
333 private boolean mEnableCarDockHomeCapture = true;
334
Craig Mautnera631d492014-08-05 15:16:01 -0700335 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800336 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700337 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700338 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700339 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700340 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
341 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
342 }
343 };
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700344 final DrawnListener mKeyguardDrawnCallback = new DrawnListener() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700345 @Override
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700346 public void onDrawn() {
347 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn.");
Craig Mautner8a0da012014-05-31 15:13:37 -0700348 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
349 }
350 };
351
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800352 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800353 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900354 WindowState mLastInputMethodWindow = null;
355 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800356
Jeff Brown13f00f02014-10-31 14:45:50 -0700357 // FIXME This state is shared between the input reader and handler thread.
358 // Technically it's broken and buggy but it has been like this for many years
359 // and we have not yet seen any problems. Someday we'll rewrite this logic
360 // so that only one thread is involved in handling input policy. Unfortunately
361 // it's on a critical path for power management so we can't just post the work to the
362 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
363 // to hold wakelocks during dispatch and eliminating the critical path.
364 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800365 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700366 volatile int mPowerKeyPressCounter;
367 volatile boolean mEndCallKeyHandled;
368
Winson Chungd42a6cf2014-06-03 16:24:04 -0700369 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700370 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700371 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800372
Jeff Brown2e7760e2012-04-11 15:14:55 -0700373 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700374 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700375 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800376
Dianne Hackbornc777e072010-02-12 13:07:59 -0800377 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700378 boolean mSystemBooted;
Adrian Roos3542f7d2015-07-13 15:57:53 -0700379 private boolean mDeferBindKeyguard;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800380 boolean mHdmiPlugged;
Jinsuk Kime601b712015-07-07 08:01:02 +0900381 HdmiControl mHdmiControl;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700382 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400383 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700384 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700385 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400386 int mCarDockRotation;
387 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700388 int mUndockedHdmiRotation;
389 int mDemoHdmiRotation;
390 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800391 int mDemoRotation;
392 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400393
Jeff Browna20dda42014-05-27 20:57:24 -0700394 boolean mWakeGestureEnabledSetting;
395 MyWakeGestureListener mWakeGestureListener;
396
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700397 // Default display does not rotate, apps that require non-default orientation will have to
398 // have the orientation emulated.
399 private boolean mForceDefaultOrientation = false;
400
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400401 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
402 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700403 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400404
Jeff Brownbcdfc622014-03-06 19:13:04 -0800405 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700406 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400407 boolean mCarDockEnablesAccelerometer;
408 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700409 int mLidKeyboardAccessibility;
410 int mLidNavigationAccessibility;
Edward Savage-Jones7def60d2015-11-13 13:27:03 +0100411 boolean mLidControlsScreenLock;
Jeff Brownc458ce92012-04-30 14:58:40 -0700412 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700413 int mShortPressOnPowerBehavior;
414 int mLongPressOnPowerBehavior;
415 int mDoublePressOnPowerBehavior;
416 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000417 int mShortPressOnSleepBehavior;
Jaewan Kim49117872016-01-19 17:24:08 +0900418 int mShortPressWindowBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700419 boolean mAwake;
420 boolean mScreenOnEarly;
421 boolean mScreenOnFully;
422 ScreenOnListener mScreenOnListener;
423 boolean mKeyguardDrawComplete;
424 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800425 boolean mOrientationSensorEnabled = false;
426 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800427 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400428 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800429 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700430
Jeff Brown70825162012-03-28 17:27:48 -0700431 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800432
433 // The last window we were told about in focusChanged.
434 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800435 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800436
Jeff Brown70825162012-03-28 17:27:48 -0700437 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800438
Dianne Hackbornc652de82013-02-15 16:32:56 -0800439 // The current size of the screen; really; extends into the overscan area of
440 // the screen and doesn't account for any system elements like the status bar.
441 int mOverscanScreenLeft, mOverscanScreenTop;
442 int mOverscanScreenWidth, mOverscanScreenHeight;
443 // The current visible size of the screen; really; (ir)regardless of whether the status
444 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800445 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
446 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800447 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
448 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
449 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700450 // The current size of the screen; these may be different than (0,0)-(dw,dh)
451 // if the status bar can't be hidden; in that case it effectively carves out
452 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800453 int mRestrictedScreenLeft, mRestrictedScreenTop;
454 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700455 // During layout, the current screen borders accounting for any currently
456 // visible system UI elements.
457 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700458 // For applications requesting stable content insets, these are them.
459 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700460 // For applications requesting stable content insets but have also set the
461 // fullscreen window flag, these are the stable dimensions without the status bar.
462 int mStableFullscreenLeft, mStableFullscreenTop;
463 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800464 // During layout, the current screen borders with all outer decoration
465 // (status bar, input method dock) accounted for.
466 int mCurLeft, mCurTop, mCurRight, mCurBottom;
467 // During layout, the frame in which content should be displayed
468 // to the user, accounting for all screen decoration except for any
469 // space they deem as available for other content. This is usually
470 // the same as mCur*, but may be larger if the screen decor has supplied
471 // content insets.
472 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700473 // During layout, the frame in which voice content should be displayed
474 // to the user, accounting for all screen decoration except for any
475 // space they deem as available for other content.
476 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800477 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800478 // windows are placed.
479 int mDockLeft, mDockTop, mDockRight, mDockBottom;
480 // During layout, the layer at which the doc window is placed.
481 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700482 // During layout, this is the layer of the status bar.
483 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700484 int mLastSystemUiFlags;
485 // Bits that we are in the process of clearing, so we want to prevent
486 // them from being set by applications until everything has been updated
487 // to have them clear.
488 int mResettingSystemUiFlags = 0;
489 // Bits that we are currently always keeping cleared.
490 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800491 // What we last reported to system UI about whether the compatibility
492 // menu needs to be displayed.
493 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700494 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
495 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700496
Selim Cinekf83e8242015-05-19 18:08:14 -0700497 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700498
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800499 static final Rect mTmpParentFrame = new Rect();
500 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800501 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800502 static final Rect mTmpContentFrame = new Rect();
503 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400504 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700505 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700506 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700507 static final Rect mTmpOutsetFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700508
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800509 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100510 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700511 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200512 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400513 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800514 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700515 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700516 private boolean mForceStatusBarTransparent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700517 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800518 boolean mForcingShowNavBar;
519 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700520
521 // States of keyguard dismiss.
522 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
523 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
524 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
525 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
526
527 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
528 * be done once per window. */
529 private WindowState mWinDismissingKeyguard;
530
tingna_sunge785ffa2015-05-12 13:23:15 +0800531 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
532 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
533 * lock SIM card. This variable is used to record the previous keyguard secure state for
534 * monitoring secure state change on window dismissing keyguard. */
535 private boolean mSecureDismissingKeyguard;
536
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700537 /** The window that is currently showing "over" the keyguard. If there is an app window
538 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
539 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
540 * the wallpaper. */
541 private WindowState mWinShowWhenLocked;
542
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700543 boolean mShowingLockscreen;
544 boolean mShowingDream;
545 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700546 boolean mDreamingSleepTokenNeeded;
547 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700548 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700549 boolean mKeyguardSecure;
550 boolean mKeyguardSecureIncludingHidden;
551 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800552 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700553 boolean mHomeConsumed;
554 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800555 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700556 Intent mCarDockIntent;
557 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700558 boolean mSearchKeyShortcutPending;
559 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700560 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700561 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800562
Mike Lockwood28569302010-01-28 11:54:40 -0500563 // support for activating the lock screen while the screen is on
564 boolean mAllowLockscreenWhenOn;
565 int mLockScreenTimeout;
566 boolean mLockScreenTimerActive;
567
David Brownbaf8d092010-03-08 21:52:59 -0800568 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800569 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800570
571 // Behavior of POWER button while in-call and screen on.
572 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
573 int mIncallPowerBehavior;
574
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700575 Display mDisplay;
576
Filip Gruszczynski2987f612015-06-30 15:03:30 -0700577 private int mDisplayRotation;
578
Dianne Hackborn9d132642011-04-21 17:26:39 -0700579 int mLandscapeRotation = 0; // default landscape rotation
580 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
581 int mPortraitRotation = 0; // default portrait rotation
582 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700583
Dianne Hackbornc652de82013-02-15 16:32:56 -0800584 int mOverscanLeft = 0;
585 int mOverscanTop = 0;
586 int mOverscanRight = 0;
587 int mOverscanBottom = 0;
588
Joe Onorato46b0d682010-11-22 17:37:27 -0800589 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700590 private int mLongPressOnHomeBehavior;
591
592 // What we do when the user double-taps on home
593 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800594
Bryce Lee584a4452014-10-21 15:55:55 -0700595 // Allowed theater mode wake actions
596 private boolean mAllowTheaterModeWakeFromKey;
597 private boolean mAllowTheaterModeWakeFromPowerKey;
598 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800599 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700600 private boolean mAllowTheaterModeWakeFromCameraLens;
601 private boolean mAllowTheaterModeWakeFromLidSwitch;
602 private boolean mAllowTheaterModeWakeFromWakeGesture;
603
Bryce Leed3b28402015-03-09 15:49:13 +0000604 // Whether to support long press from power button in non-interactive mode
605 private boolean mSupportLongPressPowerWhenNonInteractive;
606
Bryce Lee55e846d2014-11-04 12:43:44 -0800607 // Whether to go to sleep entering theater mode from power button
608 private boolean mGoToSleepOnButtonPressTheaterMode;
609
Winson Chung9112ec32011-06-27 13:15:32 -0700610 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700611 // Time to volume and power must be pressed within this interval of each other.
612 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700613 // Increase the chord delay when taking a screenshot from the keyguard
614 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800615 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700616 private boolean mScreenshotChordVolumeDownKeyTriggered;
617 private long mScreenshotChordVolumeDownKeyTime;
618 private boolean mScreenshotChordVolumeDownKeyConsumed;
619 private boolean mScreenshotChordVolumeUpKeyTriggered;
620 private boolean mScreenshotChordPowerKeyTriggered;
621 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700622
Michael Wrightb854e242013-02-05 17:54:02 -0800623 /* The number of steps between min and max brightness */
624 private static final int BRIGHTNESS_STEPS = 10;
625
Christopher Tate5e08af02012-09-21 17:17:22 -0700626 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800627 ShortcutManager mShortcutManager;
628 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700629 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700630 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800631
Craig Mautnerd625ab22013-09-06 13:40:31 -0700632 private int mCurrentUserId;
633
Justin Kohd378ad72013-04-01 12:18:26 -0700634 // Maps global key codes to the components that will handle them.
635 private GlobalKeyManager mGlobalKeyManager;
636
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700637 // Fallback actions by key code.
638 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
639 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800640
Jorim Jaggi76a16232014-08-08 17:00:47 +0200641 private final LogDecelerateInterpolator mLogDecelerateInterpolator
642 = new LogDecelerateInterpolator(100, 0);
643
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800644 private boolean mForceWindowDrawsStatusBarBackground;
645
Jeff Brown70825162012-03-28 17:27:48 -0700646 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
647 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700648 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
649 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700650 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
651 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
652 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700653 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700654 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700655 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700656 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700657 private static final int MSG_POWER_DELAYED_PRESS = 13;
658 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700659 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700660 private static final int MSG_REQUEST_TRANSIENT_BARS = 16;
Jaewan Kimc552b042016-01-18 16:08:45 +0900661 private static final int MSG_REQUEST_TV_PICTURE_IN_PICTURE = 17;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700662
663 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
664 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
Jeff Brown70825162012-03-28 17:27:48 -0700665
666 private class PolicyHandler extends Handler {
667 @Override
668 public void handleMessage(Message msg) {
669 switch (msg.what) {
670 case MSG_ENABLE_POINTER_LOCATION:
671 enablePointerLocation();
672 break;
673 case MSG_DISABLE_POINTER_LOCATION:
674 disablePointerLocation();
675 break;
Jeff Brown40013652012-05-16 21:22:36 -0700676 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
677 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
678 break;
679 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
680 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
681 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700682 case MSG_DISPATCH_SHOW_RECENTS:
683 showRecentApps(false);
684 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700685 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
686 showGlobalActionsInternal();
687 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700688 case MSG_KEYGUARD_DRAWN_COMPLETE:
689 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700690 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700691 break;
692 case MSG_KEYGUARD_DRAWN_TIMEOUT:
693 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700694 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700695 break;
696 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
697 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700698 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700699 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700700 case MSG_HIDE_BOOT_MESSAGE:
701 handleHideBootMessage();
702 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700703 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
704 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
705 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700706 case MSG_POWER_DELAYED_PRESS:
707 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
708 finishPowerKeyPress();
709 break;
710 case MSG_POWER_LONG_PRESS:
711 powerLongPress();
712 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700713 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
714 updateDreamingSleepToken(msg.arg1 != 0);
715 break;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700716 case MSG_REQUEST_TRANSIENT_BARS:
717 WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ?
718 mStatusBar : mNavigationBar;
719 if (targetBar != null) {
720 requestTransientBars(targetBar);
721 }
722 break;
Jaewan Kimc552b042016-01-18 16:08:45 +0900723 case MSG_REQUEST_TV_PICTURE_IN_PICTURE:
724 requestTvPictureInPictureInternal();
725 break;
Jeff Brown70825162012-03-28 17:27:48 -0700726 }
727 }
728 }
729
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800730 private UEventObserver mHDMIObserver = new UEventObserver() {
731 @Override
732 public void onUEvent(UEventObserver.UEvent event) {
733 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
734 }
735 };
736
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800737 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800738 SettingsObserver(Handler handler) {
739 super(handler);
740 }
David Brownbaf8d092010-03-08 21:52:59 -0800741
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800742 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700743 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800744 ContentResolver resolver = mContext.getContentResolver();
745 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700746 Settings.System.END_BUTTON_BEHAVIOR), false, this,
747 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800748 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700749 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
750 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700751 resolver.registerContentObserver(Settings.Secure.getUriFor(
752 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
753 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800754 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700755 Settings.System.ACCELEROMETER_ROTATION), false, this,
756 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500757 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700758 Settings.System.USER_ROTATION), false, this,
759 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400760 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700761 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
762 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800763 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700764 Settings.System.POINTER_LOCATION), false, this,
765 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800766 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700767 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
768 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500769 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400770 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700771 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500772 resolver.registerContentObserver(Settings.Global.getUriFor(
773 Settings.Global.POLICY_CONTROL), false, this,
774 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800775 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800776 }
777
778 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800779 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700780 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800781 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800782 }
Craig Mautner967212c2013-04-13 21:10:58 -0700783
Jeff Browna20dda42014-05-27 20:57:24 -0700784 class MyWakeGestureListener extends WakeGestureListener {
785 MyWakeGestureListener(Context context, Handler handler) {
786 super(context, handler);
787 }
788
789 @Override
790 public void onWakeUp() {
791 synchronized (mLock) {
792 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700793 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700794 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture,
795 "android.policy:GESTURE");
Jeff Browna20dda42014-05-27 20:57:24 -0700796 }
797 }
798 }
799 }
800
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800801 class MyOrientationListener extends WindowOrientationListener {
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700802 private final Runnable mUpdateRotationRunnable = new Runnable() {
803 @Override
804 public void run() {
Tim Murray1f407642015-10-01 17:07:12 -0700805 // send interaction hint to improve redraw performance
806 mPowerManagerInternal.powerHint(PowerManagerInternal.POWER_HINT_INTERACTION, 0);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700807 updateRotation(false);
808 }
809 };
810
Craig Mautnereee29c42013-01-17 14:44:34 -0800811 MyOrientationListener(Context context, Handler handler) {
812 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800813 }
Craig Mautner967212c2013-04-13 21:10:58 -0700814
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800815 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700816 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700817 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700818 mHandler.post(mUpdateRotationRunnable);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700819 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800820 }
821 MyOrientationListener mOrientationListener;
822
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100823 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400824
John Spurlock27735a42013-08-14 17:57:38 -0400825 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400826 View.NAVIGATION_BAR_TRANSIENT,
827 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400828 View.NAVIGATION_BAR_TRANSLUCENT,
829 StatusBarManager.WINDOW_NAVIGATION_BAR,
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800830 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
831 View.NAVIGATION_BAR_TRANSPARENT);
John Spurlock5b9145b2013-08-20 15:13:47 -0400832
John Spurlockf1a36642013-10-12 17:50:42 -0400833 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400834
Craig Mautner037aa8d2013-06-07 10:35:44 -0700835 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400836
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700837 IStatusBarService getStatusBarService() {
838 synchronized (mServiceAquireLock) {
839 if (mStatusBarService == null) {
840 mStatusBarService = IStatusBarService.Stub.asInterface(
841 ServiceManager.getService("statusbar"));
842 }
843 return mStatusBarService;
844 }
845 }
846
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700847 /*
848 * We always let the sensor be switched on by default except when
849 * the user has explicitly disabled sensor based rotation or when the
850 * screen is switched off.
851 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700852 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800853 if (mSupportAutoRotation) {
854 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
855 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
856 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
857 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
858 // If the application has explicitly requested to follow the
859 // orientation, then we need to turn the sensor on.
860 return true;
861 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800862 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700863 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800864 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
865 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
866 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400867 // enable accelerometer if we are docked in a dock that enables accelerometer
868 // orientation management,
869 return true;
870 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700871 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800872 // If the setting for using the sensor by default is enabled, then
873 // we will always leave it on. Note that the user could go to
874 // a window that forces an orientation that does not use the
875 // sensor and in theory we could turn it off... however, when next
876 // turning it on we won't have a good value for the current
877 // orientation for a little bit, which can cause orientation
878 // changes to lag, so we'd like to keep it always on. (It will
879 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700880 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800881 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800882 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800883 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700884
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800885 /*
886 * Various use cases for invoking this function
887 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700888 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800889 * if not already enabled
890 * screen turned on and current app does not have sensor orientation, disable listeners if
891 * already enabled
892 * screen turning on and current app has sensor based orientation, enable listeners if needed
893 * screen turning on and current app has nosensor based orientation, do nothing
894 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700895 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800896 if (!mOrientationListener.canDetectOrientation()) {
897 // If sensor is turned off or nonexistent for some reason
898 return;
899 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000900 // Could have been invoked due to screen turning on or off or
901 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -0700902 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
903 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000904 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
905 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
906 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800907 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000908 // Note: We postpone the rotating of the screen until the keyguard as well as the
909 // window manager have reported a draw complete.
910 if (mScreenOnEarly && mAwake &&
911 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700912 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800913 disable = false;
914 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700915 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800916 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700917 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800918 mOrientationSensorEnabled = true;
919 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700920 }
921 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800922 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700923 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800924 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700925 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800926 mOrientationSensorEnabled = false;
927 }
928 }
929
Jeff Brown13f00f02014-10-31 14:45:50 -0700930 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
931 // Hold a wake lock until the power key is released.
932 if (!mPowerKeyWakeLock.isHeld()) {
933 mPowerKeyWakeLock.acquire();
934 }
935
936 // Cancel multi-press detection timeout.
937 if (mPowerKeyPressCounter != 0) {
938 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
939 }
940
941 // Detect user pressing the power button in panic when an application has
942 // taken over the whole screen.
943 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800944 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700945 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700946 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700947 }
948
949 // Latch power key state to detect screenshot chord.
950 if (interactive && !mScreenshotChordPowerKeyTriggered
951 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
952 mScreenshotChordPowerKeyTriggered = true;
953 mScreenshotChordPowerKeyTime = event.getDownTime();
954 interceptScreenshotChord();
955 }
956
957 // Stop ringing or end call if configured to do so when power is pressed.
958 TelecomManager telecomManager = getTelecommService();
959 boolean hungUp = false;
960 if (telecomManager != null) {
961 if (telecomManager.isRinging()) {
962 // Pressing Power while there's a ringing incoming
963 // call should silence the ringer.
964 telecomManager.silenceRinger();
965 } else if ((mIncallPowerBehavior
966 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
967 && telecomManager.isInCall() && interactive) {
968 // Otherwise, if "Power button ends call" is enabled,
969 // the Power button will hang up any current active call.
970 hungUp = telecomManager.endCall();
971 }
972 }
973
Adrian Roos5941c982015-09-03 15:59:49 -0700974 GestureLauncherService gestureService = LocalServices.getService(
975 GestureLauncherService.class);
976 boolean gesturedServiceIntercepted = false;
977 if (gestureService != null) {
978 gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive);
979 }
980
Jeff Brown13f00f02014-10-31 14:45:50 -0700981 // If the power key has still not yet been handled, then detect short
982 // press, long press, or multi press and decide what to do.
983 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
Adrian Roos5941c982015-09-03 15:59:49 -0700984 || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted;
Jeff Brown13f00f02014-10-31 14:45:50 -0700985 if (!mPowerKeyHandled) {
986 if (interactive) {
987 // When interactive, we're already awake.
988 // Wait for a long press or for the button to be released to decide what to do.
989 if (hasLongPressOnPowerBehavior()) {
990 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
991 msg.setAsynchronous(true);
992 mHandler.sendMessageDelayed(msg,
993 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
994 }
995 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800996 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800997
Bryce Leed3b28402015-03-09 15:49:13 +0000998 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
999 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1000 msg.setAsynchronous(true);
1001 mHandler.sendMessageDelayed(msg,
1002 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -08001003 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +00001004 } else {
1005 final int maxCount = getMaxMultiPressPowerCount();
1006
1007 if (maxCount <= 1) {
1008 mPowerKeyHandled = true;
1009 } else {
1010 mBeganFromNonInteractive = true;
1011 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001012 }
1013 }
Jeff Brown4d396052010-10-29 21:50:21 -07001014 }
1015 }
1016
Jeff Brown13f00f02014-10-31 14:45:50 -07001017 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
1018 final boolean handled = canceled || mPowerKeyHandled;
1019 mScreenshotChordPowerKeyTriggered = false;
1020 cancelPendingScreenshotChordAction();
1021 cancelPendingPowerKeyAction();
1022
1023 if (!handled) {
1024 // Figure out how to handle the key now that it has been released.
1025 mPowerKeyPressCounter += 1;
1026
1027 final int maxCount = getMaxMultiPressPowerCount();
1028 final long eventTime = event.getDownTime();
1029 if (mPowerKeyPressCounter < maxCount) {
1030 // This could be a multi-press. Wait a little bit longer to confirm.
1031 // Continue holding the wake lock.
1032 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
1033 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
1034 msg.setAsynchronous(true);
1035 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
1036 return;
1037 }
1038
1039 // No other actions. Handle it immediately.
1040 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -07001041 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001042
1043 // Done. Reset our state.
1044 finishPowerKeyPress();
1045 }
1046
1047 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -08001048 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001049 mPowerKeyPressCounter = 0;
1050 if (mPowerKeyWakeLock.isHeld()) {
1051 mPowerKeyWakeLock.release();
1052 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001053 }
1054
1055 private void cancelPendingPowerKeyAction() {
1056 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001057 mPowerKeyHandled = true;
1058 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001059 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001060 }
1061
1062 private void powerPress(long eventTime, boolean interactive, int count) {
1063 if (mScreenOnEarly && !mScreenOnFully) {
1064 Slog.i(TAG, "Suppressed redundant power key press while "
1065 + "already in the process of turning the screen on.");
1066 return;
Jeff Brownff204712011-10-25 21:27:54 -07001067 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001068
1069 if (count == 2) {
1070 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1071 } else if (count == 3) {
1072 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001073 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001074 switch (mShortPressOnPowerBehavior) {
1075 case SHORT_PRESS_POWER_NOTHING:
1076 break;
1077 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1078 mPowerManager.goToSleep(eventTime,
1079 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1080 break;
1081 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1082 mPowerManager.goToSleep(eventTime,
1083 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1084 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1085 break;
1086 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1087 mPowerManager.goToSleep(eventTime,
1088 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1089 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1090 launchHomeFromHotKey();
1091 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001092 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001093 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001094 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001095 }
1096 }
1097 }
1098
1099 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1100 switch (behavior) {
1101 case MULTI_PRESS_POWER_NOTHING:
1102 break;
1103 case MULTI_PRESS_POWER_THEATER_MODE:
Bryce Lee3ae447e2015-06-30 12:31:41 -07001104 if (!isUserSetupComplete()) {
1105 Slog.i(TAG, "Ignoring toggling theater mode - device not setup.");
1106 break;
1107 }
1108
Jeff Brown13f00f02014-10-31 14:45:50 -07001109 if (isTheaterModeEnabled()) {
1110 Slog.i(TAG, "Toggling theater mode off.");
1111 Settings.Global.putInt(mContext.getContentResolver(),
1112 Settings.Global.THEATER_MODE_ON, 0);
1113 if (!interactive) {
1114 wakeUpFromPowerKey(eventTime);
1115 }
1116 } else {
1117 Slog.i(TAG, "Toggling theater mode on.");
1118 Settings.Global.putInt(mContext.getContentResolver(),
1119 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001120
1121 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001122 mPowerManager.goToSleep(eventTime,
1123 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1124 }
1125 }
1126 break;
1127 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001128 Slog.i(TAG, "Starting brightness boost.");
1129 if (!interactive) {
1130 wakeUpFromPowerKey(eventTime);
1131 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001132 mPowerManager.boostScreenBrightness(eventTime);
1133 break;
1134 }
1135 }
1136
1137 private int getMaxMultiPressPowerCount() {
1138 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1139 return 3;
1140 }
1141 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1142 return 2;
1143 }
1144 return 1;
1145 }
1146
1147 private void powerLongPress() {
1148 final int behavior = getResolvedLongPressOnPowerBehavior();
1149 switch (behavior) {
1150 case LONG_PRESS_POWER_NOTHING:
1151 break;
1152 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1153 mPowerKeyHandled = true;
1154 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1155 performAuditoryFeedbackForAccessibilityIfNeed();
1156 }
1157 showGlobalActionsInternal();
1158 break;
1159 case LONG_PRESS_POWER_SHUT_OFF:
1160 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1161 mPowerKeyHandled = true;
1162 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1163 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1164 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1165 break;
1166 }
1167 }
1168
Nick Vaccarob593a812015-05-15 11:23:05 -07001169 private void sleepPress(long eventTime) {
1170 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1171 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1172 }
1173 }
1174
1175 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001176 switch (mShortPressOnSleepBehavior) {
1177 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001178 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001179 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1180 mPowerManager.goToSleep(eventTime,
1181 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001182 break;
1183 }
1184 }
1185
Jeff Brown13f00f02014-10-31 14:45:50 -07001186 private int getResolvedLongPressOnPowerBehavior() {
1187 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1188 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1189 }
1190 return mLongPressOnPowerBehavior;
1191 }
1192
1193 private boolean hasLongPressOnPowerBehavior() {
1194 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001195 }
1196
1197 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001198 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001199 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1200 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001201 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001202 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1203 && now <= mScreenshotChordPowerKeyTime
1204 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1205 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001206 cancelPendingPowerKeyAction();
1207
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001208 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001209 }
1210 }
1211 }
1212
Winson Chung1cea2f32012-10-08 20:42:01 -07001213 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001214 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001215 // Double the time it takes to take a screenshot from the keyguard
1216 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001217 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001218 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001219 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001220 }
1221
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001222 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001223 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001224 }
1225
Jeff Brown13f00f02014-10-31 14:45:50 -07001226 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001227 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001228 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001229 mEndCallKeyHandled = true;
1230 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1231 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001232 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001233 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001234 }
1235 };
1236
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001237 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001238 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001239 public void run() {
1240 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001241 }
1242 };
1243
Alan Viverettee34560b22014-07-10 14:50:06 -07001244 @Override
1245 public void showGlobalActions() {
1246 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1247 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1248 }
1249
1250 void showGlobalActionsInternal() {
1251 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001252 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001253 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001254 }
Jim Millerab954542014-10-10 18:21:49 -07001255 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001256 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1257 if (keyguardShowing) {
1258 // since it took two seconds of long press to bring this up,
1259 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001260 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001261 }
1262 }
1263
1264 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001265 return Settings.Global.getInt(
1266 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001267 }
1268
Maurice Lam99c6e072014-04-28 18:24:28 -07001269 boolean isUserSetupComplete() {
1270 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1271 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1272 }
1273
Jeff Brown13f00f02014-10-31 14:45:50 -07001274 private void handleShortPressOnHome() {
Jinsuk Kime601b712015-07-07 08:01:02 +09001275 // Turn on the connected TV and switch HDMI input if we're a HDMI playback device.
1276 getHdmiControl().turnOnTv();
1277
Jeff Brown13f00f02014-10-31 14:45:50 -07001278 // If there's a dream running then use home to escape the dream
1279 // but don't actually go home.
1280 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1281 mDreamManagerInternal.stopDream(false /*immediate*/);
1282 return;
1283 }
1284
1285 // Go home!
1286 launchHomeFromHotKey();
1287 }
1288
Jinsuk Kime601b712015-07-07 08:01:02 +09001289 /**
1290 * Creates an accessor to HDMI control service that performs the operation of
1291 * turning on TV (optional) and switching input to us. If HDMI control service
1292 * is not available or we're not a HDMI playback device, the operation is no-op.
1293 */
1294 private HdmiControl getHdmiControl() {
1295 if (null == mHdmiControl) {
1296 HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService(
1297 Context.HDMI_CONTROL_SERVICE);
1298 HdmiPlaybackClient client = null;
1299 if (manager != null) {
1300 client = manager.getPlaybackClient();
1301 }
1302 mHdmiControl = new HdmiControl(client);
1303 }
1304 return mHdmiControl;
1305 }
1306
1307 private static class HdmiControl {
1308 private final HdmiPlaybackClient mClient;
1309
1310 private HdmiControl(HdmiPlaybackClient client) {
1311 mClient = client;
1312 }
1313
1314 public void turnOnTv() {
1315 if (mClient == null) {
1316 return;
1317 }
1318 mClient.oneTouchPlay(new OneTouchPlayCallback() {
1319 @Override
1320 public void onComplete(int result) {
1321 if (result != HdmiControlManager.RESULT_SUCCESS) {
1322 Log.w(TAG, "One touch play failed: " + result);
1323 }
1324 }
1325 });
1326 }
1327 }
1328
Jaewan Kim52632e22016-01-14 18:01:52 +09001329 private void handleLongPressOnHome(int deviceId, KeyEvent event) {
1330 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) {
1331 return;
1332 }
1333 mHomeConsumed = true;
1334 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001335
Jaewan Kim52632e22016-01-14 18:01:52 +09001336 switch (mLongPressOnHomeBehavior) {
1337 case LONG_PRESS_HOME_RECENT_SYSTEM_UI:
Jeff Browncaca8812013-05-09 13:34:33 -07001338 toggleRecentApps();
Jaewan Kim52632e22016-01-14 18:01:52 +09001339 break;
1340 case LONG_PRESS_HOME_ASSIST:
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001341 launchAssistAction(null, deviceId);
Jaewan Kim52632e22016-01-14 18:01:52 +09001342 break;
1343 case LONG_PRESS_HOME_PICTURE_IN_PICTURE:
Jaewan Kimc552b042016-01-18 16:08:45 +09001344 requestTvPictureInPicture(event);
Jaewan Kim52632e22016-01-14 18:01:52 +09001345 break;
1346 default:
1347 Log.w(TAG, "Not defined home long press behavior: " + mLongPressOnHomeBehavior);
1348 break;
Jim Millere6ad1a82010-08-20 19:25:39 -07001349 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001350 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001351
Jeff Browncaca8812013-05-09 13:34:33 -07001352 private void handleDoubleTapOnHome() {
1353 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1354 mHomeConsumed = true;
1355 toggleRecentApps();
1356 }
1357 }
1358
Jaewan Kimc552b042016-01-18 16:08:45 +09001359 private void requestTvPictureInPicture(KeyEvent event) {
1360 if (DEBUG_INPUT) Log.d(TAG, "requestTvPictureInPicture event=" + event);
1361 mHandler.removeMessages(MSG_REQUEST_TV_PICTURE_IN_PICTURE);
1362 Message msg = mHandler.obtainMessage(MSG_REQUEST_TV_PICTURE_IN_PICTURE);
1363 msg.setAsynchronous(true);
1364 msg.sendToTarget();
1365 }
1366
1367 private void requestTvPictureInPictureInternal() {
1368 try {
1369 IStatusBarService statusbar = getStatusBarService();
1370 if (statusbar != null) {
1371 statusbar.requestTvPictureInPicture();
1372 }
1373 } catch (RemoteException|IllegalArgumentException e) {
1374 Slog.e(TAG, "Cannot handle picture-in-picture key", e);
1375 // re-acquire status bar service next time it is needed.
1376 mStatusBarService = null;
1377 }
Jaewan Kim52632e22016-01-14 18:01:52 +09001378 }
1379
Jeff Browncaca8812013-05-09 13:34:33 -07001380 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1381 @Override
1382 public void run() {
1383 if (mHomeDoubleTapPending) {
1384 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001385 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001386 }
1387 }
1388 };
1389
Mark Renoufc1256912015-03-11 14:38:23 -04001390 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001391 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001392 }
1393
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001394 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001395 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001396 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001397 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001398 mContext = context;
1399 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001400 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001401 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001402 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001403 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Michael Wrighta4d22d72015-09-16 23:19:26 +01001404 mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001405 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Mark Renoufc1256912015-03-11 14:38:23 -04001406
1407 // Init display burn-in protection
1408 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1409 com.android.internal.R.bool.config_enableBurnInProtection);
1410 // Allow a system property to override this. Used by developer settings.
1411 boolean burnInProtectionDevMode =
1412 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1413 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1414 final int minHorizontal;
1415 final int maxHorizontal;
1416 final int minVertical;
1417 final int maxVertical;
1418 final int maxRadius;
1419 if (burnInProtectionDevMode) {
1420 minHorizontal = -8;
1421 maxHorizontal = 8;
1422 minVertical = -8;
1423 maxVertical = -4;
1424 maxRadius = (isRoundWindow()) ? 6 : -1;
1425 } else {
1426 Resources resources = context.getResources();
1427 minHorizontal = resources.getInteger(
1428 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1429 maxHorizontal = resources.getInteger(
1430 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1431 minVertical = resources.getInteger(
1432 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1433 maxVertical = resources.getInteger(
1434 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1435 maxRadius = resources.getInteger(
1436 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1437 }
1438 mBurnInProtectionHelper = new BurnInProtectionHelper(
1439 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001440 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001441
Jeff Brown70825162012-03-28 17:27:48 -07001442 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001443 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001444 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001445 try {
1446 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1447 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001448 mSettingsObserver = new SettingsObserver(mHandler);
1449 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001450 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001451 mUiMode = context.getResources().getInteger(
1452 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001453 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1454 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1455 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1456 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
keunyounga7710492015-09-23 11:33:58 -07001457 mEnableCarDockHomeCapture = context.getResources().getBoolean(
1458 com.android.internal.R.bool.config_enableCarDockHomeLaunch);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001459 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1460 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1461 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1462 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1463 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1464 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1465 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1466 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001467
Jeff Brown96307042012-07-27 15:51:34 -07001468 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1469 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001470 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001471 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1472 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001473 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001474 mSupportAutoRotation = mContext.getResources().getBoolean(
1475 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001476 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001477 com.android.internal.R.integer.config_lidOpenRotation);
1478 mCarDockRotation = readRotation(
1479 com.android.internal.R.integer.config_carDockRotation);
1480 mDeskDockRotation = readRotation(
1481 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001482 mUndockedHdmiRotation = readRotation(
1483 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001484 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1485 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1486 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1487 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001488 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1489 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1490 mLidNavigationAccessibility = mContext.getResources().getInteger(
1491 com.android.internal.R.integer.config_lidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01001492 mLidControlsScreenLock = mContext.getResources().getBoolean(
1493 com.android.internal.R.bool.config_lidControlsScreenLock);
Jeff Brownc458ce92012-04-30 14:58:40 -07001494 mLidControlsSleep = mContext.getResources().getBoolean(
1495 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001496 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1497 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001498
1499 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1500 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1501 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1502 || mContext.getResources().getBoolean(
1503 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1504 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1505 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001506 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1507 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001508 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1509 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1510 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1511 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1512 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1513 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1514
Bryce Lee55e846d2014-11-04 12:43:44 -08001515 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1516 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1517
Bryce Leed3b28402015-03-09 15:49:13 +00001518 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1519 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1520
Jeff Brown13f00f02014-10-31 14:45:50 -07001521 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1522 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1523 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1524 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1525 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1526 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1527 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1528 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001529 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1530 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001531
John Spurlock61560172015-02-06 19:46:04 -05001532 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001533
Jeff Brownf71343d2013-05-31 17:59:11 -07001534 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001535
Svetoslav8e3feb12014-02-24 13:46:47 -08001536 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1537 Context.ACCESSIBILITY_SERVICE);
1538
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001539 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001540 IntentFilter filter = new IntentFilter();
1541 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1542 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1543 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1544 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001545 filter.addAction(Intent.ACTION_DOCK_EVENT);
1546 Intent intent = context.registerReceiver(mDockReceiver, filter);
1547 if (intent != null) {
1548 // Retrieve current sticky dock event broadcast.
1549 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1550 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1551 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001552
Jeff Brown6aaf2952012-10-05 16:01:08 -07001553 // register for dream-related broadcasts
1554 filter = new IntentFilter();
1555 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1556 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1557 context.registerReceiver(mDreamReceiver, filter);
1558
Christopher Tate5e08af02012-09-21 17:17:22 -07001559 // register for multiuser-relevant broadcasts
1560 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1561 context.registerReceiver(mMultiuserReceiver, filter);
1562
John Spurlock57306e62013-04-22 09:48:49 -04001563 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001564 mSystemGestures = new SystemGesturesPointerEventListener(context,
1565 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001566 @Override
1567 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001568 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001569 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001570 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001571 }
1572 @Override
1573 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001574 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001575 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001576 }
1577 }
1578 @Override
1579 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001580 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001581 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001582 }
1583 }
1584 @Override
Michael Wrighta4d22d72015-09-16 23:19:26 +01001585 public void onFling(int duration) {
1586 if (mPowerManagerInternal != null) {
1587 mPowerManagerInternal.powerHint(
1588 PowerManagerInternal.POWER_HINT_INTERACTION, duration);
1589 }
1590 }
1591 @Override
John Spurlockad3e6cb2013-04-30 08:47:43 -04001592 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001593 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001594 }
Adrian Roos3595be42015-03-05 16:31:15 +01001595 @Override
1596 public void onDown() {
1597 mOrientationListener.onTouchStart();
1598 }
1599 @Override
1600 public void onUpOrCancel() {
1601 mOrientationListener.onTouchEnd();
1602 }
Jun Mukaid2e7e352015-07-22 17:14:02 -07001603 @Override
1604 public void onMouseHoverAtTop() {
1605 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1606 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1607 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS;
1608 mHandler.sendMessageDelayed(msg, 500);
1609 }
1610 @Override
1611 public void onMouseHoverAtBottom() {
1612 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1613 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1614 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION;
1615 mHandler.sendMessageDelayed(msg, 500);
1616 }
1617 @Override
1618 public void onMouseLeaveFromEdge() {
1619 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1620 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001621 });
John Spurlockf1a36642013-10-12 17:50:42 -04001622 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001623 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001624
Jeff Brownc2346132012-04-13 01:55:38 -07001625 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001626 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1627 com.android.internal.R.array.config_longPressVibePattern);
1628 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1629 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001630 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1631 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001632 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1633 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001634 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1635 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001636 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1637 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1638 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1639 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001640 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1641 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001642
Christopher Tatee90585f2012-03-05 18:56:25 -08001643 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1644 com.android.internal.R.bool.config_enableScreenshotChord);
Jorim Jaggi406585a2015-12-21 10:58:56 +01001645 mForceWindowDrawsStatusBarBackground = mContext.getResources().getBoolean(
1646 R.bool.config_forceWindowDrawsStatusBarBackground);
Christopher Tatee90585f2012-03-05 18:56:25 -08001647
Justin Kohd378ad72013-04-01 12:18:26 -07001648 mGlobalKeyManager = new GlobalKeyManager(mContext);
1649
Joe Onoratoea495d42011-04-06 11:41:11 -07001650 // Controls rotation and the like.
1651 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001652
1653 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001654 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001655 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1656 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001657 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001658
1659 mWindowManagerInternal.registerAppTransitionListener(
1660 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001661 }
1662
Jeff Brownf71343d2013-05-31 17:59:11 -07001663 /**
1664 * Read values from config.xml that may be overridden depending on
1665 * the configuration of the device.
1666 * eg. Disable long press on home goes to recents on sw600dp.
1667 */
1668 private void readConfigurationDependentBehaviors() {
Jaewan Kimc552b042016-01-18 16:08:45 +09001669 final Resources res = mContext.getResources();
1670
1671 mLongPressOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001672 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1673 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
Jaewan Kim52632e22016-01-14 18:01:52 +09001674 mLongPressOnHomeBehavior > LAST_LONG_PRESS_HOME_BEHAVIOR) {
Jeff Brownf71343d2013-05-31 17:59:11 -07001675 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1676 }
1677
Jaewan Kimc552b042016-01-18 16:08:45 +09001678 mDoubleTapOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001679 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1680 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1681 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1682 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1683 }
Jaewan Kim49117872016-01-19 17:24:08 +09001684
1685 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_NOTHING;
1686 if (mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)) {
1687 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE;
1688 }
Jeff Brownf71343d2013-05-31 17:59:11 -07001689 }
1690
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001691 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001692 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001693 // This method might be called before the policy has been fully initialized
1694 // or for other displays we don't care about.
1695 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1696 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001697 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001698 mDisplay = display;
1699
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001700 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001701 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001702 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001703 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001704 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001705 mLandscapeRotation = Surface.ROTATION_0;
1706 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001707 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001708 mPortraitRotation = Surface.ROTATION_90;
1709 mUpsideDownRotation = Surface.ROTATION_270;
1710 } else {
1711 mPortraitRotation = Surface.ROTATION_270;
1712 mUpsideDownRotation = Surface.ROTATION_90;
1713 }
1714 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001715 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001716 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001717 mPortraitRotation = Surface.ROTATION_0;
1718 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001719 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001720 mLandscapeRotation = Surface.ROTATION_270;
1721 mSeascapeRotation = Surface.ROTATION_90;
1722 } else {
1723 mLandscapeRotation = Surface.ROTATION_90;
1724 mSeascapeRotation = Surface.ROTATION_270;
1725 }
1726 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001727
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001728 mStatusBarHeight =
1729 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001730
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001731 // Height of the navigation bar when presented horizontally at bottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001732 mNavigationBarHeightForRotationDefault[mPortraitRotation] =
1733 mNavigationBarHeightForRotationDefault[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001734 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001735 mNavigationBarHeightForRotationDefault[mLandscapeRotation] =
1736 mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize(
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001737 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001738
1739 // Width of the navigation bar when presented vertically along one side
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001740 mNavigationBarWidthForRotationDefault[mPortraitRotation] =
1741 mNavigationBarWidthForRotationDefault[mUpsideDownRotation] =
1742 mNavigationBarWidthForRotationDefault[mLandscapeRotation] =
1743 mNavigationBarWidthForRotationDefault[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001744 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001745
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001746 // Height of the navigation bar when presented horizontally at bottom
1747 mNavigationBarHeightForRotationInCarMode[mPortraitRotation] =
1748 mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] =
1749 res.getDimensionPixelSize(
1750 com.android.internal.R.dimen.navigation_bar_height_car_mode);
1751 mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] =
1752 mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize(
1753 com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode);
1754
1755 // Width of the navigation bar when presented vertically along one side
1756 mNavigationBarWidthForRotationInCarMode[mPortraitRotation] =
1757 mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] =
1758 mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] =
1759 mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] =
1760 res.getDimensionPixelSize(
1761 com.android.internal.R.dimen.navigation_bar_width_car_mode);
1762
Daniel Sandler4a066c52012-04-20 14:49:13 -04001763 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001764 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001765 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001766
Devin Kimd7b12b42014-05-05 14:34:58 -07001767 // Allow the navigation bar to move on non-square small devices (phones).
1768 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001769
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001770 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001771 // Allow a system property to override this. Used by the emulator.
1772 // See also hasNavigationBar().
1773 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1774 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001775 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001776 } else if ("0".equals(navBarOverride)) {
1777 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001778 }
1779
Jeff Brown27f1d672012-10-17 18:32:34 -07001780 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1781 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001782 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001783 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001784 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001785 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001786 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001787 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001788
Chong Zhangae6119ff2014-11-11 18:54:39 -08001789 // For demo purposes, allow the rotation of the remote display to be controlled.
1790 // By default, remote display locks rotation to landscape.
1791 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1792 mDemoRotation = mPortraitRotation;
1793 } else {
1794 mDemoRotation = mLandscapeRotation;
1795 }
1796 mDemoRotationLock = SystemProperties.getBoolean(
1797 "persist.demo.rotationlock", false);
1798
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001799 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1800 // http://developer.android.com/guide/practices/screens_support.html#range
1801 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1802 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1803 // For debug purposes the next line turns this feature off with:
1804 // $ adb shell setprop config.override_forced_orient true
1805 // $ adb shell wm size reset
1806 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1807 }
1808
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001809 /**
1810 * @return whether the navigation bar can be hidden, e.g. the device has a
1811 * navigation bar and touch exploration is not enabled
1812 */
1813 private boolean canHideNavigationBar() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04001814 return mHasNavigationBar;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001815 }
1816
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001817 @Override
1818 public boolean isDefaultOrientationForced() {
1819 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001820 }
1821
Dianne Hackbornc652de82013-02-15 16:32:56 -08001822 @Override
1823 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1824 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1825 mOverscanLeft = left;
1826 mOverscanTop = top;
1827 mOverscanRight = right;
1828 mOverscanBottom = bottom;
1829 }
1830 }
1831
Dianne Hackbornc777e072010-02-12 13:07:59 -08001832 public void updateSettings() {
1833 ContentResolver resolver = mContext.getContentResolver();
1834 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001835 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001836 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001837 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001838 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1839 UserHandle.USER_CURRENT);
1840 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001841 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001842 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1843 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001844
Jeff Browna20dda42014-05-27 20:57:24 -07001845 // Configure wake gesture.
1846 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1847 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1848 UserHandle.USER_CURRENT) != 0;
1849 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1850 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1851 updateWakeGestureListenerLp();
1852 }
1853
Jeff Brown207673cd2012-06-05 17:47:11 -07001854 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001855 int userRotation = Settings.System.getIntForUser(resolver,
1856 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1857 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001858 if (mUserRotation != userRotation) {
1859 mUserRotation = userRotation;
1860 updateRotation = true;
1861 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001862 int userRotationMode = Settings.System.getIntForUser(resolver,
1863 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001864 WindowManagerPolicy.USER_ROTATION_FREE :
1865 WindowManagerPolicy.USER_ROTATION_LOCKED;
1866 if (mUserRotationMode != userRotationMode) {
1867 mUserRotationMode = userRotationMode;
1868 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001869 updateOrientationListenerLp();
1870 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001871
Dianne Hackbornc777e072010-02-12 13:07:59 -08001872 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001873 int pointerLocation = Settings.System.getIntForUser(resolver,
1874 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001875 if (mPointerLocationMode != pointerLocation) {
1876 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001877 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1878 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001879 }
1880 }
1881 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001882 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1883 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1884 String imId = Settings.Secure.getStringForUser(resolver,
1885 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001886 boolean hasSoftInput = imId != null && imId.length() > 0;
1887 if (mHasSoftInput != hasSoftInput) {
1888 mHasSoftInput = hasSoftInput;
1889 updateRotation = true;
1890 }
John Spurlockf1a36642013-10-12 17:50:42 -04001891 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001892 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001893 }
tiger_huangcc6366d2015-06-29 17:17:30 +08001894 }
1895 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05001896 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001897 }
1898 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001899 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001900 }
Jeff Brown70825162012-03-28 17:27:48 -07001901 }
1902
Jeff Browna20dda42014-05-27 20:57:24 -07001903 private void updateWakeGestureListenerLp() {
1904 if (shouldEnableWakeGestureLp()) {
1905 mWakeGestureListener.requestWakeUpTrigger();
1906 } else {
1907 mWakeGestureListener.cancelWakeUpTrigger();
1908 }
1909 }
1910
1911 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001912 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001913 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1914 && mWakeGestureListener.isSupported();
1915 }
1916
Jeff Brown70825162012-03-28 17:27:48 -07001917 private void enablePointerLocation() {
1918 if (mPointerLocationView == null) {
1919 mPointerLocationView = new PointerLocationView(mContext);
1920 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001921 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1922 WindowManager.LayoutParams.MATCH_PARENT,
1923 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001924 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001925 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1926 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1927 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1928 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001929 if (ActivityManager.isHighEndGfx()) {
1930 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1931 lp.privateFlags |=
1932 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1933 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001934 lp.format = PixelFormat.TRANSLUCENT;
1935 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001936 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001937 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001938 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001939 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001940 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001941 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001942 }
Jeff Brown70825162012-03-28 17:27:48 -07001943
1944 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001945 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001946 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1947 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001948 wm.removeView(mPointerLocationView);
1949 mPointerLocationView = null;
1950 }
1951 }
1952
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001953 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001954 try {
1955 int rotation = mContext.getResources().getInteger(resID);
1956 switch (rotation) {
1957 case 0:
1958 return Surface.ROTATION_0;
1959 case 90:
1960 return Surface.ROTATION_90;
1961 case 180:
1962 return Surface.ROTATION_180;
1963 case 270:
1964 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001965 }
1966 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001967 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001968 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001969 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001970 }
1971
1972 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001973 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001974 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001975 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001976
1977 outAppOp[0] = AppOpsManager.OP_NONE;
1978
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001979 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1980 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1981 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1982 return WindowManagerGlobal.ADD_INVALID_TYPE;
1983 }
1984
1985 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1986 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001987 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001988 }
1989 String permission = null;
1990 switch (type) {
1991 case TYPE_TOAST:
1992 // XXX right now the app process has complete control over
1993 // this... should introduce a token to let the system
1994 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001995 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001996 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001997 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001998 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001999 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07002000 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002001 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07002002 case TYPE_ACCESSIBILITY_OVERLAY:
Jason Monk8f7f3182015-11-18 16:35:14 -05002003 case TYPE_QS_DIALOG:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07002004 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002005 break;
2006 case TYPE_PHONE:
2007 case TYPE_PRIORITY_PHONE:
2008 case TYPE_SYSTEM_ALERT:
2009 case TYPE_SYSTEM_ERROR:
2010 case TYPE_SYSTEM_OVERLAY:
2011 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08002012 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002013 break;
2014 default:
2015 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
2016 }
2017 if (permission != null) {
Billy Laucbe540f2015-06-25 01:51:44 +01002018 if (permission == android.Manifest.permission.SYSTEM_ALERT_WINDOW) {
2019 final int callingUid = Binder.getCallingUid();
Billy Lau060275f2015-07-15 22:29:19 +01002020 // system processes will be automatically allowed privilege to draw
Billy Laucbe540f2015-06-25 01:51:44 +01002021 if (callingUid == Process.SYSTEM_UID) {
2022 return WindowManagerGlobal.ADD_OKAY;
2023 }
2024
Billy Lau060275f2015-07-15 22:29:19 +01002025 // check if user has enabled this operation. SecurityException will be thrown if
2026 // this app has not been allowed by the user
Billy Laucbe540f2015-06-25 01:51:44 +01002027 final int mode = mAppOpsManager.checkOp(outAppOp[0], callingUid,
2028 attrs.packageName);
Billy Lau060275f2015-07-15 22:29:19 +01002029 switch (mode) {
2030 case AppOpsManager.MODE_ALLOWED:
2031 case AppOpsManager.MODE_IGNORED:
2032 // although we return ADD_OKAY for MODE_IGNORED, the added window will
2033 // actually be hidden in WindowManagerService
2034 return WindowManagerGlobal.ADD_OKAY;
2035 case AppOpsManager.MODE_ERRORED:
Billy Laucbe540f2015-06-25 01:51:44 +01002036 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
Billy Lau060275f2015-07-15 22:29:19 +01002037 default:
2038 // in the default mode, we will make a decision here based on
2039 // checkCallingPermission()
2040 if (mContext.checkCallingPermission(permission) !=
2041 PackageManager.PERMISSION_GRANTED) {
2042 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
2043 } else {
2044 return WindowManagerGlobal.ADD_OKAY;
2045 }
Billy Laucbe540f2015-06-25 01:51:44 +01002046 }
Billy Laucbe540f2015-06-25 01:51:44 +01002047 }
2048
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002049 if (mContext.checkCallingOrSelfPermission(permission)
2050 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07002051 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002052 }
2053 }
Jeff Brown98365d72012-08-19 20:30:52 -07002054 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002055 }
Craig Mautner88400d32012-09-30 12:35:45 -07002056
2057 @Override
2058 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
2059
2060 // If this switch statement is modified, modify the comment in the declarations of
2061 // the type in {@link WindowManager.LayoutParams} as well.
2062 switch (attrs.type) {
2063 default:
2064 // These are the windows that by default are shown only to the user that created
2065 // them. If this needs to be overridden, set
2066 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
2067 // {@link WindowManager.LayoutParams}. Note that permission
2068 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
2069 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
2070 return true;
2071 }
2072 break;
2073
2074 // These are the windows that by default are shown to all users. However, to
2075 // protect against spoofing, check permissions below.
2076 case TYPE_APPLICATION_STARTING:
2077 case TYPE_BOOT_PROGRESS:
2078 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07002079 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08002080 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07002081 case TYPE_KEYGUARD_DIALOG:
2082 case TYPE_MAGNIFICATION_OVERLAY:
2083 case TYPE_NAVIGATION_BAR:
2084 case TYPE_NAVIGATION_BAR_PANEL:
2085 case TYPE_PHONE:
2086 case TYPE_POINTER:
2087 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07002088 case TYPE_SEARCH_BAR:
2089 case TYPE_STATUS_BAR:
2090 case TYPE_STATUS_BAR_PANEL:
2091 case TYPE_STATUS_BAR_SUB_PANEL:
2092 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07002093 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07002094 case TYPE_PRIVATE_PRESENTATION:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002095 case TYPE_DOCK_DIVIDER:
Craig Mautner88400d32012-09-30 12:35:45 -07002096 break;
2097 }
2098
2099 // Check if third party app has set window to system window type.
2100 return mContext.checkCallingOrSelfPermission(
2101 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
2102 != PackageManager.PERMISSION_GRANTED;
2103 }
2104
Craig Mautner967212c2013-04-13 21:10:58 -07002105 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002106 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
2107 switch (attrs.type) {
2108 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07002109 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002110 // These types of windows can't receive input events.
2111 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2112 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002113 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002114 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002115 case TYPE_STATUS_BAR:
2116
2117 // If the Keyguard is in a hidden state (occluded by another window), we force to
2118 // remove the wallpaper and keyguard flag so that any change in-flight after setting
2119 // the keyguard as occluded wouldn't set these flags again.
2120 // See {@link #processKeyguardSetHiddenResultLw}.
2121 if (mKeyguardHidden) {
2122 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2123 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2124 }
2125 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002126 }
Adrian Roos38502112014-04-09 21:04:11 +02002127
2128 if (attrs.type != TYPE_STATUS_BAR) {
2129 // The status bar is the only window allowed to exhibit keyguard behavior.
2130 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2131 }
Adrian Roosea562512014-05-05 13:33:03 +02002132
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002133 if (ActivityManager.isHighEndGfx()) {
2134 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
2135 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
2136 }
2137 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0
Jorim Jaggi406585a2015-12-21 10:58:56 +01002138 || (mForceWindowDrawsStatusBarBackground
2139 && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT)) {
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002140 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
2141 }
Adrian Roosea562512014-05-05 13:33:03 +02002142 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002143 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002144
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002145 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07002146 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002147 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002148
Michael Wright3818c922014-09-02 13:59:07 -07002149 private void readCameraLensCoverState() {
2150 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
2151 }
2152
Jeff Browndaa37532012-05-01 15:54:03 -07002153 private boolean isHidden(int accessibilityMode) {
2154 switch (accessibilityMode) {
2155 case 1:
2156 return mLidState == LID_CLOSED;
2157 case 2:
2158 return mLidState == LID_OPEN;
2159 default:
2160 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002161 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002162 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002163
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002164 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002165 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07002166 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
2167 int navigationPresence) {
2168 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
2169
Jeff Brownf71343d2013-05-31 17:59:11 -07002170 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002171 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07002172 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08002173
Jeff Browndaa37532012-05-01 15:54:03 -07002174 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
2175 || (keyboardPresence == PRESENCE_INTERNAL
2176 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002177 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07002178 if (!mHasSoftInput) {
2179 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
2180 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002181 }
2182
Jeff Browndaa37532012-05-01 15:54:03 -07002183 if (config.navigation == Configuration.NAVIGATION_NONAV
2184 || (navigationPresence == PRESENCE_INTERNAL
2185 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002186 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08002187 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002188 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002189
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002190 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002191 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002192 public int windowTypeToLayerLw(int type) {
2193 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002194 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002195 }
2196 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07002197 case TYPE_PRIVATE_PRESENTATION:
2198 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002199 case TYPE_WALLPAPER:
2200 // wallpaper is at the bottom, though the window manager may move it.
2201 return 2;
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002202 case TYPE_DOCK_DIVIDER:
2203 return 2;
Jason Monk8f7f3182015-11-18 16:35:14 -05002204 case TYPE_QS_DIALOG:
2205 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002206 case TYPE_PHONE:
2207 return 3;
2208 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002209 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002210 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002211 case TYPE_VOICE_INTERACTION:
2212 // voice interaction layer is almost immediately above apps.
2213 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07002214 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002215 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07002216 case TYPE_SYSTEM_DIALOG:
2217 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002218 case TYPE_TOAST:
2219 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07002220 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002221 case TYPE_PRIORITY_PHONE:
2222 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07002223 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002224 case TYPE_DREAM:
2225 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07002226 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002227 case TYPE_SYSTEM_ALERT:
2228 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002229 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002230 case TYPE_INPUT_METHOD:
2231 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002232 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002233 case TYPE_INPUT_METHOD_DIALOG:
2234 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002235 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08002236 case TYPE_KEYGUARD_SCRIM:
2237 // the safety window that shows behind keyguard while keyguard is starting
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002238 return 14;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002239 case TYPE_STATUS_BAR_SUB_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002240 return 15;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002241 case TYPE_STATUS_BAR:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002242 return 16;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002243 case TYPE_STATUS_BAR_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002244 return 17;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002245 case TYPE_KEYGUARD_DIALOG:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002246 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002247 case TYPE_VOLUME_OVERLAY:
2248 // the on-screen volume indicator and controller shown when the user
2249 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002250 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002251 case TYPE_SYSTEM_OVERLAY:
2252 // the on-screen volume indicator and controller shown when the user
2253 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002254 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002255 case TYPE_NAVIGATION_BAR:
2256 // the navigation bar, if available, shows atop most things
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002257 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002258 case TYPE_NAVIGATION_BAR_PANEL:
2259 // some panels (e.g. search) need to show on top of the navigation bar
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002260 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002261 case TYPE_SYSTEM_ERROR:
2262 // system-level error dialogs
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002263 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002264 case TYPE_MAGNIFICATION_OVERLAY:
2265 // used to highlight the magnified portion of a display
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002266 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002267 case TYPE_DISPLAY_OVERLAY:
2268 // used to simulate secondary display devices
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002269 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002270 case TYPE_DRAG:
2271 // the drag layer: input for drag-and-drop is associated with this window,
2272 // which sits above all other focusable windows
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002273 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002274 case TYPE_ACCESSIBILITY_OVERLAY:
2275 // overlay put by accessibility services to intercept user interaction
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002276 return 27;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002277 case TYPE_SECURE_SYSTEM_OVERLAY:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002278 return 28;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002279 case TYPE_BOOT_PROGRESS:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002280 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002281 case TYPE_POINTER:
2282 // the (mouse) pointer layer
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002283 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002284 }
2285 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002286 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002287 }
2288
2289 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002290 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002291 public int subWindowTypeToLayerLw(int type) {
2292 switch (type) {
2293 case TYPE_APPLICATION_PANEL:
2294 case TYPE_APPLICATION_ATTACHED_DIALOG:
2295 return APPLICATION_PANEL_SUBLAYER;
2296 case TYPE_APPLICATION_MEDIA:
2297 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002298 case TYPE_APPLICATION_MEDIA_OVERLAY:
2299 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002300 case TYPE_APPLICATION_SUB_PANEL:
2301 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002302 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2303 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002304 }
2305 Log.e(TAG, "Unknown sub-window type: " + type);
2306 return 0;
2307 }
2308
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002309 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002310 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002311 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002312 }
2313
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002314 private int getNavigationBarWidth(int rotation, int uiMode) {
2315 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2316 return mNavigationBarWidthForRotationInCarMode[rotation];
2317 } else {
2318 return mNavigationBarWidthForRotationDefault[rotation];
2319 }
2320 }
2321
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002322 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002323 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation,
2324 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002325 if (mHasNavigationBar) {
2326 // For a basic navigation bar, when we are in landscape mode we place
2327 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002328 if (mNavigationBarCanMove && fullWidth > fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002329 return fullWidth - getNavigationBarWidth(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002330 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002331 }
2332 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002333 }
2334
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002335 private int getNavigationBarHeight(int rotation, int uiMode) {
2336 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2337 return mNavigationBarHeightForRotationInCarMode[rotation];
2338 } else {
2339 return mNavigationBarHeightForRotationDefault[rotation];
2340 }
2341 }
2342
Jose Lima9546b202014-07-02 17:21:51 -07002343 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002344 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation,
2345 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002346 if (mHasNavigationBar) {
2347 // For a basic navigation bar, when we are in portrait mode we place
2348 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002349 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002350 return fullHeight - getNavigationBarHeight(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002351 }
2352 }
2353 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002354 }
2355
Jose Lima9546b202014-07-02 17:21:51 -07002356 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002357 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode) {
2358 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002359 }
2360
Jose Lima9546b202014-07-02 17:21:51 -07002361 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002362 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode) {
John Spurlock80f00c12013-06-13 11:10:51 -04002363 // There is a separate status bar at the top of the display. We don't count that as part
2364 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002365 // we do want to exclude it since applications can't generally use that part
2366 // of the screen.
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002367 return getNonDecorDisplayHeight(
2368 fullWidth, fullHeight, rotation, uiMode) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002369 }
2370
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002371 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002372 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2373 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002374 (isKeyguardHostWindow(attrs) &&
2375 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002376 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002377 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002378
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002379 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002380 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2381 return attrs.type == TYPE_STATUS_BAR;
2382 }
2383
2384 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002385 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002386 switch (attrs.type) {
2387 case TYPE_STATUS_BAR:
2388 case TYPE_NAVIGATION_BAR:
2389 case TYPE_WALLPAPER:
2390 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002391 case TYPE_KEYGUARD_SCRIM:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002392 case TYPE_DOCK_DIVIDER:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002393 return false;
2394 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002395 // Hide only windows below the keyguard host window.
2396 return windowTypeToLayerLw(win.getBaseType())
2397 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002398 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002399 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002400
Craig Mautner7d7808f2014-09-11 18:02:38 -07002401 @Override
2402 public WindowState getWinShowWhenLockedLw() {
2403 return mWinShowWhenLocked;
2404 }
2405
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002406 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002407 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002408 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2409 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002410 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002411 if (!SHOW_STARTING_ANIMATIONS) {
2412 return null;
2413 }
2414 if (packageName == null) {
2415 return null;
2416 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002417
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002418 WindowManager wm = null;
2419 View view = null;
2420
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002421 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002422 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002423 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2424 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2425 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002426 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002427 try {
2428 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002429 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002430 } catch (PackageManager.NameNotFoundException e) {
2431 // Ignore
2432 }
2433 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002434
Jorim Jaggia16cc152015-06-01 16:55:05 -07002435 PhoneWindow win = new PhoneWindow(context);
2436 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002437
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002438 Resources r = context.getResources();
2439 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002440
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002441 win.setType(
2442 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002443
2444 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2445 // Assumes it's safe to show starting windows of launched apps while
2446 // the keyguard is being hidden. This is okay because starting windows never show
2447 // secret information.
2448 if (mKeyguardHidden) {
2449 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2450 }
2451 }
2452
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002453 // Force the window flags: this is a fake window, so it is not really
2454 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2455 // flag because we do know that the next window will take input
2456 // focus, so we want to get the IME window up on top of us right away.
2457 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002458 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002459 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2460 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2461 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002462 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002463 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2464 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2465 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002466
Adam Powell04fe6eb2013-05-31 14:39:48 -07002467 win.setDefaultIcon(icon);
2468 win.setDefaultLogo(logo);
2469
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002470 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002471 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002472
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002473 final WindowManager.LayoutParams params = win.getAttributes();
2474 params.token = appToken;
2475 params.packageName = packageName;
2476 params.windowAnimations = win.getWindowStyle().getResourceId(
2477 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002478 params.privateFlags |=
2479 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002480 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002481
2482 if (!compatInfo.supportsScreen()) {
2483 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2484 }
2485
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002486 params.setTitle("Starting " + packageName);
2487
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002488 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2489 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002490
Craig Mautner6fbda632012-07-03 09:26:39 -07002491 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002492 TAG, "Adding starting window for " + packageName
2493 + " / " + appToken + ": "
2494 + (view.getParent() != null ? view : null));
2495
2496 wm.addView(view, params);
2497
2498 // Only return the view if it was successfully added to the
2499 // window manager... which we can tell by it having a parent.
2500 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002501 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002502 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002503 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2504 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002505 } catch (RuntimeException e) {
2506 // don't crash if something else bad happens, for example a
2507 // failure loading resources because we are loading from an app
2508 // on external storage that has been unmounted.
2509 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002510 } finally {
2511 if (view != null && view.getParent() == null) {
2512 Log.w(TAG, "view not successfully added to wm, removing view");
2513 wm.removeViewImmediate(view);
2514 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002515 }
2516
2517 return null;
2518 }
2519
2520 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002521 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002522 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002523 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2524 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002525
2526 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002527 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002528 wm.removeView(window);
2529 }
2530 }
2531
2532 /**
2533 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002534 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002535 * Currently enforces that three window types are singletons:
2536 * <ul>
2537 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002538 * <li>KEYGUARD_TYPE</li>
2539 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002540 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002541 * @param win The window to be added
2542 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002543 *
Jeff Brown98365d72012-08-19 20:30:52 -07002544 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2545 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002546 */
Jose Lima9546b202014-07-02 17:21:51 -07002547 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002548 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2549 switch (attrs.type) {
2550 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002551 mContext.enforceCallingOrSelfPermission(
2552 android.Manifest.permission.STATUS_BAR_SERVICE,
2553 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002554 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002555 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002556 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002557 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002558 }
2559 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002560 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002561 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002562 case TYPE_NAVIGATION_BAR:
2563 mContext.enforceCallingOrSelfPermission(
2564 android.Manifest.permission.STATUS_BAR_SERVICE,
2565 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002566 if (mNavigationBar != null) {
2567 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002568 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002569 }
2570 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002571 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002572 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002573 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002574 break;
Jim Millere898ac52012-04-06 17:10:57 -07002575 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002576 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002577 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002578 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002579 mContext.enforceCallingOrSelfPermission(
2580 android.Manifest.permission.STATUS_BAR_SERVICE,
2581 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002582 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002583 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002584 if (mKeyguardScrim != null) {
2585 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2586 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002587 mKeyguardScrim = win;
2588 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002589 }
Jeff Brown98365d72012-08-19 20:30:52 -07002590 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002591 }
2592
2593 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002594 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002595 public void removeWindowLw(WindowState win) {
2596 if (mStatusBar == win) {
2597 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002598 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002599 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002600 } else if (mKeyguardScrim == win) {
2601 Log.v(TAG, "Removing keyguard scrim");
2602 mKeyguardScrim = null;
2603 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002604 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002605 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002606 }
2607 }
2608
2609 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002610
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002611 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002612 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002613 public int selectAnimationLw(WindowState win, int transit) {
2614 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2615 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002616 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002617 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002618 if (transit == TRANSIT_EXIT
2619 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002620 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002621 } else if (transit == TRANSIT_ENTER
2622 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002623 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002624 }
2625 } else if (win == mNavigationBar) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002626 if (win.getAttrs().windowAnimations != 0) {
2627 return 0;
2628 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002629 // This can be on either the bottom or the right.
2630 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002631 if (transit == TRANSIT_EXIT
2632 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002633 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002634 } else if (transit == TRANSIT_ENTER
2635 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002636 return R.anim.dock_bottom_enter;
2637 }
2638 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002639 if (transit == TRANSIT_EXIT
2640 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002641 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002642 } else if (transit == TRANSIT_ENTER
2643 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002644 return R.anim.dock_right_enter;
2645 }
2646 }
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08002647 } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08002648 return selectDockedDividerAnimationLw(win, transit);
Craig Mautner4b71aa12012-12-27 17:20:01 -08002649 }
2650
2651 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002652 if (win.hasAppShownWindows()) {
2653 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2654 return com.android.internal.R.anim.app_starting_exit;
2655 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002656 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002657 && transit == TRANSIT_ENTER) {
2658 // Special case: we are animating in a dream, while the keyguard
2659 // is shown. We don't want an animation on the dream, because
2660 // we need it shown immediately with the keyguard animating away
2661 // to reveal it.
2662 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002663 }
2664
2665 return 0;
2666 }
2667
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08002668 private int selectDockedDividerAnimationLw(WindowState win, int transit) {
2669 int insets = mWindowManagerFuncs.getDockedDividerInsetsLw();
2670
2671 // If the divider is behind the navigation bar, don't animate.
2672 if (mNavigationBar != null
2673 && (win.getFrameLw().top + insets >= mNavigationBar.getFrameLw().top
2674 || win.getFrameLw().left + insets >= mNavigationBar.getFrameLw().left)) {
2675 return 0;
2676 }
2677 if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
2678 return R.anim.fade_in;
2679 } else if (transit == TRANSIT_EXIT) {
2680 return R.anim.fade_out;
2681 } else {
2682 return 0;
2683 }
2684 }
2685
Craig Mautner3c174372013-02-21 17:54:37 -08002686 @Override
2687 public void selectRotationAnimationLw(int anim[]) {
2688 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2689 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2690 + (mTopFullscreenOpaqueWindowState == null ?
2691 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2692 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2693 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2694 case ROTATION_ANIMATION_CROSSFADE:
2695 anim[0] = R.anim.rotation_animation_xfade_exit;
2696 anim[1] = R.anim.rotation_animation_enter;
2697 break;
2698 case ROTATION_ANIMATION_JUMPCUT:
2699 anim[0] = R.anim.rotation_animation_jump_exit;
2700 anim[1] = R.anim.rotation_animation_enter;
2701 break;
2702 case ROTATION_ANIMATION_ROTATE:
2703 default:
2704 anim[0] = anim[1] = 0;
2705 break;
2706 }
2707 } else {
2708 anim[0] = anim[1] = 0;
2709 }
2710 }
2711
2712 @Override
2713 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2714 boolean forceDefault) {
2715 switch (exitAnimId) {
2716 case R.anim.rotation_animation_xfade_exit:
2717 case R.anim.rotation_animation_jump_exit:
2718 // These are the only cases that matter.
2719 if (forceDefault) {
2720 return false;
2721 }
2722 int anim[] = new int[2];
2723 selectRotationAnimationLw(anim);
2724 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2725 default:
2726 return true;
2727 }
2728 }
2729
2730 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002731 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2732 boolean goingToNotificationShade) {
2733 if (goingToNotificationShade) {
2734 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002735 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002736
2737 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2738 R.anim.lock_screen_behind_enter_wallpaper :
2739 R.anim.lock_screen_behind_enter);
2740
2741 // TODO: Use XML interpolators when we have log interpolators available in XML.
2742 final List<Animation> animations = set.getAnimations();
2743 for (int i = animations.size() - 1; i >= 0; --i) {
2744 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2745 }
2746
2747 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002748 }
2749
2750
2751 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002752 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2753 if (goingToNotificationShade) {
2754 return null;
2755 } else {
2756 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2757 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002758 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002759
2760 private static void awakenDreams() {
2761 IDreamManager dreamManager = getDreamManager();
2762 if (dreamManager != null) {
2763 try {
2764 dreamManager.awaken();
2765 } catch (RemoteException e) {
2766 // fine, stay asleep then
2767 }
2768 }
2769 }
2770
2771 static IDreamManager getDreamManager() {
2772 return IDreamManager.Stub.asInterface(
2773 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2774 }
2775
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002776 TelecomManager getTelecommService() {
2777 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002778 }
2779
Jeff Brown4d396052010-10-29 21:50:21 -07002780 static IAudioService getAudioService() {
2781 IAudioService audioService = IAudioService.Stub.asInterface(
2782 ServiceManager.checkService(Context.AUDIO_SERVICE));
2783 if (audioService == null) {
2784 Log.w(TAG, "Unable to find IAudioService interface.");
2785 }
2786 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002787 }
2788
2789 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002790 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002791 }
2792
2793 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2794 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2795 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2796 };
2797
2798 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002799 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002800 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002801 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002802 final int keyCode = event.getKeyCode();
2803 final int repeatCount = event.getRepeatCount();
2804 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002805 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002806 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2807 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002808
Jeff Brown40013652012-05-16 21:22:36 -07002809 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002810 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002811 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2812 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002813 }
2814
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002815 // If we think we might have a volume down & power key chord on the way
2816 // but we're not sure, then tell the dispatcher to wait a little while and
2817 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002818 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002819 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002820 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002821 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2822 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002823 if (now < timeoutTime) {
2824 return timeoutTime - now;
2825 }
2826 }
2827 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002828 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002829 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002830 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002831 }
2832 return -1;
2833 }
2834 }
2835
Michael Wright6a62e552014-06-03 19:19:48 -07002836 // Cancel any pending meta actions if we see any other keys being pressed between the down
2837 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002838 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002839 mPendingMetaAction = false;
2840 }
2841
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002842 // First we always handle the home key here, so applications
2843 // can never break it, although if keyguard is on, we do let
2844 // it handle it, because that gives us the correct 5 second
2845 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002846 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002847
Jeff Brown49ed71d2010-12-06 17:13:33 -08002848 // If we have released the home key, and didn't do anything else
2849 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002850 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002851 cancelPreloadRecentApps();
2852
Jeff Brown49ed71d2010-12-06 17:13:33 -08002853 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002854 if (mHomeConsumed) {
2855 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002856 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002857 }
Jeff Browncaca8812013-05-09 13:34:33 -07002858
2859 if (canceled) {
2860 Log.i(TAG, "Ignoring HOME; event canceled.");
2861 return -1;
2862 }
2863
Yorke Lee4f803242014-12-15 23:22:06 +00002864 // If an incoming call is ringing, HOME is totally disabled.
2865 // (The user is already on the InCallUI at this point,
2866 // and his ONLY options are to answer or reject the call.)
2867 TelecomManager telecomManager = getTelecommService();
2868 if (telecomManager != null && telecomManager.isRinging()) {
2869 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2870 return -1;
2871 }
2872
Jeff Browncaca8812013-05-09 13:34:33 -07002873 // Delay handling home if a double-tap is possible.
2874 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2875 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2876 mHomeDoubleTapPending = true;
2877 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2878 ViewConfiguration.getDoubleTapTimeout());
2879 return -1;
2880 }
2881
Jeff Brown13f00f02014-10-31 14:45:50 -07002882 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002883 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002884 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002885
2886 // If a system window has focus, then it doesn't make sense
2887 // right now to interact with applications.
2888 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2889 if (attrs != null) {
2890 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002891 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2892 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2893 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002894 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002895 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002896 }
2897 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2898 for (int i=0; i<typeCount; i++) {
2899 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2900 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002901 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002902 }
2903 }
2904 }
Jeff Browncaca8812013-05-09 13:34:33 -07002905
2906 // Remember that home is pressed and handle special actions.
2907 if (repeatCount == 0) {
2908 mHomePressed = true;
2909 if (mHomeDoubleTapPending) {
2910 mHomeDoubleTapPending = false;
2911 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2912 handleDoubleTapOnHome();
2913 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2914 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2915 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002916 }
Jeff Browncaca8812013-05-09 13:34:33 -07002917 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2918 if (!keyguardOn) {
Jaewan Kim52632e22016-01-14 18:01:52 +09002919 handleLongPressOnHome(event.getDeviceId(), event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002920 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002921 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002922 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002923 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002924 // Hijack modified menu keys for debugging features
2925 final int chordBug = KeyEvent.META_SHIFT_ON;
2926
2927 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002928 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002929 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002930 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2931 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002932 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002933 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002934 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002935 Intent service = new Intent();
2936 service.setClassName(mContext, "com.android.server.LoadAverageService");
2937 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002938 boolean shown = Settings.Global.getInt(
2939 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002940 if (!shown) {
2941 mContext.startService(service);
2942 } else {
2943 mContext.stopService(service);
2944 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002945 Settings.Global.putInt(
2946 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002947 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002948 }
2949 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002950 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002951 if (down) {
2952 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002953 mSearchKeyShortcutPending = true;
2954 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002955 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002956 } else {
2957 mSearchKeyShortcutPending = false;
2958 if (mConsumeSearchKeyUp) {
2959 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002960 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002961 }
2962 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002963 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002964 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002965 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002966 if (down && repeatCount == 0) {
2967 preloadRecentApps();
2968 } else if (!down) {
2969 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002970 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002971 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002972 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002973 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2974 if (down) {
2975 IStatusBarService service = getStatusBarService();
2976 if (service != null) {
2977 try {
2978 service.expandNotificationsPanel();
2979 } catch (RemoteException e) {
2980 // do nothing.
2981 }
2982 }
2983 }
Clara Bayarrif2debb12015-07-10 14:47:17 +01002984 } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) {
2985 if (down) {
2986 if (repeatCount == 0) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00002987 toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01002988 }
2989 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002990 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2991 if (down) {
2992 if (repeatCount == 0) {
2993 mAssistKeyLongPressed = false;
2994 } else if (repeatCount == 1) {
2995 mAssistKeyLongPressed = true;
2996 if (!keyguardOn) {
2997 launchAssistLongPressAction();
2998 }
2999 }
3000 } else {
3001 if (mAssistKeyLongPressed) {
3002 mAssistKeyLongPressed = false;
3003 } else {
3004 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003005 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003006 }
3007 }
3008 }
3009 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003010 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
3011 if (!down) {
3012 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07003013 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003014 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3015 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07003016 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
3017 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
3018 if (dic != null) {
3019 try {
3020 dic.exitIdle("voice-search");
3021 } catch (RemoteException e) {
3022 }
3023 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003024 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07003025 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003026 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003027 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003028 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003029 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
3030 if (down && repeatCount == 0) {
3031 mHandler.post(mScreenshotRunnable);
3032 }
3033 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08003034 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
3035 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
3036 if (down) {
3037 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
3038
3039 // Disable autobrightness if it's on
3040 int auto = Settings.System.getIntForUser(
3041 mContext.getContentResolver(),
3042 Settings.System.SCREEN_BRIGHTNESS_MODE,
3043 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3044 UserHandle.USER_CURRENT_OR_SELF);
3045 if (auto != 0) {
3046 Settings.System.putIntForUser(mContext.getContentResolver(),
3047 Settings.System.SCREEN_BRIGHTNESS_MODE,
3048 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3049 UserHandle.USER_CURRENT_OR_SELF);
3050 }
3051
3052 int min = mPowerManager.getMinimumScreenBrightnessSetting();
3053 int max = mPowerManager.getMaximumScreenBrightnessSetting();
3054 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
3055 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
3056 Settings.System.SCREEN_BRIGHTNESS,
3057 mPowerManager.getDefaultScreenBrightnessSetting(),
3058 UserHandle.USER_CURRENT_OR_SELF);
3059 brightness += step;
3060 // Make sure we don't go beyond the limits.
3061 brightness = Math.min(max, brightness);
3062 brightness = Math.max(min, brightness);
3063
3064 Settings.System.putIntForUser(mContext.getContentResolver(),
3065 Settings.System.SCREEN_BRIGHTNESS, brightness,
3066 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00003067 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07003068 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08003069 }
3070 return -1;
Jaewan Kim765487f2016-01-12 14:45:42 +09003071 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
3072 || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
3073 || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
3074 if (mUseTvRouting) {
3075 // On TVs volume keys never go to the foreground app.
3076 dispatchDirectAudioEvent(event);
3077 return -1;
3078 }
Michael Wrightce0c13a2014-07-30 10:49:21 -07003079 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07003080 if (down) {
3081 mPendingMetaAction = true;
3082 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003083 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07003084 }
3085 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003086 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003087
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003088 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08003089 // Any printing key that is chorded with Search should be consumed
3090 // even if no shortcut was invoked. This prevents text from being
3091 // inadvertently inserted when using a keyboard that has built-in macro
3092 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003093 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08003094 final KeyCharacterMap kcm = event.getKeyCharacterMap();
3095 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003096 mConsumeSearchKeyUp = true;
3097 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08003098 if (down && repeatCount == 0 && !keyguardOn) {
3099 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
3100 if (shortcutIntent != null) {
3101 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003102 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003103 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003104 } catch (ActivityNotFoundException ex) {
3105 Slog.w(TAG, "Dropping shortcut key combination because "
3106 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003107 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003108 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003109 } else {
3110 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003111 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003112 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003113 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003114 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003115 }
3116 }
3117
Jeff Brown68b909d2011-12-07 16:36:01 -08003118 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07003119 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08003120 && (metaState & KeyEvent.META_META_ON) != 0) {
3121 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07003122 if (kcm.isPrintingKey(keyCode)) {
3123 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
3124 metaState & ~(KeyEvent.META_META_ON
3125 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
3126 if (shortcutIntent != null) {
3127 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3128 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003129 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07003130 } catch (ActivityNotFoundException ex) {
3131 Slog.w(TAG, "Dropping shortcut key combination because "
3132 + "the activity to which it is registered was not found: "
3133 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
3134 }
3135 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08003136 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003137 }
3138 }
3139
Jeff Brown6651a632011-11-28 12:59:11 -08003140 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07003141 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08003142 String category = sApplicationLaunchKeyCategories.get(keyCode);
3143 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08003144 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08003145 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3146 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003147 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08003148 } catch (ActivityNotFoundException ex) {
3149 Slog.w(TAG, "Dropping application launch key because "
3150 + "the activity to which it is registered was not found: "
3151 + "keyCode=" + keyCode + ", category=" + category, ex);
3152 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003153 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08003154 }
3155 }
3156
Michael Wright61c46752014-08-21 16:57:33 -07003157 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08003158 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Michael Wrightd847ad52015-10-24 13:24:15 +01003159 if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) {
Jeff Brown68b909d2011-12-07 16:36:01 -08003160 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07003161 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003162 mRecentAppsHeldModifiers = shiftlessModifiers;
3163 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08003164 return -1;
3165 }
3166 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07003167 } else if (!down && mRecentAppsHeldModifiers != 0
3168 && (metaState & mRecentAppsHeldModifiers) == 0) {
3169 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07003170 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003171 }
3172
Yohei Yukawaae61f712015-12-09 13:00:10 -08003173 // Handle input method switching.
Jeff Browncf39bdf2012-05-18 14:41:19 -07003174 if (down && repeatCount == 0
3175 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3176 || (keyCode == KeyEvent.KEYCODE_SPACE
Yohei Yukawaae61f712015-12-09 13:00:10 -08003177 && (metaState & KeyEvent.META_META_MASK) != 0))) {
3178 final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0;
3179 mWindowManagerFuncs.switchInputMethod(forwardDirection);
Jeff Browncf39bdf2012-05-18 14:41:19 -07003180 return -1;
3181 }
3182 if (mLanguageSwitchKeyPressed && !down
3183 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3184 || keyCode == KeyEvent.KEYCODE_SPACE)) {
3185 mLanguageSwitchKeyPressed = false;
3186 return -1;
3187 }
3188
Jeff Brown13f00f02014-10-31 14:45:50 -07003189 if (isValidGlobalKey(keyCode)
3190 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07003191 return -1;
3192 }
3193
Michael Wright6a62e552014-06-03 19:19:48 -07003194 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07003195 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07003196 return -1;
3197 }
3198
Jeff Brown68b909d2011-12-07 16:36:01 -08003199 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003200 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003201 }
3202
Jeff Brown3915bb82010-11-05 15:02:16 -07003203 /** {@inheritDoc} */
3204 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08003205 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07003206 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07003207 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08003208 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
3209 + ", flags=" + event.getFlags()
3210 + ", keyCode=" + event.getKeyCode()
3211 + ", scanCode=" + event.getScanCode()
3212 + ", metaState=" + event.getMetaState()
3213 + ", repeatCount=" + event.getRepeatCount()
3214 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07003215 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003216
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003217 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003218 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3219 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003220 final int keyCode = event.getKeyCode();
3221 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003222 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
3223 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003224
Jeff Brown54875002011-04-06 15:33:01 -07003225 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003226 final FallbackAction fallbackAction;
3227 if (initialDown) {
3228 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
3229 } else {
3230 fallbackAction = mFallbackActions.get(keyCode);
3231 }
3232
3233 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07003234 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003235 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
3236 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003237 }
3238
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003239 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
3240 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08003241 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003242 event.getAction(), fallbackAction.keyCode,
3243 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08003244 event.getDeviceId(), event.getScanCode(),
3245 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003246
3247 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
3248 fallbackEvent.recycle();
3249 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003250 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003251
3252 if (initialDown) {
3253 mFallbackActions.put(keyCode, fallbackAction);
3254 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3255 mFallbackActions.remove(keyCode);
3256 fallbackAction.recycle();
3257 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003258 }
3259 }
3260
Jeff Brown40013652012-05-16 21:22:36 -07003261 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003262 if (fallbackEvent == null) {
3263 Slog.d(TAG, "No fallback.");
3264 } else {
3265 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3266 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003267 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003268 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003269 }
3270
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003271 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003272 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003273 if ((actions & ACTION_PASS_TO_USER) != 0) {
3274 long delayMillis = interceptKeyBeforeDispatching(
3275 win, fallbackEvent, policyFlags);
3276 if (delayMillis == 0) {
3277 return true;
3278 }
3279 }
3280 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003281 }
3282
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003283 private void launchAssistLongPressAction() {
3284 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3285 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3286
3287 // launch the search activity
3288 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3289 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3290 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003291 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003292 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003293 SearchManager searchManager = getSearchManager();
3294 if (searchManager != null) {
3295 searchManager.stopSearch();
3296 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003297 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003298 } catch (ActivityNotFoundException e) {
3299 Slog.w(TAG, "No activity to handle assist long press action.", e);
3300 }
3301 }
3302
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003303 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003304 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Maurice Lam39d13812015-07-23 20:49:20 -07003305 if (!isUserSetupComplete()) {
3306 // Disable opening assist window during setup
3307 return;
3308 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003309 Bundle args = null;
3310 if (deviceId > Integer.MIN_VALUE) {
3311 args = new Bundle();
3312 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003313 }
Jorim Jaggi165ce062015-07-06 16:18:11 -07003314 if ((mContext.getResources().getConfiguration().uiMode
3315 & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
3316 // On TV, use legacy handling until assistants are implemented in the proper way.
3317 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3318 .launchLegacyAssist(hint, UserHandle.myUserId(), args);
3319 } else {
3320 try {
3321 if (hint != null) {
3322 if (args == null) {
3323 args = new Bundle();
3324 }
3325 args.putBoolean(hint, true);
3326 }
3327 IStatusBarService statusbar = getStatusBarService();
3328 if (statusbar != null) {
3329 statusbar.startAssist(args);
3330 }
3331 } catch (RemoteException e) {
3332 Slog.e(TAG, "RemoteException when starting assist", e);
3333 // re-acquire status bar service next time it is needed.
3334 mStatusBarService = null;
3335 }
3336 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003337 }
3338
Bart Sears8b1c27c2015-03-18 23:51:02 +00003339 private void startActivityAsUser(Intent intent, UserHandle handle) {
3340 if (isUserSetupComplete()) {
3341 mContext.startActivityAsUser(intent, handle);
3342 } else {
3343 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3344 }
3345 }
3346
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003347 private SearchManager getSearchManager() {
3348 if (mSearchManager == null) {
3349 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3350 }
3351 return mSearchManager;
3352 }
3353
Jeff Browncaca8812013-05-09 13:34:33 -07003354 private void preloadRecentApps() {
3355 mPreloadedRecentApps = true;
3356 try {
3357 IStatusBarService statusbar = getStatusBarService();
3358 if (statusbar != null) {
3359 statusbar.preloadRecentApps();
3360 }
3361 } catch (RemoteException e) {
3362 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3363 // re-acquire status bar service next time it is needed.
3364 mStatusBarService = null;
3365 }
3366 }
3367
3368 private void cancelPreloadRecentApps() {
3369 if (mPreloadedRecentApps) {
3370 mPreloadedRecentApps = false;
3371 try {
3372 IStatusBarService statusbar = getStatusBarService();
3373 if (statusbar != null) {
3374 statusbar.cancelPreloadRecentApps();
3375 }
3376 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003377 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003378 // re-acquire status bar service next time it is needed.
3379 mStatusBarService = null;
3380 }
3381 }
3382 }
3383
3384 private void toggleRecentApps() {
3385 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003386 try {
3387 IStatusBarService statusbar = getStatusBarService();
3388 if (statusbar != null) {
3389 statusbar.toggleRecentApps();
3390 }
3391 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003392 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3393 // re-acquire status bar service next time it is needed.
3394 mStatusBarService = null;
3395 }
3396 }
3397
Craig Mautner84984fa2014-06-19 11:19:20 -07003398 @Override
3399 public void showRecentApps() {
3400 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3401 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3402 }
3403
Winson Chung1e8d71b2014-05-16 17:05:22 -07003404 private void showRecentApps(boolean triggeredFromAltTab) {
3405 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3406 try {
3407 IStatusBarService statusbar = getStatusBarService();
3408 if (statusbar != null) {
3409 statusbar.showRecentApps(triggeredFromAltTab);
3410 }
3411 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003412 Slog.e(TAG, "RemoteException when showing recent apps", e);
3413 // re-acquire status bar service next time it is needed.
3414 mStatusBarService = null;
3415 }
3416 }
3417
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003418 private void toggleKeyboardShortcutsMenu() {
Clara Bayarrif2debb12015-07-10 14:47:17 +01003419 try {
3420 IStatusBarService statusbar = getStatusBarService();
3421 if (statusbar != null) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003422 statusbar.toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01003423 }
3424 } catch (RemoteException e) {
3425 Slog.e(TAG, "RemoteException when showing keyboard shortcuts menu", e);
3426 }
3427 }
3428
Winson Chungcdcd4872014-08-05 18:00:13 -07003429 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003430 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3431 try {
3432 IStatusBarService statusbar = getStatusBarService();
3433 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003434 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003435 }
3436 } catch (RemoteException e) {
3437 Slog.e(TAG, "RemoteException when closing recent apps", e);
3438 // re-acquire status bar service next time it is needed.
3439 mStatusBarService = null;
3440 }
3441 }
3442
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003443 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003444 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003445 }
3446
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003447 /**
3448 * A home key -> launch home action was detected. Take the appropriate action
3449 * given the situation with the keyguard.
3450 */
Bryce Lee662ed802015-04-10 20:11:39 +00003451 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3452 if (respectKeyguard) {
3453 if (isKeyguardShowingAndNotOccluded()) {
3454 // don't launch home if keyguard showing
3455 return;
3456 }
3457
3458 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3459 // when in keyguard restricted mode, must first verify unlock
3460 // before launching home
3461 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3462 @Override
3463 public void onKeyguardExitResult(boolean success) {
3464 if (success) {
3465 try {
3466 ActivityManagerNative.getDefault().stopAppSwitches();
3467 } catch (RemoteException e) {
3468 }
3469 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3470 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003471 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003472 }
Bryce Lee662ed802015-04-10 20:11:39 +00003473 });
3474 return;
3475 }
3476 }
3477
3478 // no keyguard stuff to worry about, just launch home!
3479 try {
3480 ActivityManagerNative.getDefault().stopAppSwitches();
3481 } catch (RemoteException e) {
3482 }
3483 if (mRecentsVisible) {
3484 // Hide Recents and notify it to launch Home
3485 if (awakenFromDreams) {
3486 awakenDreams();
3487 }
Bryce Lee662ed802015-04-10 20:11:39 +00003488 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003489 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003490 // Otherwise, just launch Home
3491 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3492 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003493 }
3494 }
3495
John Spurlock04db1762013-05-13 12:46:41 -04003496 private final Runnable mClearHideNavigationFlag = new Runnable() {
3497 @Override
3498 public void run() {
3499 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3500 // Clear flags.
3501 mForceClearedSystemUiFlags &=
3502 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3503 }
3504 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003505 }
3506 };
3507
3508 /**
3509 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3510 * to determine when the nav bar should be shown and prevent applications from
3511 * receiving those touches.
3512 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003513 final class HideNavInputEventReceiver extends InputEventReceiver {
3514 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3515 super(inputChannel, looper);
3516 }
3517
Dianne Hackborndf89e652011-10-06 22:35:11 -07003518 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003519 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003520 boolean handled = false;
3521 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003522 if (event instanceof MotionEvent
3523 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3524 final MotionEvent motionEvent = (MotionEvent)event;
3525 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003526 // When the user taps down, we re-show the nav bar.
3527 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003528 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003529 // Any user activity always causes us to show the
3530 // navigation controls, if they had been hidden.
3531 // We also clear the low profile and only content
3532 // flags so that tapping on the screen will atomically
3533 // restore all currently hidden screen decorations.
3534 int newVal = mResettingSystemUiFlags |
3535 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3536 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3537 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003538 if (mResettingSystemUiFlags != newVal) {
3539 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003540 changed = true;
3541 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003542 // We don't allow the system's nav bar to be hidden
3543 // again for 1 second, to prevent applications from
3544 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003545 newVal = mForceClearedSystemUiFlags |
3546 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003547 if (mForceClearedSystemUiFlags != newVal) {
3548 mForceClearedSystemUiFlags = newVal;
3549 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003550 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003551 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003552 }
3553 if (changed) {
3554 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3555 }
3556 }
3557 }
3558 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003559 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003560 }
3561 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003562 }
3563 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3564 new InputEventReceiver.Factory() {
3565 @Override
3566 public InputEventReceiver createInputEventReceiver(
3567 InputChannel inputChannel, Looper looper) {
3568 return new HideNavInputEventReceiver(inputChannel, looper);
3569 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003570 };
3571
3572 @Override
3573 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003574 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3575 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003576 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003577
Dianne Hackborndf89e652011-10-06 22:35:11 -07003578 // Reset any bits in mForceClearingStatusBarVisibility that
3579 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003580 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003581 // Clear any bits in the new visibility that are currently being
3582 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003583 return visibility & ~mResettingSystemUiFlags
3584 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003585 }
3586
Craig Mautner69b08182012-09-05 13:07:13 -07003587 @Override
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003588 public void getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation,
3589 Rect outContentInsets, Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003590 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003591 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3592 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003593
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003594 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
3595 if (useOutsets) {
3596 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
3597 if (outset > 0) {
3598 if (displayRotation == Surface.ROTATION_0) {
3599 outOutsets.bottom += outset;
3600 } else if (displayRotation == Surface.ROTATION_90) {
3601 outOutsets.right += outset;
3602 } else if (displayRotation == Surface.ROTATION_180) {
3603 outOutsets.top += outset;
3604 } else if (displayRotation == Surface.ROTATION_270) {
3605 outOutsets.left += outset;
3606 }
3607 }
3608 }
3609
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003610 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003611 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003612 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003613 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003614 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003615 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3616 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3617 } else {
3618 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3619 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3620 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003621 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3622 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003623 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003624 availRight - mStableFullscreenRight,
3625 availBottom - mStableFullscreenBottom);
3626 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003627 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003628 availRight - mStableRight, availBottom - mStableBottom);
3629 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003630 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003631 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003632 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003633 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003634 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003635 availRight - mCurRight, availBottom - mCurBottom);
3636 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003637 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003638 availRight - mCurRight, availBottom - mCurBottom);
3639 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003640
3641 outStableInsets.set(mStableLeft, mStableTop,
3642 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003643 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003644 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003645 outContentInsets.setEmpty();
3646 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003647 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003648
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003649 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
3650 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
3651 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
3652 }
3653
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003654 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003655 @Override
3656 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003657 int displayRotation, int uiMode) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003658 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003659 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3660 if (isDefaultDisplay) {
3661 switch (displayRotation) {
3662 case Surface.ROTATION_90:
3663 overscanLeft = mOverscanTop;
3664 overscanTop = mOverscanRight;
3665 overscanRight = mOverscanBottom;
3666 overscanBottom = mOverscanLeft;
3667 break;
3668 case Surface.ROTATION_180:
3669 overscanLeft = mOverscanRight;
3670 overscanTop = mOverscanBottom;
3671 overscanRight = mOverscanLeft;
3672 overscanBottom = mOverscanTop;
3673 break;
3674 case Surface.ROTATION_270:
3675 overscanLeft = mOverscanBottom;
3676 overscanTop = mOverscanLeft;
3677 overscanRight = mOverscanTop;
3678 overscanBottom = mOverscanRight;
3679 break;
3680 default:
3681 overscanLeft = mOverscanLeft;
3682 overscanTop = mOverscanTop;
3683 overscanRight = mOverscanRight;
3684 overscanBottom = mOverscanBottom;
3685 break;
3686 }
3687 } else {
3688 overscanLeft = 0;
3689 overscanTop = 0;
3690 overscanRight = 0;
3691 overscanBottom = 0;
3692 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003693 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3694 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3695 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3696 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003697 mSystemLeft = 0;
3698 mSystemTop = 0;
3699 mSystemRight = displayWidth;
3700 mSystemBottom = displayHeight;
3701 mUnrestrictedScreenLeft = overscanLeft;
3702 mUnrestrictedScreenTop = overscanTop;
3703 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3704 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3705 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3706 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003707 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3708 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003709 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003710 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003711 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003712 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003713 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003714 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003715 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003716 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003717 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003718 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003719
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003720 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3721 final Rect pf = mTmpParentFrame;
3722 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003723 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003724 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003725 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003726 pf.left = df.left = of.left = vf.left = mDockLeft;
3727 pf.top = df.top = of.top = vf.top = mDockTop;
3728 pf.right = df.right = of.right = vf.right = mDockRight;
3729 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003730 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003731
Craig Mautner69b08182012-09-05 13:07:13 -07003732 if (isDefaultDisplay) {
3733 // For purposes of putting out fake window up to steal focus, we will
3734 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003735 final int sysui = mLastSystemUiFlags;
3736 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003737 boolean navTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003738 & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003739 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3740 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3741 boolean navAllowedHidden = immersive || immersiveSticky;
3742 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003743 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3744 if (!isKeyguardShowing) {
3745 navTranslucent &= areTranslucentBarsAllowed();
3746 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003747
Craig Mautner69b08182012-09-05 13:07:13 -07003748 // When the navigation bar isn't visible, we put up a fake
3749 // input window to catch all touch events. This way we can
3750 // detect when the user presses anywhere to bring back the nav
3751 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003752 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003753 if (mInputConsumer != null) {
3754 mInputConsumer.dismiss();
3755 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003756 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003757 } else if (mInputConsumer == null) {
3758 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3759 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003760 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003761
Craig Mautner69b08182012-09-05 13:07:13 -07003762 // For purposes of positioning and showing the nav bar, if we have
3763 // decided that it can't be hidden (because of the screen aspect ratio),
3764 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003765 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003766
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003767 boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003768 displayRotation, uiMode, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003769 navAllowedHidden);
Craig Mautnereda67292013-04-28 13:50:14 -07003770 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003771 mDockLeft, mDockTop, mDockRight, mDockBottom));
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003772 updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003773 if (updateSysUiVisibility) {
3774 updateSystemUiVisibilityLw();
3775 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003776 }
3777 }
3778
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003779 private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui,
3780 boolean isKeyguardShowing) {
3781 // decide where the status bar goes ahead of time
3782 if (mStatusBar != null) {
3783 // apply any navigation bar insets
3784 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3785 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3786 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3787 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3788 + mUnrestrictedScreenTop;
3789 vf.left = mStableLeft;
3790 vf.top = mStableTop;
3791 vf.right = mStableRight;
3792 vf.bottom = mStableBottom;
3793
3794 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3795
3796 // Let the status bar determine its size.
3797 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3798 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3799 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
3800
3801 // For layout, the status bar is always at the top with our fixed height.
3802 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3803
3804 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
3805 boolean statusBarTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003806 & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0;
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003807 if (!isKeyguardShowing) {
3808 statusBarTranslucent &= areTranslucentBarsAllowed();
3809 }
3810
3811 // If the status bar is hidden, we don't want to cause
3812 // windows behind it to scroll.
3813 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
3814 // Status bar may go away, so the screen area it occupies
3815 // is available to apps but just covering them when the
3816 // status bar is visible.
3817 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3818
3819 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3820 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3821 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3822 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3823
3824 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
3825 String.format(
3826 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3827 mDockLeft, mDockTop, mDockRight, mDockBottom,
3828 mContentLeft, mContentTop, mContentRight, mContentBottom,
3829 mCurLeft, mCurTop, mCurRight, mCurBottom));
3830 }
3831 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
3832 && !statusBarTransient && !statusBarTranslucent
3833 && !mStatusBarController.wasRecentlyTranslucent()) {
3834 // If the opaque status bar is currently requested to be visible,
3835 // and not in the process of animating on or off, then
3836 // we can tell the app that it is covered by it.
3837 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3838 }
3839 if (mStatusBarController.checkHiddenLw()) {
3840 return true;
3841 }
3842 }
3843 return false;
3844 }
3845
3846 private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003847 int uiMode, int overscanRight, int overscanBottom, Rect dcf, boolean navVisible,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003848 boolean navTranslucent, boolean navAllowedHidden) {
3849 if (mNavigationBar != null) {
3850 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
3851 // Force the navigation bar to its appropriate place and
3852 // size. We need to do this directly, instead of relying on
3853 // it to bubble up from the nav bar, because this needs to
3854 // change atomically with screen rotations.
Jorim Jaggi737af722015-12-31 10:42:27 +01003855 mNavigationBarOnBottom = isNavigationBarOnBottom(displayWidth, displayHeight);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003856 if (mNavigationBarOnBottom) {
3857 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
3858 int top = displayHeight - overscanBottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003859 - getNavigationBarHeight(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003860 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
3861 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
3862 if (transientNavBarShowing) {
3863 mNavigationBarController.setBarShowingLw(true);
3864 } else if (navVisible) {
3865 mNavigationBarController.setBarShowingLw(true);
3866 mDockBottom = mTmpNavigationFrame.top;
3867 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3868 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
3869 } else {
3870 // We currently want to hide the navigation UI.
3871 mNavigationBarController.setBarShowingLw(false);
3872 }
3873 if (navVisible && !navTranslucent && !navAllowedHidden
3874 && !mNavigationBar.isAnimatingLw()
3875 && !mNavigationBarController.wasRecentlyTranslucent()) {
3876 // If the opaque nav bar is currently requested to be visible,
3877 // and not in the process of animating on or off, then
3878 // we can tell the app that it is covered by it.
3879 mSystemBottom = mTmpNavigationFrame.top;
3880 }
3881 } else {
3882 // Landscape screen; nav bar goes to the right.
3883 int left = displayWidth - overscanRight
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003884 - getNavigationBarWidth(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003885 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
3886 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
3887 if (transientNavBarShowing) {
3888 mNavigationBarController.setBarShowingLw(true);
3889 } else if (navVisible) {
3890 mNavigationBarController.setBarShowingLw(true);
3891 mDockRight = mTmpNavigationFrame.left;
3892 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3893 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
3894 } else {
3895 // We currently want to hide the navigation UI.
3896 mNavigationBarController.setBarShowingLw(false);
3897 }
3898 if (navVisible && !navTranslucent && !navAllowedHidden
3899 && !mNavigationBar.isAnimatingLw()
3900 && !mNavigationBarController.wasRecentlyTranslucent()) {
3901 // If the nav bar is currently requested to be visible,
3902 // and not in the process of animating on or off, then
3903 // we can tell the app that it is covered by it.
3904 mSystemRight = mTmpNavigationFrame.left;
3905 }
3906 }
3907 // Make sure the content and current rectangles are updated to
3908 // account for the restrictions from the navigation bar.
3909 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3910 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3911 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3912 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3913 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3914 // And compute the final frame.
3915 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
3916 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3917 mTmpNavigationFrame, mTmpNavigationFrame);
3918 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
3919 if (mNavigationBarController.checkHiddenLw()) {
3920 return true;
3921 }
3922 }
3923 return false;
3924 }
3925
Jorim Jaggi737af722015-12-31 10:42:27 +01003926 private boolean isNavigationBarOnBottom(int displayWidth, int displayHeight) {
3927 return !mNavigationBarCanMove || displayWidth < displayHeight;
3928 }
3929
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003930 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003931 @Override
John Spurlock46646232013-09-30 22:32:42 -04003932 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003933 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3934 return mStatusBar.getSurfaceLayer();
3935 }
3936
3937 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3938 return mNavigationBar.getSurfaceLayer();
3939 }
3940
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003941 return 0;
3942 }
3943
Craig Mautner967212c2013-04-13 21:10:58 -07003944 @Override
3945 public void getContentRectLw(Rect r) {
3946 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3947 }
3948
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003949 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3950 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003951 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3952 // Here's a special case: if this attached window is a panel that is
3953 // above the dock window, and the window it is attached to is below
3954 // the dock window, then the frames we computed for the window it is
3955 // attached to can not be used because the dock is effectively part
3956 // of the underlying window and the attached window is floating on top
3957 // of the whole thing. So, we ignore the attached window and explicitly
3958 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003959 df.left = of.left = cf.left = vf.left = mDockLeft;
3960 df.top = of.top = cf.top = vf.top = mDockTop;
3961 df.right = of.right = cf.right = vf.right = mDockRight;
3962 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003963 } else {
3964 // The effective display frame of the attached window depends on
3965 // whether it is taking care of insetting its content. If not,
3966 // we need to use the parent's content frame so that the entire
3967 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003968 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003969 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003970 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003971 // Set the content frame of the attached window to the parent's decor frame
3972 // (same as content frame when IME isn't present) if specifically requested by
3973 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3974 // Otherwise, use the overscan frame.
3975 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3976 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003977 } else {
3978 // If the window is resizing, then we want to base the content
3979 // frame on our attached content frame to resize... however,
3980 // things can be tricky if the attached window is NOT in resize
3981 // mode, in which case its content frame will be larger.
3982 // Ungh. So to deal with that, make sure the content frame
3983 // we end up using is not covering the IM dock.
3984 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003985 if (attached.isVoiceInteraction()) {
3986 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3987 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3988 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3989 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3990 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003991 if (cf.left < mContentLeft) cf.left = mContentLeft;
3992 if (cf.top < mContentTop) cf.top = mContentTop;
3993 if (cf.right > mContentRight) cf.right = mContentRight;
3994 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3995 }
3996 }
3997 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003998 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003999 vf.set(attached.getVisibleFrameLw());
4000 }
4001 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
4002 // window should be positioned relative to its parent or the entire
4003 // screen.
4004 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
4005 ? attached.getFrameLw() : df);
4006 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004007
4008 private void applyStableConstraints(int sysui, int fl, Rect r) {
4009 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
4010 // If app is requesting a stable layout, don't let the
4011 // content insets go below the stable values.
4012 if ((fl & FLAG_FULLSCREEN) != 0) {
4013 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
4014 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
4015 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
4016 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
4017 } else {
4018 if (r.left < mStableLeft) r.left = mStableLeft;
4019 if (r.top < mStableTop) r.top = mStableTop;
4020 if (r.right > mStableRight) r.right = mStableRight;
4021 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
4022 }
4023 }
4024 }
4025
Jorim Jaggiaa806142015-05-20 18:04:16 -07004026 private boolean canReceiveInput(WindowState win) {
4027 boolean notFocusable =
4028 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
4029 boolean altFocusableIm =
4030 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
4031 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
4032 return !notFocusableForIm;
4033 }
4034
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004035 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07004036 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004037 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07004038 // We've already done the navigation bar and status bar. If the status bar can receive
4039 // input, we need to layout it again to accomodate for the IME window.
4040 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004041 return;
4042 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07004043 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07004044 final boolean isDefaultDisplay = win.isDefaultDisplay();
4045 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09004046 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
4047 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07004048 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09004049 offsetInputMethodWindowLw(mLastInputMethodWindow);
4050 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004051
John Spurlockc6d1c602014-01-17 15:22:06 -05004052 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004053 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05004054 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004055
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004056 final Rect pf = mTmpParentFrame;
4057 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004058 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004059 final Rect cf = mTmpContentFrame;
4060 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04004061 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07004062 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004063 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04004064 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07004065
4066 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04004067 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004068
Craig Mautnerf683b562012-10-02 11:10:57 -07004069 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
4070
Adrian Roosfa104232014-06-20 16:10:14 -07004071 if (isDefaultDisplay) {
4072 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
4073 } else {
4074 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
4075 }
4076
Craig Mautner69b08182012-09-05 13:07:13 -07004077 if (!isDefaultDisplay) {
4078 if (attached != null) {
4079 // If this window is attached to another, our display
4080 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004081 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07004082 } else {
4083 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004084 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4085 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4086 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004087 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004088 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004089 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07004090 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004091 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004092 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
4093 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
4094 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04004095 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04004096 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04004097 // ...with content insets above the nav bar
4098 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004099 // IM dock windows always go to the bottom of the screen.
4100 attrs.gravity = Gravity.BOTTOM;
4101 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004102 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004103 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004104 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004105 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4106 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004107 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004108 // Note: In Phone landscape mode, the button bar should also be excluded.
4109 cf.right = vf.right = mStableRight;
4110 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004111 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07004112 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02004113 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4114 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4115 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
4116 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
4117 cf.left = vf.left = mStableLeft;
4118 cf.top = vf.top = mStableTop;
4119 cf.right = vf.right = mStableRight;
4120 vf.bottom = mStableBottom;
Adrian Roosdc5b4532016-01-06 20:49:41 +01004121
4122 if (adjust == SOFT_INPUT_ADJUST_RESIZE) {
4123 cf.bottom = mContentBottom;
4124 } else {
4125 cf.bottom = mDockBottom;
4126 vf.bottom = mContentBottom;
4127 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004128 } else {
John Spurlock46646232013-09-30 22:32:42 -04004129
4130 // Default policy decor for the default display
4131 dcf.left = mSystemLeft;
4132 dcf.top = mSystemTop;
4133 dcf.right = mSystemRight;
4134 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04004135 final boolean inheritTranslucentDecor = (attrs.privateFlags
4136 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04004137 final boolean isAppWindow =
4138 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
4139 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
4140 final boolean topAtRest =
4141 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
4142 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04004143 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
4144 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004145 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
4146 && (fl & WindowManager.LayoutParams.
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004147 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0
4148 && !mForceWindowDrawsStatusBarBackground) {
John Spurlock46646232013-09-30 22:32:42 -04004149 // Ensure policy decor includes status bar
4150 dcf.top = mStableTop;
4151 }
John Spurlockbd957402013-10-03 11:38:39 -04004152 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004153 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
4154 && (fl & WindowManager.LayoutParams.
4155 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004156 // Ensure policy decor includes navigation bar
4157 dcf.bottom = mStableBottom;
4158 dcf.right = mStableRight;
4159 }
4160 }
4161
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004162 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
4163 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07004164 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004165 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004166 // This is the case for a normal activity window: we want it
4167 // to cover all of the screen space, and it can take care of
4168 // moving its contents to account for screen decorations that
4169 // intrude into that space.
4170 if (attached != null) {
4171 // If this window is attached to another, our display
4172 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004173 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004174 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004175 if (attrs.type == TYPE_STATUS_BAR_PANEL
4176 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08004177 // Status bar panels are the only windows who can go on top of
4178 // the status bar. They are protected by the STATUS_BAR_SERVICE
4179 // permission, so they have the same privileges as the status
4180 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004181 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004182 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004183
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004184 pf.left = df.left = of.left = hasNavBar
4185 ? mDockLeft : mUnrestrictedScreenLeft;
4186 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4187 pf.right = df.right = of.right = hasNavBar
4188 ? mRestrictedScreenLeft+mRestrictedScreenWidth
4189 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4190 pf.bottom = df.bottom = of.bottom = hasNavBar
4191 ? mRestrictedScreenTop+mRestrictedScreenHeight
4192 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004193
Craig Mautnereda67292013-04-28 13:50:14 -07004194 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004195 "Laying out status bar window: (%d,%d - %d,%d)",
4196 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04004197 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004198 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4199 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4200 // Asking to layout into the overscan region, so give it that pure
4201 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004202 pf.left = df.left = of.left = mOverscanScreenLeft;
4203 pf.top = df.top = of.top = mOverscanScreenTop;
4204 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
4205 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
4206 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004207 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004208 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004209 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4210 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004211 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08004212 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004213 // only do this for application windows to ensure no window that
4214 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08004215 pf.left = df.left = mOverscanScreenLeft;
4216 pf.top = df.top = mOverscanScreenTop;
4217 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4218 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004219 // We need to tell the app about where the frame inside the overscan
4220 // is, so it can inset its content by that amount -- it didn't ask
4221 // to actually extend itself into the overscan region.
4222 of.left = mUnrestrictedScreenLeft;
4223 of.top = mUnrestrictedScreenTop;
4224 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4225 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004226 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08004227 pf.left = df.left = mRestrictedOverscanScreenLeft;
4228 pf.top = df.top = mRestrictedOverscanScreenTop;
4229 pf.right = df.right = mRestrictedOverscanScreenLeft
4230 + mRestrictedOverscanScreenWidth;
4231 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
4232 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004233 // We need to tell the app about where the frame inside the overscan
4234 // is, so it can inset its content by that amount -- it didn't ask
4235 // to actually extend itself into the overscan region.
4236 of.left = mUnrestrictedScreenLeft;
4237 of.top = mUnrestrictedScreenTop;
4238 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4239 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004240 }
Craig Mautner69b08182012-09-05 13:07:13 -07004241
John Spurlock46646232013-09-30 22:32:42 -04004242 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004243 if (win.isVoiceInteraction()) {
4244 cf.left = mVoiceContentLeft;
4245 cf.top = mVoiceContentTop;
4246 cf.right = mVoiceContentRight;
4247 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004248 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004249 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4250 cf.left = mDockLeft;
4251 cf.top = mDockTop;
4252 cf.right = mDockRight;
4253 cf.bottom = mDockBottom;
4254 } else {
4255 cf.left = mContentLeft;
4256 cf.top = mContentTop;
4257 cf.right = mContentRight;
4258 cf.bottom = mContentBottom;
4259 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004260 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004261 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004262 // Full screen windows are always given a layout that is as if the
4263 // status bar and other transient decors are gone. This is to avoid
4264 // bad states when moving from a window that is not hding the
4265 // status bar to one that is.
4266 cf.left = mRestrictedScreenLeft;
4267 cf.top = mRestrictedScreenTop;
4268 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4269 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004270 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004271 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004272 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4273 vf.left = mCurLeft;
4274 vf.top = mCurTop;
4275 vf.right = mCurRight;
4276 vf.bottom = mCurBottom;
4277 } else {
4278 vf.set(cf);
4279 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004280 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004281 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
4282 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
4283 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07004284 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4285 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004286 // A window that has requested to fill the entire screen just
4287 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004288 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04004289 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
4290 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004291 pf.left = df.left = of.left = cf.left = hasNavBar
4292 ? mDockLeft : mUnrestrictedScreenLeft;
4293 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4294 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004295 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08004296 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004297 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004298 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004299 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004300 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04004301 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
4302 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07004303 } else if (attrs.type == TYPE_NAVIGATION_BAR
4304 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004305 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004306 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4307 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4308 pf.right = df.right = of.right = mUnrestrictedScreenLeft
4309 + mUnrestrictedScreenWidth;
4310 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
4311 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004312 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004313 "Laying out navigation bar window: (%d,%d - %d,%d)",
4314 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08004315 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
4316 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07004317 && ((fl & FLAG_FULLSCREEN) != 0)) {
4318 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004319 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4320 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4321 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4322 + mOverscanScreenWidth;
4323 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4324 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08004325 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08004326 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004327 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4328 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4329 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4330 + mOverscanScreenWidth;
4331 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4332 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04004333 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004334 // The wallpaper also has Real Ultimate Power, but we want to tell
4335 // it about the overscan area.
4336 pf.left = df.left = mOverscanScreenLeft;
4337 pf.top = df.top = mOverscanScreenTop;
4338 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4339 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4340 of.left = cf.left = mUnrestrictedScreenLeft;
4341 of.top = cf.top = mUnrestrictedScreenTop;
4342 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4343 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004344 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004345 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4346 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4347 // Asking to layout into the overscan region, so give it that pure
4348 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004349 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4350 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4351 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004352 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004353 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004354 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004355 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004356 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004357 && (attrs.type == TYPE_STATUS_BAR
4358 || attrs.type == TYPE_TOAST
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01004359 || attrs.type == TYPE_DOCK_DIVIDER
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004360 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004361 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4362 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004363 // Asking for layout as if the nav bar is hidden, lets the
4364 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004365 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004366 // can be above the nav bar can do this.
4367 // XXX This assumes that an app asking for this will also
4368 // ask for layout in only content. We can't currently figure out
4369 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004370 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4371 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4372 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4373 + mUnrestrictedScreenWidth;
4374 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4375 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004376 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004377 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4378 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4379 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4380 + mRestrictedScreenWidth;
4381 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4382 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004383 }
Craig Mautner69b08182012-09-05 13:07:13 -07004384
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004385 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004386
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004387 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4388 vf.left = mCurLeft;
4389 vf.top = mCurTop;
4390 vf.right = mCurRight;
4391 vf.bottom = mCurBottom;
4392 } else {
4393 vf.set(cf);
4394 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004395 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004396 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4397 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004398 // A child window should be placed inside of the same visible
4399 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004400 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004401 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004402 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4403 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004404 // Otherwise, a normal window must be placed inside the content
4405 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004406 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4407 // Status bar panels and the volume dialog are the only windows who can go on
4408 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004409 // permission, so they have the same privileges as the status
4410 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004411 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4412 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4413 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4414 + mRestrictedScreenWidth;
4415 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4416 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004417 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004418 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004419 pf.left = df.left = of.left = cf.left = mStableLeft;
4420 pf.top = df.top = of.top = cf.top = mStableTop;
4421 pf.right = df.right = of.right = cf.right = mStableRight;
4422 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004423 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004424 pf.left = mContentLeft;
4425 pf.top = mContentTop;
4426 pf.right = mContentRight;
4427 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004428 if (win.isVoiceInteraction()) {
4429 df.left = of.left = cf.left = mVoiceContentLeft;
4430 df.top = of.top = cf.top = mVoiceContentTop;
4431 df.right = of.right = cf.right = mVoiceContentRight;
4432 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4433 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004434 df.left = of.left = cf.left = mDockLeft;
4435 df.top = of.top = cf.top = mDockTop;
4436 df.right = of.right = cf.right = mDockRight;
4437 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004438 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004439 df.left = of.left = cf.left = mContentLeft;
4440 df.top = of.top = cf.top = mContentTop;
4441 df.right = of.right = cf.right = mContentRight;
4442 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004443 }
4444 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4445 vf.left = mCurLeft;
4446 vf.top = mCurTop;
4447 vf.right = mCurRight;
4448 vf.bottom = mCurBottom;
4449 } else {
4450 vf.set(cf);
4451 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004452 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004453 }
4454 }
Craig Mautner69b08182012-09-05 13:07:13 -07004455
Craig Mautnerb816bed2013-07-23 10:26:17 -07004456 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4457 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004458 df.left = df.top = -10000;
4459 df.right = df.bottom = 10000;
4460 if (attrs.type != TYPE_WALLPAPER) {
4461 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4462 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4463 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004464 }
4465
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004466 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4467 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004468 // We only want to apply outsets to certain types of windows. For example, we never want to
4469 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004470 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004471 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004472 osf = mTmpOutsetFrame;
4473 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4474 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4475 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004476 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004477 if (rotation == Surface.ROTATION_0) {
4478 osf.bottom += outset;
4479 } else if (rotation == Surface.ROTATION_90) {
4480 osf.right += outset;
4481 } else if (rotation == Surface.ROTATION_180) {
4482 osf.top -= outset;
4483 } else if (rotation == Surface.ROTATION_270) {
4484 osf.left -= outset;
4485 }
4486 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4487 + " with rotation " + rotation + ", result: " + osf);
4488 }
4489 }
4490
Craig Mautnereda67292013-04-28 13:50:14 -07004491 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004492 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004493 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004494 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004495 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004496 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004497 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004498 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004499 + " sf=" + sf.toShortString()
4500 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004501
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004502 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004503
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004504 // Dock windows carve out the bottom of the screen, so normal windows
4505 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004506 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4507 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004508 setLastInputMethodWindowLw(null, null);
4509 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004510 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004511 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4512 && !win.getGivenInsetsPendingLw()) {
4513 offsetVoiceInputWindowLw(win);
4514 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004515 }
4516
satok1bc0a492012-04-25 22:47:12 +09004517 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004518 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004519 top += win.getGivenContentInsetsLw().top;
4520 if (mContentBottom > top) {
4521 mContentBottom = top;
4522 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004523 if (mVoiceContentBottom > top) {
4524 mVoiceContentBottom = top;
4525 }
satok1bc0a492012-04-25 22:47:12 +09004526 top = win.getVisibleFrameLw().top;
4527 top += win.getGivenVisibleInsetsLw().top;
4528 if (mCurBottom > top) {
4529 mCurBottom = top;
4530 }
Craig Mautnereda67292013-04-28 13:50:14 -07004531 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004532 + mDockBottom + " mContentBottom="
4533 + mContentBottom + " mCurBottom=" + mCurBottom);
4534 }
4535
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004536 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004537 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004538 top += win.getGivenContentInsetsLw().top;
4539 if (mVoiceContentBottom > top) {
4540 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004541 }
4542 }
4543
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004544 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004545 @Override
4546 public void finishLayoutLw() {
4547 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004548 }
4549
4550 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004551 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004552 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004553 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004554 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004555 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004556 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004557 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004558 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004559 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004560 mForcingShowNavBar = false;
4561 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004562
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004563 mHideLockScreen = false;
4564 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004565 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004566 mShowingLockscreen = false;
4567 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004568 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004569 mKeyguardSecure = isKeyguardSecure();
4570 mKeyguardSecureIncludingHidden = mKeyguardSecure
4571 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004572 }
4573
4574 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004575 @Override
Yohei Yukawad1a09222015-06-30 16:22:05 -07004576 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,
4577 WindowState attached) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004578 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4579 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004580 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004581 if (mTopFullscreenOpaqueWindowState == null
4582 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4583 mForcingShowNavBar = true;
4584 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004585 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004586 if (attrs.type == TYPE_STATUS_BAR) {
4587 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4588 mForceStatusBarFromKeyguard = true;
Jorim Jaggie1de9f62015-09-23 14:59:50 -07004589 mShowingLockscreen = true;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004590 }
4591 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4592 mForceStatusBarTransparent = true;
4593 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004594 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004595
4596 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4597 && attrs.type < FIRST_SYSTEM_WINDOW;
4598 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4599 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4600
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004601 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004602 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004603 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004604 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004605 mForceStatusBarFromKeyguard = true;
4606 } else {
4607 mForceStatusBar = true;
4608 }
4609 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004610 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004611 // If the lockscreen was showing when the dream started then wait
4612 // for the dream to draw before hiding the lockscreen.
4613 if (!mDreamingLockscreen
4614 || (win.isVisibleLw() && win.hasDrawnLw())) {
4615 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004616 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004617 }
4618 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004619
Yohei Yukawad1a09222015-06-30 16:22:05 -07004620 final IApplicationToken appToken = win.getAppToken();
4621
4622 // For app windows that are not attached, we decide if all windows in the app they
4623 // represent should be hidden or if we should hide the lockscreen. For attached app
4624 // windows we defer the decision to the window it is attached to.
4625 if (appWindow && attached == null) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004626 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004627 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004628 mAppsToBeHidden.remove(appToken);
4629 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004630 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004631 if (dismissKeyguard && !mKeyguardSecure) {
4632 mAppsThatDismissKeyguard.add(appToken);
Selim Cinek90b5e072015-08-28 17:05:56 -07004633 } else if (win.isDrawnLw() || win.hasAppShownWindows()) {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004634 mWinShowWhenLocked = win;
4635 mHideLockScreen = true;
4636 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004637 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004638 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004639 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004640 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004641 mAppsToBeHidden.add(appToken);
4642 } else {
4643 mAppsToBeHidden.remove(appToken);
4644 }
4645 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004646 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004647 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004648 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004649 if (attrs.x == 0 && attrs.y == 0
4650 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4651 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4652 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4653 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004654 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4655 mTopFullscreenOpaqueOrDimmingWindowState = win;
4656 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004657 if (!mAppsThatDismissKeyguard.isEmpty() &&
4658 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4659 if (DEBUG_LAYOUT) Slog.v(TAG,
4660 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004661 mDismissKeyguard = (mWinDismissingKeyguard == win
4662 && mSecureDismissingKeyguard == mKeyguardSecure)
4663 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004664 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004665 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004666 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Selim Cinek90b5e072015-08-28 17:05:56 -07004667 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked
4668 && (win.isDrawnLw() || win.hasAppShownWindows())) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004669 if (DEBUG_LAYOUT) Slog.v(TAG,
4670 "Setting mHideLockScreen to true by win " + win);
4671 mHideLockScreen = true;
4672 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004673 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004674 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004675 mAllowLockscreenWhenOn = true;
4676 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004677 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004678
4679 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004680 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4681 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004682 win.hideLw(false);
4683 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004684 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004685 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4686 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4687 // that is being hidden in an animation - keep the
4688 // keyguard hidden until the new window shows up and
4689 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004690 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004691 mHideLockScreen = true;
4692 mWinShowWhenLocked = win;
4693 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004694 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004695 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4696 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4697 && win.isDimming()) {
4698 mTopFullscreenOpaqueOrDimmingWindowState = win;
4699 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004700 }
4701
4702 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004703 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004704 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004705 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4706 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4707 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004708 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4709 // fullscreen window.
4710 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4711 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4712 mTopFullscreenOpaqueWindowState.hideLw(false);
4713 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4714 }
4715
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004716 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004717 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004718
4719 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4720 ? mTopFullscreenOpaqueWindowState.getAttrs()
4721 : null;
4722
Jeff Brownc8018eb2012-10-29 21:33:27 -07004723 // If we are not currently showing a dream then remember the current
4724 // lockscreen state. We will use this to determine whether the dream
4725 // started while the lockscreen was showing and remember this state
4726 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004727 if (!mShowingDream) {
4728 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004729 if (mDreamingSleepTokenNeeded) {
4730 mDreamingSleepTokenNeeded = false;
4731 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4732 }
4733 } else {
4734 if (!mDreamingSleepTokenNeeded) {
4735 mDreamingSleepTokenNeeded = true;
4736 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4737 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004738 }
4739
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004740 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004741 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004742 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004743 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004744 boolean shouldBeTransparent = mForceStatusBarTransparent
4745 && !mForceStatusBar
4746 && !mForceStatusBarFromKeyguard;
4747 if (!shouldBeTransparent) {
4748 mStatusBarController.setShowTransparent(false /* transparent */);
4749 } else if (!mStatusBar.isVisibleLw()) {
4750 mStatusBarController.setShowTransparent(true /* transparent */);
4751 }
4752 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004753 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004754 if (mStatusBarController.setBarShowingLw(true)) {
4755 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4756 }
Craig Mautner81defc72013-10-29 11:10:42 -07004757 // Maintain fullscreen layout until incoming animation is complete.
4758 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004759 // Transient status bar on the lockscreen is not allowed
4760 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4761 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4762 mLastSystemUiFlags, mLastSystemUiFlags);
4763 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004764 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004765 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004766 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004767 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07004768 + " shown position: "
4769 + mTopFullscreenOpaqueWindowState.getShownPositionLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004770 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004771 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004772 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004773 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004774 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004775 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004776 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004777 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4778 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004779 if (mStatusBarController.isTransientShowing()) {
4780 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004781 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4782 }
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07004783 } else if (topIsFullscreen
4784 && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID)
4785 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) {
Craig Mautnereda67292013-04-28 13:50:14 -07004786 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004787 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004788 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004789 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004790 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004791 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004792 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004793 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004794 if (mStatusBarController.setBarShowingLw(true)) {
4795 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4796 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004797 }
4798 }
4799 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004800
Craig Mautner81defc72013-10-29 11:10:42 -07004801 if (mTopIsFullscreen != topIsFullscreen) {
4802 if (!topIsFullscreen) {
4803 // Force another layout when status bar becomes fully shown.
4804 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4805 }
4806 mTopIsFullscreen = topIsFullscreen;
4807 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004808
Craig Mautner39834192012-09-02 07:47:24 -07004809 // Hide the key guard if a visible window explicitly specifies that it wants to be
4810 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004811 if (mKeyguardDelegate != null && mStatusBar != null) {
4812 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4813 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004814 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004815 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004816 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004817 changes |= FINISH_LAYOUT_REDO_LAYOUT
4818 | FINISH_LAYOUT_REDO_CONFIG
4819 | FINISH_LAYOUT_REDO_WALLPAPER;
4820 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004821 if (mKeyguardDelegate.isShowing()) {
4822 mHandler.post(new Runnable() {
4823 @Override
4824 public void run() {
4825 mKeyguardDelegate.keyguardDone(false, false);
4826 }
4827 });
4828 }
4829 } else if (mHideLockScreen) {
4830 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004831 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004832 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004833 changes |= FINISH_LAYOUT_REDO_LAYOUT
4834 | FINISH_LAYOUT_REDO_CONFIG
4835 | FINISH_LAYOUT_REDO_WALLPAPER;
4836 }
4837 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004838 mKeyguardHidden = false;
4839 if (setKeyguardOccludedLw(false)) {
4840 changes |= FINISH_LAYOUT_REDO_LAYOUT
4841 | FINISH_LAYOUT_REDO_CONFIG
4842 | FINISH_LAYOUT_REDO_WALLPAPER;
4843 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004844 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4845 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004846 mHandler.post(new Runnable() {
4847 @Override
4848 public void run() {
4849 mKeyguardDelegate.dismiss();
4850 }
4851 });
4852 }
4853 } else {
4854 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004855 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004856 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004857 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004858 changes |= FINISH_LAYOUT_REDO_LAYOUT
4859 | FINISH_LAYOUT_REDO_CONFIG
4860 | FINISH_LAYOUT_REDO_WALLPAPER;
4861 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004862 }
4863 }
Joe Onorato664644d2011-01-23 17:53:23 -08004864
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004865 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004866 // If the navigation bar has been hidden or shown, we need to do another
4867 // layout pass to update that window.
4868 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4869 }
Joe Onorato664644d2011-01-23 17:53:23 -08004870
Mike Lockwood28569302010-01-28 11:54:40 -05004871 // update since mAllowLockscreenWhenOn might have changed
4872 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004873 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004874 }
4875
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004876 /**
Jim Millerab954542014-10-10 18:21:49 -07004877 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004878 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004879 * @return Whether the flags have changed and we have to redo the layout.
4880 */
Jim Millerab954542014-10-10 18:21:49 -07004881 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4882 boolean wasOccluded = mKeyguardOccluded;
4883 boolean showing = mKeyguardDelegate.isShowing();
4884 if (wasOccluded && !isOccluded && showing) {
4885 mKeyguardOccluded = false;
4886 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004887 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4888 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4889 return true;
Jim Millerab954542014-10-10 18:21:49 -07004890 } else if (!wasOccluded && isOccluded && showing) {
4891 mKeyguardOccluded = true;
4892 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004893 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4894 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4895 return true;
4896 } else {
4897 return false;
4898 }
4899 }
4900
4901 private boolean isStatusBarKeyguard() {
4902 return mStatusBar != null
4903 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4904 }
4905
Jose Lima9546b202014-07-02 17:21:51 -07004906 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004907 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004908 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004909 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004910 return false;
4911 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004912 return true;
4913 }
4914
Jose Lima9546b202014-07-02 17:21:51 -07004915 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004916 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004917 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004918 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004919 // If the navigation bar has been hidden or shown, we need to do another
4920 // layout pass to update that window.
4921 return FINISH_LAYOUT_REDO_LAYOUT;
4922 }
4923 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004924 }
4925
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004926 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004927 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004928 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4929 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004930 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4931 if (newLidState == mLidState) {
4932 return;
4933 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004934
Jeff Brownc458ce92012-04-30 14:58:40 -07004935 mLidState = newLidState;
4936 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004937 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004938
4939 if (lidOpen) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07004940 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch,
4941 "android.policy:LID");
Jeff Brownc458ce92012-04-30 14:58:40 -07004942 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004943 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004944 }
4945 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004946
Michael Wright3818c922014-09-02 13:59:07 -07004947 @Override
4948 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4949 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4950 if (mCameraLensCoverState == lensCoverState) {
4951 return;
4952 }
4953 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4954 lensCoverState == CAMERA_LENS_UNCOVERED) {
4955 Intent intent;
4956 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4957 mKeyguardDelegate.isShowing();
4958 if (keyguardActive) {
4959 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4960 } else {
4961 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4962 }
Dianne Hackborn280a64e2015-07-13 14:48:08 -07004963 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens,
4964 "android.policy:CAMERA_COVER");
Bart Sears8b1c27c2015-03-18 23:51:02 +00004965 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004966 }
4967 mCameraLensCoverState = lensCoverState;
4968 }
4969
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004970 void setHdmiPlugged(boolean plugged) {
4971 if (mHdmiPlugged != plugged) {
4972 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004973 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004974 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004975 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004976 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004977 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004978 }
4979 }
4980
Joe Onoratoea495d42011-04-06 11:41:11 -07004981 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004982 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004983 // watch for HDMI plug messages if the hdmi switch exists
4984 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4985 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4986
Joe Onoratoea495d42011-04-06 11:41:11 -07004987 final String filename = "/sys/class/switch/hdmi/state";
4988 FileReader reader = null;
4989 try {
4990 reader = new FileReader(filename);
4991 char[] buf = new char[15];
4992 int n = reader.read(buf);
4993 if (n > 1) {
4994 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4995 }
4996 } catch (IOException ex) {
4997 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4998 } catch (NumberFormatException ex) {
4999 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5000 } finally {
5001 if (reader != null) {
5002 try {
5003 reader.close();
5004 } catch (IOException ex) {
5005 }
Joe Onoratodc100302011-01-11 17:07:41 -08005006 }
5007 }
5008 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07005009 // This dance forces the code in setHdmiPlugged to run.
5010 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
5011 mHdmiPlugged = !plugged;
5012 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08005013 }
5014
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07005015 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005016 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005017
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005018 final Runnable mScreenshotTimeout = new Runnable() {
5019 @Override public void run() {
5020 synchronized (mScreenshotLock) {
5021 if (mScreenshotConnection != null) {
5022 mContext.unbindService(mScreenshotConnection);
5023 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005024 }
Winson Chung9112ec32011-06-27 13:15:32 -07005025 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005026 }
5027 };
5028
5029 // Assume this is called from the Handler thread.
5030 private void takeScreenshot() {
5031 synchronized (mScreenshotLock) {
5032 if (mScreenshotConnection != null) {
5033 return;
5034 }
5035 ComponentName cn = new ComponentName("com.android.systemui",
5036 "com.android.systemui.screenshot.TakeScreenshotService");
5037 Intent intent = new Intent();
5038 intent.setComponent(cn);
5039 ServiceConnection conn = new ServiceConnection() {
5040 @Override
5041 public void onServiceConnected(ComponentName name, IBinder service) {
5042 synchronized (mScreenshotLock) {
5043 if (mScreenshotConnection != this) {
5044 return;
5045 }
5046 Messenger messenger = new Messenger(service);
5047 Message msg = Message.obtain(null, 1);
5048 final ServiceConnection myConn = this;
5049 Handler h = new Handler(mHandler.getLooper()) {
5050 @Override
5051 public void handleMessage(Message msg) {
5052 synchronized (mScreenshotLock) {
5053 if (mScreenshotConnection == myConn) {
5054 mContext.unbindService(mScreenshotConnection);
5055 mScreenshotConnection = null;
5056 mHandler.removeCallbacks(mScreenshotTimeout);
5057 }
5058 }
5059 }
5060 };
5061 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07005062 msg.arg1 = msg.arg2 = 0;
5063 if (mStatusBar != null && mStatusBar.isVisibleLw())
5064 msg.arg1 = 1;
5065 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
5066 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005067 try {
5068 messenger.send(msg);
5069 } catch (RemoteException e) {
5070 }
5071 }
5072 }
5073 @Override
5074 public void onServiceDisconnected(ComponentName name) {}
5075 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08005076 if (mContext.bindServiceAsUser(
5077 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005078 mScreenshotConnection = conn;
5079 mHandler.postDelayed(mScreenshotTimeout, 10000);
5080 }
5081 }
Winson Chung9112ec32011-06-27 13:15:32 -07005082 }
5083
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005084 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005085 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07005086 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07005087 if (!mSystemBooted) {
5088 // If we have not yet booted, don't let key events do anything.
5089 return 0;
5090 }
5091
Jeff Brown037c33e2014-04-09 00:31:55 -07005092 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08005093 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
5094 final boolean canceled = event.isCanceled();
5095 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07005096
Jeff Brown3122e442010-10-11 23:32:49 -07005097 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07005098
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05005099 // If screen is off then we treat the case where the keyguard is open but hidden
5100 // the same as if it were open and in front.
5101 // This will prevent any keys other than the power button from waking the screen
5102 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08005103 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07005104 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07005105 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08005106 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005107
Jeff Brown40013652012-05-16 21:22:36 -07005108 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005109 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07005110 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08005111 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005112 }
5113
Jeff Brown037c33e2014-04-09 00:31:55 -07005114 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07005115 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07005116 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
5117 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07005118 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07005119 // When the device is interactive or the key is injected pass the
5120 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07005121 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005122 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07005123 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
5124 // If we're currently dozing with the screen on and the keyguard showing, pass the key
5125 // to the application but preserve its wake key status to make sure we still move
5126 // from dozing to fully interactive if we would normally go from off to fully
5127 // interactive.
5128 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07005129 } else {
5130 // When the screen is off and the key is not injected, determine whether
5131 // to wake the device but don't pass the key to the application.
5132 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08005133 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
5134 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005135 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005136 }
5137
Justin Kohd378ad72013-04-01 12:18:26 -07005138 // If the key would be handled globally, just return the result, don't worry about special
5139 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07005140 if (isValidGlobalKey(keyCode)
5141 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07005142 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005143 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Michael Wright85b1af62014-06-04 14:51:58 -07005144 }
Justin Kohd378ad72013-04-01 12:18:26 -07005145 return result;
5146 }
5147
Jeff Brownbae8e772014-06-12 19:59:45 -07005148 boolean useHapticFeedback = down
5149 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
5150 && event.getRepeatCount() == 0;
5151
Jeff Brown4d396052010-10-29 21:50:21 -07005152 // Handle special keys.
5153 switch (keyCode) {
5154 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07005155 case KeyEvent.KEYCODE_VOLUME_UP:
5156 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005157 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
5158 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005159 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005160 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005161 mScreenshotChordVolumeDownKeyTriggered = true;
5162 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
5163 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005164 cancelPendingPowerKeyAction();
5165 interceptScreenshotChord();
5166 }
5167 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005168 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005169 cancelPendingScreenshotChordAction();
5170 }
5171 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
5172 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005173 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005174 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005175 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005176 cancelPendingPowerKeyAction();
5177 cancelPendingScreenshotChordAction();
5178 }
5179 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005180 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005181 cancelPendingScreenshotChordAction();
5182 }
5183 }
Jeff Brown4d396052010-10-29 21:50:21 -07005184 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005185 TelecomManager telecomManager = getTelecommService();
5186 if (telecomManager != null) {
5187 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005188 // If an incoming call is ringing, either VOLUME key means
5189 // "silence ringer". We handle these keys here, rather than
5190 // in the InCallScreen, to make sure we'll respond to them
5191 // even if the InCallScreen hasn't come to the foreground yet.
5192 // Look for the DOWN event here, to agree with the "fallback"
5193 // behavior in the InCallScreen.
5194 Log.i(TAG, "interceptKeyBeforeQueueing:"
5195 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07005196
Santos Cordon6848f722014-05-21 15:22:12 -07005197 // Silence the ringer. (It's safe to call this
5198 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005199 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07005200
Santos Cordon6848f722014-05-21 15:22:12 -07005201 // And *don't* pass this key thru to the current activity
5202 // (which is probably the InCallScreen.)
5203 result &= ~ACTION_PASS_TO_USER;
5204 break;
5205 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005206 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07005207 && (result & ACTION_PASS_TO_USER) == 0) {
5208 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07005209 // the application, just pass it to the session service.
5210
5211 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07005212 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07005213 break;
Jeff Brown4d396052010-10-29 21:50:21 -07005214 }
5215 }
Jaewan Kim765487f2016-01-12 14:45:42 +09005216 }
5217 if (mUseTvRouting) {
5218 // On TVs, defer special key handlings to
5219 // {@link interceptKeyBeforeDispatching()}.
5220 result |= ACTION_PASS_TO_USER;
5221 } else if ((result & ACTION_PASS_TO_USER) == 0) {
5222 // If we aren't passing to the user and no one else
5223 // handled it send it to the session manager to
5224 // figure out.
5225 MediaSessionLegacyHelper.getHelper(mContext)
5226 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07005227 }
5228 break;
5229 }
5230
5231 case KeyEvent.KEYCODE_ENDCALL: {
5232 result &= ~ACTION_PASS_TO_USER;
5233 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005234 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07005235 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005236 if (telecomManager != null) {
5237 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07005238 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005239 if (interactive && !hungUp) {
5240 mEndCallKeyHandled = false;
5241 mHandler.postDelayed(mEndCallLongPress,
5242 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
5243 } else {
5244 mEndCallKeyHandled = true;
5245 }
Jeff Brown4d396052010-10-29 21:50:21 -07005246 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005247 if (!mEndCallKeyHandled) {
5248 mHandler.removeCallbacks(mEndCallLongPress);
5249 if (!canceled) {
5250 if ((mEndcallBehavior
5251 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
5252 if (goHome()) {
5253 break;
5254 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07005255 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005256 if ((mEndcallBehavior
5257 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
5258 mPowerManager.goToSleep(event.getEventTime(),
5259 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
5260 isWakeKey = false;
5261 }
Jeff Brown4d396052010-10-29 21:50:21 -07005262 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005263 }
Jeff Brown4d396052010-10-29 21:50:21 -07005264 }
5265 break;
5266 }
5267
5268 case KeyEvent.KEYCODE_POWER: {
5269 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07005270 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07005271 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005272 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005273 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005274 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07005275 }
5276 break;
5277 }
5278
Jeff Brown6212a492014-03-07 13:58:47 -08005279 case KeyEvent.KEYCODE_SLEEP: {
5280 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005281 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07005282 if (!mPowerManager.isInteractive()) {
5283 useHapticFeedback = false; // suppress feedback if already non-interactive
5284 }
Nick Vaccarob593a812015-05-15 11:23:05 -07005285 if (down) {
5286 sleepPress(event.getEventTime());
5287 } else {
5288 sleepRelease(event.getEventTime());
5289 }
Jeff Brown6212a492014-03-07 13:58:47 -08005290 break;
5291 }
5292
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -07005293 case KeyEvent.KEYCODE_SOFT_SLEEP: {
5294 result &= ~ACTION_PASS_TO_USER;
5295 isWakeKey = false;
5296 if (!down) {
5297 mPowerManagerInternal.setUserInactiveOverrideFromWindowManager();
5298 }
5299 break;
5300 }
5301
Jeff Brown6212a492014-03-07 13:58:47 -08005302 case KeyEvent.KEYCODE_WAKEUP: {
5303 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005304 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08005305 break;
5306 }
5307
Jeff Brown4d396052010-10-29 21:50:21 -07005308 case KeyEvent.KEYCODE_MEDIA_PLAY:
5309 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5310 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07005311 case KeyEvent.KEYCODE_HEADSETHOOK:
5312 case KeyEvent.KEYCODE_MUTE:
5313 case KeyEvent.KEYCODE_MEDIA_STOP:
5314 case KeyEvent.KEYCODE_MEDIA_NEXT:
5315 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5316 case KeyEvent.KEYCODE_MEDIA_REWIND:
5317 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005318 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
5319 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07005320 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
5321 // If the global session is active pass all media keys to it
5322 // instead of the active window.
5323 result &= ~ACTION_PASS_TO_USER;
5324 }
Jeff Brown4d396052010-10-29 21:50:21 -07005325 if ((result & ACTION_PASS_TO_USER) == 0) {
5326 // Only do this if we would otherwise not pass it to the user. In that
5327 // case, the PhoneWindow class will do the same thing, except it will
5328 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07005329 // Note that we need to make a copy of the key event here because the
5330 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07005331 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07005332 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
5333 new KeyEvent(event));
5334 msg.setAsynchronous(true);
5335 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005336 }
5337 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005338 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005339
Jeff Brown4d396052010-10-29 21:50:21 -07005340 case KeyEvent.KEYCODE_CALL: {
5341 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005342 TelecomManager telecomManager = getTelecommService();
5343 if (telecomManager != null) {
5344 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005345 Log.i(TAG, "interceptKeyBeforeQueueing:"
5346 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005347 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005348
Santos Cordon6848f722014-05-21 15:22:12 -07005349 // And *don't* pass this key thru to the current activity
5350 // (which is presumably the InCallScreen.)
5351 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005352 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005353 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005354 }
Jeff Brown4d396052010-10-29 21:50:21 -07005355 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005356 }
Michael Wright869a67c2014-08-26 19:33:06 -07005357 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5358 // Only do this if we would otherwise not pass it to the user. In that case,
5359 // interceptKeyBeforeDispatching would apply a similar but different policy in
5360 // order to invoke voice assist actions. Note that we need to make a copy of the
5361 // key event here because the original key event will be recycled when we return.
5362 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5363 mBroadcastWakeLock.acquire();
5364 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5365 keyguardActive ? 1 : 0, 0);
5366 msg.setAsynchronous(true);
5367 msg.sendToTarget();
5368 }
Jaewan Kim49117872016-01-19 17:24:08 +09005369 break;
5370 }
5371 case KeyEvent.KEYCODE_WINDOW: {
5372 if (mShortPressWindowBehavior == SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE) {
5373 if (!down) {
Jaewan Kimc552b042016-01-18 16:08:45 +09005374 requestTvPictureInPicture(event);
Jaewan Kim49117872016-01-19 17:24:08 +09005375 }
5376 result &= ~ACTION_PASS_TO_USER;
5377 }
5378 break;
Michael Wright869a67c2014-08-26 19:33:06 -07005379 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005380 }
Jeff Brown26875502014-01-30 21:47:47 -08005381
Jeff Brownbae8e772014-06-12 19:59:45 -07005382 if (useHapticFeedback) {
5383 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5384 }
5385
Jeff Brown26875502014-01-30 21:47:47 -08005386 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005387 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Jeff Brown26875502014-01-30 21:47:47 -08005388 }
Bryce Lee584a4452014-10-21 15:55:55 -07005389
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005390 return result;
5391 }
5392
Jeff Brown1c2e4942012-11-06 16:32:01 -08005393 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005394 * Returns true if the key can have global actions attached to it.
5395 * We reserve all power management keys for the system since they require
5396 * very careful handling.
5397 */
5398 private static boolean isValidGlobalKey(int keyCode) {
5399 switch (keyCode) {
5400 case KeyEvent.KEYCODE_POWER:
5401 case KeyEvent.KEYCODE_WAKEUP:
5402 case KeyEvent.KEYCODE_SLEEP:
5403 return false;
5404 default:
5405 return true;
5406 }
5407 }
5408
5409 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005410 * When the screen is off we ignore some keys that might otherwise typically
5411 * be considered wake keys. We filter them out here.
5412 *
5413 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5414 * is always considered a wake key.
5415 */
5416 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5417 switch (keyCode) {
5418 // ignore volume keys unless docked
5419 case KeyEvent.KEYCODE_VOLUME_UP:
5420 case KeyEvent.KEYCODE_VOLUME_DOWN:
5421 case KeyEvent.KEYCODE_VOLUME_MUTE:
5422 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5423
5424 // ignore media and camera keys
5425 case KeyEvent.KEYCODE_MUTE:
5426 case KeyEvent.KEYCODE_HEADSETHOOK:
5427 case KeyEvent.KEYCODE_MEDIA_PLAY:
5428 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5429 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5430 case KeyEvent.KEYCODE_MEDIA_STOP:
5431 case KeyEvent.KEYCODE_MEDIA_NEXT:
5432 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5433 case KeyEvent.KEYCODE_MEDIA_REWIND:
5434 case KeyEvent.KEYCODE_MEDIA_RECORD:
5435 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005436 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005437 case KeyEvent.KEYCODE_CAMERA:
5438 return false;
5439 }
5440 return true;
5441 }
5442
5443
Jeff Brown56194eb2011-03-02 19:23:13 -08005444 /** {@inheritDoc} */
5445 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005446 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5447 if ((policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005448 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion,
5449 "android.policy:MOTION")) {
Bryce Lee5c138322014-11-03 08:26:09 -08005450 return 0;
5451 }
Michael Wright70af00a2014-09-03 19:30:20 -07005452 }
Bryce Lee5c138322014-11-03 08:26:09 -08005453
Michael Wright70af00a2014-09-03 19:30:20 -07005454 if (shouldDispatchInputWhenNonInteractive()) {
5455 return ACTION_PASS_TO_USER;
5456 }
Bryce Lee5c138322014-11-03 08:26:09 -08005457
Bryce Lee812d7022014-11-10 13:33:28 -08005458 // If we have not passed the action up and we are in theater mode without dreaming,
5459 // there will be no dream to intercept the touch and wake into ambient. The device should
5460 // wake up in this case.
5461 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005462 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming,
5463 "android.policy:MOTION");
Bryce Lee812d7022014-11-10 13:33:28 -08005464 }
5465
Jeff Brown037c33e2014-04-09 00:31:55 -07005466 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005467 }
5468
Michael Wright70af00a2014-09-03 19:30:20 -07005469 private boolean shouldDispatchInputWhenNonInteractive() {
Joe LaPennaf2b9b2d2015-11-17 22:22:37 +00005470 // Send events to keyguard while the screen is on.
5471 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5472 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005473 return true;
5474 }
5475
5476 // Send events to a dozing dream even if the screen is off since the dream
5477 // is in control of the state of the screen.
5478 IDreamManager dreamManager = getDreamManager();
5479
5480 try {
5481 if (dreamManager != null && dreamManager.isDreaming()) {
5482 return true;
5483 }
5484 } catch (RemoteException e) {
5485 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5486 }
5487
5488 // Otherwise, consume events since the user can't see what is being
5489 // interacted with.
5490 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005491 }
5492
RoboErik001c59c2015-01-26 15:53:51 -08005493 private void dispatchDirectAudioEvent(KeyEvent event) {
5494 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5495 return;
5496 }
5497 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005498 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5499 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005500 String pkgName = mContext.getOpPackageName();
5501 switch (keyCode) {
5502 case KeyEvent.KEYCODE_VOLUME_UP:
5503 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005504 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005505 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005506 } catch (RemoteException e) {
5507 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5508 }
5509 break;
5510 case KeyEvent.KEYCODE_VOLUME_DOWN:
5511 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005512 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005513 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005514 } catch (RemoteException e) {
5515 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5516 }
5517 break;
5518 case KeyEvent.KEYCODE_VOLUME_MUTE:
5519 try {
5520 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005521 getAudioService().adjustSuggestedStreamVolume(
5522 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005523 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005524 }
5525 } catch (RemoteException e) {
5526 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5527 }
5528 break;
5529 }
5530 }
5531
Jeff Brown40013652012-05-16 21:22:36 -07005532 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5533 if (DEBUG_INPUT) {
5534 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005535 }
5536
Jeff Brown40013652012-05-16 21:22:36 -07005537 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5538 if (DEBUG_INPUT) {
5539 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5540 }
5541
5542 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5543 mHavePendingMediaKeyRepeatWithWakeLock = false;
5544 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5545 }
5546
5547 dispatchMediaKeyWithWakeLockToAudioService(event);
5548
5549 if (event.getAction() == KeyEvent.ACTION_DOWN
5550 && event.getRepeatCount() == 0) {
5551 mHavePendingMediaKeyRepeatWithWakeLock = true;
5552
5553 Message msg = mHandler.obtainMessage(
5554 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5555 msg.setAsynchronous(true);
5556 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5557 } else {
5558 mBroadcastWakeLock.release();
5559 }
5560 }
5561
5562 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5563 mHavePendingMediaKeyRepeatWithWakeLock = false;
5564
5565 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5566 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5567 if (DEBUG_INPUT) {
5568 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5569 }
5570
5571 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5572 mBroadcastWakeLock.release();
5573 }
5574
5575 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5576 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005577 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005578 }
5579 }
5580
Michael Wright869a67c2014-08-26 19:33:06 -07005581 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005582 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5583 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5584 if (dic != null) {
5585 try {
5586 dic.exitIdle("voice-search");
5587 } catch (RemoteException e) {
5588 }
5589 }
Michael Wright869a67c2014-08-26 19:33:06 -07005590 Intent voiceIntent =
5591 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5592 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005593 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005594 mBroadcastWakeLock.release();
5595 }
5596
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005597 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005598 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005599 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005600 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5601 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5602 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005603 } else {
5604 try {
5605 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5606 ServiceManager.getService(Context.UI_MODE_SERVICE));
5607 mUiMode = uiModeService.getCurrentModeType();
5608 } catch (RemoteException e) {
5609 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005610 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005611 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005612 synchronized (mLock) {
5613 updateOrientationListenerLp();
5614 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005615 }
5616 };
5617
Jeff Brown6aaf2952012-10-05 16:01:08 -07005618 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5619 @Override
5620 public void onReceive(Context context, Intent intent) {
5621 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005622 if (mKeyguardDelegate != null) {
5623 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005624 }
5625 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005626 if (mKeyguardDelegate != null) {
5627 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005628 }
5629 }
5630 }
5631 };
5632
Christopher Tate5e08af02012-09-21 17:17:22 -07005633 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5634 @Override
5635 public void onReceive(Context context, Intent intent) {
5636 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5637 // tickle the settings observer: this first ensures that we're
5638 // observing the relevant settings for the newly-active user,
5639 // and then updates our own bookkeeping based on the now-
5640 // current user.
5641 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005642
5643 // force a re-application of focused window sysui visibility.
5644 // the window may never have been shown for this user
5645 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005646 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005647 mLastSystemUiFlags = 0;
5648 updateSystemUiVisibilityLw();
5649 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005650 }
5651 }
5652 };
5653
Adrian Roosddc8b272015-05-21 16:28:27 -07005654 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005655 @Override
5656 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005657 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5658 if (!isUserSetupComplete()) {
5659 // Swipe-up for navigation bar is disabled during setup
5660 return;
5661 }
5662 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5663 mNavigationBarController.showTransient();
5664 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005665 }
5666 };
5667
John Spurlocke1f366f2013-08-05 12:22:40 -04005668 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005669 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005670 if (!isUserSetupComplete()) {
5671 // Swipe-up for navigation bar is disabled during setup
5672 return;
5673 }
John Spurlock27735a42013-08-14 17:57:38 -04005674 boolean sb = mStatusBarController.checkShowTransientBarLw();
5675 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005676 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005677 // Don't show status bar when swiping on already visible navigation bar
5678 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005679 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005680 return;
5681 }
John Spurlock27735a42013-08-14 17:57:38 -04005682 if (sb) mStatusBarController.showTransient();
5683 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005684 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005685 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005686 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005687 }
5688 }
5689
Jeff Brown3ee549c2014-09-22 20:14:39 -07005690 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005691 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005692 public void startedGoingToSleep(int why) {
5693 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005694 if (mKeyguardDelegate != null) {
5695 mKeyguardDelegate.onStartedGoingToSleep(why);
5696 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005697 }
5698
5699 // Called on the PowerManager's Notifier thread.
5700 @Override
5701 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005702 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005703 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04005704 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005705
5706 // We must get this work done here because the power manager will drop
5707 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005708 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005709 mAwake = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005710 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005711 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005712 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005713 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005714 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005715 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005716 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005717 }
5718
Jeff Brown3ee549c2014-09-22 20:14:39 -07005719 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005720 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005721 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005722 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005723 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005724
Jeff Brown3ee549c2014-09-22 20:14:39 -07005725 // Since goToSleep performs these functions synchronously, we must
5726 // do the same here. We cannot post this work to a handler because
5727 // that might cause it to become reordered with respect to what
5728 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005729 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005730 mAwake = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005731
Jeff Browna20dda42014-05-27 20:57:24 -07005732 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005733 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005734 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005735 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005736
Jim Miller5ecd8112013-01-09 18:50:26 -08005737 if (mKeyguardDelegate != null) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005738 mKeyguardDelegate.onStartedWakingUp();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005739 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005740 }
5741
Jeff Brown416c49c2015-05-26 19:50:18 -07005742 // Called on the PowerManager's Notifier thread.
5743 @Override
5744 public void finishedWakingUp() {
5745 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5746 }
5747
5748 private void wakeUpFromPowerKey(long eventTime) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005749 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER");
Jeff Brown416c49c2015-05-26 19:50:18 -07005750 }
5751
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005752 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) {
Bryce Leed3896842015-06-23 17:06:51 -07005753 final boolean theaterModeEnabled = isTheaterModeEnabled();
5754 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07005755 return false;
5756 }
5757
Bryce Leed3896842015-06-23 17:06:51 -07005758 if (theaterModeEnabled) {
5759 Settings.Global.putInt(mContext.getContentResolver(),
5760 Settings.Global.THEATER_MODE_ON, 0);
5761 }
5762
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005763 mPowerManager.wakeUp(wakeTime, reason);
Jeff Brown416c49c2015-05-26 19:50:18 -07005764 return true;
5765 }
5766
Jeff Brown36c4db82014-09-19 12:05:31 -07005767 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005768 synchronized (mLock) {
Jorim Jaggif3255482015-07-24 12:32:42 -07005769 if (!mScreenOnEarly || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005770 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005771 }
5772
Jeff Brown36c4db82014-09-19 12:05:31 -07005773 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005774 if (mKeyguardDelegate != null) {
5775 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5776 }
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005777 mWindowManagerDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005778 }
5779
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005780 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
5781 // as well as enabling the orientation change logic/sensor.
5782 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5783 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005784 }
5785
5786 // Called on the DisplayManager's DisplayPowerController thread.
5787 @Override
5788 public void screenTurnedOff() {
5789 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5790
Jeff Brown48d1b142015-06-10 16:36:03 -07005791 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005792 synchronized (mLock) {
5793 mScreenOnEarly = false;
5794 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005795 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005796 mWindowManagerDrawComplete = false;
5797 mScreenOnListener = null;
5798 updateOrientationListenerLp();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005799
5800 if (mKeyguardDelegate != null) {
5801 mKeyguardDelegate.onScreenTurnedOff();
5802 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005803 }
5804 }
5805
Jeff Brown3ee549c2014-09-22 20:14:39 -07005806 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005807 @Override
5808 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005809 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005810
Jeff Brown48d1b142015-06-10 16:36:03 -07005811 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005812 synchronized (mLock) {
5813 mScreenOnEarly = true;
5814 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005815 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005816 mWindowManagerDrawComplete = false;
5817 mScreenOnListener = screenOnListener;
Jeff Brown36c4db82014-09-19 12:05:31 -07005818
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005819 if (mKeyguardDelegate != null) {
Jorim Jaggia4b51bc2015-08-10 18:20:43 -07005820 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5821 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005822 mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback);
5823 } else {
5824 if (DEBUG_WAKEUP) Slog.d(TAG,
5825 "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
5826 finishKeyguardDrawn();
5827 }
5828 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005829 }
5830
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005831 // Called on the DisplayManager's DisplayPowerController thread.
5832 @Override
5833 public void screenTurnedOn() {
5834 synchronized (mLock) {
5835 if (mKeyguardDelegate != null) {
5836 mKeyguardDelegate.onScreenTurnedOn();
5837 }
5838 }
5839 }
5840
Jeff Brown36c4db82014-09-19 12:05:31 -07005841 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005842 synchronized (mLock) {
5843 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005844 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005845 }
5846
Jeff Brown36c4db82014-09-19 12:05:31 -07005847 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005848 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005849
5850 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005851 }
5852
Craig Mautner8a0da012014-05-31 15:13:37 -07005853 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005854 synchronized (mLock) {
5855 // We have just finished drawing screen content. Since the orientation listener
5856 // gets only installed when all windows are drawn, we try to install it again.
5857 updateOrientationListenerLp();
5858 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005859 final ScreenOnListener listener;
5860 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005861 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005862 if (DEBUG_WAKEUP) Slog.d(TAG,
5863 "finishScreenTurningOn: mAwake=" + mAwake
5864 + ", mScreenOnEarly=" + mScreenOnEarly
5865 + ", mScreenOnFully=" + mScreenOnFully
5866 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5867 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5868
5869 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5870 || (mAwake && !mKeyguardDrawComplete)) {
5871 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005872 }
5873
Jeff Brown3ee549c2014-09-22 20:14:39 -07005874 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5875 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005876 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005877 mScreenOnFully = true;
5878
5879 // Remember the first time we draw the keyguard so we know when we're done with
5880 // the main part of booting and can enable the screen and hide boot messages.
5881 if (!mKeyguardDrawnOnce && mAwake) {
5882 mKeyguardDrawnOnce = true;
5883 enableScreen = true;
5884 if (mBootMessageNeedsHiding) {
5885 mBootMessageNeedsHiding = false;
5886 hideBootMessages();
5887 }
5888 } else {
5889 enableScreen = false;
5890 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005891 }
5892
Jeff Brown3ee549c2014-09-22 20:14:39 -07005893 if (listener != null) {
5894 listener.onScreenOn();
5895 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005896
Jeff Brown3ee549c2014-09-22 20:14:39 -07005897 if (enableScreen) {
5898 try {
5899 mWindowManager.enableScreenIfNeeded();
5900 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005901 }
Craig Mautnera631d492014-08-05 15:16:01 -07005902 }
5903 }
5904
5905 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005906 synchronized (mLock) {
5907 if (!mKeyguardDrawnOnce) {
5908 mBootMessageNeedsHiding = true;
5909 return; // keyguard hasn't drawn the first time yet, not done booting
5910 }
Craig Mautnera631d492014-08-05 15:16:01 -07005911 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005912
5913 if (mBootMsgDialog != null) {
5914 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5915 mBootMsgDialog.dismiss();
5916 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005917 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005918 }
5919
5920 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005921 public boolean isScreenOn() {
5922 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005923 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005924
Dianne Hackborn08743722009-12-21 12:16:51 -08005925 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005926 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005927 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005928 if (mKeyguardDelegate != null) {
5929 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005930 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005931 }
5932
5933 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005934 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005935 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005936 if (mKeyguardDelegate != null) {
5937 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005938 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005939 }
5940
Jim Millerab954542014-10-10 18:21:49 -07005941 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005942 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005943 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005944 }
5945
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005946 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005947 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005948 public boolean isKeyguardLocked() {
5949 return keyguardOn();
5950 }
5951
5952 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005953 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005954 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005955 if (mKeyguardDelegate == null) return false;
5956 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005957 }
5958
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005959 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005960 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07005961 public boolean isKeyguardShowingOrOccluded() {
5962 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
5963 }
5964
5965 /** {@inheritDoc} */
5966 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005967 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005968 if (mKeyguardDelegate == null) return false;
5969 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005970 }
5971
Jose Lima9546b202014-07-02 17:21:51 -07005972 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005973 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005974 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005975 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005976 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005977 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005978 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005979 // ask the keyguard to prompt the user to authenticate if necessary
5980 mKeyguardDelegate.dismiss();
5981 }
5982 });
5983 }
5984 }
5985
5986 public void notifyActivityDrawnForKeyguardLw() {
5987 if (mKeyguardDelegate != null) {
5988 mHandler.post(new Runnable() {
5989 @Override
5990 public void run() {
5991 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005992 }
5993 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005994 }
5995 }
5996
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005997 @Override
5998 public boolean isKeyguardDrawnLw() {
5999 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006000 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006001 }
6002 }
6003
Jorim Jaggi0d674622014-05-21 01:34:15 +02006004 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006005 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02006006 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006007 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006008 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02006009 }
6010 }
6011
Jorim Jaggi737af722015-12-31 10:42:27 +01006012 @Override
6013 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6014 Rect outInsets) {
6015 outInsets.setEmpty();
6016 if (mStatusBar != null) {
6017 outInsets.top = mStatusBarHeight;
6018 }
6019 if (mNavigationBar != null) {
6020 if (isNavigationBarOnBottom(displayWidth, displayHeight)) {
6021 outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode);
6022 } else {
6023 outInsets.right = getNavigationBarWidth(displayRotation, mUiMode);
6024 }
6025 }
6026 }
6027
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006028 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006029 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006030 }
6031
6032 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006033 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006034 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07006035
Jeff Brown01a98dd2011-09-20 15:08:29 -07006036 @Override
6037 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006038 if (false) {
6039 Slog.v(TAG, "rotationForOrientationLw(orient="
6040 + orientation + ", last=" + lastRotation
6041 + "); user=" + mUserRotation + " "
6042 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
6043 ? "USER_ROTATION_LOCKED" : "")
6044 );
6045 }
6046
Craig Mautner46ac6fa2013-08-01 10:06:34 -07006047 if (mForceDefaultOrientation) {
6048 return Surface.ROTATION_0;
6049 }
6050
The Android Open Source Project0727d222009-03-11 12:11:58 -07006051 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07006052 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
6053 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07006054 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07006055 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006056
Jeff Browndec6cf42011-11-15 14:08:20 -08006057 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07006058 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006059 // Ignore sensor when lid switch is open and rotation is forced.
6060 preferredRotation = mLidOpenRotation;
6061 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07006062 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006063 // Ignore sensor when in car dock unless explicitly enabled.
6064 // This case can override the behavior of NOSENSOR, and can also
6065 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006066 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006067 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08006068 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6069 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
6070 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07006071 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006072 // Ignore sensor when in desk dock unless explicitly enabled.
6073 // This case can override the behavior of NOSENSOR, and can also
6074 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006075 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006076 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006077 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
6078 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08006079 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006080 preferredRotation = mDemoHdmiRotation;
6081 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
6082 && mUndockedHdmiRotation >= 0) {
6083 // Ignore sensor when plugged into HDMI and an undocked orientation has
6084 // been specified in the configuration (only for legacy devices without
6085 // full multi-display support).
6086 // Note that the dock orientation overrides the HDMI orientation.
6087 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08006088 } else if (mDemoRotationLock) {
6089 // Ignore sensor when demo rotation lock is enabled.
6090 // Note that the dock orientation and HDMI rotation lock override this.
6091 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006092 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
6093 // Application just wants to remain locked in the last rotation.
6094 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08006095 } else if (!mSupportAutoRotation) {
6096 // If we don't support auto-rotation then bail out here and ignore
6097 // the sensor and any rotation lock settings.
6098 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07006099 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07006100 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006101 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
6102 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
6103 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
6104 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07006105 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
6106 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6107 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
6108 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
6109 // Otherwise, use sensor only if requested by the application or enabled
6110 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07006111 if (mAllowAllRotations < 0) {
6112 // Can't read this during init() because the context doesn't
6113 // have display metrics at that time so we cannot determine
6114 // tablet vs. phone then.
6115 mAllowAllRotations = mContext.getResources().getBoolean(
6116 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
6117 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006118 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07006119 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006120 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6121 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006122 preferredRotation = sensorRotation;
6123 } else {
6124 preferredRotation = lastRotation;
6125 }
Jeff Brown207673cd2012-06-05 17:47:11 -07006126 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
6127 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
6128 // Apply rotation lock. Does not apply to NOSENSOR.
6129 // The idea is that the user rotation expresses a weak preference for the direction
6130 // of gravity and as NOSENSOR is never affected by gravity, then neither should
6131 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07006132 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08006133 } else {
6134 // No overriding preference.
6135 // We will do exactly what the application asked us to do.
6136 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07006137 }
6138
Dianne Hackborne5439f22010-10-02 16:53:50 -07006139 switch (orientation) {
6140 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006141 // Return portrait unless overridden.
6142 if (isAnyPortrait(preferredRotation)) {
6143 return preferredRotation;
6144 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07006145 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006146
Jeff Brown01a98dd2011-09-20 15:08:29 -07006147 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006148 // Return landscape unless overridden.
6149 if (isLandscapeOrSeascape(preferredRotation)) {
6150 return preferredRotation;
6151 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006152 return mLandscapeRotation;
6153
6154 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006155 // Return reverse portrait unless overridden.
6156 if (isAnyPortrait(preferredRotation)) {
6157 return preferredRotation;
6158 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006159 return mUpsideDownRotation;
6160
6161 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006162 // Return seascape unless overridden.
6163 if (isLandscapeOrSeascape(preferredRotation)) {
6164 return preferredRotation;
6165 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006166 return mSeascapeRotation;
6167
6168 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006169 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006170 // Return either landscape rotation.
6171 if (isLandscapeOrSeascape(preferredRotation)) {
6172 return preferredRotation;
6173 }
6174 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08006175 return lastRotation;
6176 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006177 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006178
Jeff Brown01a98dd2011-09-20 15:08:29 -07006179 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006180 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006181 // Return either portrait rotation.
6182 if (isAnyPortrait(preferredRotation)) {
6183 return preferredRotation;
6184 }
6185 if (isAnyPortrait(lastRotation)) {
6186 return lastRotation;
6187 }
6188 return mPortraitRotation;
6189
6190 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07006191 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
6192 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07006193 if (preferredRotation >= 0) {
6194 return preferredRotation;
6195 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07006196 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05006197 }
6198 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006199 }
6200
Jeff Brown01a98dd2011-09-20 15:08:29 -07006201 @Override
6202 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
6203 switch (orientation) {
6204 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
6205 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
6206 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
6207 return isAnyPortrait(rotation);
6208
6209 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
6210 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
6211 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
6212 return isLandscapeOrSeascape(rotation);
6213
6214 default:
6215 return true;
6216 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006217 }
6218
Jeff Brownc0347aa2011-09-23 17:26:09 -07006219 @Override
6220 public void setRotationLw(int rotation) {
6221 mOrientationListener.setCurrentRotation(rotation);
6222 }
6223
Jeff Brown01a98dd2011-09-20 15:08:29 -07006224 private boolean isLandscapeOrSeascape(int rotation) {
6225 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006226 }
6227
Jeff Brown01a98dd2011-09-20 15:08:29 -07006228 private boolean isAnyPortrait(int rotation) {
6229 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006230 }
6231
Jose Lima9546b202014-07-02 17:21:51 -07006232 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006233 public int getUserRotationMode() {
6234 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07006235 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
6236 WindowManagerPolicy.USER_ROTATION_FREE :
6237 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006238 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006239
6240 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07006241 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006242 public void setUserRotationMode(int mode, int rot) {
6243 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006244
6245 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006246 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07006247 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006248 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006249 rot,
6250 UserHandle.USER_CURRENT);
6251 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006252 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006253 0,
6254 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006255 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07006256 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006257 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006258 1,
6259 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006260 }
6261 }
6262
Jose Lima9546b202014-07-02 17:21:51 -07006263 @Override
Jeff Brownac143512012-04-05 18:57:33 -07006264 public void setSafeMode(boolean safeMode) {
6265 mSafeMode = safeMode;
6266 performHapticFeedbackLw(null, safeMode
6267 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
6268 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006269 }
Craig Mautnereda67292013-04-28 13:50:14 -07006270
Dianne Hackborn181ceb52009-08-27 22:16:40 -07006271 static long[] getLongIntArray(Resources r, int resid) {
6272 int[] ar = r.getIntArray(resid);
6273 if (ar == null) {
6274 return null;
6275 }
6276 long[] out = new long[ar.length];
6277 for (int i=0; i<ar.length; i++) {
6278 out[i] = ar[i];
6279 }
6280 return out;
6281 }
Craig Mautnereda67292013-04-28 13:50:14 -07006282
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006283 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006284 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006285 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07006286 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08006287 mKeyguardDelegate.onSystemReady();
6288
Michael Wright3818c922014-09-02 13:59:07 -07006289 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07006290 updateUiMode();
Adrian Roos3542f7d2015-07-13 15:57:53 -07006291 boolean bindKeyguardNow;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006292 synchronized (mLock) {
6293 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08006294 mSystemReady = true;
6295 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006296 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08006297 public void run() {
6298 updateSettings();
6299 }
6300 });
Adrian Roos3542f7d2015-07-13 15:57:53 -07006301
6302 bindKeyguardNow = mDeferBindKeyguard;
6303 if (bindKeyguardNow) {
6304 // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now.
6305 mDeferBindKeyguard = false;
6306 }
6307 }
6308
6309 if (bindKeyguardNow) {
6310 mKeyguardDelegate.bindService(mContext);
6311 mKeyguardDelegate.onBootCompleted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006312 }
Michael Wrighta4d22d72015-09-16 23:19:26 +01006313 mSystemGestures.systemReady();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006314 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006315
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006316 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006317 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006318 public void systemBooted() {
Adrian Roos3542f7d2015-07-13 15:57:53 -07006319 boolean bindKeyguardNow = false;
6320 synchronized (mLock) {
6321 // Time to bind Keyguard; take care to only bind it once, either here if ready or
6322 // in systemReady if not.
6323 if (mKeyguardDelegate != null) {
6324 bindKeyguardNow = true;
6325 } else {
6326 // Because mKeyguardDelegate is null, we know that the synchronized block in
6327 // systemReady didn't run yet and setting this will actually have an effect.
6328 mDeferBindKeyguard = true;
6329 }
6330 }
6331 if (bindKeyguardNow) {
Jason Monk5eeebf52014-09-26 12:36:51 -04006332 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07006333 mKeyguardDelegate.onBootCompleted();
6334 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006335 synchronized (mLock) {
6336 mSystemBooted = true;
6337 }
Jeff Brown416c49c2015-05-26 19:50:18 -07006338 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07006339 screenTurningOn(null);
Jorim Jaggic0496072015-08-19 15:14:52 -07006340 screenTurnedOn();
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006341 }
6342
Dianne Hackborn661cd522011-08-22 00:26:20 -07006343 ProgressDialog mBootMsgDialog = null;
6344
6345 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006346 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006347 public void showBootMessage(final CharSequence msg, final boolean always) {
6348 mHandler.post(new Runnable() {
6349 @Override public void run() {
6350 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006351 int theme;
Jaewan Kim49117872016-01-19 17:24:08 +09006352 if (mContext.getPackageManager().hasSystemFeature(FEATURE_WATCH)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006353 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
Jaewan Kim49117872016-01-19 17:24:08 +09006354 } else if (mContext.getPackageManager().hasSystemFeature(FEATURE_TELEVISION)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006355 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
6356 } else {
6357 theme = 0;
6358 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07006359
6360 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07006361 // This dialog will consume all events coming in to
6362 // it, to avoid it trying to do things too early in boot.
6363 @Override public boolean dispatchKeyEvent(KeyEvent event) {
6364 return true;
6365 }
6366 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
6367 return true;
6368 }
6369 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
6370 return true;
6371 }
6372 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
6373 return true;
6374 }
6375 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
6376 return true;
6377 }
6378 @Override public boolean dispatchPopulateAccessibilityEvent(
6379 AccessibilityEvent event) {
6380 return true;
6381 }
6382 };
Jeff Hao9f60c082014-10-28 18:51:07 -07006383 if (mContext.getPackageManager().isUpgrade()) {
6384 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
6385 } else {
6386 mBootMsgDialog.setTitle(R.string.android_start_title);
6387 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006388 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
6389 mBootMsgDialog.setIndeterminate(true);
6390 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07006391 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006392 mBootMsgDialog.getWindow().addFlags(
6393 WindowManager.LayoutParams.FLAG_DIM_BEHIND
6394 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
6395 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08006396 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
6397 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
6398 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006399 mBootMsgDialog.setCancelable(false);
6400 mBootMsgDialog.show();
6401 }
6402 mBootMsgDialog.setMessage(msg);
6403 }
6404 });
6405 }
6406
6407 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006408 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006409 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07006410 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006411 }
6412
Mike Lockwood28569302010-01-28 11:54:40 -05006413 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006414 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006415 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006416 // ***************************************
6417 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
6418 // ***************************************
6419 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
6420 // WITH ITS LOCKS HELD.
6421 //
6422 // This code must be VERY careful about the locks
6423 // it acquires.
6424 // In fact, the current code acquires way too many,
6425 // and probably has lurking deadlocks.
6426
Mike Lockwood28569302010-01-28 11:54:40 -05006427 synchronized (mScreenLockTimeout) {
6428 if (mLockScreenTimerActive) {
6429 // reset the timer
6430 mHandler.removeCallbacks(mScreenLockTimeout);
6431 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6432 }
6433 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006434 }
6435
Adam Cohenf7522022012-10-03 20:03:18 -07006436 class ScreenLockTimeout implements Runnable {
6437 Bundle options;
6438
6439 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006440 public void run() {
6441 synchronized (this) {
6442 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006443 if (mKeyguardDelegate != null) {
6444 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006445 }
Mike Lockwood28569302010-01-28 11:54:40 -05006446 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006447 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006448 }
6449 }
Mike Lockwood28569302010-01-28 11:54:40 -05006450
Adam Cohenf7522022012-10-03 20:03:18 -07006451 public void setLockOptions(Bundle options) {
6452 this.options = options;
6453 }
6454 }
6455
6456 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6457
Jose Lima9546b202014-07-02 17:21:51 -07006458 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006459 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006460 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6461 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006462 if (options != null) {
6463 // In case multiple calls are made to lockNow, we don't wipe out the options
6464 // until the runnable actually executes.
6465 mScreenLockTimeout.setLockOptions(options);
6466 }
Jim Miller93c518e2012-01-17 15:55:31 -08006467 mHandler.post(mScreenLockTimeout);
6468 }
6469
Mike Lockwood28569302010-01-28 11:54:40 -05006470 private void updateLockScreenTimeout() {
6471 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006472 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006473 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006474 if (mLockScreenTimerActive != enable) {
6475 if (enable) {
6476 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
Jim Miller2967f482016-01-07 15:05:32 -08006477 mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests
Mike Lockwood28569302010-01-28 11:54:40 -05006478 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6479 } else {
6480 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6481 mHandler.removeCallbacks(mScreenLockTimeout);
6482 }
6483 mLockScreenTimerActive = enable;
6484 }
6485 }
6486 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006487
Jeff Brown061ea992015-04-17 19:55:47 -07006488 private void updateDreamingSleepToken(boolean acquire) {
6489 if (acquire) {
6490 if (mDreamingSleepToken == null) {
6491 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6492 }
6493 } else {
6494 if (mDreamingSleepToken != null) {
6495 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006496 mDreamingSleepToken = null;
6497 }
6498 }
6499 }
6500
6501 private void updateScreenOffSleepToken(boolean acquire) {
6502 if (acquire) {
6503 if (mScreenOffSleepToken == null) {
6504 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6505 }
6506 } else {
6507 if (mScreenOffSleepToken != null) {
6508 mScreenOffSleepToken.release();
6509 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006510 }
6511 }
6512 }
6513
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006514 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006515 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006516 public void enableScreenAfterBoot() {
6517 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006518 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006519 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006520 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006521
Jeff Brownc458ce92012-04-30 14:58:40 -07006522 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006523 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006524 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006525 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006526 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01006527 } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) {
6528 mWindowManagerFuncs.lockDeviceNow();
Jeff Brownc458ce92012-04-30 14:58:40 -07006529 }
Jeff Browna20dda42014-05-27 20:57:24 -07006530
6531 synchronized (mLock) {
6532 updateWakeGestureListenerLp();
6533 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006534 }
6535
Jeff Brown4f5fa282014-06-12 19:19:15 -07006536 void updateUiMode() {
6537 if (mUiModeManager == null) {
6538 mUiModeManager = IUiModeManager.Stub.asInterface(
6539 ServiceManager.getService(Context.UI_MODE_SERVICE));
6540 }
6541 try {
6542 mUiMode = mUiModeManager.getCurrentModeType();
6543 } catch (RemoteException e) {
6544 }
6545 }
6546
Jeff Brown01a98dd2011-09-20 15:08:29 -07006547 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006548 try {
6549 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006550 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6551 } catch (RemoteException e) {
6552 // Ignore
6553 }
6554 }
6555
6556 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6557 try {
6558 //set orientation on WindowManager
6559 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006560 } catch (RemoteException e) {
6561 // Ignore
6562 }
6563 }
6564
Daniel Sandler6396c722013-04-16 20:19:09 -04006565 /**
6566 * Return an Intent to launch the currently active dock app as home. Returns
6567 * null if the standard home should be launched, which is the case if any of the following is
6568 * true:
6569 * <ul>
6570 * <li>The device is not in either car mode or desk mode
keunyounga7710492015-09-23 11:33:58 -07006571 * <li>The device is in car mode but mEnableCarDockHomeCapture is false
Daniel Sandler6396c722013-04-16 20:19:09 -04006572 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6573 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6574 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6575 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006576 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006577 */
6578 Intent createHomeDockIntent() {
6579 Intent intent = null;
6580
6581 // What home does is based on the mode, not the dock state. That
6582 // is, when in car mode you should be taken to car home regardless
6583 // of whether we are actually in a car dock.
6584 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
keunyounga7710492015-09-23 11:33:58 -07006585 if (mEnableCarDockHomeCapture) {
Daniel Sandler6396c722013-04-16 20:19:09 -04006586 intent = mCarDockIntent;
6587 }
6588 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6589 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6590 intent = mDeskDockIntent;
6591 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006592 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6593 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6594 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6595 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6596 // Always launch dock home from home when watch is docked, if it exists.
6597 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006598 }
6599
6600 if (intent == null) {
6601 return null;
6602 }
6603
6604 ActivityInfo ai = null;
6605 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6606 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006607 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006608 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006609 if (info != null) {
6610 ai = info.activityInfo;
6611 }
6612 if (ai != null
6613 && ai.metaData != null
6614 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6615 intent = new Intent(intent);
6616 intent.setClassName(ai.packageName, ai.name);
6617 return intent;
6618 }
6619
6620 return null;
6621 }
6622
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006623 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6624 if (awakenFromDreams) {
6625 awakenDreams();
6626 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006627
6628 Intent dock = createHomeDockIntent();
6629 if (dock != null) {
6630 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006631 if (fromHomeKey) {
6632 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6633 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006634 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006635 return;
6636 } catch (ActivityNotFoundException e) {
6637 }
6638 }
6639
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006640 Intent intent;
6641
6642 if (fromHomeKey) {
6643 intent = new Intent(mHomeIntent);
6644 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6645 } else {
6646 intent = mHomeIntent;
6647 }
6648
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006649 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006650 }
Craig Mautnereda67292013-04-28 13:50:14 -07006651
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006652 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006653 * goes to the home screen
6654 * @return whether it did anything
6655 */
6656 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006657 if (!isUserSetupComplete()) {
6658 Slog.i(TAG, "Not going home because user setup is in progress.");
6659 return false;
6660 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006661 if (false) {
6662 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006663 try {
6664 ActivityManagerNative.getDefault().stopAppSwitches();
6665 } catch (RemoteException e) {
6666 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006667 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006668 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006669 } else {
6670 // This code brings home to the front or, if it is already
6671 // at the front, puts the device to sleep.
6672 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006673 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6674 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6675 Log.d(TAG, "UTS-TEST-MODE");
6676 } else {
6677 ActivityManagerNative.getDefault().stopAppSwitches();
6678 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006679 Intent dock = createHomeDockIntent();
6680 if (dock != null) {
6681 int result = ActivityManagerNative.getDefault()
6682 .startActivityAsUser(null, null, dock,
6683 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6684 null, null, 0,
6685 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006686 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006687 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6688 return false;
6689 }
6690 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006691 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006692 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006693 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006694 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006695 null, null, 0,
6696 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006697 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006698 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006699 return false;
6700 }
6701 } catch (RemoteException ex) {
6702 // bummer, the activity manager, which is in this process, is dead
6703 }
6704 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006705 return true;
6706 }
Craig Mautnereda67292013-04-28 13:50:14 -07006707
6708 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006709 public void setCurrentOrientationLw(int newOrientation) {
6710 synchronized (mLock) {
6711 if (newOrientation != mCurrentAppOrientation) {
6712 mCurrentAppOrientation = newOrientation;
6713 updateOrientationListenerLp();
6714 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006715 }
6716 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006717
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006718 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6719 if (!isGlobalAccessibilityGestureEnabled()) {
6720 return;
6721 }
6722 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6723 Context.AUDIO_SERVICE);
6724 if (audioManager.isSilentMode()) {
6725 return;
6726 }
6727 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6728 Settings.System.DEFAULT_NOTIFICATION_URI);
6729 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6730 ringTone.play();
6731 }
Craig Mautnereda67292013-04-28 13:50:14 -07006732
Bryce Lee584a4452014-10-21 15:55:55 -07006733 private boolean isTheaterModeEnabled() {
6734 return Settings.Global.getInt(mContext.getContentResolver(),
6735 Settings.Global.THEATER_MODE_ON, 0) == 1;
6736 }
6737
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006738 private boolean isGlobalAccessibilityGestureEnabled() {
6739 return Settings.Global.getInt(mContext.getContentResolver(),
6740 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6741 }
6742
Craig Mautnereda67292013-04-28 13:50:14 -07006743 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006744 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006745 if (!mVibrator.hasVibrator()) {
6746 return false;
6747 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006748 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6749 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006750 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006751 return false;
6752 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006753 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006754 switch (effectId) {
6755 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006756 pattern = mLongPressVibePattern;
6757 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006758 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006759 pattern = mVirtualKeyVibePattern;
6760 break;
6761 case HapticFeedbackConstants.KEYBOARD_TAP:
6762 pattern = mKeyboardTapVibePattern;
6763 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006764 case HapticFeedbackConstants.CLOCK_TICK:
6765 pattern = mClockTickVibePattern;
6766 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006767 case HapticFeedbackConstants.CALENDAR_DATE:
6768 pattern = mCalendarDateVibePattern;
6769 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006770 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006771 pattern = mSafeModeDisabledVibePattern;
6772 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006773 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006774 pattern = mSafeModeEnabledVibePattern;
6775 break;
Mady Mellore8608912015-06-05 09:02:55 -07006776 case HapticFeedbackConstants.CONTEXT_CLICK:
6777 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006778 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006779 default:
6780 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006781 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006782 int owningUid;
6783 String owningPackage;
6784 if (win != null) {
6785 owningUid = win.getOwningUid();
6786 owningPackage = win.getOwningPackage();
6787 } else {
6788 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006789 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006790 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006791 if (pattern.length == 1) {
6792 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006793 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006794 } else {
6795 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006796 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006797 }
6798 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006799 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006800
6801 @Override
6802 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006803 }
6804
Jeff Brownc38c9be2012-10-04 13:16:19 -07006805 @Override
6806 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006807 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006808 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006809 }
6810 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006811
Dianne Hackborndf89e652011-10-06 22:35:11 -07006812 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006813 // If there is no window focused, there will be nobody to handle the events
6814 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006815 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6816 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006817 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006818 return 0;
6819 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006820 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006821 // We are updating at a point where the keyguard has gotten
6822 // focus, but we were last in a state where the top window is
6823 // hiding it. This is probably because the keyguard as been
6824 // shown while the top window was displayed, so we want to ignore
6825 // it here because this is just a very transient change and it
6826 // will quickly lose focus once it correctly gets hidden.
6827 return 0;
6828 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006829
John Spurlock1db8b682014-02-18 11:18:59 -05006830 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006831 & ~mResettingSystemUiFlags
6832 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006833 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006834 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006835 }
Thanh Hai Mai6c009f52015-09-01 16:27:32 -07006836
6837 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6838 tmpVisibility |= StatusBarManager.DISABLE_RECENT;
6839 }
6840
Adrian Rooscd3884d2015-02-18 17:25:23 +01006841 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006842 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006843 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006844 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006845 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006846 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006847 return 0;
6848 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006849 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006850 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006851 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006852 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006853 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006854 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006855 try {
6856 IStatusBarService statusbar = getStatusBarService();
6857 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006858 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006859 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006860 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006861 } catch (RemoteException e) {
6862 // re-acquire status bar service next time it is needed.
6863 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006864 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006865 }
6866 });
6867 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006868 }
6869
Adrian Rooscd3884d2015-02-18 17:25:23 +01006870 private int updateLightStatusBarLw(int vis) {
6871 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6872 ? mStatusBar
6873 : mTopFullscreenOpaqueOrDimmingWindowState;
6874
6875 if (statusColorWin != null) {
6876 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6877 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6878 // its light flag.
6879 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6880 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6881 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6882 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6883 // Otherwise if it's dimming, clear the light flag.
6884 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6885 }
6886 }
6887 return vis;
6888 }
6889
John Spurlock79da8332013-09-20 12:04:47 -04006890 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006891 final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
6892 final boolean freeformStackVisible =
6893 mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID);
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08006894 final boolean resizing = mWindowManagerInternal.isDockedDividerResizing();
6895
6896 // We need to force system bars when the docked stack is visible, when the freeform stack
6897 // is visible but also when we are resizing for the transitions when docked stack
6898 // visibility changes.
6899 final boolean forceShowSystemBars = dockedStackVisible || freeformStackVisible || resizing;
Jorim Jaggi4fa78922015-11-30 17:13:56 -08006900 final boolean forceOpaqueSystemBars = forceShowSystemBars && !mForceStatusBarFromKeyguard;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006901
John Spurlockbd957402013-10-03 11:38:39 -04006902 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006903 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6904 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006905 : mTopFullscreenOpaqueWindowState;
6906 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6907 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6908
John Spurlock27735a42013-08-14 17:57:38 -04006909 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006910 int type = win.getAttrs().type;
6911 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006912 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006913 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6914 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006915 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006916 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6917 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006918 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006919 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6920 }
John Spurlockbd957402013-10-03 11:38:39 -04006921 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006922 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006923
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006924 if ((!areTranslucentBarsAllowed() && transWin != mStatusBar)
6925 || forceOpaqueSystemBars) {
Adrian Roosea562512014-05-05 13:33:03 +02006926 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6927 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006928 }
6929
Jorim Jaggi4fa78922015-11-30 17:13:56 -08006930 if (mForceWindowDrawsStatusBarBackground) {
6931 vis |= View.STATUS_BAR_TRANSPARENT;
6932 vis &= ~View.STATUS_BAR_TRANSLUCENT;
6933 }
6934
John Spurlock27735a42013-08-14 17:57:38 -04006935 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006936 boolean immersiveSticky =
6937 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006938 final boolean hideStatusBarWM =
6939 mTopFullscreenOpaqueWindowState != null
6940 && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006941 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006942 final boolean hideStatusBarSysui =
John Spurlock27735a42013-08-14 17:57:38 -04006943 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006944 final boolean hideNavBarSysui =
John Spurlockf1a36642013-10-12 17:50:42 -04006945 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006946
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006947 final boolean transientStatusBarAllowed = mStatusBar != null
6948 && (statusBarHasFocus || (!forceShowSystemBars
6949 && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky))));
John Spurlock27735a42013-08-14 17:57:38 -04006950
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006951 final boolean transientNavBarAllowed = mNavigationBar != null
6952 && !forceShowSystemBars && hideNavBarSysui && immersiveSticky;
John Spurlockf1a36642013-10-12 17:50:42 -04006953
Adrian Roosddc8b272015-05-21 16:28:27 -07006954 final long now = SystemClock.uptimeMillis();
6955 final boolean pendingPanic = mPendingPanicGestureUptime != 0
6956 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
6957 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
6958 // The user performed the panic gesture recently, we're about to hide the bars,
6959 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
6960 mPendingPanicGestureUptime = 0;
6961 mStatusBarController.showTransient();
6962 mNavigationBarController.showTransient();
6963 }
6964
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006965 final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006966 && !transientStatusBarAllowed && hideStatusBarSysui;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006967 final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006968 && !transientNavBarAllowed;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006969 if (denyTransientStatus || denyTransientNav || forceShowSystemBars) {
John Spurlock27735a42013-08-14 17:57:38 -04006970 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006971 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006972 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006973 }
John Spurlock27735a42013-08-14 17:57:38 -04006974
Selim Cinekf98702e2015-05-20 22:48:40 -07006975 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
6976 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
6977 final boolean navAllowedHidden = immersive || immersiveSticky;
6978
Selim Cinekd6623612015-05-22 18:56:22 -07006979 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
6980 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07006981 // We can't hide the navbar from this window otherwise the input consumer would not get
6982 // the input events.
6983 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
6984 }
6985
John Spurlock27735a42013-08-14 17:57:38 -04006986 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6987
6988 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006989 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6990 boolean newImmersiveMode = isImmersiveMode(vis);
6991 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006992 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006993 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6994 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006995 }
John Spurlock27735a42013-08-14 17:57:38 -04006996
John Spurlockf1a36642013-10-12 17:50:42 -04006997 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6998
John Spurlocke1f366f2013-08-05 12:22:40 -04006999 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007000 }
7001
John Spurlockf1a36642013-10-12 17:50:42 -04007002 private void clearClearableFlagsLw() {
7003 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
7004 if (newVal != mResettingSystemUiFlags) {
7005 mResettingSystemUiFlags = newVal;
7006 mWindowManagerFuncs.reevaluateStatusBarVisibility();
7007 }
7008 }
7009
7010 private boolean isImmersiveMode(int vis) {
7011 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04007012 return mNavigationBar != null
7013 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04007014 && (vis & flags) != 0
7015 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04007016 }
7017
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007018 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007019 * @return whether the navigation or status bar can be made translucent
7020 *
7021 * This should return true unless touch exploration is not enabled or
7022 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007023 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007024 private boolean areTranslucentBarsAllowed() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04007025 return mTranslucentDecorEnabled;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007026 }
7027
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007028 // Use this instead of checking config_showNavigationBar so that it can be consistently
7029 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07007030 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007031 public boolean hasNavigationBar() {
7032 return mHasNavigationBar;
7033 }
7034
satok1bc0a492012-04-25 22:47:12 +09007035 @Override
7036 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
7037 mLastInputMethodWindow = ime;
7038 mLastInputMethodTargetWindow = target;
7039 }
7040
Craig Mautnerf1b67412012-09-19 13:18:29 -07007041 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09007042 public int getInputMethodWindowVisibleHeightLw() {
7043 return mDockBottom - mCurBottom;
7044 }
7045
7046 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07007047 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07007048 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08007049 if (mKeyguardDelegate != null) {
7050 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007051 }
John Spurlock13451a22012-09-28 14:40:41 -04007052 if (mStatusBarService != null) {
7053 try {
7054 mStatusBarService.setCurrentUser(newUserId);
7055 } catch (RemoteException e) {
7056 // oh well
7057 }
7058 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007059 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007060 }
7061
7062 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08007063 public boolean canMagnifyWindow(int windowType) {
7064 switch (windowType) {
7065 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
7066 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
7067 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
7068 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
7069 return false;
7070 }
7071 }
7072 return true;
7073 }
7074
7075 @Override
7076 public boolean isTopLevelWindow(int windowType) {
7077 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
7078 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
7079 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
7080 }
7081 return true;
7082 }
7083
Jim Miller4eeb4f62012-11-08 00:04:29 -08007084 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07007085 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007086 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007087 pw.print(" mSystemReady="); pw.print(mSystemReady);
7088 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07007089 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007090 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07007091 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007092 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07007093 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
7094 || mForceClearedSystemUiFlags != 0) {
7095 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
7096 pw.print(Integer.toHexString(mLastSystemUiFlags));
7097 pw.print(" mResettingSystemUiFlags=0x");
7098 pw.print(Integer.toHexString(mResettingSystemUiFlags));
7099 pw.print(" mForceClearedSystemUiFlags=0x");
7100 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07007101 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007102 if (mLastFocusNeedsMenu) {
7103 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
7104 pw.println(mLastFocusNeedsMenu);
7105 }
Jeff Browna20dda42014-05-27 20:57:24 -07007106 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
7107 pw.println(mWakeGestureEnabledSetting);
7108
Jeff Brownbcdfc622014-03-06 19:13:04 -08007109 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04007110 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
7111 pw.print(" mDockMode="); pw.print(mDockMode);
keunyounga7710492015-09-23 11:33:58 -07007112 pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007113 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
7114 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
7115 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
7116 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05007117 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007118 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007119 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
7120 pw.print(mCarDockEnablesAccelerometer);
7121 pw.print(" mDeskDockEnablesAccelerometer=");
7122 pw.println(mDeskDockEnablesAccelerometer);
7123 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
7124 pw.print(mLidKeyboardAccessibility);
7125 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01007126 pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007127 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007128 pw.print(prefix);
7129 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
7130 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07007131 pw.print(prefix);
7132 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
7133 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007134 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07007135 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
7136 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
7137 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
7138 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
7139 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
7140 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
7141 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08007142 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
7143 pw.print(","); pw.print(mOverscanScreenTop);
7144 pw.print(") "); pw.print(mOverscanScreenWidth);
7145 pw.print("x"); pw.println(mOverscanScreenHeight);
7146 if (mOverscanLeft != 0 || mOverscanTop != 0
7147 || mOverscanRight != 0 || mOverscanBottom != 0) {
7148 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
7149 pw.print(" top="); pw.print(mOverscanTop);
7150 pw.print(" right="); pw.print(mOverscanRight);
7151 pw.print(" bottom="); pw.println(mOverscanBottom);
7152 }
Dianne Hackborn313440842013-02-19 19:22:59 -08007153 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
7154 pw.print(mRestrictedOverscanScreenLeft);
7155 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
7156 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
7157 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007158 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
7159 pw.print(","); pw.print(mUnrestrictedScreenTop);
7160 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
7161 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
7162 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
7163 pw.print(","); pw.print(mRestrictedScreenTop);
7164 pw.print(") "); pw.print(mRestrictedScreenWidth);
7165 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07007166 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
7167 pw.print(","); pw.print(mStableFullscreenTop);
7168 pw.print(")-("); pw.print(mStableFullscreenRight);
7169 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07007170 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
7171 pw.print(","); pw.print(mStableTop);
7172 pw.print(")-("); pw.print(mStableRight);
7173 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007174 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
7175 pw.print(","); pw.print(mSystemTop);
7176 pw.print(")-("); pw.print(mSystemRight);
7177 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007178 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
7179 pw.print(","); pw.print(mCurTop);
7180 pw.print(")-("); pw.print(mCurRight);
7181 pw.print(","); pw.print(mCurBottom); pw.println(")");
7182 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
7183 pw.print(","); pw.print(mContentTop);
7184 pw.print(")-("); pw.print(mContentRight);
7185 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07007186 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
7187 pw.print(","); pw.print(mVoiceContentTop);
7188 pw.print(")-("); pw.print(mVoiceContentRight);
7189 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007190 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
7191 pw.print(","); pw.print(mDockTop);
7192 pw.print(")-("); pw.print(mDockRight);
7193 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007194 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
7195 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007196 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
7197 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07007198 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
7199 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007200 if (mLastInputMethodWindow != null) {
7201 pw.print(prefix); pw.print("mLastInputMethodWindow=");
7202 pw.println(mLastInputMethodWindow);
7203 }
7204 if (mLastInputMethodTargetWindow != null) {
7205 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
7206 pw.println(mLastInputMethodTargetWindow);
7207 }
7208 if (mStatusBar != null) {
7209 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08007210 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
7211 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007212 }
7213 if (mNavigationBar != null) {
7214 pw.print(prefix); pw.print("mNavigationBar=");
7215 pw.println(mNavigationBar);
7216 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007217 if (mFocusedWindow != null) {
7218 pw.print(prefix); pw.print("mFocusedWindow=");
7219 pw.println(mFocusedWindow);
7220 }
7221 if (mFocusedApp != null) {
7222 pw.print(prefix); pw.print("mFocusedApp=");
7223 pw.println(mFocusedApp);
7224 }
7225 if (mWinDismissingKeyguard != null) {
7226 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
7227 pw.println(mWinDismissingKeyguard);
7228 }
7229 if (mTopFullscreenOpaqueWindowState != null) {
7230 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
7231 pw.println(mTopFullscreenOpaqueWindowState);
7232 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01007233 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
7234 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
7235 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
7236 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007237 if (mForcingShowNavBar) {
7238 pw.print(prefix); pw.print("mForcingShowNavBar=");
7239 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
7240 pw.println(mForcingShowNavBarLayer);
7241 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007242 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007243 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007244 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
7245 pw.print(" mForceStatusBarFromKeyguard=");
7246 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007247 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07007248 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007249 pw.print(" mHomePressed="); pw.println(mHomePressed);
7250 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
7251 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
7252 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
7253 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
7254 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
7255 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
7256 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
7257 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
7258 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
7259 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07007260 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
7261 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
7262 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07007263
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07007264 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04007265 mStatusBarController.dump(pw, prefix);
7266 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05007267 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07007268
Jeff Browna20dda42014-05-27 20:57:24 -07007269 if (mWakeGestureListener != null) {
7270 mWakeGestureListener.dump(pw, prefix);
7271 }
Jeff Brown600f0032014-05-22 17:06:00 -07007272 if (mOrientationListener != null) {
7273 mOrientationListener.dump(pw, prefix);
7274 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00007275 if (mBurnInProtectionHelper != null) {
7276 mBurnInProtectionHelper.dump(prefix, pw);
7277 }
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07007278 if (mKeyguardDelegate != null) {
7279 mKeyguardDelegate.dump(prefix, pw);
7280 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007281 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007282}