blob: a92cc31659e64cb23d34fb2993e376b606c0c6e8 [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) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -08002648 if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08002649 return R.anim.fade_in;
2650 } else if (transit == TRANSIT_EXIT) {
2651 return R.anim.fade_out;
2652 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002653 }
2654
2655 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002656 if (win.hasAppShownWindows()) {
2657 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2658 return com.android.internal.R.anim.app_starting_exit;
2659 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002660 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002661 && transit == TRANSIT_ENTER) {
2662 // Special case: we are animating in a dream, while the keyguard
2663 // is shown. We don't want an animation on the dream, because
2664 // we need it shown immediately with the keyguard animating away
2665 // to reveal it.
2666 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002667 }
2668
2669 return 0;
2670 }
2671
Craig Mautner3c174372013-02-21 17:54:37 -08002672 @Override
2673 public void selectRotationAnimationLw(int anim[]) {
2674 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2675 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2676 + (mTopFullscreenOpaqueWindowState == null ?
2677 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2678 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2679 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2680 case ROTATION_ANIMATION_CROSSFADE:
2681 anim[0] = R.anim.rotation_animation_xfade_exit;
2682 anim[1] = R.anim.rotation_animation_enter;
2683 break;
2684 case ROTATION_ANIMATION_JUMPCUT:
2685 anim[0] = R.anim.rotation_animation_jump_exit;
2686 anim[1] = R.anim.rotation_animation_enter;
2687 break;
2688 case ROTATION_ANIMATION_ROTATE:
2689 default:
2690 anim[0] = anim[1] = 0;
2691 break;
2692 }
2693 } else {
2694 anim[0] = anim[1] = 0;
2695 }
2696 }
2697
2698 @Override
2699 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2700 boolean forceDefault) {
2701 switch (exitAnimId) {
2702 case R.anim.rotation_animation_xfade_exit:
2703 case R.anim.rotation_animation_jump_exit:
2704 // These are the only cases that matter.
2705 if (forceDefault) {
2706 return false;
2707 }
2708 int anim[] = new int[2];
2709 selectRotationAnimationLw(anim);
2710 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2711 default:
2712 return true;
2713 }
2714 }
2715
2716 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002717 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2718 boolean goingToNotificationShade) {
2719 if (goingToNotificationShade) {
2720 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002721 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002722
2723 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2724 R.anim.lock_screen_behind_enter_wallpaper :
2725 R.anim.lock_screen_behind_enter);
2726
2727 // TODO: Use XML interpolators when we have log interpolators available in XML.
2728 final List<Animation> animations = set.getAnimations();
2729 for (int i = animations.size() - 1; i >= 0; --i) {
2730 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2731 }
2732
2733 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002734 }
2735
2736
2737 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002738 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2739 if (goingToNotificationShade) {
2740 return null;
2741 } else {
2742 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2743 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002744 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002745
2746 private static void awakenDreams() {
2747 IDreamManager dreamManager = getDreamManager();
2748 if (dreamManager != null) {
2749 try {
2750 dreamManager.awaken();
2751 } catch (RemoteException e) {
2752 // fine, stay asleep then
2753 }
2754 }
2755 }
2756
2757 static IDreamManager getDreamManager() {
2758 return IDreamManager.Stub.asInterface(
2759 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2760 }
2761
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002762 TelecomManager getTelecommService() {
2763 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002764 }
2765
Jeff Brown4d396052010-10-29 21:50:21 -07002766 static IAudioService getAudioService() {
2767 IAudioService audioService = IAudioService.Stub.asInterface(
2768 ServiceManager.checkService(Context.AUDIO_SERVICE));
2769 if (audioService == null) {
2770 Log.w(TAG, "Unable to find IAudioService interface.");
2771 }
2772 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002773 }
2774
2775 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002776 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002777 }
2778
2779 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2780 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2781 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2782 };
2783
2784 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002785 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002786 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002787 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002788 final int keyCode = event.getKeyCode();
2789 final int repeatCount = event.getRepeatCount();
2790 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002791 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002792 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2793 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002794
Jeff Brown40013652012-05-16 21:22:36 -07002795 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002796 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002797 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2798 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002799 }
2800
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002801 // If we think we might have a volume down & power key chord on the way
2802 // but we're not sure, then tell the dispatcher to wait a little while and
2803 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002804 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002805 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002806 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002807 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2808 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002809 if (now < timeoutTime) {
2810 return timeoutTime - now;
2811 }
2812 }
2813 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002814 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002815 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002816 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002817 }
2818 return -1;
2819 }
2820 }
2821
Michael Wright6a62e552014-06-03 19:19:48 -07002822 // Cancel any pending meta actions if we see any other keys being pressed between the down
2823 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002824 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002825 mPendingMetaAction = false;
2826 }
2827
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002828 // First we always handle the home key here, so applications
2829 // can never break it, although if keyguard is on, we do let
2830 // it handle it, because that gives us the correct 5 second
2831 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002832 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002833
Jeff Brown49ed71d2010-12-06 17:13:33 -08002834 // If we have released the home key, and didn't do anything else
2835 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002836 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002837 cancelPreloadRecentApps();
2838
Jeff Brown49ed71d2010-12-06 17:13:33 -08002839 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002840 if (mHomeConsumed) {
2841 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002842 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002843 }
Jeff Browncaca8812013-05-09 13:34:33 -07002844
2845 if (canceled) {
2846 Log.i(TAG, "Ignoring HOME; event canceled.");
2847 return -1;
2848 }
2849
Yorke Lee4f803242014-12-15 23:22:06 +00002850 // If an incoming call is ringing, HOME is totally disabled.
2851 // (The user is already on the InCallUI at this point,
2852 // and his ONLY options are to answer or reject the call.)
2853 TelecomManager telecomManager = getTelecommService();
2854 if (telecomManager != null && telecomManager.isRinging()) {
2855 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2856 return -1;
2857 }
2858
Jeff Browncaca8812013-05-09 13:34:33 -07002859 // Delay handling home if a double-tap is possible.
2860 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2861 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2862 mHomeDoubleTapPending = true;
2863 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2864 ViewConfiguration.getDoubleTapTimeout());
2865 return -1;
2866 }
2867
Jeff Brown13f00f02014-10-31 14:45:50 -07002868 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002869 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002870 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002871
2872 // If a system window has focus, then it doesn't make sense
2873 // right now to interact with applications.
2874 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2875 if (attrs != null) {
2876 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002877 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2878 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2879 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002880 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002881 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002882 }
2883 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2884 for (int i=0; i<typeCount; i++) {
2885 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2886 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002887 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002888 }
2889 }
2890 }
Jeff Browncaca8812013-05-09 13:34:33 -07002891
2892 // Remember that home is pressed and handle special actions.
2893 if (repeatCount == 0) {
2894 mHomePressed = true;
2895 if (mHomeDoubleTapPending) {
2896 mHomeDoubleTapPending = false;
2897 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2898 handleDoubleTapOnHome();
2899 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2900 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2901 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002902 }
Jeff Browncaca8812013-05-09 13:34:33 -07002903 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2904 if (!keyguardOn) {
Jaewan Kim52632e22016-01-14 18:01:52 +09002905 handleLongPressOnHome(event.getDeviceId(), event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002906 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002907 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002908 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002909 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002910 // Hijack modified menu keys for debugging features
2911 final int chordBug = KeyEvent.META_SHIFT_ON;
2912
2913 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002914 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002915 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002916 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2917 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002918 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002919 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002920 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002921 Intent service = new Intent();
2922 service.setClassName(mContext, "com.android.server.LoadAverageService");
2923 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002924 boolean shown = Settings.Global.getInt(
2925 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002926 if (!shown) {
2927 mContext.startService(service);
2928 } else {
2929 mContext.stopService(service);
2930 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002931 Settings.Global.putInt(
2932 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002933 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002934 }
2935 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002936 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002937 if (down) {
2938 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002939 mSearchKeyShortcutPending = true;
2940 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002941 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002942 } else {
2943 mSearchKeyShortcutPending = false;
2944 if (mConsumeSearchKeyUp) {
2945 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002946 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002947 }
2948 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002949 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002950 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002951 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002952 if (down && repeatCount == 0) {
2953 preloadRecentApps();
2954 } else if (!down) {
2955 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002956 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002957 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002958 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002959 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2960 if (down) {
2961 IStatusBarService service = getStatusBarService();
2962 if (service != null) {
2963 try {
2964 service.expandNotificationsPanel();
2965 } catch (RemoteException e) {
2966 // do nothing.
2967 }
2968 }
2969 }
Clara Bayarrif2debb12015-07-10 14:47:17 +01002970 } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) {
2971 if (down) {
2972 if (repeatCount == 0) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00002973 toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01002974 }
2975 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002976 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2977 if (down) {
2978 if (repeatCount == 0) {
2979 mAssistKeyLongPressed = false;
2980 } else if (repeatCount == 1) {
2981 mAssistKeyLongPressed = true;
2982 if (!keyguardOn) {
2983 launchAssistLongPressAction();
2984 }
2985 }
2986 } else {
2987 if (mAssistKeyLongPressed) {
2988 mAssistKeyLongPressed = false;
2989 } else {
2990 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002991 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002992 }
2993 }
2994 }
2995 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002996 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2997 if (!down) {
2998 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002999 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003000 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3001 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07003002 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
3003 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
3004 if (dic != null) {
3005 try {
3006 dic.exitIdle("voice-search");
3007 } catch (RemoteException e) {
3008 }
3009 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003010 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07003011 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003012 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003013 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003014 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003015 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
3016 if (down && repeatCount == 0) {
3017 mHandler.post(mScreenshotRunnable);
3018 }
3019 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08003020 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
3021 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
3022 if (down) {
3023 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
3024
3025 // Disable autobrightness if it's on
3026 int auto = Settings.System.getIntForUser(
3027 mContext.getContentResolver(),
3028 Settings.System.SCREEN_BRIGHTNESS_MODE,
3029 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3030 UserHandle.USER_CURRENT_OR_SELF);
3031 if (auto != 0) {
3032 Settings.System.putIntForUser(mContext.getContentResolver(),
3033 Settings.System.SCREEN_BRIGHTNESS_MODE,
3034 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3035 UserHandle.USER_CURRENT_OR_SELF);
3036 }
3037
3038 int min = mPowerManager.getMinimumScreenBrightnessSetting();
3039 int max = mPowerManager.getMaximumScreenBrightnessSetting();
3040 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
3041 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
3042 Settings.System.SCREEN_BRIGHTNESS,
3043 mPowerManager.getDefaultScreenBrightnessSetting(),
3044 UserHandle.USER_CURRENT_OR_SELF);
3045 brightness += step;
3046 // Make sure we don't go beyond the limits.
3047 brightness = Math.min(max, brightness);
3048 brightness = Math.max(min, brightness);
3049
3050 Settings.System.putIntForUser(mContext.getContentResolver(),
3051 Settings.System.SCREEN_BRIGHTNESS, brightness,
3052 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00003053 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07003054 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08003055 }
3056 return -1;
Jaewan Kim765487f2016-01-12 14:45:42 +09003057 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
3058 || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
3059 || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
3060 if (mUseTvRouting) {
3061 // On TVs volume keys never go to the foreground app.
3062 dispatchDirectAudioEvent(event);
3063 return -1;
3064 }
Michael Wrightce0c13a2014-07-30 10:49:21 -07003065 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07003066 if (down) {
3067 mPendingMetaAction = true;
3068 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003069 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07003070 }
3071 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003072 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003073
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003074 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08003075 // Any printing key that is chorded with Search should be consumed
3076 // even if no shortcut was invoked. This prevents text from being
3077 // inadvertently inserted when using a keyboard that has built-in macro
3078 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003079 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08003080 final KeyCharacterMap kcm = event.getKeyCharacterMap();
3081 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003082 mConsumeSearchKeyUp = true;
3083 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08003084 if (down && repeatCount == 0 && !keyguardOn) {
3085 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
3086 if (shortcutIntent != null) {
3087 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003088 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003089 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003090 } catch (ActivityNotFoundException ex) {
3091 Slog.w(TAG, "Dropping shortcut key combination because "
3092 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003093 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003094 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003095 } else {
3096 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003097 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003098 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003099 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003100 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003101 }
3102 }
3103
Jeff Brown68b909d2011-12-07 16:36:01 -08003104 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07003105 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08003106 && (metaState & KeyEvent.META_META_ON) != 0) {
3107 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07003108 if (kcm.isPrintingKey(keyCode)) {
3109 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
3110 metaState & ~(KeyEvent.META_META_ON
3111 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
3112 if (shortcutIntent != null) {
3113 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3114 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003115 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07003116 } catch (ActivityNotFoundException ex) {
3117 Slog.w(TAG, "Dropping shortcut key combination because "
3118 + "the activity to which it is registered was not found: "
3119 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
3120 }
3121 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08003122 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003123 }
3124 }
3125
Jeff Brown6651a632011-11-28 12:59:11 -08003126 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07003127 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08003128 String category = sApplicationLaunchKeyCategories.get(keyCode);
3129 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08003130 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08003131 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3132 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003133 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08003134 } catch (ActivityNotFoundException ex) {
3135 Slog.w(TAG, "Dropping application launch key because "
3136 + "the activity to which it is registered was not found: "
3137 + "keyCode=" + keyCode + ", category=" + category, ex);
3138 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003139 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08003140 }
3141 }
3142
Michael Wright61c46752014-08-21 16:57:33 -07003143 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08003144 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Michael Wrightd847ad52015-10-24 13:24:15 +01003145 if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) {
Jeff Brown68b909d2011-12-07 16:36:01 -08003146 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07003147 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003148 mRecentAppsHeldModifiers = shiftlessModifiers;
3149 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08003150 return -1;
3151 }
3152 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07003153 } else if (!down && mRecentAppsHeldModifiers != 0
3154 && (metaState & mRecentAppsHeldModifiers) == 0) {
3155 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07003156 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003157 }
3158
Yohei Yukawaae61f712015-12-09 13:00:10 -08003159 // Handle input method switching.
Jeff Browncf39bdf2012-05-18 14:41:19 -07003160 if (down && repeatCount == 0
3161 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3162 || (keyCode == KeyEvent.KEYCODE_SPACE
Yohei Yukawaae61f712015-12-09 13:00:10 -08003163 && (metaState & KeyEvent.META_META_MASK) != 0))) {
3164 final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0;
3165 mWindowManagerFuncs.switchInputMethod(forwardDirection);
Jeff Browncf39bdf2012-05-18 14:41:19 -07003166 return -1;
3167 }
3168 if (mLanguageSwitchKeyPressed && !down
3169 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3170 || keyCode == KeyEvent.KEYCODE_SPACE)) {
3171 mLanguageSwitchKeyPressed = false;
3172 return -1;
3173 }
3174
Jeff Brown13f00f02014-10-31 14:45:50 -07003175 if (isValidGlobalKey(keyCode)
3176 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07003177 return -1;
3178 }
3179
Michael Wright6a62e552014-06-03 19:19:48 -07003180 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07003181 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07003182 return -1;
3183 }
3184
Jeff Brown68b909d2011-12-07 16:36:01 -08003185 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003186 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003187 }
3188
Jeff Brown3915bb82010-11-05 15:02:16 -07003189 /** {@inheritDoc} */
3190 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08003191 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07003192 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07003193 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08003194 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
3195 + ", flags=" + event.getFlags()
3196 + ", keyCode=" + event.getKeyCode()
3197 + ", scanCode=" + event.getScanCode()
3198 + ", metaState=" + event.getMetaState()
3199 + ", repeatCount=" + event.getRepeatCount()
3200 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07003201 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003202
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003203 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003204 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3205 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003206 final int keyCode = event.getKeyCode();
3207 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003208 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
3209 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003210
Jeff Brown54875002011-04-06 15:33:01 -07003211 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003212 final FallbackAction fallbackAction;
3213 if (initialDown) {
3214 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
3215 } else {
3216 fallbackAction = mFallbackActions.get(keyCode);
3217 }
3218
3219 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07003220 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003221 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
3222 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003223 }
3224
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003225 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
3226 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08003227 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003228 event.getAction(), fallbackAction.keyCode,
3229 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08003230 event.getDeviceId(), event.getScanCode(),
3231 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003232
3233 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
3234 fallbackEvent.recycle();
3235 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003236 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003237
3238 if (initialDown) {
3239 mFallbackActions.put(keyCode, fallbackAction);
3240 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3241 mFallbackActions.remove(keyCode);
3242 fallbackAction.recycle();
3243 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003244 }
3245 }
3246
Jeff Brown40013652012-05-16 21:22:36 -07003247 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003248 if (fallbackEvent == null) {
3249 Slog.d(TAG, "No fallback.");
3250 } else {
3251 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3252 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003253 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003254 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003255 }
3256
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003257 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003258 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003259 if ((actions & ACTION_PASS_TO_USER) != 0) {
3260 long delayMillis = interceptKeyBeforeDispatching(
3261 win, fallbackEvent, policyFlags);
3262 if (delayMillis == 0) {
3263 return true;
3264 }
3265 }
3266 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003267 }
3268
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003269 private void launchAssistLongPressAction() {
3270 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3271 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3272
3273 // launch the search activity
3274 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3275 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3276 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003277 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003278 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003279 SearchManager searchManager = getSearchManager();
3280 if (searchManager != null) {
3281 searchManager.stopSearch();
3282 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003283 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003284 } catch (ActivityNotFoundException e) {
3285 Slog.w(TAG, "No activity to handle assist long press action.", e);
3286 }
3287 }
3288
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003289 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003290 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Maurice Lam39d13812015-07-23 20:49:20 -07003291 if (!isUserSetupComplete()) {
3292 // Disable opening assist window during setup
3293 return;
3294 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003295 Bundle args = null;
3296 if (deviceId > Integer.MIN_VALUE) {
3297 args = new Bundle();
3298 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003299 }
Jorim Jaggi165ce062015-07-06 16:18:11 -07003300 if ((mContext.getResources().getConfiguration().uiMode
3301 & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
3302 // On TV, use legacy handling until assistants are implemented in the proper way.
3303 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3304 .launchLegacyAssist(hint, UserHandle.myUserId(), args);
3305 } else {
3306 try {
3307 if (hint != null) {
3308 if (args == null) {
3309 args = new Bundle();
3310 }
3311 args.putBoolean(hint, true);
3312 }
3313 IStatusBarService statusbar = getStatusBarService();
3314 if (statusbar != null) {
3315 statusbar.startAssist(args);
3316 }
3317 } catch (RemoteException e) {
3318 Slog.e(TAG, "RemoteException when starting assist", e);
3319 // re-acquire status bar service next time it is needed.
3320 mStatusBarService = null;
3321 }
3322 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003323 }
3324
Bart Sears8b1c27c2015-03-18 23:51:02 +00003325 private void startActivityAsUser(Intent intent, UserHandle handle) {
3326 if (isUserSetupComplete()) {
3327 mContext.startActivityAsUser(intent, handle);
3328 } else {
3329 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3330 }
3331 }
3332
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003333 private SearchManager getSearchManager() {
3334 if (mSearchManager == null) {
3335 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3336 }
3337 return mSearchManager;
3338 }
3339
Jeff Browncaca8812013-05-09 13:34:33 -07003340 private void preloadRecentApps() {
3341 mPreloadedRecentApps = true;
3342 try {
3343 IStatusBarService statusbar = getStatusBarService();
3344 if (statusbar != null) {
3345 statusbar.preloadRecentApps();
3346 }
3347 } catch (RemoteException e) {
3348 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3349 // re-acquire status bar service next time it is needed.
3350 mStatusBarService = null;
3351 }
3352 }
3353
3354 private void cancelPreloadRecentApps() {
3355 if (mPreloadedRecentApps) {
3356 mPreloadedRecentApps = false;
3357 try {
3358 IStatusBarService statusbar = getStatusBarService();
3359 if (statusbar != null) {
3360 statusbar.cancelPreloadRecentApps();
3361 }
3362 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003363 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003364 // re-acquire status bar service next time it is needed.
3365 mStatusBarService = null;
3366 }
3367 }
3368 }
3369
3370 private void toggleRecentApps() {
3371 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003372 try {
3373 IStatusBarService statusbar = getStatusBarService();
3374 if (statusbar != null) {
3375 statusbar.toggleRecentApps();
3376 }
3377 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003378 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3379 // re-acquire status bar service next time it is needed.
3380 mStatusBarService = null;
3381 }
3382 }
3383
Craig Mautner84984fa2014-06-19 11:19:20 -07003384 @Override
3385 public void showRecentApps() {
3386 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3387 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3388 }
3389
Winson Chung1e8d71b2014-05-16 17:05:22 -07003390 private void showRecentApps(boolean triggeredFromAltTab) {
3391 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3392 try {
3393 IStatusBarService statusbar = getStatusBarService();
3394 if (statusbar != null) {
3395 statusbar.showRecentApps(triggeredFromAltTab);
3396 }
3397 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003398 Slog.e(TAG, "RemoteException when showing recent apps", e);
3399 // re-acquire status bar service next time it is needed.
3400 mStatusBarService = null;
3401 }
3402 }
3403
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003404 private void toggleKeyboardShortcutsMenu() {
Clara Bayarrif2debb12015-07-10 14:47:17 +01003405 try {
3406 IStatusBarService statusbar = getStatusBarService();
3407 if (statusbar != null) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003408 statusbar.toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01003409 }
3410 } catch (RemoteException e) {
3411 Slog.e(TAG, "RemoteException when showing keyboard shortcuts menu", e);
3412 }
3413 }
3414
Winson Chungcdcd4872014-08-05 18:00:13 -07003415 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003416 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3417 try {
3418 IStatusBarService statusbar = getStatusBarService();
3419 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003420 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003421 }
3422 } catch (RemoteException e) {
3423 Slog.e(TAG, "RemoteException when closing recent apps", e);
3424 // re-acquire status bar service next time it is needed.
3425 mStatusBarService = null;
3426 }
3427 }
3428
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003429 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003430 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003431 }
3432
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003433 /**
3434 * A home key -> launch home action was detected. Take the appropriate action
3435 * given the situation with the keyguard.
3436 */
Bryce Lee662ed802015-04-10 20:11:39 +00003437 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3438 if (respectKeyguard) {
3439 if (isKeyguardShowingAndNotOccluded()) {
3440 // don't launch home if keyguard showing
3441 return;
3442 }
3443
3444 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3445 // when in keyguard restricted mode, must first verify unlock
3446 // before launching home
3447 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3448 @Override
3449 public void onKeyguardExitResult(boolean success) {
3450 if (success) {
3451 try {
3452 ActivityManagerNative.getDefault().stopAppSwitches();
3453 } catch (RemoteException e) {
3454 }
3455 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3456 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003457 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003458 }
Bryce Lee662ed802015-04-10 20:11:39 +00003459 });
3460 return;
3461 }
3462 }
3463
3464 // no keyguard stuff to worry about, just launch home!
3465 try {
3466 ActivityManagerNative.getDefault().stopAppSwitches();
3467 } catch (RemoteException e) {
3468 }
3469 if (mRecentsVisible) {
3470 // Hide Recents and notify it to launch Home
3471 if (awakenFromDreams) {
3472 awakenDreams();
3473 }
Bryce Lee662ed802015-04-10 20:11:39 +00003474 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003475 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003476 // Otherwise, just launch Home
3477 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3478 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003479 }
3480 }
3481
John Spurlock04db1762013-05-13 12:46:41 -04003482 private final Runnable mClearHideNavigationFlag = new Runnable() {
3483 @Override
3484 public void run() {
3485 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3486 // Clear flags.
3487 mForceClearedSystemUiFlags &=
3488 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3489 }
3490 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003491 }
3492 };
3493
3494 /**
3495 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3496 * to determine when the nav bar should be shown and prevent applications from
3497 * receiving those touches.
3498 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003499 final class HideNavInputEventReceiver extends InputEventReceiver {
3500 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3501 super(inputChannel, looper);
3502 }
3503
Dianne Hackborndf89e652011-10-06 22:35:11 -07003504 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003505 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003506 boolean handled = false;
3507 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003508 if (event instanceof MotionEvent
3509 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3510 final MotionEvent motionEvent = (MotionEvent)event;
3511 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003512 // When the user taps down, we re-show the nav bar.
3513 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003514 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003515 // Any user activity always causes us to show the
3516 // navigation controls, if they had been hidden.
3517 // We also clear the low profile and only content
3518 // flags so that tapping on the screen will atomically
3519 // restore all currently hidden screen decorations.
3520 int newVal = mResettingSystemUiFlags |
3521 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3522 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3523 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003524 if (mResettingSystemUiFlags != newVal) {
3525 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003526 changed = true;
3527 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003528 // We don't allow the system's nav bar to be hidden
3529 // again for 1 second, to prevent applications from
3530 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003531 newVal = mForceClearedSystemUiFlags |
3532 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003533 if (mForceClearedSystemUiFlags != newVal) {
3534 mForceClearedSystemUiFlags = newVal;
3535 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003536 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003537 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003538 }
3539 if (changed) {
3540 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3541 }
3542 }
3543 }
3544 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003545 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003546 }
3547 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003548 }
3549 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3550 new InputEventReceiver.Factory() {
3551 @Override
3552 public InputEventReceiver createInputEventReceiver(
3553 InputChannel inputChannel, Looper looper) {
3554 return new HideNavInputEventReceiver(inputChannel, looper);
3555 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003556 };
3557
3558 @Override
3559 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003560 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3561 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003562 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003563
Dianne Hackborndf89e652011-10-06 22:35:11 -07003564 // Reset any bits in mForceClearingStatusBarVisibility that
3565 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003566 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003567 // Clear any bits in the new visibility that are currently being
3568 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003569 return visibility & ~mResettingSystemUiFlags
3570 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003571 }
3572
Craig Mautner69b08182012-09-05 13:07:13 -07003573 @Override
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003574 public void getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation,
3575 Rect outContentInsets, Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003576 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003577 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3578 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003579
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003580 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
3581 if (useOutsets) {
3582 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
3583 if (outset > 0) {
3584 if (displayRotation == Surface.ROTATION_0) {
3585 outOutsets.bottom += outset;
3586 } else if (displayRotation == Surface.ROTATION_90) {
3587 outOutsets.right += outset;
3588 } else if (displayRotation == Surface.ROTATION_180) {
3589 outOutsets.top += outset;
3590 } else if (displayRotation == Surface.ROTATION_270) {
3591 outOutsets.left += outset;
3592 }
3593 }
3594 }
3595
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003596 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003597 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003598 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003599 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003600 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003601 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3602 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3603 } else {
3604 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3605 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3606 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003607 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3608 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003609 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003610 availRight - mStableFullscreenRight,
3611 availBottom - mStableFullscreenBottom);
3612 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003613 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003614 availRight - mStableRight, availBottom - mStableBottom);
3615 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003616 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003617 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003618 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003619 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003620 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003621 availRight - mCurRight, availBottom - mCurBottom);
3622 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003623 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003624 availRight - mCurRight, availBottom - mCurBottom);
3625 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003626
3627 outStableInsets.set(mStableLeft, mStableTop,
3628 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003629 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003630 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003631 outContentInsets.setEmpty();
3632 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003633 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003634
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003635 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
3636 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
3637 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
3638 }
3639
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003640 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003641 @Override
3642 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003643 int displayRotation, int uiMode) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003644 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003645 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3646 if (isDefaultDisplay) {
3647 switch (displayRotation) {
3648 case Surface.ROTATION_90:
3649 overscanLeft = mOverscanTop;
3650 overscanTop = mOverscanRight;
3651 overscanRight = mOverscanBottom;
3652 overscanBottom = mOverscanLeft;
3653 break;
3654 case Surface.ROTATION_180:
3655 overscanLeft = mOverscanRight;
3656 overscanTop = mOverscanBottom;
3657 overscanRight = mOverscanLeft;
3658 overscanBottom = mOverscanTop;
3659 break;
3660 case Surface.ROTATION_270:
3661 overscanLeft = mOverscanBottom;
3662 overscanTop = mOverscanLeft;
3663 overscanRight = mOverscanTop;
3664 overscanBottom = mOverscanRight;
3665 break;
3666 default:
3667 overscanLeft = mOverscanLeft;
3668 overscanTop = mOverscanTop;
3669 overscanRight = mOverscanRight;
3670 overscanBottom = mOverscanBottom;
3671 break;
3672 }
3673 } else {
3674 overscanLeft = 0;
3675 overscanTop = 0;
3676 overscanRight = 0;
3677 overscanBottom = 0;
3678 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003679 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3680 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3681 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3682 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003683 mSystemLeft = 0;
3684 mSystemTop = 0;
3685 mSystemRight = displayWidth;
3686 mSystemBottom = displayHeight;
3687 mUnrestrictedScreenLeft = overscanLeft;
3688 mUnrestrictedScreenTop = overscanTop;
3689 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3690 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3691 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3692 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003693 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3694 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003695 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003696 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003697 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003698 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003699 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003700 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003701 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003702 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003703 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003704 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003705
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003706 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3707 final Rect pf = mTmpParentFrame;
3708 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003709 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003710 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003711 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003712 pf.left = df.left = of.left = vf.left = mDockLeft;
3713 pf.top = df.top = of.top = vf.top = mDockTop;
3714 pf.right = df.right = of.right = vf.right = mDockRight;
3715 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003716 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003717
Craig Mautner69b08182012-09-05 13:07:13 -07003718 if (isDefaultDisplay) {
3719 // For purposes of putting out fake window up to steal focus, we will
3720 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003721 final int sysui = mLastSystemUiFlags;
3722 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003723 boolean navTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003724 & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003725 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3726 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3727 boolean navAllowedHidden = immersive || immersiveSticky;
3728 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003729 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3730 if (!isKeyguardShowing) {
3731 navTranslucent &= areTranslucentBarsAllowed();
3732 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003733
Craig Mautner69b08182012-09-05 13:07:13 -07003734 // When the navigation bar isn't visible, we put up a fake
3735 // input window to catch all touch events. This way we can
3736 // detect when the user presses anywhere to bring back the nav
3737 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003738 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003739 if (mInputConsumer != null) {
3740 mInputConsumer.dismiss();
3741 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003742 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003743 } else if (mInputConsumer == null) {
3744 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3745 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003746 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003747
Craig Mautner69b08182012-09-05 13:07:13 -07003748 // For purposes of positioning and showing the nav bar, if we have
3749 // decided that it can't be hidden (because of the screen aspect ratio),
3750 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003751 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003752
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003753 boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003754 displayRotation, uiMode, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003755 navAllowedHidden);
Craig Mautnereda67292013-04-28 13:50:14 -07003756 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003757 mDockLeft, mDockTop, mDockRight, mDockBottom));
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003758 updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003759 if (updateSysUiVisibility) {
3760 updateSystemUiVisibilityLw();
3761 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003762 }
3763 }
3764
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003765 private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui,
3766 boolean isKeyguardShowing) {
3767 // decide where the status bar goes ahead of time
3768 if (mStatusBar != null) {
3769 // apply any navigation bar insets
3770 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3771 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3772 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3773 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3774 + mUnrestrictedScreenTop;
3775 vf.left = mStableLeft;
3776 vf.top = mStableTop;
3777 vf.right = mStableRight;
3778 vf.bottom = mStableBottom;
3779
3780 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3781
3782 // Let the status bar determine its size.
3783 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3784 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3785 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
3786
3787 // For layout, the status bar is always at the top with our fixed height.
3788 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3789
3790 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
3791 boolean statusBarTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003792 & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0;
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003793 if (!isKeyguardShowing) {
3794 statusBarTranslucent &= areTranslucentBarsAllowed();
3795 }
3796
3797 // If the status bar is hidden, we don't want to cause
3798 // windows behind it to scroll.
3799 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
3800 // Status bar may go away, so the screen area it occupies
3801 // is available to apps but just covering them when the
3802 // status bar is visible.
3803 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3804
3805 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3806 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3807 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3808 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3809
3810 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
3811 String.format(
3812 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3813 mDockLeft, mDockTop, mDockRight, mDockBottom,
3814 mContentLeft, mContentTop, mContentRight, mContentBottom,
3815 mCurLeft, mCurTop, mCurRight, mCurBottom));
3816 }
3817 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
3818 && !statusBarTransient && !statusBarTranslucent
3819 && !mStatusBarController.wasRecentlyTranslucent()) {
3820 // If the opaque status bar is currently requested to be visible,
3821 // and not in the process of animating on or off, then
3822 // we can tell the app that it is covered by it.
3823 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3824 }
3825 if (mStatusBarController.checkHiddenLw()) {
3826 return true;
3827 }
3828 }
3829 return false;
3830 }
3831
3832 private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003833 int uiMode, int overscanRight, int overscanBottom, Rect dcf, boolean navVisible,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003834 boolean navTranslucent, boolean navAllowedHidden) {
3835 if (mNavigationBar != null) {
3836 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
3837 // Force the navigation bar to its appropriate place and
3838 // size. We need to do this directly, instead of relying on
3839 // it to bubble up from the nav bar, because this needs to
3840 // change atomically with screen rotations.
Jorim Jaggi737af722015-12-31 10:42:27 +01003841 mNavigationBarOnBottom = isNavigationBarOnBottom(displayWidth, displayHeight);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003842 if (mNavigationBarOnBottom) {
3843 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
3844 int top = displayHeight - overscanBottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003845 - getNavigationBarHeight(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003846 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
3847 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
3848 if (transientNavBarShowing) {
3849 mNavigationBarController.setBarShowingLw(true);
3850 } else if (navVisible) {
3851 mNavigationBarController.setBarShowingLw(true);
3852 mDockBottom = mTmpNavigationFrame.top;
3853 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3854 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
3855 } else {
3856 // We currently want to hide the navigation UI.
3857 mNavigationBarController.setBarShowingLw(false);
3858 }
3859 if (navVisible && !navTranslucent && !navAllowedHidden
3860 && !mNavigationBar.isAnimatingLw()
3861 && !mNavigationBarController.wasRecentlyTranslucent()) {
3862 // If the opaque nav bar is currently requested to be visible,
3863 // and not in the process of animating on or off, then
3864 // we can tell the app that it is covered by it.
3865 mSystemBottom = mTmpNavigationFrame.top;
3866 }
3867 } else {
3868 // Landscape screen; nav bar goes to the right.
3869 int left = displayWidth - overscanRight
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003870 - getNavigationBarWidth(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003871 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
3872 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
3873 if (transientNavBarShowing) {
3874 mNavigationBarController.setBarShowingLw(true);
3875 } else if (navVisible) {
3876 mNavigationBarController.setBarShowingLw(true);
3877 mDockRight = mTmpNavigationFrame.left;
3878 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3879 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
3880 } else {
3881 // We currently want to hide the navigation UI.
3882 mNavigationBarController.setBarShowingLw(false);
3883 }
3884 if (navVisible && !navTranslucent && !navAllowedHidden
3885 && !mNavigationBar.isAnimatingLw()
3886 && !mNavigationBarController.wasRecentlyTranslucent()) {
3887 // If the nav bar is currently requested to be visible,
3888 // and not in the process of animating on or off, then
3889 // we can tell the app that it is covered by it.
3890 mSystemRight = mTmpNavigationFrame.left;
3891 }
3892 }
3893 // Make sure the content and current rectangles are updated to
3894 // account for the restrictions from the navigation bar.
3895 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3896 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3897 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3898 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3899 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3900 // And compute the final frame.
3901 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
3902 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3903 mTmpNavigationFrame, mTmpNavigationFrame);
3904 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
3905 if (mNavigationBarController.checkHiddenLw()) {
3906 return true;
3907 }
3908 }
3909 return false;
3910 }
3911
Jorim Jaggi737af722015-12-31 10:42:27 +01003912 private boolean isNavigationBarOnBottom(int displayWidth, int displayHeight) {
3913 return !mNavigationBarCanMove || displayWidth < displayHeight;
3914 }
3915
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003916 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003917 @Override
John Spurlock46646232013-09-30 22:32:42 -04003918 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003919 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3920 return mStatusBar.getSurfaceLayer();
3921 }
3922
3923 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3924 return mNavigationBar.getSurfaceLayer();
3925 }
3926
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003927 return 0;
3928 }
3929
Craig Mautner967212c2013-04-13 21:10:58 -07003930 @Override
3931 public void getContentRectLw(Rect r) {
3932 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3933 }
3934
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003935 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3936 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003937 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3938 // Here's a special case: if this attached window is a panel that is
3939 // above the dock window, and the window it is attached to is below
3940 // the dock window, then the frames we computed for the window it is
3941 // attached to can not be used because the dock is effectively part
3942 // of the underlying window and the attached window is floating on top
3943 // of the whole thing. So, we ignore the attached window and explicitly
3944 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003945 df.left = of.left = cf.left = vf.left = mDockLeft;
3946 df.top = of.top = cf.top = vf.top = mDockTop;
3947 df.right = of.right = cf.right = vf.right = mDockRight;
3948 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003949 } else {
3950 // The effective display frame of the attached window depends on
3951 // whether it is taking care of insetting its content. If not,
3952 // we need to use the parent's content frame so that the entire
3953 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003954 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003955 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003956 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003957 // Set the content frame of the attached window to the parent's decor frame
3958 // (same as content frame when IME isn't present) if specifically requested by
3959 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3960 // Otherwise, use the overscan frame.
3961 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3962 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003963 } else {
3964 // If the window is resizing, then we want to base the content
3965 // frame on our attached content frame to resize... however,
3966 // things can be tricky if the attached window is NOT in resize
3967 // mode, in which case its content frame will be larger.
3968 // Ungh. So to deal with that, make sure the content frame
3969 // we end up using is not covering the IM dock.
3970 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003971 if (attached.isVoiceInteraction()) {
3972 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3973 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3974 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3975 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3976 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003977 if (cf.left < mContentLeft) cf.left = mContentLeft;
3978 if (cf.top < mContentTop) cf.top = mContentTop;
3979 if (cf.right > mContentRight) cf.right = mContentRight;
3980 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3981 }
3982 }
3983 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003984 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003985 vf.set(attached.getVisibleFrameLw());
3986 }
3987 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3988 // window should be positioned relative to its parent or the entire
3989 // screen.
3990 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3991 ? attached.getFrameLw() : df);
3992 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003993
3994 private void applyStableConstraints(int sysui, int fl, Rect r) {
3995 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3996 // If app is requesting a stable layout, don't let the
3997 // content insets go below the stable values.
3998 if ((fl & FLAG_FULLSCREEN) != 0) {
3999 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
4000 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
4001 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
4002 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
4003 } else {
4004 if (r.left < mStableLeft) r.left = mStableLeft;
4005 if (r.top < mStableTop) r.top = mStableTop;
4006 if (r.right > mStableRight) r.right = mStableRight;
4007 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
4008 }
4009 }
4010 }
4011
Jorim Jaggiaa806142015-05-20 18:04:16 -07004012 private boolean canReceiveInput(WindowState win) {
4013 boolean notFocusable =
4014 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
4015 boolean altFocusableIm =
4016 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
4017 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
4018 return !notFocusableForIm;
4019 }
4020
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004021 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07004022 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004023 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07004024 // We've already done the navigation bar and status bar. If the status bar can receive
4025 // input, we need to layout it again to accomodate for the IME window.
4026 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004027 return;
4028 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07004029 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07004030 final boolean isDefaultDisplay = win.isDefaultDisplay();
4031 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09004032 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
4033 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07004034 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09004035 offsetInputMethodWindowLw(mLastInputMethodWindow);
4036 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004037
John Spurlockc6d1c602014-01-17 15:22:06 -05004038 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004039 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05004040 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004041
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004042 final Rect pf = mTmpParentFrame;
4043 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004044 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004045 final Rect cf = mTmpContentFrame;
4046 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04004047 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07004048 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004049 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04004050 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07004051
4052 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04004053 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004054
Craig Mautnerf683b562012-10-02 11:10:57 -07004055 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
4056
Adrian Roosfa104232014-06-20 16:10:14 -07004057 if (isDefaultDisplay) {
4058 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
4059 } else {
4060 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
4061 }
4062
Craig Mautner69b08182012-09-05 13:07:13 -07004063 if (!isDefaultDisplay) {
4064 if (attached != null) {
4065 // If this window is attached to another, our display
4066 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004067 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07004068 } else {
4069 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004070 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4071 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4072 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004073 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004074 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004075 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07004076 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004077 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004078 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
4079 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
4080 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04004081 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04004082 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04004083 // ...with content insets above the nav bar
4084 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004085 // IM dock windows always go to the bottom of the screen.
4086 attrs.gravity = Gravity.BOTTOM;
4087 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004088 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004089 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004090 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004091 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4092 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004093 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004094 // Note: In Phone landscape mode, the button bar should also be excluded.
4095 cf.right = vf.right = mStableRight;
4096 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004097 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07004098 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02004099 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4100 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4101 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
4102 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
4103 cf.left = vf.left = mStableLeft;
4104 cf.top = vf.top = mStableTop;
4105 cf.right = vf.right = mStableRight;
4106 vf.bottom = mStableBottom;
Adrian Roosdc5b4532016-01-06 20:49:41 +01004107
4108 if (adjust == SOFT_INPUT_ADJUST_RESIZE) {
4109 cf.bottom = mContentBottom;
4110 } else {
4111 cf.bottom = mDockBottom;
4112 vf.bottom = mContentBottom;
4113 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004114 } else {
John Spurlock46646232013-09-30 22:32:42 -04004115
4116 // Default policy decor for the default display
4117 dcf.left = mSystemLeft;
4118 dcf.top = mSystemTop;
4119 dcf.right = mSystemRight;
4120 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04004121 final boolean inheritTranslucentDecor = (attrs.privateFlags
4122 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04004123 final boolean isAppWindow =
4124 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
4125 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
4126 final boolean topAtRest =
4127 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
4128 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04004129 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
4130 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004131 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
4132 && (fl & WindowManager.LayoutParams.
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004133 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0
4134 && !mForceWindowDrawsStatusBarBackground) {
John Spurlock46646232013-09-30 22:32:42 -04004135 // Ensure policy decor includes status bar
4136 dcf.top = mStableTop;
4137 }
John Spurlockbd957402013-10-03 11:38:39 -04004138 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004139 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
4140 && (fl & WindowManager.LayoutParams.
4141 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004142 // Ensure policy decor includes navigation bar
4143 dcf.bottom = mStableBottom;
4144 dcf.right = mStableRight;
4145 }
4146 }
4147
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004148 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
4149 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07004150 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004151 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004152 // This is the case for a normal activity window: we want it
4153 // to cover all of the screen space, and it can take care of
4154 // moving its contents to account for screen decorations that
4155 // intrude into that space.
4156 if (attached != null) {
4157 // If this window is attached to another, our display
4158 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004159 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004160 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004161 if (attrs.type == TYPE_STATUS_BAR_PANEL
4162 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08004163 // Status bar panels are the only windows who can go on top of
4164 // the status bar. They are protected by the STATUS_BAR_SERVICE
4165 // permission, so they have the same privileges as the status
4166 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004167 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004168 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004169
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004170 pf.left = df.left = of.left = hasNavBar
4171 ? mDockLeft : mUnrestrictedScreenLeft;
4172 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4173 pf.right = df.right = of.right = hasNavBar
4174 ? mRestrictedScreenLeft+mRestrictedScreenWidth
4175 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4176 pf.bottom = df.bottom = of.bottom = hasNavBar
4177 ? mRestrictedScreenTop+mRestrictedScreenHeight
4178 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004179
Craig Mautnereda67292013-04-28 13:50:14 -07004180 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004181 "Laying out status bar window: (%d,%d - %d,%d)",
4182 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04004183 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004184 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4185 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4186 // Asking to layout into the overscan region, so give it that pure
4187 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004188 pf.left = df.left = of.left = mOverscanScreenLeft;
4189 pf.top = df.top = of.top = mOverscanScreenTop;
4190 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
4191 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
4192 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004193 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004194 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004195 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4196 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004197 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08004198 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004199 // only do this for application windows to ensure no window that
4200 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08004201 pf.left = df.left = mOverscanScreenLeft;
4202 pf.top = df.top = mOverscanScreenTop;
4203 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4204 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004205 // We need to tell the app about where the frame inside the overscan
4206 // is, so it can inset its content by that amount -- it didn't ask
4207 // to actually extend itself into the overscan region.
4208 of.left = mUnrestrictedScreenLeft;
4209 of.top = mUnrestrictedScreenTop;
4210 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4211 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004212 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08004213 pf.left = df.left = mRestrictedOverscanScreenLeft;
4214 pf.top = df.top = mRestrictedOverscanScreenTop;
4215 pf.right = df.right = mRestrictedOverscanScreenLeft
4216 + mRestrictedOverscanScreenWidth;
4217 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
4218 + mRestrictedOverscanScreenHeight;
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 }
Craig Mautner69b08182012-09-05 13:07:13 -07004227
John Spurlock46646232013-09-30 22:32:42 -04004228 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004229 if (win.isVoiceInteraction()) {
4230 cf.left = mVoiceContentLeft;
4231 cf.top = mVoiceContentTop;
4232 cf.right = mVoiceContentRight;
4233 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004234 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004235 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4236 cf.left = mDockLeft;
4237 cf.top = mDockTop;
4238 cf.right = mDockRight;
4239 cf.bottom = mDockBottom;
4240 } else {
4241 cf.left = mContentLeft;
4242 cf.top = mContentTop;
4243 cf.right = mContentRight;
4244 cf.bottom = mContentBottom;
4245 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004246 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004247 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004248 // Full screen windows are always given a layout that is as if the
4249 // status bar and other transient decors are gone. This is to avoid
4250 // bad states when moving from a window that is not hding the
4251 // status bar to one that is.
4252 cf.left = mRestrictedScreenLeft;
4253 cf.top = mRestrictedScreenTop;
4254 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4255 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004256 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004257 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004258 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4259 vf.left = mCurLeft;
4260 vf.top = mCurTop;
4261 vf.right = mCurRight;
4262 vf.bottom = mCurBottom;
4263 } else {
4264 vf.set(cf);
4265 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004266 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004267 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
4268 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
4269 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07004270 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4271 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004272 // A window that has requested to fill the entire screen just
4273 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004274 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04004275 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
4276 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004277 pf.left = df.left = of.left = cf.left = hasNavBar
4278 ? mDockLeft : mUnrestrictedScreenLeft;
4279 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4280 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004281 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08004282 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004283 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004284 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004285 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004286 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04004287 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
4288 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07004289 } else if (attrs.type == TYPE_NAVIGATION_BAR
4290 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004291 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004292 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4293 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4294 pf.right = df.right = of.right = mUnrestrictedScreenLeft
4295 + mUnrestrictedScreenWidth;
4296 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
4297 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004298 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004299 "Laying out navigation bar window: (%d,%d - %d,%d)",
4300 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08004301 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
4302 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07004303 && ((fl & FLAG_FULLSCREEN) != 0)) {
4304 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004305 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4306 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4307 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4308 + mOverscanScreenWidth;
4309 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4310 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08004311 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08004312 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004313 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4314 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4315 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4316 + mOverscanScreenWidth;
4317 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4318 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04004319 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004320 // The wallpaper also has Real Ultimate Power, but we want to tell
4321 // it about the overscan area.
4322 pf.left = df.left = mOverscanScreenLeft;
4323 pf.top = df.top = mOverscanScreenTop;
4324 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4325 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4326 of.left = cf.left = mUnrestrictedScreenLeft;
4327 of.top = cf.top = mUnrestrictedScreenTop;
4328 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4329 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004330 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004331 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4332 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4333 // Asking to layout into the overscan region, so give it that pure
4334 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004335 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4336 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4337 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004338 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004339 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004340 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004341 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004342 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004343 && (attrs.type == TYPE_STATUS_BAR
4344 || attrs.type == TYPE_TOAST
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01004345 || attrs.type == TYPE_DOCK_DIVIDER
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004346 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004347 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4348 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004349 // Asking for layout as if the nav bar is hidden, lets the
4350 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004351 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004352 // can be above the nav bar can do this.
4353 // XXX This assumes that an app asking for this will also
4354 // ask for layout in only content. We can't currently figure out
4355 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004356 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4357 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4358 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4359 + mUnrestrictedScreenWidth;
4360 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4361 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004362 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004363 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4364 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4365 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4366 + mRestrictedScreenWidth;
4367 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4368 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004369 }
Craig Mautner69b08182012-09-05 13:07:13 -07004370
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004371 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004372
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004373 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4374 vf.left = mCurLeft;
4375 vf.top = mCurTop;
4376 vf.right = mCurRight;
4377 vf.bottom = mCurBottom;
4378 } else {
4379 vf.set(cf);
4380 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004381 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004382 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4383 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004384 // A child window should be placed inside of the same visible
4385 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004386 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004387 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004388 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4389 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004390 // Otherwise, a normal window must be placed inside the content
4391 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004392 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4393 // Status bar panels and the volume dialog are the only windows who can go on
4394 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004395 // permission, so they have the same privileges as the status
4396 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004397 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4398 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4399 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4400 + mRestrictedScreenWidth;
4401 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4402 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004403 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004404 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004405 pf.left = df.left = of.left = cf.left = mStableLeft;
4406 pf.top = df.top = of.top = cf.top = mStableTop;
4407 pf.right = df.right = of.right = cf.right = mStableRight;
4408 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004409 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004410 pf.left = mContentLeft;
4411 pf.top = mContentTop;
4412 pf.right = mContentRight;
4413 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004414 if (win.isVoiceInteraction()) {
4415 df.left = of.left = cf.left = mVoiceContentLeft;
4416 df.top = of.top = cf.top = mVoiceContentTop;
4417 df.right = of.right = cf.right = mVoiceContentRight;
4418 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4419 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004420 df.left = of.left = cf.left = mDockLeft;
4421 df.top = of.top = cf.top = mDockTop;
4422 df.right = of.right = cf.right = mDockRight;
4423 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004424 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004425 df.left = of.left = cf.left = mContentLeft;
4426 df.top = of.top = cf.top = mContentTop;
4427 df.right = of.right = cf.right = mContentRight;
4428 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004429 }
4430 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4431 vf.left = mCurLeft;
4432 vf.top = mCurTop;
4433 vf.right = mCurRight;
4434 vf.bottom = mCurBottom;
4435 } else {
4436 vf.set(cf);
4437 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004438 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004439 }
4440 }
Craig Mautner69b08182012-09-05 13:07:13 -07004441
Craig Mautnerb816bed2013-07-23 10:26:17 -07004442 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4443 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004444 df.left = df.top = -10000;
4445 df.right = df.bottom = 10000;
4446 if (attrs.type != TYPE_WALLPAPER) {
4447 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4448 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4449 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004450 }
4451
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004452 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4453 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004454 // We only want to apply outsets to certain types of windows. For example, we never want to
4455 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004456 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004457 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004458 osf = mTmpOutsetFrame;
4459 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4460 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4461 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004462 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004463 if (rotation == Surface.ROTATION_0) {
4464 osf.bottom += outset;
4465 } else if (rotation == Surface.ROTATION_90) {
4466 osf.right += outset;
4467 } else if (rotation == Surface.ROTATION_180) {
4468 osf.top -= outset;
4469 } else if (rotation == Surface.ROTATION_270) {
4470 osf.left -= outset;
4471 }
4472 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4473 + " with rotation " + rotation + ", result: " + osf);
4474 }
4475 }
4476
Craig Mautnereda67292013-04-28 13:50:14 -07004477 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004478 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004479 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004480 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004481 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004482 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004483 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004484 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004485 + " sf=" + sf.toShortString()
4486 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004487
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004488 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004489
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004490 // Dock windows carve out the bottom of the screen, so normal windows
4491 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004492 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4493 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004494 setLastInputMethodWindowLw(null, null);
4495 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004496 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004497 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4498 && !win.getGivenInsetsPendingLw()) {
4499 offsetVoiceInputWindowLw(win);
4500 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004501 }
4502
satok1bc0a492012-04-25 22:47:12 +09004503 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004504 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004505 top += win.getGivenContentInsetsLw().top;
4506 if (mContentBottom > top) {
4507 mContentBottom = top;
4508 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004509 if (mVoiceContentBottom > top) {
4510 mVoiceContentBottom = top;
4511 }
satok1bc0a492012-04-25 22:47:12 +09004512 top = win.getVisibleFrameLw().top;
4513 top += win.getGivenVisibleInsetsLw().top;
4514 if (mCurBottom > top) {
4515 mCurBottom = top;
4516 }
Craig Mautnereda67292013-04-28 13:50:14 -07004517 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004518 + mDockBottom + " mContentBottom="
4519 + mContentBottom + " mCurBottom=" + mCurBottom);
4520 }
4521
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004522 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004523 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004524 top += win.getGivenContentInsetsLw().top;
4525 if (mVoiceContentBottom > top) {
4526 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004527 }
4528 }
4529
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004530 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004531 @Override
4532 public void finishLayoutLw() {
4533 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004534 }
4535
4536 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004537 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004538 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004539 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004540 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004541 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004542 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004543 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004544 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004545 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004546 mForcingShowNavBar = false;
4547 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004548
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004549 mHideLockScreen = false;
4550 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004551 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004552 mShowingLockscreen = false;
4553 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004554 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004555 mKeyguardSecure = isKeyguardSecure();
4556 mKeyguardSecureIncludingHidden = mKeyguardSecure
4557 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004558 }
4559
4560 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004561 @Override
Yohei Yukawad1a09222015-06-30 16:22:05 -07004562 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,
4563 WindowState attached) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004564 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4565 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004566 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004567 if (mTopFullscreenOpaqueWindowState == null
4568 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4569 mForcingShowNavBar = true;
4570 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004571 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004572 if (attrs.type == TYPE_STATUS_BAR) {
4573 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4574 mForceStatusBarFromKeyguard = true;
Jorim Jaggie1de9f62015-09-23 14:59:50 -07004575 mShowingLockscreen = true;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004576 }
4577 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4578 mForceStatusBarTransparent = true;
4579 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004580 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004581
4582 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4583 && attrs.type < FIRST_SYSTEM_WINDOW;
4584 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4585 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4586
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004587 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004588 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004589 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004590 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004591 mForceStatusBarFromKeyguard = true;
4592 } else {
4593 mForceStatusBar = true;
4594 }
4595 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004596 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004597 // If the lockscreen was showing when the dream started then wait
4598 // for the dream to draw before hiding the lockscreen.
4599 if (!mDreamingLockscreen
4600 || (win.isVisibleLw() && win.hasDrawnLw())) {
4601 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004602 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004603 }
4604 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004605
Yohei Yukawad1a09222015-06-30 16:22:05 -07004606 final IApplicationToken appToken = win.getAppToken();
4607
4608 // For app windows that are not attached, we decide if all windows in the app they
4609 // represent should be hidden or if we should hide the lockscreen. For attached app
4610 // windows we defer the decision to the window it is attached to.
4611 if (appWindow && attached == null) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004612 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004613 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004614 mAppsToBeHidden.remove(appToken);
4615 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004616 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004617 if (dismissKeyguard && !mKeyguardSecure) {
4618 mAppsThatDismissKeyguard.add(appToken);
Selim Cinek90b5e072015-08-28 17:05:56 -07004619 } else if (win.isDrawnLw() || win.hasAppShownWindows()) {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004620 mWinShowWhenLocked = win;
4621 mHideLockScreen = true;
4622 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004623 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004624 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004625 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004626 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004627 mAppsToBeHidden.add(appToken);
4628 } else {
4629 mAppsToBeHidden.remove(appToken);
4630 }
4631 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004632 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004633 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004634 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004635 if (attrs.x == 0 && attrs.y == 0
4636 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4637 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4638 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4639 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004640 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4641 mTopFullscreenOpaqueOrDimmingWindowState = win;
4642 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004643 if (!mAppsThatDismissKeyguard.isEmpty() &&
4644 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4645 if (DEBUG_LAYOUT) Slog.v(TAG,
4646 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004647 mDismissKeyguard = (mWinDismissingKeyguard == win
4648 && mSecureDismissingKeyguard == mKeyguardSecure)
4649 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004650 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004651 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004652 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Selim Cinek90b5e072015-08-28 17:05:56 -07004653 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked
4654 && (win.isDrawnLw() || win.hasAppShownWindows())) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004655 if (DEBUG_LAYOUT) Slog.v(TAG,
4656 "Setting mHideLockScreen to true by win " + win);
4657 mHideLockScreen = true;
4658 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004659 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004660 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004661 mAllowLockscreenWhenOn = true;
4662 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004663 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004664
4665 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004666 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4667 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004668 win.hideLw(false);
4669 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004670 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004671 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4672 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4673 // that is being hidden in an animation - keep the
4674 // keyguard hidden until the new window shows up and
4675 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004676 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004677 mHideLockScreen = true;
4678 mWinShowWhenLocked = win;
4679 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004680 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004681 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4682 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4683 && win.isDimming()) {
4684 mTopFullscreenOpaqueOrDimmingWindowState = win;
4685 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004686 }
4687
4688 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004689 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004690 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004691 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4692 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4693 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004694 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4695 // fullscreen window.
4696 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4697 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4698 mTopFullscreenOpaqueWindowState.hideLw(false);
4699 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4700 }
4701
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004702 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004703 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004704
4705 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4706 ? mTopFullscreenOpaqueWindowState.getAttrs()
4707 : null;
4708
Jeff Brownc8018eb2012-10-29 21:33:27 -07004709 // If we are not currently showing a dream then remember the current
4710 // lockscreen state. We will use this to determine whether the dream
4711 // started while the lockscreen was showing and remember this state
4712 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004713 if (!mShowingDream) {
4714 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004715 if (mDreamingSleepTokenNeeded) {
4716 mDreamingSleepTokenNeeded = false;
4717 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4718 }
4719 } else {
4720 if (!mDreamingSleepTokenNeeded) {
4721 mDreamingSleepTokenNeeded = true;
4722 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4723 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004724 }
4725
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004726 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004727 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004728 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004729 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004730 boolean shouldBeTransparent = mForceStatusBarTransparent
4731 && !mForceStatusBar
4732 && !mForceStatusBarFromKeyguard;
4733 if (!shouldBeTransparent) {
4734 mStatusBarController.setShowTransparent(false /* transparent */);
4735 } else if (!mStatusBar.isVisibleLw()) {
4736 mStatusBarController.setShowTransparent(true /* transparent */);
4737 }
4738 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004739 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004740 if (mStatusBarController.setBarShowingLw(true)) {
4741 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4742 }
Craig Mautner81defc72013-10-29 11:10:42 -07004743 // Maintain fullscreen layout until incoming animation is complete.
4744 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004745 // Transient status bar on the lockscreen is not allowed
4746 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4747 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4748 mLastSystemUiFlags, mLastSystemUiFlags);
4749 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004750 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004751 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004752 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004753 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07004754 + " shown position: "
4755 + mTopFullscreenOpaqueWindowState.getShownPositionLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004756 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004757 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004758 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004759 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004760 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004761 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004762 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004763 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4764 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004765 if (mStatusBarController.isTransientShowing()) {
4766 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004767 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4768 }
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07004769 } else if (topIsFullscreen
4770 && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID)
4771 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) {
Craig Mautnereda67292013-04-28 13:50:14 -07004772 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004773 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004774 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004775 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004776 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004777 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004778 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004779 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004780 if (mStatusBarController.setBarShowingLw(true)) {
4781 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4782 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004783 }
4784 }
4785 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004786
Craig Mautner81defc72013-10-29 11:10:42 -07004787 if (mTopIsFullscreen != topIsFullscreen) {
4788 if (!topIsFullscreen) {
4789 // Force another layout when status bar becomes fully shown.
4790 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4791 }
4792 mTopIsFullscreen = topIsFullscreen;
4793 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004794
Craig Mautner39834192012-09-02 07:47:24 -07004795 // Hide the key guard if a visible window explicitly specifies that it wants to be
4796 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004797 if (mKeyguardDelegate != null && mStatusBar != null) {
4798 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4799 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004800 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004801 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004802 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004803 changes |= FINISH_LAYOUT_REDO_LAYOUT
4804 | FINISH_LAYOUT_REDO_CONFIG
4805 | FINISH_LAYOUT_REDO_WALLPAPER;
4806 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004807 if (mKeyguardDelegate.isShowing()) {
4808 mHandler.post(new Runnable() {
4809 @Override
4810 public void run() {
4811 mKeyguardDelegate.keyguardDone(false, false);
4812 }
4813 });
4814 }
4815 } else if (mHideLockScreen) {
4816 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004817 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004818 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004819 changes |= FINISH_LAYOUT_REDO_LAYOUT
4820 | FINISH_LAYOUT_REDO_CONFIG
4821 | FINISH_LAYOUT_REDO_WALLPAPER;
4822 }
4823 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004824 mKeyguardHidden = false;
4825 if (setKeyguardOccludedLw(false)) {
4826 changes |= FINISH_LAYOUT_REDO_LAYOUT
4827 | FINISH_LAYOUT_REDO_CONFIG
4828 | FINISH_LAYOUT_REDO_WALLPAPER;
4829 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004830 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4831 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004832 mHandler.post(new Runnable() {
4833 @Override
4834 public void run() {
4835 mKeyguardDelegate.dismiss();
4836 }
4837 });
4838 }
4839 } else {
4840 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004841 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004842 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004843 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004844 changes |= FINISH_LAYOUT_REDO_LAYOUT
4845 | FINISH_LAYOUT_REDO_CONFIG
4846 | FINISH_LAYOUT_REDO_WALLPAPER;
4847 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004848 }
4849 }
Joe Onorato664644d2011-01-23 17:53:23 -08004850
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004851 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004852 // If the navigation bar has been hidden or shown, we need to do another
4853 // layout pass to update that window.
4854 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4855 }
Joe Onorato664644d2011-01-23 17:53:23 -08004856
Mike Lockwood28569302010-01-28 11:54:40 -05004857 // update since mAllowLockscreenWhenOn might have changed
4858 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004859 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004860 }
4861
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004862 /**
Jim Millerab954542014-10-10 18:21:49 -07004863 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004864 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004865 * @return Whether the flags have changed and we have to redo the layout.
4866 */
Jim Millerab954542014-10-10 18:21:49 -07004867 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4868 boolean wasOccluded = mKeyguardOccluded;
4869 boolean showing = mKeyguardDelegate.isShowing();
4870 if (wasOccluded && !isOccluded && showing) {
4871 mKeyguardOccluded = false;
4872 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004873 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4874 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4875 return true;
Jim Millerab954542014-10-10 18:21:49 -07004876 } else if (!wasOccluded && isOccluded && showing) {
4877 mKeyguardOccluded = true;
4878 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004879 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4880 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4881 return true;
4882 } else {
4883 return false;
4884 }
4885 }
4886
4887 private boolean isStatusBarKeyguard() {
4888 return mStatusBar != null
4889 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4890 }
4891
Jose Lima9546b202014-07-02 17:21:51 -07004892 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004893 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004894 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004895 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004896 return false;
4897 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004898 return true;
4899 }
4900
Jose Lima9546b202014-07-02 17:21:51 -07004901 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004902 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004903 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004904 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004905 // If the navigation bar has been hidden or shown, we need to do another
4906 // layout pass to update that window.
4907 return FINISH_LAYOUT_REDO_LAYOUT;
4908 }
4909 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004910 }
4911
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004912 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004913 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004914 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4915 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004916 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4917 if (newLidState == mLidState) {
4918 return;
4919 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004920
Jeff Brownc458ce92012-04-30 14:58:40 -07004921 mLidState = newLidState;
4922 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004923 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004924
4925 if (lidOpen) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07004926 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch,
4927 "android.policy:LID");
Jeff Brownc458ce92012-04-30 14:58:40 -07004928 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004929 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004930 }
4931 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004932
Michael Wright3818c922014-09-02 13:59:07 -07004933 @Override
4934 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4935 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4936 if (mCameraLensCoverState == lensCoverState) {
4937 return;
4938 }
4939 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4940 lensCoverState == CAMERA_LENS_UNCOVERED) {
4941 Intent intent;
4942 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4943 mKeyguardDelegate.isShowing();
4944 if (keyguardActive) {
4945 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4946 } else {
4947 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4948 }
Dianne Hackborn280a64e2015-07-13 14:48:08 -07004949 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens,
4950 "android.policy:CAMERA_COVER");
Bart Sears8b1c27c2015-03-18 23:51:02 +00004951 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004952 }
4953 mCameraLensCoverState = lensCoverState;
4954 }
4955
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004956 void setHdmiPlugged(boolean plugged) {
4957 if (mHdmiPlugged != plugged) {
4958 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004959 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004960 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004961 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004962 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004963 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004964 }
4965 }
4966
Joe Onoratoea495d42011-04-06 11:41:11 -07004967 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004968 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004969 // watch for HDMI plug messages if the hdmi switch exists
4970 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4971 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4972
Joe Onoratoea495d42011-04-06 11:41:11 -07004973 final String filename = "/sys/class/switch/hdmi/state";
4974 FileReader reader = null;
4975 try {
4976 reader = new FileReader(filename);
4977 char[] buf = new char[15];
4978 int n = reader.read(buf);
4979 if (n > 1) {
4980 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4981 }
4982 } catch (IOException ex) {
4983 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4984 } catch (NumberFormatException ex) {
4985 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4986 } finally {
4987 if (reader != null) {
4988 try {
4989 reader.close();
4990 } catch (IOException ex) {
4991 }
Joe Onoratodc100302011-01-11 17:07:41 -08004992 }
4993 }
4994 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004995 // This dance forces the code in setHdmiPlugged to run.
4996 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4997 mHdmiPlugged = !plugged;
4998 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004999 }
5000
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07005001 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005002 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005003
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005004 final Runnable mScreenshotTimeout = new Runnable() {
5005 @Override public void run() {
5006 synchronized (mScreenshotLock) {
5007 if (mScreenshotConnection != null) {
5008 mContext.unbindService(mScreenshotConnection);
5009 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005010 }
Winson Chung9112ec32011-06-27 13:15:32 -07005011 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005012 }
5013 };
5014
5015 // Assume this is called from the Handler thread.
5016 private void takeScreenshot() {
5017 synchronized (mScreenshotLock) {
5018 if (mScreenshotConnection != null) {
5019 return;
5020 }
5021 ComponentName cn = new ComponentName("com.android.systemui",
5022 "com.android.systemui.screenshot.TakeScreenshotService");
5023 Intent intent = new Intent();
5024 intent.setComponent(cn);
5025 ServiceConnection conn = new ServiceConnection() {
5026 @Override
5027 public void onServiceConnected(ComponentName name, IBinder service) {
5028 synchronized (mScreenshotLock) {
5029 if (mScreenshotConnection != this) {
5030 return;
5031 }
5032 Messenger messenger = new Messenger(service);
5033 Message msg = Message.obtain(null, 1);
5034 final ServiceConnection myConn = this;
5035 Handler h = new Handler(mHandler.getLooper()) {
5036 @Override
5037 public void handleMessage(Message msg) {
5038 synchronized (mScreenshotLock) {
5039 if (mScreenshotConnection == myConn) {
5040 mContext.unbindService(mScreenshotConnection);
5041 mScreenshotConnection = null;
5042 mHandler.removeCallbacks(mScreenshotTimeout);
5043 }
5044 }
5045 }
5046 };
5047 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07005048 msg.arg1 = msg.arg2 = 0;
5049 if (mStatusBar != null && mStatusBar.isVisibleLw())
5050 msg.arg1 = 1;
5051 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
5052 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005053 try {
5054 messenger.send(msg);
5055 } catch (RemoteException e) {
5056 }
5057 }
5058 }
5059 @Override
5060 public void onServiceDisconnected(ComponentName name) {}
5061 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08005062 if (mContext.bindServiceAsUser(
5063 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005064 mScreenshotConnection = conn;
5065 mHandler.postDelayed(mScreenshotTimeout, 10000);
5066 }
5067 }
Winson Chung9112ec32011-06-27 13:15:32 -07005068 }
5069
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005070 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005071 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07005072 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07005073 if (!mSystemBooted) {
5074 // If we have not yet booted, don't let key events do anything.
5075 return 0;
5076 }
5077
Jeff Brown037c33e2014-04-09 00:31:55 -07005078 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08005079 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
5080 final boolean canceled = event.isCanceled();
5081 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07005082
Jeff Brown3122e442010-10-11 23:32:49 -07005083 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07005084
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05005085 // If screen is off then we treat the case where the keyguard is open but hidden
5086 // the same as if it were open and in front.
5087 // This will prevent any keys other than the power button from waking the screen
5088 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08005089 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07005090 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07005091 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08005092 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005093
Jeff Brown40013652012-05-16 21:22:36 -07005094 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005095 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07005096 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08005097 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005098 }
5099
Jeff Brown037c33e2014-04-09 00:31:55 -07005100 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07005101 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07005102 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
5103 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07005104 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07005105 // When the device is interactive or the key is injected pass the
5106 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07005107 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005108 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07005109 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
5110 // If we're currently dozing with the screen on and the keyguard showing, pass the key
5111 // to the application but preserve its wake key status to make sure we still move
5112 // from dozing to fully interactive if we would normally go from off to fully
5113 // interactive.
5114 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07005115 } else {
5116 // When the screen is off and the key is not injected, determine whether
5117 // to wake the device but don't pass the key to the application.
5118 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08005119 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
5120 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005121 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005122 }
5123
Justin Kohd378ad72013-04-01 12:18:26 -07005124 // If the key would be handled globally, just return the result, don't worry about special
5125 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07005126 if (isValidGlobalKey(keyCode)
5127 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07005128 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005129 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Michael Wright85b1af62014-06-04 14:51:58 -07005130 }
Justin Kohd378ad72013-04-01 12:18:26 -07005131 return result;
5132 }
5133
Jeff Brownbae8e772014-06-12 19:59:45 -07005134 boolean useHapticFeedback = down
5135 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
5136 && event.getRepeatCount() == 0;
5137
Jeff Brown4d396052010-10-29 21:50:21 -07005138 // Handle special keys.
5139 switch (keyCode) {
5140 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07005141 case KeyEvent.KEYCODE_VOLUME_UP:
5142 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005143 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
5144 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005145 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005146 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005147 mScreenshotChordVolumeDownKeyTriggered = true;
5148 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
5149 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005150 cancelPendingPowerKeyAction();
5151 interceptScreenshotChord();
5152 }
5153 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005154 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005155 cancelPendingScreenshotChordAction();
5156 }
5157 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
5158 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005159 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005160 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005161 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005162 cancelPendingPowerKeyAction();
5163 cancelPendingScreenshotChordAction();
5164 }
5165 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005166 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005167 cancelPendingScreenshotChordAction();
5168 }
5169 }
Jeff Brown4d396052010-10-29 21:50:21 -07005170 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005171 TelecomManager telecomManager = getTelecommService();
5172 if (telecomManager != null) {
5173 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005174 // If an incoming call is ringing, either VOLUME key means
5175 // "silence ringer". We handle these keys here, rather than
5176 // in the InCallScreen, to make sure we'll respond to them
5177 // even if the InCallScreen hasn't come to the foreground yet.
5178 // Look for the DOWN event here, to agree with the "fallback"
5179 // behavior in the InCallScreen.
5180 Log.i(TAG, "interceptKeyBeforeQueueing:"
5181 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07005182
Santos Cordon6848f722014-05-21 15:22:12 -07005183 // Silence the ringer. (It's safe to call this
5184 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005185 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07005186
Santos Cordon6848f722014-05-21 15:22:12 -07005187 // And *don't* pass this key thru to the current activity
5188 // (which is probably the InCallScreen.)
5189 result &= ~ACTION_PASS_TO_USER;
5190 break;
5191 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005192 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07005193 && (result & ACTION_PASS_TO_USER) == 0) {
5194 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07005195 // the application, just pass it to the session service.
5196
5197 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07005198 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07005199 break;
Jeff Brown4d396052010-10-29 21:50:21 -07005200 }
5201 }
Jaewan Kim765487f2016-01-12 14:45:42 +09005202 }
5203 if (mUseTvRouting) {
5204 // On TVs, defer special key handlings to
5205 // {@link interceptKeyBeforeDispatching()}.
5206 result |= ACTION_PASS_TO_USER;
5207 } else if ((result & ACTION_PASS_TO_USER) == 0) {
5208 // If we aren't passing to the user and no one else
5209 // handled it send it to the session manager to
5210 // figure out.
5211 MediaSessionLegacyHelper.getHelper(mContext)
5212 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07005213 }
5214 break;
5215 }
5216
5217 case KeyEvent.KEYCODE_ENDCALL: {
5218 result &= ~ACTION_PASS_TO_USER;
5219 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005220 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07005221 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005222 if (telecomManager != null) {
5223 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07005224 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005225 if (interactive && !hungUp) {
5226 mEndCallKeyHandled = false;
5227 mHandler.postDelayed(mEndCallLongPress,
5228 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
5229 } else {
5230 mEndCallKeyHandled = true;
5231 }
Jeff Brown4d396052010-10-29 21:50:21 -07005232 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005233 if (!mEndCallKeyHandled) {
5234 mHandler.removeCallbacks(mEndCallLongPress);
5235 if (!canceled) {
5236 if ((mEndcallBehavior
5237 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
5238 if (goHome()) {
5239 break;
5240 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07005241 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005242 if ((mEndcallBehavior
5243 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
5244 mPowerManager.goToSleep(event.getEventTime(),
5245 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
5246 isWakeKey = false;
5247 }
Jeff Brown4d396052010-10-29 21:50:21 -07005248 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005249 }
Jeff Brown4d396052010-10-29 21:50:21 -07005250 }
5251 break;
5252 }
5253
5254 case KeyEvent.KEYCODE_POWER: {
5255 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07005256 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07005257 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005258 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005259 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005260 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07005261 }
5262 break;
5263 }
5264
Jeff Brown6212a492014-03-07 13:58:47 -08005265 case KeyEvent.KEYCODE_SLEEP: {
5266 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005267 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07005268 if (!mPowerManager.isInteractive()) {
5269 useHapticFeedback = false; // suppress feedback if already non-interactive
5270 }
Nick Vaccarob593a812015-05-15 11:23:05 -07005271 if (down) {
5272 sleepPress(event.getEventTime());
5273 } else {
5274 sleepRelease(event.getEventTime());
5275 }
Jeff Brown6212a492014-03-07 13:58:47 -08005276 break;
5277 }
5278
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -07005279 case KeyEvent.KEYCODE_SOFT_SLEEP: {
5280 result &= ~ACTION_PASS_TO_USER;
5281 isWakeKey = false;
5282 if (!down) {
5283 mPowerManagerInternal.setUserInactiveOverrideFromWindowManager();
5284 }
5285 break;
5286 }
5287
Jeff Brown6212a492014-03-07 13:58:47 -08005288 case KeyEvent.KEYCODE_WAKEUP: {
5289 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005290 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08005291 break;
5292 }
5293
Jeff Brown4d396052010-10-29 21:50:21 -07005294 case KeyEvent.KEYCODE_MEDIA_PLAY:
5295 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5296 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07005297 case KeyEvent.KEYCODE_HEADSETHOOK:
5298 case KeyEvent.KEYCODE_MUTE:
5299 case KeyEvent.KEYCODE_MEDIA_STOP:
5300 case KeyEvent.KEYCODE_MEDIA_NEXT:
5301 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5302 case KeyEvent.KEYCODE_MEDIA_REWIND:
5303 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005304 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
5305 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07005306 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
5307 // If the global session is active pass all media keys to it
5308 // instead of the active window.
5309 result &= ~ACTION_PASS_TO_USER;
5310 }
Jeff Brown4d396052010-10-29 21:50:21 -07005311 if ((result & ACTION_PASS_TO_USER) == 0) {
5312 // Only do this if we would otherwise not pass it to the user. In that
5313 // case, the PhoneWindow class will do the same thing, except it will
5314 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07005315 // Note that we need to make a copy of the key event here because the
5316 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07005317 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07005318 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
5319 new KeyEvent(event));
5320 msg.setAsynchronous(true);
5321 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005322 }
5323 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005324 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005325
Jeff Brown4d396052010-10-29 21:50:21 -07005326 case KeyEvent.KEYCODE_CALL: {
5327 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005328 TelecomManager telecomManager = getTelecommService();
5329 if (telecomManager != null) {
5330 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005331 Log.i(TAG, "interceptKeyBeforeQueueing:"
5332 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005333 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005334
Santos Cordon6848f722014-05-21 15:22:12 -07005335 // And *don't* pass this key thru to the current activity
5336 // (which is presumably the InCallScreen.)
5337 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005338 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005339 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005340 }
Jeff Brown4d396052010-10-29 21:50:21 -07005341 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005342 }
Michael Wright869a67c2014-08-26 19:33:06 -07005343 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5344 // Only do this if we would otherwise not pass it to the user. In that case,
5345 // interceptKeyBeforeDispatching would apply a similar but different policy in
5346 // order to invoke voice assist actions. Note that we need to make a copy of the
5347 // key event here because the original key event will be recycled when we return.
5348 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5349 mBroadcastWakeLock.acquire();
5350 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5351 keyguardActive ? 1 : 0, 0);
5352 msg.setAsynchronous(true);
5353 msg.sendToTarget();
5354 }
Jaewan Kim49117872016-01-19 17:24:08 +09005355 break;
5356 }
5357 case KeyEvent.KEYCODE_WINDOW: {
5358 if (mShortPressWindowBehavior == SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE) {
5359 if (!down) {
Jaewan Kimc552b042016-01-18 16:08:45 +09005360 requestTvPictureInPicture(event);
Jaewan Kim49117872016-01-19 17:24:08 +09005361 }
5362 result &= ~ACTION_PASS_TO_USER;
5363 }
5364 break;
Michael Wright869a67c2014-08-26 19:33:06 -07005365 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005366 }
Jeff Brown26875502014-01-30 21:47:47 -08005367
Jeff Brownbae8e772014-06-12 19:59:45 -07005368 if (useHapticFeedback) {
5369 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5370 }
5371
Jeff Brown26875502014-01-30 21:47:47 -08005372 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005373 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Jeff Brown26875502014-01-30 21:47:47 -08005374 }
Bryce Lee584a4452014-10-21 15:55:55 -07005375
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005376 return result;
5377 }
5378
Jeff Brown1c2e4942012-11-06 16:32:01 -08005379 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005380 * Returns true if the key can have global actions attached to it.
5381 * We reserve all power management keys for the system since they require
5382 * very careful handling.
5383 */
5384 private static boolean isValidGlobalKey(int keyCode) {
5385 switch (keyCode) {
5386 case KeyEvent.KEYCODE_POWER:
5387 case KeyEvent.KEYCODE_WAKEUP:
5388 case KeyEvent.KEYCODE_SLEEP:
5389 return false;
5390 default:
5391 return true;
5392 }
5393 }
5394
5395 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005396 * When the screen is off we ignore some keys that might otherwise typically
5397 * be considered wake keys. We filter them out here.
5398 *
5399 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5400 * is always considered a wake key.
5401 */
5402 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5403 switch (keyCode) {
5404 // ignore volume keys unless docked
5405 case KeyEvent.KEYCODE_VOLUME_UP:
5406 case KeyEvent.KEYCODE_VOLUME_DOWN:
5407 case KeyEvent.KEYCODE_VOLUME_MUTE:
5408 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5409
5410 // ignore media and camera keys
5411 case KeyEvent.KEYCODE_MUTE:
5412 case KeyEvent.KEYCODE_HEADSETHOOK:
5413 case KeyEvent.KEYCODE_MEDIA_PLAY:
5414 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5415 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5416 case KeyEvent.KEYCODE_MEDIA_STOP:
5417 case KeyEvent.KEYCODE_MEDIA_NEXT:
5418 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5419 case KeyEvent.KEYCODE_MEDIA_REWIND:
5420 case KeyEvent.KEYCODE_MEDIA_RECORD:
5421 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005422 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005423 case KeyEvent.KEYCODE_CAMERA:
5424 return false;
5425 }
5426 return true;
5427 }
5428
5429
Jeff Brown56194eb2011-03-02 19:23:13 -08005430 /** {@inheritDoc} */
5431 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005432 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5433 if ((policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005434 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion,
5435 "android.policy:MOTION")) {
Bryce Lee5c138322014-11-03 08:26:09 -08005436 return 0;
5437 }
Michael Wright70af00a2014-09-03 19:30:20 -07005438 }
Bryce Lee5c138322014-11-03 08:26:09 -08005439
Michael Wright70af00a2014-09-03 19:30:20 -07005440 if (shouldDispatchInputWhenNonInteractive()) {
5441 return ACTION_PASS_TO_USER;
5442 }
Bryce Lee5c138322014-11-03 08:26:09 -08005443
Bryce Lee812d7022014-11-10 13:33:28 -08005444 // If we have not passed the action up and we are in theater mode without dreaming,
5445 // there will be no dream to intercept the touch and wake into ambient. The device should
5446 // wake up in this case.
5447 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005448 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming,
5449 "android.policy:MOTION");
Bryce Lee812d7022014-11-10 13:33:28 -08005450 }
5451
Jeff Brown037c33e2014-04-09 00:31:55 -07005452 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005453 }
5454
Michael Wright70af00a2014-09-03 19:30:20 -07005455 private boolean shouldDispatchInputWhenNonInteractive() {
Joe LaPennaf2b9b2d2015-11-17 22:22:37 +00005456 // Send events to keyguard while the screen is on.
5457 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5458 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005459 return true;
5460 }
5461
5462 // Send events to a dozing dream even if the screen is off since the dream
5463 // is in control of the state of the screen.
5464 IDreamManager dreamManager = getDreamManager();
5465
5466 try {
5467 if (dreamManager != null && dreamManager.isDreaming()) {
5468 return true;
5469 }
5470 } catch (RemoteException e) {
5471 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5472 }
5473
5474 // Otherwise, consume events since the user can't see what is being
5475 // interacted with.
5476 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005477 }
5478
RoboErik001c59c2015-01-26 15:53:51 -08005479 private void dispatchDirectAudioEvent(KeyEvent event) {
5480 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5481 return;
5482 }
5483 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005484 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5485 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005486 String pkgName = mContext.getOpPackageName();
5487 switch (keyCode) {
5488 case KeyEvent.KEYCODE_VOLUME_UP:
5489 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005490 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005491 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005492 } catch (RemoteException e) {
5493 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5494 }
5495 break;
5496 case KeyEvent.KEYCODE_VOLUME_DOWN:
5497 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005498 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005499 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005500 } catch (RemoteException e) {
5501 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5502 }
5503 break;
5504 case KeyEvent.KEYCODE_VOLUME_MUTE:
5505 try {
5506 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005507 getAudioService().adjustSuggestedStreamVolume(
5508 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005509 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005510 }
5511 } catch (RemoteException e) {
5512 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5513 }
5514 break;
5515 }
5516 }
5517
Jeff Brown40013652012-05-16 21:22:36 -07005518 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5519 if (DEBUG_INPUT) {
5520 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005521 }
5522
Jeff Brown40013652012-05-16 21:22:36 -07005523 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5524 if (DEBUG_INPUT) {
5525 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5526 }
5527
5528 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5529 mHavePendingMediaKeyRepeatWithWakeLock = false;
5530 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5531 }
5532
5533 dispatchMediaKeyWithWakeLockToAudioService(event);
5534
5535 if (event.getAction() == KeyEvent.ACTION_DOWN
5536 && event.getRepeatCount() == 0) {
5537 mHavePendingMediaKeyRepeatWithWakeLock = true;
5538
5539 Message msg = mHandler.obtainMessage(
5540 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5541 msg.setAsynchronous(true);
5542 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5543 } else {
5544 mBroadcastWakeLock.release();
5545 }
5546 }
5547
5548 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5549 mHavePendingMediaKeyRepeatWithWakeLock = false;
5550
5551 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5552 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5553 if (DEBUG_INPUT) {
5554 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5555 }
5556
5557 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5558 mBroadcastWakeLock.release();
5559 }
5560
5561 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5562 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005563 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005564 }
5565 }
5566
Michael Wright869a67c2014-08-26 19:33:06 -07005567 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005568 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5569 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5570 if (dic != null) {
5571 try {
5572 dic.exitIdle("voice-search");
5573 } catch (RemoteException e) {
5574 }
5575 }
Michael Wright869a67c2014-08-26 19:33:06 -07005576 Intent voiceIntent =
5577 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5578 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005579 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005580 mBroadcastWakeLock.release();
5581 }
5582
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005583 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005584 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005585 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005586 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5587 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5588 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005589 } else {
5590 try {
5591 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5592 ServiceManager.getService(Context.UI_MODE_SERVICE));
5593 mUiMode = uiModeService.getCurrentModeType();
5594 } catch (RemoteException e) {
5595 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005596 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005597 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005598 synchronized (mLock) {
5599 updateOrientationListenerLp();
5600 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005601 }
5602 };
5603
Jeff Brown6aaf2952012-10-05 16:01:08 -07005604 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5605 @Override
5606 public void onReceive(Context context, Intent intent) {
5607 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005608 if (mKeyguardDelegate != null) {
5609 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005610 }
5611 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005612 if (mKeyguardDelegate != null) {
5613 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005614 }
5615 }
5616 }
5617 };
5618
Christopher Tate5e08af02012-09-21 17:17:22 -07005619 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5620 @Override
5621 public void onReceive(Context context, Intent intent) {
5622 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5623 // tickle the settings observer: this first ensures that we're
5624 // observing the relevant settings for the newly-active user,
5625 // and then updates our own bookkeeping based on the now-
5626 // current user.
5627 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005628
5629 // force a re-application of focused window sysui visibility.
5630 // the window may never have been shown for this user
5631 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005632 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005633 mLastSystemUiFlags = 0;
5634 updateSystemUiVisibilityLw();
5635 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005636 }
5637 }
5638 };
5639
Adrian Roosddc8b272015-05-21 16:28:27 -07005640 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005641 @Override
5642 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005643 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5644 if (!isUserSetupComplete()) {
5645 // Swipe-up for navigation bar is disabled during setup
5646 return;
5647 }
5648 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5649 mNavigationBarController.showTransient();
5650 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005651 }
5652 };
5653
John Spurlocke1f366f2013-08-05 12:22:40 -04005654 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005655 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005656 if (!isUserSetupComplete()) {
5657 // Swipe-up for navigation bar is disabled during setup
5658 return;
5659 }
John Spurlock27735a42013-08-14 17:57:38 -04005660 boolean sb = mStatusBarController.checkShowTransientBarLw();
5661 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005662 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005663 // Don't show status bar when swiping on already visible navigation bar
5664 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005665 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005666 return;
5667 }
John Spurlock27735a42013-08-14 17:57:38 -04005668 if (sb) mStatusBarController.showTransient();
5669 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005670 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005671 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005672 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005673 }
5674 }
5675
Jeff Brown3ee549c2014-09-22 20:14:39 -07005676 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005677 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005678 public void startedGoingToSleep(int why) {
5679 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005680 if (mKeyguardDelegate != null) {
5681 mKeyguardDelegate.onStartedGoingToSleep(why);
5682 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005683 }
5684
5685 // Called on the PowerManager's Notifier thread.
5686 @Override
5687 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005688 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005689 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04005690 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005691
5692 // We must get this work done here because the power manager will drop
5693 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005694 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005695 mAwake = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005696 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005697 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005698 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005699 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005700 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005701 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005702 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005703 }
5704
Jeff Brown3ee549c2014-09-22 20:14:39 -07005705 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005706 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005707 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005708 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005709 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005710
Jeff Brown3ee549c2014-09-22 20:14:39 -07005711 // Since goToSleep performs these functions synchronously, we must
5712 // do the same here. We cannot post this work to a handler because
5713 // that might cause it to become reordered with respect to what
5714 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005715 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005716 mAwake = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005717
Jeff Browna20dda42014-05-27 20:57:24 -07005718 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005719 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005720 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005721 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005722
Jim Miller5ecd8112013-01-09 18:50:26 -08005723 if (mKeyguardDelegate != null) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005724 mKeyguardDelegate.onStartedWakingUp();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005725 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005726 }
5727
Jeff Brown416c49c2015-05-26 19:50:18 -07005728 // Called on the PowerManager's Notifier thread.
5729 @Override
5730 public void finishedWakingUp() {
5731 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5732 }
5733
5734 private void wakeUpFromPowerKey(long eventTime) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005735 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER");
Jeff Brown416c49c2015-05-26 19:50:18 -07005736 }
5737
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005738 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) {
Bryce Leed3896842015-06-23 17:06:51 -07005739 final boolean theaterModeEnabled = isTheaterModeEnabled();
5740 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07005741 return false;
5742 }
5743
Bryce Leed3896842015-06-23 17:06:51 -07005744 if (theaterModeEnabled) {
5745 Settings.Global.putInt(mContext.getContentResolver(),
5746 Settings.Global.THEATER_MODE_ON, 0);
5747 }
5748
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005749 mPowerManager.wakeUp(wakeTime, reason);
Jeff Brown416c49c2015-05-26 19:50:18 -07005750 return true;
5751 }
5752
Jeff Brown36c4db82014-09-19 12:05:31 -07005753 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005754 synchronized (mLock) {
Jorim Jaggif3255482015-07-24 12:32:42 -07005755 if (!mScreenOnEarly || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005756 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005757 }
5758
Jeff Brown36c4db82014-09-19 12:05:31 -07005759 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005760 if (mKeyguardDelegate != null) {
5761 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5762 }
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005763 mWindowManagerDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005764 }
5765
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005766 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
5767 // as well as enabling the orientation change logic/sensor.
5768 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5769 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005770 }
5771
5772 // Called on the DisplayManager's DisplayPowerController thread.
5773 @Override
5774 public void screenTurnedOff() {
5775 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5776
Jeff Brown48d1b142015-06-10 16:36:03 -07005777 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005778 synchronized (mLock) {
5779 mScreenOnEarly = false;
5780 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005781 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005782 mWindowManagerDrawComplete = false;
5783 mScreenOnListener = null;
5784 updateOrientationListenerLp();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005785
5786 if (mKeyguardDelegate != null) {
5787 mKeyguardDelegate.onScreenTurnedOff();
5788 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005789 }
5790 }
5791
Jeff Brown3ee549c2014-09-22 20:14:39 -07005792 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005793 @Override
5794 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005795 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005796
Jeff Brown48d1b142015-06-10 16:36:03 -07005797 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005798 synchronized (mLock) {
5799 mScreenOnEarly = true;
5800 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005801 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005802 mWindowManagerDrawComplete = false;
5803 mScreenOnListener = screenOnListener;
Jeff Brown36c4db82014-09-19 12:05:31 -07005804
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005805 if (mKeyguardDelegate != null) {
Jorim Jaggia4b51bc2015-08-10 18:20:43 -07005806 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5807 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005808 mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback);
5809 } else {
5810 if (DEBUG_WAKEUP) Slog.d(TAG,
5811 "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
5812 finishKeyguardDrawn();
5813 }
5814 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005815 }
5816
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005817 // Called on the DisplayManager's DisplayPowerController thread.
5818 @Override
5819 public void screenTurnedOn() {
5820 synchronized (mLock) {
5821 if (mKeyguardDelegate != null) {
5822 mKeyguardDelegate.onScreenTurnedOn();
5823 }
5824 }
5825 }
5826
Jeff Brown36c4db82014-09-19 12:05:31 -07005827 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005828 synchronized (mLock) {
5829 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005830 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005831 }
5832
Jeff Brown36c4db82014-09-19 12:05:31 -07005833 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005834 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005835
5836 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005837 }
5838
Craig Mautner8a0da012014-05-31 15:13:37 -07005839 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005840 synchronized (mLock) {
5841 // We have just finished drawing screen content. Since the orientation listener
5842 // gets only installed when all windows are drawn, we try to install it again.
5843 updateOrientationListenerLp();
5844 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005845 final ScreenOnListener listener;
5846 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005847 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005848 if (DEBUG_WAKEUP) Slog.d(TAG,
5849 "finishScreenTurningOn: mAwake=" + mAwake
5850 + ", mScreenOnEarly=" + mScreenOnEarly
5851 + ", mScreenOnFully=" + mScreenOnFully
5852 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5853 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5854
5855 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5856 || (mAwake && !mKeyguardDrawComplete)) {
5857 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005858 }
5859
Jeff Brown3ee549c2014-09-22 20:14:39 -07005860 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5861 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005862 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005863 mScreenOnFully = true;
5864
5865 // Remember the first time we draw the keyguard so we know when we're done with
5866 // the main part of booting and can enable the screen and hide boot messages.
5867 if (!mKeyguardDrawnOnce && mAwake) {
5868 mKeyguardDrawnOnce = true;
5869 enableScreen = true;
5870 if (mBootMessageNeedsHiding) {
5871 mBootMessageNeedsHiding = false;
5872 hideBootMessages();
5873 }
5874 } else {
5875 enableScreen = false;
5876 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005877 }
5878
Jeff Brown3ee549c2014-09-22 20:14:39 -07005879 if (listener != null) {
5880 listener.onScreenOn();
5881 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005882
Jeff Brown3ee549c2014-09-22 20:14:39 -07005883 if (enableScreen) {
5884 try {
5885 mWindowManager.enableScreenIfNeeded();
5886 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005887 }
Craig Mautnera631d492014-08-05 15:16:01 -07005888 }
5889 }
5890
5891 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005892 synchronized (mLock) {
5893 if (!mKeyguardDrawnOnce) {
5894 mBootMessageNeedsHiding = true;
5895 return; // keyguard hasn't drawn the first time yet, not done booting
5896 }
Craig Mautnera631d492014-08-05 15:16:01 -07005897 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005898
5899 if (mBootMsgDialog != null) {
5900 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5901 mBootMsgDialog.dismiss();
5902 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005903 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005904 }
5905
5906 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005907 public boolean isScreenOn() {
5908 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005909 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005910
Dianne Hackborn08743722009-12-21 12:16:51 -08005911 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005912 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005913 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005914 if (mKeyguardDelegate != null) {
5915 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005916 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005917 }
5918
5919 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005920 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005921 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005922 if (mKeyguardDelegate != null) {
5923 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005924 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005925 }
5926
Jim Millerab954542014-10-10 18:21:49 -07005927 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005928 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005929 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005930 }
5931
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005932 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005933 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005934 public boolean isKeyguardLocked() {
5935 return keyguardOn();
5936 }
5937
5938 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005939 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005940 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005941 if (mKeyguardDelegate == null) return false;
5942 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005943 }
5944
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005945 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005946 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07005947 public boolean isKeyguardShowingOrOccluded() {
5948 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
5949 }
5950
5951 /** {@inheritDoc} */
5952 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005953 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005954 if (mKeyguardDelegate == null) return false;
5955 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005956 }
5957
Jose Lima9546b202014-07-02 17:21:51 -07005958 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005959 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005960 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005961 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005962 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005963 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005964 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005965 // ask the keyguard to prompt the user to authenticate if necessary
5966 mKeyguardDelegate.dismiss();
5967 }
5968 });
5969 }
5970 }
5971
5972 public void notifyActivityDrawnForKeyguardLw() {
5973 if (mKeyguardDelegate != null) {
5974 mHandler.post(new Runnable() {
5975 @Override
5976 public void run() {
5977 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005978 }
5979 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005980 }
5981 }
5982
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005983 @Override
5984 public boolean isKeyguardDrawnLw() {
5985 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005986 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005987 }
5988 }
5989
Jorim Jaggi0d674622014-05-21 01:34:15 +02005990 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005991 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005992 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005993 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005994 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005995 }
5996 }
5997
Jorim Jaggi737af722015-12-31 10:42:27 +01005998 @Override
5999 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6000 Rect outInsets) {
6001 outInsets.setEmpty();
6002 if (mStatusBar != null) {
6003 outInsets.top = mStatusBarHeight;
6004 }
6005 if (mNavigationBar != null) {
6006 if (isNavigationBarOnBottom(displayWidth, displayHeight)) {
6007 outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode);
6008 } else {
6009 outInsets.right = getNavigationBarWidth(displayRotation, mUiMode);
6010 }
6011 }
6012 }
6013
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006014 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006015 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006016 }
6017
6018 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006019 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006020 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07006021
Jeff Brown01a98dd2011-09-20 15:08:29 -07006022 @Override
6023 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006024 if (false) {
6025 Slog.v(TAG, "rotationForOrientationLw(orient="
6026 + orientation + ", last=" + lastRotation
6027 + "); user=" + mUserRotation + " "
6028 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
6029 ? "USER_ROTATION_LOCKED" : "")
6030 );
6031 }
6032
Craig Mautner46ac6fa2013-08-01 10:06:34 -07006033 if (mForceDefaultOrientation) {
6034 return Surface.ROTATION_0;
6035 }
6036
The Android Open Source Project0727d222009-03-11 12:11:58 -07006037 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07006038 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
6039 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07006040 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07006041 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006042
Jeff Browndec6cf42011-11-15 14:08:20 -08006043 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07006044 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006045 // Ignore sensor when lid switch is open and rotation is forced.
6046 preferredRotation = mLidOpenRotation;
6047 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07006048 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006049 // Ignore sensor when in car dock unless explicitly enabled.
6050 // This case can override the behavior of NOSENSOR, and can also
6051 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006052 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006053 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08006054 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6055 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
6056 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07006057 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006058 // Ignore sensor when in desk dock unless explicitly enabled.
6059 // This case can override the behavior of NOSENSOR, and can also
6060 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006061 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006062 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006063 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
6064 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08006065 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006066 preferredRotation = mDemoHdmiRotation;
6067 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
6068 && mUndockedHdmiRotation >= 0) {
6069 // Ignore sensor when plugged into HDMI and an undocked orientation has
6070 // been specified in the configuration (only for legacy devices without
6071 // full multi-display support).
6072 // Note that the dock orientation overrides the HDMI orientation.
6073 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08006074 } else if (mDemoRotationLock) {
6075 // Ignore sensor when demo rotation lock is enabled.
6076 // Note that the dock orientation and HDMI rotation lock override this.
6077 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006078 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
6079 // Application just wants to remain locked in the last rotation.
6080 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08006081 } else if (!mSupportAutoRotation) {
6082 // If we don't support auto-rotation then bail out here and ignore
6083 // the sensor and any rotation lock settings.
6084 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07006085 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07006086 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006087 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
6088 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
6089 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
6090 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07006091 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
6092 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6093 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
6094 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
6095 // Otherwise, use sensor only if requested by the application or enabled
6096 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07006097 if (mAllowAllRotations < 0) {
6098 // Can't read this during init() because the context doesn't
6099 // have display metrics at that time so we cannot determine
6100 // tablet vs. phone then.
6101 mAllowAllRotations = mContext.getResources().getBoolean(
6102 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
6103 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006104 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07006105 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006106 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6107 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006108 preferredRotation = sensorRotation;
6109 } else {
6110 preferredRotation = lastRotation;
6111 }
Jeff Brown207673cd2012-06-05 17:47:11 -07006112 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
6113 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
6114 // Apply rotation lock. Does not apply to NOSENSOR.
6115 // The idea is that the user rotation expresses a weak preference for the direction
6116 // of gravity and as NOSENSOR is never affected by gravity, then neither should
6117 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07006118 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08006119 } else {
6120 // No overriding preference.
6121 // We will do exactly what the application asked us to do.
6122 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07006123 }
6124
Dianne Hackborne5439f22010-10-02 16:53:50 -07006125 switch (orientation) {
6126 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006127 // Return portrait unless overridden.
6128 if (isAnyPortrait(preferredRotation)) {
6129 return preferredRotation;
6130 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07006131 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006132
Jeff Brown01a98dd2011-09-20 15:08:29 -07006133 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006134 // Return landscape unless overridden.
6135 if (isLandscapeOrSeascape(preferredRotation)) {
6136 return preferredRotation;
6137 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006138 return mLandscapeRotation;
6139
6140 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006141 // Return reverse portrait unless overridden.
6142 if (isAnyPortrait(preferredRotation)) {
6143 return preferredRotation;
6144 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006145 return mUpsideDownRotation;
6146
6147 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006148 // Return seascape unless overridden.
6149 if (isLandscapeOrSeascape(preferredRotation)) {
6150 return preferredRotation;
6151 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006152 return mSeascapeRotation;
6153
6154 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006155 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006156 // Return either landscape rotation.
6157 if (isLandscapeOrSeascape(preferredRotation)) {
6158 return preferredRotation;
6159 }
6160 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08006161 return lastRotation;
6162 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006163 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006164
Jeff Brown01a98dd2011-09-20 15:08:29 -07006165 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006166 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006167 // Return either portrait rotation.
6168 if (isAnyPortrait(preferredRotation)) {
6169 return preferredRotation;
6170 }
6171 if (isAnyPortrait(lastRotation)) {
6172 return lastRotation;
6173 }
6174 return mPortraitRotation;
6175
6176 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07006177 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
6178 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07006179 if (preferredRotation >= 0) {
6180 return preferredRotation;
6181 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07006182 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05006183 }
6184 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006185 }
6186
Jeff Brown01a98dd2011-09-20 15:08:29 -07006187 @Override
6188 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
6189 switch (orientation) {
6190 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
6191 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
6192 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
6193 return isAnyPortrait(rotation);
6194
6195 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
6196 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
6197 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
6198 return isLandscapeOrSeascape(rotation);
6199
6200 default:
6201 return true;
6202 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006203 }
6204
Jeff Brownc0347aa2011-09-23 17:26:09 -07006205 @Override
6206 public void setRotationLw(int rotation) {
6207 mOrientationListener.setCurrentRotation(rotation);
6208 }
6209
Jeff Brown01a98dd2011-09-20 15:08:29 -07006210 private boolean isLandscapeOrSeascape(int rotation) {
6211 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006212 }
6213
Jeff Brown01a98dd2011-09-20 15:08:29 -07006214 private boolean isAnyPortrait(int rotation) {
6215 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006216 }
6217
Jose Lima9546b202014-07-02 17:21:51 -07006218 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006219 public int getUserRotationMode() {
6220 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07006221 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
6222 WindowManagerPolicy.USER_ROTATION_FREE :
6223 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006224 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006225
6226 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07006227 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006228 public void setUserRotationMode(int mode, int rot) {
6229 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006230
6231 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006232 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07006233 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006234 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006235 rot,
6236 UserHandle.USER_CURRENT);
6237 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006238 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006239 0,
6240 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006241 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07006242 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006243 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006244 1,
6245 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006246 }
6247 }
6248
Jose Lima9546b202014-07-02 17:21:51 -07006249 @Override
Jeff Brownac143512012-04-05 18:57:33 -07006250 public void setSafeMode(boolean safeMode) {
6251 mSafeMode = safeMode;
6252 performHapticFeedbackLw(null, safeMode
6253 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
6254 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006255 }
Craig Mautnereda67292013-04-28 13:50:14 -07006256
Dianne Hackborn181ceb52009-08-27 22:16:40 -07006257 static long[] getLongIntArray(Resources r, int resid) {
6258 int[] ar = r.getIntArray(resid);
6259 if (ar == null) {
6260 return null;
6261 }
6262 long[] out = new long[ar.length];
6263 for (int i=0; i<ar.length; i++) {
6264 out[i] = ar[i];
6265 }
6266 return out;
6267 }
Craig Mautnereda67292013-04-28 13:50:14 -07006268
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006269 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006270 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006271 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07006272 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08006273 mKeyguardDelegate.onSystemReady();
6274
Michael Wright3818c922014-09-02 13:59:07 -07006275 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07006276 updateUiMode();
Adrian Roos3542f7d2015-07-13 15:57:53 -07006277 boolean bindKeyguardNow;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006278 synchronized (mLock) {
6279 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08006280 mSystemReady = true;
6281 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006282 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08006283 public void run() {
6284 updateSettings();
6285 }
6286 });
Adrian Roos3542f7d2015-07-13 15:57:53 -07006287
6288 bindKeyguardNow = mDeferBindKeyguard;
6289 if (bindKeyguardNow) {
6290 // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now.
6291 mDeferBindKeyguard = false;
6292 }
6293 }
6294
6295 if (bindKeyguardNow) {
6296 mKeyguardDelegate.bindService(mContext);
6297 mKeyguardDelegate.onBootCompleted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006298 }
Michael Wrighta4d22d72015-09-16 23:19:26 +01006299 mSystemGestures.systemReady();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006300 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006301
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006302 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006303 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006304 public void systemBooted() {
Adrian Roos3542f7d2015-07-13 15:57:53 -07006305 boolean bindKeyguardNow = false;
6306 synchronized (mLock) {
6307 // Time to bind Keyguard; take care to only bind it once, either here if ready or
6308 // in systemReady if not.
6309 if (mKeyguardDelegate != null) {
6310 bindKeyguardNow = true;
6311 } else {
6312 // Because mKeyguardDelegate is null, we know that the synchronized block in
6313 // systemReady didn't run yet and setting this will actually have an effect.
6314 mDeferBindKeyguard = true;
6315 }
6316 }
6317 if (bindKeyguardNow) {
Jason Monk5eeebf52014-09-26 12:36:51 -04006318 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07006319 mKeyguardDelegate.onBootCompleted();
6320 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006321 synchronized (mLock) {
6322 mSystemBooted = true;
6323 }
Jeff Brown416c49c2015-05-26 19:50:18 -07006324 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07006325 screenTurningOn(null);
Jorim Jaggic0496072015-08-19 15:14:52 -07006326 screenTurnedOn();
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006327 }
6328
Dianne Hackborn661cd522011-08-22 00:26:20 -07006329 ProgressDialog mBootMsgDialog = null;
6330
6331 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006332 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006333 public void showBootMessage(final CharSequence msg, final boolean always) {
6334 mHandler.post(new Runnable() {
6335 @Override public void run() {
6336 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006337 int theme;
Jaewan Kim49117872016-01-19 17:24:08 +09006338 if (mContext.getPackageManager().hasSystemFeature(FEATURE_WATCH)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006339 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
Jaewan Kim49117872016-01-19 17:24:08 +09006340 } else if (mContext.getPackageManager().hasSystemFeature(FEATURE_TELEVISION)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006341 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
6342 } else {
6343 theme = 0;
6344 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07006345
6346 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07006347 // This dialog will consume all events coming in to
6348 // it, to avoid it trying to do things too early in boot.
6349 @Override public boolean dispatchKeyEvent(KeyEvent event) {
6350 return true;
6351 }
6352 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
6353 return true;
6354 }
6355 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
6356 return true;
6357 }
6358 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
6359 return true;
6360 }
6361 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
6362 return true;
6363 }
6364 @Override public boolean dispatchPopulateAccessibilityEvent(
6365 AccessibilityEvent event) {
6366 return true;
6367 }
6368 };
Jeff Hao9f60c082014-10-28 18:51:07 -07006369 if (mContext.getPackageManager().isUpgrade()) {
6370 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
6371 } else {
6372 mBootMsgDialog.setTitle(R.string.android_start_title);
6373 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006374 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
6375 mBootMsgDialog.setIndeterminate(true);
6376 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07006377 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006378 mBootMsgDialog.getWindow().addFlags(
6379 WindowManager.LayoutParams.FLAG_DIM_BEHIND
6380 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
6381 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08006382 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
6383 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
6384 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006385 mBootMsgDialog.setCancelable(false);
6386 mBootMsgDialog.show();
6387 }
6388 mBootMsgDialog.setMessage(msg);
6389 }
6390 });
6391 }
6392
6393 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006394 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006395 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07006396 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006397 }
6398
Mike Lockwood28569302010-01-28 11:54:40 -05006399 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006400 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006401 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006402 // ***************************************
6403 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
6404 // ***************************************
6405 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
6406 // WITH ITS LOCKS HELD.
6407 //
6408 // This code must be VERY careful about the locks
6409 // it acquires.
6410 // In fact, the current code acquires way too many,
6411 // and probably has lurking deadlocks.
6412
Mike Lockwood28569302010-01-28 11:54:40 -05006413 synchronized (mScreenLockTimeout) {
6414 if (mLockScreenTimerActive) {
6415 // reset the timer
6416 mHandler.removeCallbacks(mScreenLockTimeout);
6417 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6418 }
6419 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006420 }
6421
Adam Cohenf7522022012-10-03 20:03:18 -07006422 class ScreenLockTimeout implements Runnable {
6423 Bundle options;
6424
6425 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006426 public void run() {
6427 synchronized (this) {
6428 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006429 if (mKeyguardDelegate != null) {
6430 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006431 }
Mike Lockwood28569302010-01-28 11:54:40 -05006432 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006433 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006434 }
6435 }
Mike Lockwood28569302010-01-28 11:54:40 -05006436
Adam Cohenf7522022012-10-03 20:03:18 -07006437 public void setLockOptions(Bundle options) {
6438 this.options = options;
6439 }
6440 }
6441
6442 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6443
Jose Lima9546b202014-07-02 17:21:51 -07006444 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006445 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006446 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6447 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006448 if (options != null) {
6449 // In case multiple calls are made to lockNow, we don't wipe out the options
6450 // until the runnable actually executes.
6451 mScreenLockTimeout.setLockOptions(options);
6452 }
Jim Miller93c518e2012-01-17 15:55:31 -08006453 mHandler.post(mScreenLockTimeout);
6454 }
6455
Mike Lockwood28569302010-01-28 11:54:40 -05006456 private void updateLockScreenTimeout() {
6457 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006458 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006459 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006460 if (mLockScreenTimerActive != enable) {
6461 if (enable) {
6462 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
Jim Miller2967f482016-01-07 15:05:32 -08006463 mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests
Mike Lockwood28569302010-01-28 11:54:40 -05006464 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6465 } else {
6466 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6467 mHandler.removeCallbacks(mScreenLockTimeout);
6468 }
6469 mLockScreenTimerActive = enable;
6470 }
6471 }
6472 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006473
Jeff Brown061ea992015-04-17 19:55:47 -07006474 private void updateDreamingSleepToken(boolean acquire) {
6475 if (acquire) {
6476 if (mDreamingSleepToken == null) {
6477 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6478 }
6479 } else {
6480 if (mDreamingSleepToken != null) {
6481 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006482 mDreamingSleepToken = null;
6483 }
6484 }
6485 }
6486
6487 private void updateScreenOffSleepToken(boolean acquire) {
6488 if (acquire) {
6489 if (mScreenOffSleepToken == null) {
6490 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6491 }
6492 } else {
6493 if (mScreenOffSleepToken != null) {
6494 mScreenOffSleepToken.release();
6495 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006496 }
6497 }
6498 }
6499
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006500 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006501 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006502 public void enableScreenAfterBoot() {
6503 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006504 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006505 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006506 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006507
Jeff Brownc458ce92012-04-30 14:58:40 -07006508 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006509 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006510 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006511 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006512 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01006513 } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) {
6514 mWindowManagerFuncs.lockDeviceNow();
Jeff Brownc458ce92012-04-30 14:58:40 -07006515 }
Jeff Browna20dda42014-05-27 20:57:24 -07006516
6517 synchronized (mLock) {
6518 updateWakeGestureListenerLp();
6519 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006520 }
6521
Jeff Brown4f5fa282014-06-12 19:19:15 -07006522 void updateUiMode() {
6523 if (mUiModeManager == null) {
6524 mUiModeManager = IUiModeManager.Stub.asInterface(
6525 ServiceManager.getService(Context.UI_MODE_SERVICE));
6526 }
6527 try {
6528 mUiMode = mUiModeManager.getCurrentModeType();
6529 } catch (RemoteException e) {
6530 }
6531 }
6532
Jeff Brown01a98dd2011-09-20 15:08:29 -07006533 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006534 try {
6535 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006536 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6537 } catch (RemoteException e) {
6538 // Ignore
6539 }
6540 }
6541
6542 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6543 try {
6544 //set orientation on WindowManager
6545 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006546 } catch (RemoteException e) {
6547 // Ignore
6548 }
6549 }
6550
Daniel Sandler6396c722013-04-16 20:19:09 -04006551 /**
6552 * Return an Intent to launch the currently active dock app as home. Returns
6553 * null if the standard home should be launched, which is the case if any of the following is
6554 * true:
6555 * <ul>
6556 * <li>The device is not in either car mode or desk mode
keunyounga7710492015-09-23 11:33:58 -07006557 * <li>The device is in car mode but mEnableCarDockHomeCapture is false
Daniel Sandler6396c722013-04-16 20:19:09 -04006558 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6559 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6560 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6561 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006562 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006563 */
6564 Intent createHomeDockIntent() {
6565 Intent intent = null;
6566
6567 // What home does is based on the mode, not the dock state. That
6568 // is, when in car mode you should be taken to car home regardless
6569 // of whether we are actually in a car dock.
6570 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
keunyounga7710492015-09-23 11:33:58 -07006571 if (mEnableCarDockHomeCapture) {
Daniel Sandler6396c722013-04-16 20:19:09 -04006572 intent = mCarDockIntent;
6573 }
6574 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6575 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6576 intent = mDeskDockIntent;
6577 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006578 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6579 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6580 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6581 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6582 // Always launch dock home from home when watch is docked, if it exists.
6583 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006584 }
6585
6586 if (intent == null) {
6587 return null;
6588 }
6589
6590 ActivityInfo ai = null;
6591 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6592 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006593 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006594 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006595 if (info != null) {
6596 ai = info.activityInfo;
6597 }
6598 if (ai != null
6599 && ai.metaData != null
6600 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6601 intent = new Intent(intent);
6602 intent.setClassName(ai.packageName, ai.name);
6603 return intent;
6604 }
6605
6606 return null;
6607 }
6608
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006609 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6610 if (awakenFromDreams) {
6611 awakenDreams();
6612 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006613
6614 Intent dock = createHomeDockIntent();
6615 if (dock != null) {
6616 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006617 if (fromHomeKey) {
6618 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6619 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006620 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006621 return;
6622 } catch (ActivityNotFoundException e) {
6623 }
6624 }
6625
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006626 Intent intent;
6627
6628 if (fromHomeKey) {
6629 intent = new Intent(mHomeIntent);
6630 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6631 } else {
6632 intent = mHomeIntent;
6633 }
6634
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006635 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006636 }
Craig Mautnereda67292013-04-28 13:50:14 -07006637
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006638 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006639 * goes to the home screen
6640 * @return whether it did anything
6641 */
6642 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006643 if (!isUserSetupComplete()) {
6644 Slog.i(TAG, "Not going home because user setup is in progress.");
6645 return false;
6646 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006647 if (false) {
6648 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006649 try {
6650 ActivityManagerNative.getDefault().stopAppSwitches();
6651 } catch (RemoteException e) {
6652 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006653 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006654 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006655 } else {
6656 // This code brings home to the front or, if it is already
6657 // at the front, puts the device to sleep.
6658 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006659 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6660 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6661 Log.d(TAG, "UTS-TEST-MODE");
6662 } else {
6663 ActivityManagerNative.getDefault().stopAppSwitches();
6664 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006665 Intent dock = createHomeDockIntent();
6666 if (dock != null) {
6667 int result = ActivityManagerNative.getDefault()
6668 .startActivityAsUser(null, null, dock,
6669 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6670 null, null, 0,
6671 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006672 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006673 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6674 return false;
6675 }
6676 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006677 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006678 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006679 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006680 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006681 null, null, 0,
6682 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006683 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006684 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006685 return false;
6686 }
6687 } catch (RemoteException ex) {
6688 // bummer, the activity manager, which is in this process, is dead
6689 }
6690 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006691 return true;
6692 }
Craig Mautnereda67292013-04-28 13:50:14 -07006693
6694 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006695 public void setCurrentOrientationLw(int newOrientation) {
6696 synchronized (mLock) {
6697 if (newOrientation != mCurrentAppOrientation) {
6698 mCurrentAppOrientation = newOrientation;
6699 updateOrientationListenerLp();
6700 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006701 }
6702 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006703
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006704 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6705 if (!isGlobalAccessibilityGestureEnabled()) {
6706 return;
6707 }
6708 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6709 Context.AUDIO_SERVICE);
6710 if (audioManager.isSilentMode()) {
6711 return;
6712 }
6713 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6714 Settings.System.DEFAULT_NOTIFICATION_URI);
6715 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6716 ringTone.play();
6717 }
Craig Mautnereda67292013-04-28 13:50:14 -07006718
Bryce Lee584a4452014-10-21 15:55:55 -07006719 private boolean isTheaterModeEnabled() {
6720 return Settings.Global.getInt(mContext.getContentResolver(),
6721 Settings.Global.THEATER_MODE_ON, 0) == 1;
6722 }
6723
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006724 private boolean isGlobalAccessibilityGestureEnabled() {
6725 return Settings.Global.getInt(mContext.getContentResolver(),
6726 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6727 }
6728
Craig Mautnereda67292013-04-28 13:50:14 -07006729 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006730 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006731 if (!mVibrator.hasVibrator()) {
6732 return false;
6733 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006734 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6735 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006736 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006737 return false;
6738 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006739 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006740 switch (effectId) {
6741 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006742 pattern = mLongPressVibePattern;
6743 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006744 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006745 pattern = mVirtualKeyVibePattern;
6746 break;
6747 case HapticFeedbackConstants.KEYBOARD_TAP:
6748 pattern = mKeyboardTapVibePattern;
6749 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006750 case HapticFeedbackConstants.CLOCK_TICK:
6751 pattern = mClockTickVibePattern;
6752 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006753 case HapticFeedbackConstants.CALENDAR_DATE:
6754 pattern = mCalendarDateVibePattern;
6755 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006756 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006757 pattern = mSafeModeDisabledVibePattern;
6758 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006759 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006760 pattern = mSafeModeEnabledVibePattern;
6761 break;
Mady Mellore8608912015-06-05 09:02:55 -07006762 case HapticFeedbackConstants.CONTEXT_CLICK:
6763 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006764 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006765 default:
6766 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006767 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006768 int owningUid;
6769 String owningPackage;
6770 if (win != null) {
6771 owningUid = win.getOwningUid();
6772 owningPackage = win.getOwningPackage();
6773 } else {
6774 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006775 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006776 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006777 if (pattern.length == 1) {
6778 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006779 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006780 } else {
6781 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006782 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006783 }
6784 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006785 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006786
6787 @Override
6788 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006789 }
6790
Jeff Brownc38c9be2012-10-04 13:16:19 -07006791 @Override
6792 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006793 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006794 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006795 }
6796 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006797
Dianne Hackborndf89e652011-10-06 22:35:11 -07006798 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006799 // If there is no window focused, there will be nobody to handle the events
6800 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006801 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6802 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006803 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006804 return 0;
6805 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006806 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006807 // We are updating at a point where the keyguard has gotten
6808 // focus, but we were last in a state where the top window is
6809 // hiding it. This is probably because the keyguard as been
6810 // shown while the top window was displayed, so we want to ignore
6811 // it here because this is just a very transient change and it
6812 // will quickly lose focus once it correctly gets hidden.
6813 return 0;
6814 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006815
John Spurlock1db8b682014-02-18 11:18:59 -05006816 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006817 & ~mResettingSystemUiFlags
6818 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006819 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006820 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006821 }
Thanh Hai Mai6c009f52015-09-01 16:27:32 -07006822
6823 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6824 tmpVisibility |= StatusBarManager.DISABLE_RECENT;
6825 }
6826
Adrian Rooscd3884d2015-02-18 17:25:23 +01006827 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006828 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006829 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006830 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006831 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006832 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006833 return 0;
6834 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006835 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006836 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006837 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006838 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006839 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006840 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006841 try {
6842 IStatusBarService statusbar = getStatusBarService();
6843 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006844 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006845 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006846 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006847 } catch (RemoteException e) {
6848 // re-acquire status bar service next time it is needed.
6849 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006850 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006851 }
6852 });
6853 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006854 }
6855
Adrian Rooscd3884d2015-02-18 17:25:23 +01006856 private int updateLightStatusBarLw(int vis) {
6857 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6858 ? mStatusBar
6859 : mTopFullscreenOpaqueOrDimmingWindowState;
6860
6861 if (statusColorWin != null) {
6862 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6863 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6864 // its light flag.
6865 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6866 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6867 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6868 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6869 // Otherwise if it's dimming, clear the light flag.
6870 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6871 }
6872 }
6873 return vis;
6874 }
6875
John Spurlock79da8332013-09-20 12:04:47 -04006876 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006877 final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
6878 final boolean freeformStackVisible =
6879 mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID);
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08006880 final boolean resizing = mWindowManagerInternal.isDockedDividerResizing();
6881
6882 // We need to force system bars when the docked stack is visible, when the freeform stack
6883 // is visible but also when we are resizing for the transitions when docked stack
6884 // visibility changes.
6885 final boolean forceShowSystemBars = dockedStackVisible || freeformStackVisible || resizing;
Jorim Jaggi4fa78922015-11-30 17:13:56 -08006886 final boolean forceOpaqueSystemBars = forceShowSystemBars && !mForceStatusBarFromKeyguard;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006887
John Spurlockbd957402013-10-03 11:38:39 -04006888 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006889 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6890 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006891 : mTopFullscreenOpaqueWindowState;
6892 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6893 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6894
John Spurlock27735a42013-08-14 17:57:38 -04006895 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006896 int type = win.getAttrs().type;
6897 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006898 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006899 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6900 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006901 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006902 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6903 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006904 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006905 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6906 }
John Spurlockbd957402013-10-03 11:38:39 -04006907 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006908 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006909
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006910 if ((!areTranslucentBarsAllowed() && transWin != mStatusBar)
6911 || forceOpaqueSystemBars) {
Adrian Roosea562512014-05-05 13:33:03 +02006912 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6913 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006914 }
6915
Jorim Jaggi4fa78922015-11-30 17:13:56 -08006916 if (mForceWindowDrawsStatusBarBackground) {
6917 vis |= View.STATUS_BAR_TRANSPARENT;
6918 vis &= ~View.STATUS_BAR_TRANSLUCENT;
6919 }
6920
John Spurlock27735a42013-08-14 17:57:38 -04006921 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006922 boolean immersiveSticky =
6923 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006924 final boolean hideStatusBarWM =
6925 mTopFullscreenOpaqueWindowState != null
6926 && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006927 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006928 final boolean hideStatusBarSysui =
John Spurlock27735a42013-08-14 17:57:38 -04006929 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006930 final boolean hideNavBarSysui =
John Spurlockf1a36642013-10-12 17:50:42 -04006931 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006932
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006933 final boolean transientStatusBarAllowed = mStatusBar != null
6934 && (statusBarHasFocus || (!forceShowSystemBars
6935 && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky))));
John Spurlock27735a42013-08-14 17:57:38 -04006936
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006937 final boolean transientNavBarAllowed = mNavigationBar != null
6938 && !forceShowSystemBars && hideNavBarSysui && immersiveSticky;
John Spurlockf1a36642013-10-12 17:50:42 -04006939
Adrian Roosddc8b272015-05-21 16:28:27 -07006940 final long now = SystemClock.uptimeMillis();
6941 final boolean pendingPanic = mPendingPanicGestureUptime != 0
6942 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
6943 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
6944 // The user performed the panic gesture recently, we're about to hide the bars,
6945 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
6946 mPendingPanicGestureUptime = 0;
6947 mStatusBarController.showTransient();
6948 mNavigationBarController.showTransient();
6949 }
6950
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006951 final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006952 && !transientStatusBarAllowed && hideStatusBarSysui;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006953 final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006954 && !transientNavBarAllowed;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006955 if (denyTransientStatus || denyTransientNav || forceShowSystemBars) {
John Spurlock27735a42013-08-14 17:57:38 -04006956 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006957 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006958 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006959 }
John Spurlock27735a42013-08-14 17:57:38 -04006960
Selim Cinekf98702e2015-05-20 22:48:40 -07006961 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
6962 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
6963 final boolean navAllowedHidden = immersive || immersiveSticky;
6964
Selim Cinekd6623612015-05-22 18:56:22 -07006965 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
6966 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07006967 // We can't hide the navbar from this window otherwise the input consumer would not get
6968 // the input events.
6969 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
6970 }
6971
John Spurlock27735a42013-08-14 17:57:38 -04006972 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6973
6974 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006975 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6976 boolean newImmersiveMode = isImmersiveMode(vis);
6977 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006978 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006979 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6980 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006981 }
John Spurlock27735a42013-08-14 17:57:38 -04006982
John Spurlockf1a36642013-10-12 17:50:42 -04006983 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6984
John Spurlocke1f366f2013-08-05 12:22:40 -04006985 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006986 }
6987
John Spurlockf1a36642013-10-12 17:50:42 -04006988 private void clearClearableFlagsLw() {
6989 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6990 if (newVal != mResettingSystemUiFlags) {
6991 mResettingSystemUiFlags = newVal;
6992 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6993 }
6994 }
6995
6996 private boolean isImmersiveMode(int vis) {
6997 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006998 return mNavigationBar != null
6999 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04007000 && (vis & flags) != 0
7001 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04007002 }
7003
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007004 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007005 * @return whether the navigation or status bar can be made translucent
7006 *
7007 * This should return true unless touch exploration is not enabled or
7008 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007009 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007010 private boolean areTranslucentBarsAllowed() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04007011 return mTranslucentDecorEnabled;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007012 }
7013
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007014 // Use this instead of checking config_showNavigationBar so that it can be consistently
7015 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07007016 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007017 public boolean hasNavigationBar() {
7018 return mHasNavigationBar;
7019 }
7020
satok1bc0a492012-04-25 22:47:12 +09007021 @Override
7022 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
7023 mLastInputMethodWindow = ime;
7024 mLastInputMethodTargetWindow = target;
7025 }
7026
Craig Mautnerf1b67412012-09-19 13:18:29 -07007027 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09007028 public int getInputMethodWindowVisibleHeightLw() {
7029 return mDockBottom - mCurBottom;
7030 }
7031
7032 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07007033 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07007034 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08007035 if (mKeyguardDelegate != null) {
7036 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007037 }
John Spurlock13451a22012-09-28 14:40:41 -04007038 if (mStatusBarService != null) {
7039 try {
7040 mStatusBarService.setCurrentUser(newUserId);
7041 } catch (RemoteException e) {
7042 // oh well
7043 }
7044 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007045 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007046 }
7047
7048 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08007049 public boolean canMagnifyWindow(int windowType) {
7050 switch (windowType) {
7051 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
7052 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
7053 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
7054 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
7055 return false;
7056 }
7057 }
7058 return true;
7059 }
7060
7061 @Override
7062 public boolean isTopLevelWindow(int windowType) {
7063 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
7064 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
7065 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
7066 }
7067 return true;
7068 }
7069
Jim Miller4eeb4f62012-11-08 00:04:29 -08007070 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07007071 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007072 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007073 pw.print(" mSystemReady="); pw.print(mSystemReady);
7074 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07007075 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007076 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07007077 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007078 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07007079 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
7080 || mForceClearedSystemUiFlags != 0) {
7081 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
7082 pw.print(Integer.toHexString(mLastSystemUiFlags));
7083 pw.print(" mResettingSystemUiFlags=0x");
7084 pw.print(Integer.toHexString(mResettingSystemUiFlags));
7085 pw.print(" mForceClearedSystemUiFlags=0x");
7086 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07007087 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007088 if (mLastFocusNeedsMenu) {
7089 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
7090 pw.println(mLastFocusNeedsMenu);
7091 }
Jeff Browna20dda42014-05-27 20:57:24 -07007092 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
7093 pw.println(mWakeGestureEnabledSetting);
7094
Jeff Brownbcdfc622014-03-06 19:13:04 -08007095 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04007096 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
7097 pw.print(" mDockMode="); pw.print(mDockMode);
keunyounga7710492015-09-23 11:33:58 -07007098 pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007099 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
7100 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
7101 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
7102 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05007103 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007104 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007105 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
7106 pw.print(mCarDockEnablesAccelerometer);
7107 pw.print(" mDeskDockEnablesAccelerometer=");
7108 pw.println(mDeskDockEnablesAccelerometer);
7109 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
7110 pw.print(mLidKeyboardAccessibility);
7111 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01007112 pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007113 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007114 pw.print(prefix);
7115 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
7116 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07007117 pw.print(prefix);
7118 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
7119 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007120 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07007121 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
7122 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
7123 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
7124 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
7125 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
7126 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
7127 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08007128 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
7129 pw.print(","); pw.print(mOverscanScreenTop);
7130 pw.print(") "); pw.print(mOverscanScreenWidth);
7131 pw.print("x"); pw.println(mOverscanScreenHeight);
7132 if (mOverscanLeft != 0 || mOverscanTop != 0
7133 || mOverscanRight != 0 || mOverscanBottom != 0) {
7134 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
7135 pw.print(" top="); pw.print(mOverscanTop);
7136 pw.print(" right="); pw.print(mOverscanRight);
7137 pw.print(" bottom="); pw.println(mOverscanBottom);
7138 }
Dianne Hackborn313440842013-02-19 19:22:59 -08007139 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
7140 pw.print(mRestrictedOverscanScreenLeft);
7141 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
7142 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
7143 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007144 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
7145 pw.print(","); pw.print(mUnrestrictedScreenTop);
7146 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
7147 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
7148 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
7149 pw.print(","); pw.print(mRestrictedScreenTop);
7150 pw.print(") "); pw.print(mRestrictedScreenWidth);
7151 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07007152 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
7153 pw.print(","); pw.print(mStableFullscreenTop);
7154 pw.print(")-("); pw.print(mStableFullscreenRight);
7155 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07007156 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
7157 pw.print(","); pw.print(mStableTop);
7158 pw.print(")-("); pw.print(mStableRight);
7159 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007160 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
7161 pw.print(","); pw.print(mSystemTop);
7162 pw.print(")-("); pw.print(mSystemRight);
7163 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007164 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
7165 pw.print(","); pw.print(mCurTop);
7166 pw.print(")-("); pw.print(mCurRight);
7167 pw.print(","); pw.print(mCurBottom); pw.println(")");
7168 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
7169 pw.print(","); pw.print(mContentTop);
7170 pw.print(")-("); pw.print(mContentRight);
7171 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07007172 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
7173 pw.print(","); pw.print(mVoiceContentTop);
7174 pw.print(")-("); pw.print(mVoiceContentRight);
7175 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007176 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
7177 pw.print(","); pw.print(mDockTop);
7178 pw.print(")-("); pw.print(mDockRight);
7179 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007180 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
7181 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007182 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
7183 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07007184 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
7185 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007186 if (mLastInputMethodWindow != null) {
7187 pw.print(prefix); pw.print("mLastInputMethodWindow=");
7188 pw.println(mLastInputMethodWindow);
7189 }
7190 if (mLastInputMethodTargetWindow != null) {
7191 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
7192 pw.println(mLastInputMethodTargetWindow);
7193 }
7194 if (mStatusBar != null) {
7195 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08007196 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
7197 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007198 }
7199 if (mNavigationBar != null) {
7200 pw.print(prefix); pw.print("mNavigationBar=");
7201 pw.println(mNavigationBar);
7202 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007203 if (mFocusedWindow != null) {
7204 pw.print(prefix); pw.print("mFocusedWindow=");
7205 pw.println(mFocusedWindow);
7206 }
7207 if (mFocusedApp != null) {
7208 pw.print(prefix); pw.print("mFocusedApp=");
7209 pw.println(mFocusedApp);
7210 }
7211 if (mWinDismissingKeyguard != null) {
7212 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
7213 pw.println(mWinDismissingKeyguard);
7214 }
7215 if (mTopFullscreenOpaqueWindowState != null) {
7216 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
7217 pw.println(mTopFullscreenOpaqueWindowState);
7218 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01007219 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
7220 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
7221 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
7222 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007223 if (mForcingShowNavBar) {
7224 pw.print(prefix); pw.print("mForcingShowNavBar=");
7225 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
7226 pw.println(mForcingShowNavBarLayer);
7227 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007228 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007229 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007230 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
7231 pw.print(" mForceStatusBarFromKeyguard=");
7232 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007233 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07007234 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007235 pw.print(" mHomePressed="); pw.println(mHomePressed);
7236 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
7237 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
7238 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
7239 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
7240 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
7241 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
7242 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
7243 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
7244 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
7245 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07007246 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
7247 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
7248 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07007249
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07007250 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04007251 mStatusBarController.dump(pw, prefix);
7252 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05007253 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07007254
Jeff Browna20dda42014-05-27 20:57:24 -07007255 if (mWakeGestureListener != null) {
7256 mWakeGestureListener.dump(pw, prefix);
7257 }
Jeff Brown600f0032014-05-22 17:06:00 -07007258 if (mOrientationListener != null) {
7259 mOrientationListener.dump(pw, prefix);
7260 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00007261 if (mBurnInProtectionHelper != null) {
7262 mBurnInProtectionHelper.dump(prefix, pw);
7263 }
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07007264 if (mKeyguardDelegate != null) {
7265 mKeyguardDelegate.dump(prefix, pw);
7266 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007267 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007268}