blob: 3b61817620d9d38eaffc75d93ddd1739ac7244bf [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;
661
662 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
663 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
Jeff Brown70825162012-03-28 17:27:48 -0700664
665 private class PolicyHandler extends Handler {
666 @Override
667 public void handleMessage(Message msg) {
668 switch (msg.what) {
669 case MSG_ENABLE_POINTER_LOCATION:
670 enablePointerLocation();
671 break;
672 case MSG_DISABLE_POINTER_LOCATION:
673 disablePointerLocation();
674 break;
Jeff Brown40013652012-05-16 21:22:36 -0700675 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
676 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
677 break;
678 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
679 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
680 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700681 case MSG_DISPATCH_SHOW_RECENTS:
682 showRecentApps(false);
683 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700684 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
685 showGlobalActionsInternal();
686 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700687 case MSG_KEYGUARD_DRAWN_COMPLETE:
688 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700689 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700690 break;
691 case MSG_KEYGUARD_DRAWN_TIMEOUT:
692 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700693 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700694 break;
695 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
696 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700697 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700698 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700699 case MSG_HIDE_BOOT_MESSAGE:
700 handleHideBootMessage();
701 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700702 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
703 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
704 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700705 case MSG_POWER_DELAYED_PRESS:
706 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
707 finishPowerKeyPress();
708 break;
709 case MSG_POWER_LONG_PRESS:
710 powerLongPress();
711 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700712 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
713 updateDreamingSleepToken(msg.arg1 != 0);
714 break;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700715 case MSG_REQUEST_TRANSIENT_BARS:
716 WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ?
717 mStatusBar : mNavigationBar;
718 if (targetBar != null) {
719 requestTransientBars(targetBar);
720 }
721 break;
Jeff Brown70825162012-03-28 17:27:48 -0700722 }
723 }
724 }
725
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800726 private UEventObserver mHDMIObserver = new UEventObserver() {
727 @Override
728 public void onUEvent(UEventObserver.UEvent event) {
729 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
730 }
731 };
732
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800733 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800734 SettingsObserver(Handler handler) {
735 super(handler);
736 }
David Brownbaf8d092010-03-08 21:52:59 -0800737
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800738 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700739 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800740 ContentResolver resolver = mContext.getContentResolver();
741 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700742 Settings.System.END_BUTTON_BEHAVIOR), false, this,
743 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800744 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700745 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
746 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700747 resolver.registerContentObserver(Settings.Secure.getUriFor(
748 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
749 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800750 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700751 Settings.System.ACCELEROMETER_ROTATION), false, this,
752 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500753 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700754 Settings.System.USER_ROTATION), false, this,
755 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400756 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700757 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
758 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800759 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700760 Settings.System.POINTER_LOCATION), false, this,
761 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800762 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700763 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
764 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500765 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400766 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700767 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500768 resolver.registerContentObserver(Settings.Global.getUriFor(
769 Settings.Global.POLICY_CONTROL), false, this,
770 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800771 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800772 }
773
774 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800775 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700776 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800777 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800778 }
Craig Mautner967212c2013-04-13 21:10:58 -0700779
Jeff Browna20dda42014-05-27 20:57:24 -0700780 class MyWakeGestureListener extends WakeGestureListener {
781 MyWakeGestureListener(Context context, Handler handler) {
782 super(context, handler);
783 }
784
785 @Override
786 public void onWakeUp() {
787 synchronized (mLock) {
788 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700789 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700790 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture,
791 "android.policy:GESTURE");
Jeff Browna20dda42014-05-27 20:57:24 -0700792 }
793 }
794 }
795 }
796
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800797 class MyOrientationListener extends WindowOrientationListener {
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700798 private final Runnable mUpdateRotationRunnable = new Runnable() {
799 @Override
800 public void run() {
Tim Murray1f407642015-10-01 17:07:12 -0700801 // send interaction hint to improve redraw performance
802 mPowerManagerInternal.powerHint(PowerManagerInternal.POWER_HINT_INTERACTION, 0);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700803 updateRotation(false);
804 }
805 };
806
Craig Mautnereee29c42013-01-17 14:44:34 -0800807 MyOrientationListener(Context context, Handler handler) {
808 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800809 }
Craig Mautner967212c2013-04-13 21:10:58 -0700810
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800811 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700812 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700813 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700814 mHandler.post(mUpdateRotationRunnable);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700815 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800816 }
817 MyOrientationListener mOrientationListener;
818
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100819 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400820
John Spurlock27735a42013-08-14 17:57:38 -0400821 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400822 View.NAVIGATION_BAR_TRANSIENT,
823 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400824 View.NAVIGATION_BAR_TRANSLUCENT,
825 StatusBarManager.WINDOW_NAVIGATION_BAR,
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800826 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
827 View.NAVIGATION_BAR_TRANSPARENT);
John Spurlock5b9145b2013-08-20 15:13:47 -0400828
John Spurlockf1a36642013-10-12 17:50:42 -0400829 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400830
Craig Mautner037aa8d2013-06-07 10:35:44 -0700831 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400832
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700833 IStatusBarService getStatusBarService() {
834 synchronized (mServiceAquireLock) {
835 if (mStatusBarService == null) {
836 mStatusBarService = IStatusBarService.Stub.asInterface(
837 ServiceManager.getService("statusbar"));
838 }
839 return mStatusBarService;
840 }
841 }
842
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700843 /*
844 * We always let the sensor be switched on by default except when
845 * the user has explicitly disabled sensor based rotation or when the
846 * screen is switched off.
847 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700848 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800849 if (mSupportAutoRotation) {
850 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
851 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
852 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
853 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
854 // If the application has explicitly requested to follow the
855 // orientation, then we need to turn the sensor on.
856 return true;
857 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800858 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700859 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800860 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
861 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
862 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400863 // enable accelerometer if we are docked in a dock that enables accelerometer
864 // orientation management,
865 return true;
866 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700867 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800868 // If the setting for using the sensor by default is enabled, then
869 // we will always leave it on. Note that the user could go to
870 // a window that forces an orientation that does not use the
871 // sensor and in theory we could turn it off... however, when next
872 // turning it on we won't have a good value for the current
873 // orientation for a little bit, which can cause orientation
874 // changes to lag, so we'd like to keep it always on. (It will
875 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700876 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800877 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800878 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800879 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700880
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800881 /*
882 * Various use cases for invoking this function
883 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700884 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800885 * if not already enabled
886 * screen turned on and current app does not have sensor orientation, disable listeners if
887 * already enabled
888 * screen turning on and current app has sensor based orientation, enable listeners if needed
889 * screen turning on and current app has nosensor based orientation, do nothing
890 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700891 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800892 if (!mOrientationListener.canDetectOrientation()) {
893 // If sensor is turned off or nonexistent for some reason
894 return;
895 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000896 // Could have been invoked due to screen turning on or off or
897 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -0700898 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
899 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000900 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
901 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
902 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800903 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000904 // Note: We postpone the rotating of the screen until the keyguard as well as the
905 // window manager have reported a draw complete.
906 if (mScreenOnEarly && mAwake &&
907 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700908 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800909 disable = false;
910 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700911 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800912 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700913 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800914 mOrientationSensorEnabled = true;
915 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700916 }
917 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800918 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700919 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800920 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700921 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800922 mOrientationSensorEnabled = false;
923 }
924 }
925
Jeff Brown13f00f02014-10-31 14:45:50 -0700926 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
927 // Hold a wake lock until the power key is released.
928 if (!mPowerKeyWakeLock.isHeld()) {
929 mPowerKeyWakeLock.acquire();
930 }
931
932 // Cancel multi-press detection timeout.
933 if (mPowerKeyPressCounter != 0) {
934 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
935 }
936
937 // Detect user pressing the power button in panic when an application has
938 // taken over the whole screen.
939 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800940 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700941 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700942 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700943 }
944
945 // Latch power key state to detect screenshot chord.
946 if (interactive && !mScreenshotChordPowerKeyTriggered
947 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
948 mScreenshotChordPowerKeyTriggered = true;
949 mScreenshotChordPowerKeyTime = event.getDownTime();
950 interceptScreenshotChord();
951 }
952
953 // Stop ringing or end call if configured to do so when power is pressed.
954 TelecomManager telecomManager = getTelecommService();
955 boolean hungUp = false;
956 if (telecomManager != null) {
957 if (telecomManager.isRinging()) {
958 // Pressing Power while there's a ringing incoming
959 // call should silence the ringer.
960 telecomManager.silenceRinger();
961 } else if ((mIncallPowerBehavior
962 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
963 && telecomManager.isInCall() && interactive) {
964 // Otherwise, if "Power button ends call" is enabled,
965 // the Power button will hang up any current active call.
966 hungUp = telecomManager.endCall();
967 }
968 }
969
Adrian Roos5941c982015-09-03 15:59:49 -0700970 GestureLauncherService gestureService = LocalServices.getService(
971 GestureLauncherService.class);
972 boolean gesturedServiceIntercepted = false;
973 if (gestureService != null) {
974 gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive);
975 }
976
Jeff Brown13f00f02014-10-31 14:45:50 -0700977 // If the power key has still not yet been handled, then detect short
978 // press, long press, or multi press and decide what to do.
979 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
Adrian Roos5941c982015-09-03 15:59:49 -0700980 || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted;
Jeff Brown13f00f02014-10-31 14:45:50 -0700981 if (!mPowerKeyHandled) {
982 if (interactive) {
983 // When interactive, we're already awake.
984 // Wait for a long press or for the button to be released to decide what to do.
985 if (hasLongPressOnPowerBehavior()) {
986 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
987 msg.setAsynchronous(true);
988 mHandler.sendMessageDelayed(msg,
989 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
990 }
991 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800992 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800993
Bryce Leed3b28402015-03-09 15:49:13 +0000994 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
995 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
996 msg.setAsynchronous(true);
997 mHandler.sendMessageDelayed(msg,
998 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800999 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +00001000 } else {
1001 final int maxCount = getMaxMultiPressPowerCount();
1002
1003 if (maxCount <= 1) {
1004 mPowerKeyHandled = true;
1005 } else {
1006 mBeganFromNonInteractive = true;
1007 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001008 }
1009 }
Jeff Brown4d396052010-10-29 21:50:21 -07001010 }
1011 }
1012
Jeff Brown13f00f02014-10-31 14:45:50 -07001013 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
1014 final boolean handled = canceled || mPowerKeyHandled;
1015 mScreenshotChordPowerKeyTriggered = false;
1016 cancelPendingScreenshotChordAction();
1017 cancelPendingPowerKeyAction();
1018
1019 if (!handled) {
1020 // Figure out how to handle the key now that it has been released.
1021 mPowerKeyPressCounter += 1;
1022
1023 final int maxCount = getMaxMultiPressPowerCount();
1024 final long eventTime = event.getDownTime();
1025 if (mPowerKeyPressCounter < maxCount) {
1026 // This could be a multi-press. Wait a little bit longer to confirm.
1027 // Continue holding the wake lock.
1028 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
1029 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
1030 msg.setAsynchronous(true);
1031 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
1032 return;
1033 }
1034
1035 // No other actions. Handle it immediately.
1036 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -07001037 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001038
1039 // Done. Reset our state.
1040 finishPowerKeyPress();
1041 }
1042
1043 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -08001044 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001045 mPowerKeyPressCounter = 0;
1046 if (mPowerKeyWakeLock.isHeld()) {
1047 mPowerKeyWakeLock.release();
1048 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001049 }
1050
1051 private void cancelPendingPowerKeyAction() {
1052 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001053 mPowerKeyHandled = true;
1054 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001055 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001056 }
1057
1058 private void powerPress(long eventTime, boolean interactive, int count) {
1059 if (mScreenOnEarly && !mScreenOnFully) {
1060 Slog.i(TAG, "Suppressed redundant power key press while "
1061 + "already in the process of turning the screen on.");
1062 return;
Jeff Brownff204712011-10-25 21:27:54 -07001063 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001064
1065 if (count == 2) {
1066 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1067 } else if (count == 3) {
1068 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001069 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001070 switch (mShortPressOnPowerBehavior) {
1071 case SHORT_PRESS_POWER_NOTHING:
1072 break;
1073 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1074 mPowerManager.goToSleep(eventTime,
1075 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1076 break;
1077 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1078 mPowerManager.goToSleep(eventTime,
1079 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1080 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1081 break;
1082 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1083 mPowerManager.goToSleep(eventTime,
1084 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1085 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1086 launchHomeFromHotKey();
1087 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001088 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001089 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001090 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001091 }
1092 }
1093 }
1094
1095 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1096 switch (behavior) {
1097 case MULTI_PRESS_POWER_NOTHING:
1098 break;
1099 case MULTI_PRESS_POWER_THEATER_MODE:
Bryce Lee3ae447e2015-06-30 12:31:41 -07001100 if (!isUserSetupComplete()) {
1101 Slog.i(TAG, "Ignoring toggling theater mode - device not setup.");
1102 break;
1103 }
1104
Jeff Brown13f00f02014-10-31 14:45:50 -07001105 if (isTheaterModeEnabled()) {
1106 Slog.i(TAG, "Toggling theater mode off.");
1107 Settings.Global.putInt(mContext.getContentResolver(),
1108 Settings.Global.THEATER_MODE_ON, 0);
1109 if (!interactive) {
1110 wakeUpFromPowerKey(eventTime);
1111 }
1112 } else {
1113 Slog.i(TAG, "Toggling theater mode on.");
1114 Settings.Global.putInt(mContext.getContentResolver(),
1115 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001116
1117 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001118 mPowerManager.goToSleep(eventTime,
1119 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1120 }
1121 }
1122 break;
1123 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001124 Slog.i(TAG, "Starting brightness boost.");
1125 if (!interactive) {
1126 wakeUpFromPowerKey(eventTime);
1127 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001128 mPowerManager.boostScreenBrightness(eventTime);
1129 break;
1130 }
1131 }
1132
1133 private int getMaxMultiPressPowerCount() {
1134 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1135 return 3;
1136 }
1137 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1138 return 2;
1139 }
1140 return 1;
1141 }
1142
1143 private void powerLongPress() {
1144 final int behavior = getResolvedLongPressOnPowerBehavior();
1145 switch (behavior) {
1146 case LONG_PRESS_POWER_NOTHING:
1147 break;
1148 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1149 mPowerKeyHandled = true;
1150 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1151 performAuditoryFeedbackForAccessibilityIfNeed();
1152 }
1153 showGlobalActionsInternal();
1154 break;
1155 case LONG_PRESS_POWER_SHUT_OFF:
1156 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1157 mPowerKeyHandled = true;
1158 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1159 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1160 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1161 break;
1162 }
1163 }
1164
Nick Vaccarob593a812015-05-15 11:23:05 -07001165 private void sleepPress(long eventTime) {
1166 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1167 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1168 }
1169 }
1170
1171 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001172 switch (mShortPressOnSleepBehavior) {
1173 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001174 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001175 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1176 mPowerManager.goToSleep(eventTime,
1177 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001178 break;
1179 }
1180 }
1181
Jeff Brown13f00f02014-10-31 14:45:50 -07001182 private int getResolvedLongPressOnPowerBehavior() {
1183 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1184 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1185 }
1186 return mLongPressOnPowerBehavior;
1187 }
1188
1189 private boolean hasLongPressOnPowerBehavior() {
1190 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001191 }
1192
1193 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001194 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001195 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1196 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001197 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001198 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1199 && now <= mScreenshotChordPowerKeyTime
1200 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1201 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001202 cancelPendingPowerKeyAction();
1203
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001204 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001205 }
1206 }
1207 }
1208
Winson Chung1cea2f32012-10-08 20:42:01 -07001209 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001210 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001211 // Double the time it takes to take a screenshot from the keyguard
1212 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001213 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001214 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001215 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001216 }
1217
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001218 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001219 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001220 }
1221
Jeff Brown13f00f02014-10-31 14:45:50 -07001222 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001223 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001224 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001225 mEndCallKeyHandled = true;
1226 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1227 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001228 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001229 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001230 }
1231 };
1232
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001233 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001234 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001235 public void run() {
1236 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001237 }
1238 };
1239
Alan Viverettee34560b22014-07-10 14:50:06 -07001240 @Override
1241 public void showGlobalActions() {
1242 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1243 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1244 }
1245
1246 void showGlobalActionsInternal() {
1247 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001248 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001249 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001250 }
Jim Millerab954542014-10-10 18:21:49 -07001251 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001252 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1253 if (keyguardShowing) {
1254 // since it took two seconds of long press to bring this up,
1255 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001256 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001257 }
1258 }
1259
1260 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001261 return Settings.Global.getInt(
1262 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001263 }
1264
Maurice Lam99c6e072014-04-28 18:24:28 -07001265 boolean isUserSetupComplete() {
1266 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1267 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1268 }
1269
Jeff Brown13f00f02014-10-31 14:45:50 -07001270 private void handleShortPressOnHome() {
Jinsuk Kime601b712015-07-07 08:01:02 +09001271 // Turn on the connected TV and switch HDMI input if we're a HDMI playback device.
1272 getHdmiControl().turnOnTv();
1273
Jeff Brown13f00f02014-10-31 14:45:50 -07001274 // If there's a dream running then use home to escape the dream
1275 // but don't actually go home.
1276 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1277 mDreamManagerInternal.stopDream(false /*immediate*/);
1278 return;
1279 }
1280
1281 // Go home!
1282 launchHomeFromHotKey();
1283 }
1284
Jinsuk Kime601b712015-07-07 08:01:02 +09001285 /**
1286 * Creates an accessor to HDMI control service that performs the operation of
1287 * turning on TV (optional) and switching input to us. If HDMI control service
1288 * is not available or we're not a HDMI playback device, the operation is no-op.
1289 */
1290 private HdmiControl getHdmiControl() {
1291 if (null == mHdmiControl) {
1292 HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService(
1293 Context.HDMI_CONTROL_SERVICE);
1294 HdmiPlaybackClient client = null;
1295 if (manager != null) {
1296 client = manager.getPlaybackClient();
1297 }
1298 mHdmiControl = new HdmiControl(client);
1299 }
1300 return mHdmiControl;
1301 }
1302
1303 private static class HdmiControl {
1304 private final HdmiPlaybackClient mClient;
1305
1306 private HdmiControl(HdmiPlaybackClient client) {
1307 mClient = client;
1308 }
1309
1310 public void turnOnTv() {
1311 if (mClient == null) {
1312 return;
1313 }
1314 mClient.oneTouchPlay(new OneTouchPlayCallback() {
1315 @Override
1316 public void onComplete(int result) {
1317 if (result != HdmiControlManager.RESULT_SUCCESS) {
1318 Log.w(TAG, "One touch play failed: " + result);
1319 }
1320 }
1321 });
1322 }
1323 }
1324
Jaewan Kim52632e22016-01-14 18:01:52 +09001325 private void handleLongPressOnHome(int deviceId, KeyEvent event) {
1326 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) {
1327 return;
1328 }
1329 mHomeConsumed = true;
1330 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001331
Jaewan Kim52632e22016-01-14 18:01:52 +09001332 switch (mLongPressOnHomeBehavior) {
1333 case LONG_PRESS_HOME_RECENT_SYSTEM_UI:
Jeff Browncaca8812013-05-09 13:34:33 -07001334 toggleRecentApps();
Jaewan Kim52632e22016-01-14 18:01:52 +09001335 break;
1336 case LONG_PRESS_HOME_ASSIST:
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001337 launchAssistAction(null, deviceId);
Jaewan Kim52632e22016-01-14 18:01:52 +09001338 break;
1339 case LONG_PRESS_HOME_PICTURE_IN_PICTURE:
1340 handlePipKey(event);
1341 break;
1342 default:
1343 Log.w(TAG, "Not defined home long press behavior: " + mLongPressOnHomeBehavior);
1344 break;
Jim Millere6ad1a82010-08-20 19:25:39 -07001345 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001346 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001347
Jeff Browncaca8812013-05-09 13:34:33 -07001348 private void handleDoubleTapOnHome() {
1349 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1350 mHomeConsumed = true;
1351 toggleRecentApps();
1352 }
1353 }
1354
Jaewan Kim52632e22016-01-14 18:01:52 +09001355 private void handlePipKey(KeyEvent event) {
1356 if (DEBUG_INPUT) Log.d(TAG, "handlePipKey event=" + event);
1357 Intent intent = new Intent(Intent.ACTION_PICTURE_IN_PICTURE_BUTTON);
1358 intent.putExtra(Intent.EXTRA_KEY_EVENT, event);
1359 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
1360 }
1361
Jeff Browncaca8812013-05-09 13:34:33 -07001362 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1363 @Override
1364 public void run() {
1365 if (mHomeDoubleTapPending) {
1366 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001367 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001368 }
1369 }
1370 };
1371
Mark Renoufc1256912015-03-11 14:38:23 -04001372 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001373 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001374 }
1375
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001376 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001377 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001378 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001379 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001380 mContext = context;
1381 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001382 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001383 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001384 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001385 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Michael Wrighta4d22d72015-09-16 23:19:26 +01001386 mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001387 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Mark Renoufc1256912015-03-11 14:38:23 -04001388
1389 // Init display burn-in protection
1390 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1391 com.android.internal.R.bool.config_enableBurnInProtection);
1392 // Allow a system property to override this. Used by developer settings.
1393 boolean burnInProtectionDevMode =
1394 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1395 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1396 final int minHorizontal;
1397 final int maxHorizontal;
1398 final int minVertical;
1399 final int maxVertical;
1400 final int maxRadius;
1401 if (burnInProtectionDevMode) {
1402 minHorizontal = -8;
1403 maxHorizontal = 8;
1404 minVertical = -8;
1405 maxVertical = -4;
1406 maxRadius = (isRoundWindow()) ? 6 : -1;
1407 } else {
1408 Resources resources = context.getResources();
1409 minHorizontal = resources.getInteger(
1410 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1411 maxHorizontal = resources.getInteger(
1412 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1413 minVertical = resources.getInteger(
1414 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1415 maxVertical = resources.getInteger(
1416 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1417 maxRadius = resources.getInteger(
1418 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1419 }
1420 mBurnInProtectionHelper = new BurnInProtectionHelper(
1421 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001422 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001423
Jeff Brown70825162012-03-28 17:27:48 -07001424 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001425 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001426 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001427 try {
1428 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1429 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001430 mSettingsObserver = new SettingsObserver(mHandler);
1431 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001432 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001433 mUiMode = context.getResources().getInteger(
1434 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001435 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1436 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1437 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1438 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
keunyounga7710492015-09-23 11:33:58 -07001439 mEnableCarDockHomeCapture = context.getResources().getBoolean(
1440 com.android.internal.R.bool.config_enableCarDockHomeLaunch);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001441 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1442 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1443 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1444 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1445 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1446 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1447 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1448 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001449
Jeff Brown96307042012-07-27 15:51:34 -07001450 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1451 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001452 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001453 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1454 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001455 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001456 mSupportAutoRotation = mContext.getResources().getBoolean(
1457 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001458 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001459 com.android.internal.R.integer.config_lidOpenRotation);
1460 mCarDockRotation = readRotation(
1461 com.android.internal.R.integer.config_carDockRotation);
1462 mDeskDockRotation = readRotation(
1463 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001464 mUndockedHdmiRotation = readRotation(
1465 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001466 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1467 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1468 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1469 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001470 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1471 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1472 mLidNavigationAccessibility = mContext.getResources().getInteger(
1473 com.android.internal.R.integer.config_lidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01001474 mLidControlsScreenLock = mContext.getResources().getBoolean(
1475 com.android.internal.R.bool.config_lidControlsScreenLock);
Jeff Brownc458ce92012-04-30 14:58:40 -07001476 mLidControlsSleep = mContext.getResources().getBoolean(
1477 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001478 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1479 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001480
1481 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1482 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1483 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1484 || mContext.getResources().getBoolean(
1485 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1486 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1487 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001488 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1489 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001490 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1491 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1492 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1493 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1494 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1495 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1496
Bryce Lee55e846d2014-11-04 12:43:44 -08001497 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1498 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1499
Bryce Leed3b28402015-03-09 15:49:13 +00001500 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1501 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1502
Jeff Brown13f00f02014-10-31 14:45:50 -07001503 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1504 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1505 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1506 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1507 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1508 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1509 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1510 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001511 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1512 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001513
John Spurlock61560172015-02-06 19:46:04 -05001514 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001515
Jeff Brownf71343d2013-05-31 17:59:11 -07001516 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001517
Svetoslav8e3feb12014-02-24 13:46:47 -08001518 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1519 Context.ACCESSIBILITY_SERVICE);
1520
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001521 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001522 IntentFilter filter = new IntentFilter();
1523 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1524 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1525 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1526 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001527 filter.addAction(Intent.ACTION_DOCK_EVENT);
1528 Intent intent = context.registerReceiver(mDockReceiver, filter);
1529 if (intent != null) {
1530 // Retrieve current sticky dock event broadcast.
1531 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1532 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1533 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001534
Jeff Brown6aaf2952012-10-05 16:01:08 -07001535 // register for dream-related broadcasts
1536 filter = new IntentFilter();
1537 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1538 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1539 context.registerReceiver(mDreamReceiver, filter);
1540
Christopher Tate5e08af02012-09-21 17:17:22 -07001541 // register for multiuser-relevant broadcasts
1542 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1543 context.registerReceiver(mMultiuserReceiver, filter);
1544
John Spurlock57306e62013-04-22 09:48:49 -04001545 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001546 mSystemGestures = new SystemGesturesPointerEventListener(context,
1547 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001548 @Override
1549 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001550 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001551 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001552 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001553 }
1554 @Override
1555 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001556 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001557 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001558 }
1559 }
1560 @Override
1561 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001562 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001563 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001564 }
1565 }
1566 @Override
Michael Wrighta4d22d72015-09-16 23:19:26 +01001567 public void onFling(int duration) {
1568 if (mPowerManagerInternal != null) {
1569 mPowerManagerInternal.powerHint(
1570 PowerManagerInternal.POWER_HINT_INTERACTION, duration);
1571 }
1572 }
1573 @Override
John Spurlockad3e6cb2013-04-30 08:47:43 -04001574 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001575 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001576 }
Adrian Roos3595be42015-03-05 16:31:15 +01001577 @Override
1578 public void onDown() {
1579 mOrientationListener.onTouchStart();
1580 }
1581 @Override
1582 public void onUpOrCancel() {
1583 mOrientationListener.onTouchEnd();
1584 }
Jun Mukaid2e7e352015-07-22 17:14:02 -07001585 @Override
1586 public void onMouseHoverAtTop() {
1587 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1588 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1589 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS;
1590 mHandler.sendMessageDelayed(msg, 500);
1591 }
1592 @Override
1593 public void onMouseHoverAtBottom() {
1594 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1595 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1596 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION;
1597 mHandler.sendMessageDelayed(msg, 500);
1598 }
1599 @Override
1600 public void onMouseLeaveFromEdge() {
1601 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1602 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001603 });
John Spurlockf1a36642013-10-12 17:50:42 -04001604 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001605 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001606
Jeff Brownc2346132012-04-13 01:55:38 -07001607 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001608 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1609 com.android.internal.R.array.config_longPressVibePattern);
1610 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1611 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001612 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1613 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001614 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1615 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001616 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1617 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001618 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1619 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1620 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1621 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001622 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1623 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001624
Christopher Tatee90585f2012-03-05 18:56:25 -08001625 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1626 com.android.internal.R.bool.config_enableScreenshotChord);
Jorim Jaggi406585a2015-12-21 10:58:56 +01001627 mForceWindowDrawsStatusBarBackground = mContext.getResources().getBoolean(
1628 R.bool.config_forceWindowDrawsStatusBarBackground);
Christopher Tatee90585f2012-03-05 18:56:25 -08001629
Justin Kohd378ad72013-04-01 12:18:26 -07001630 mGlobalKeyManager = new GlobalKeyManager(mContext);
1631
Joe Onoratoea495d42011-04-06 11:41:11 -07001632 // Controls rotation and the like.
1633 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001634
1635 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001636 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001637 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1638 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001639 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001640
1641 mWindowManagerInternal.registerAppTransitionListener(
1642 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001643 }
1644
Jeff Brownf71343d2013-05-31 17:59:11 -07001645 /**
1646 * Read values from config.xml that may be overridden depending on
1647 * the configuration of the device.
1648 * eg. Disable long press on home goes to recents on sw600dp.
1649 */
1650 private void readConfigurationDependentBehaviors() {
1651 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1652 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1653 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
Jaewan Kim52632e22016-01-14 18:01:52 +09001654 mLongPressOnHomeBehavior > LAST_LONG_PRESS_HOME_BEHAVIOR) {
Jeff Brownf71343d2013-05-31 17:59:11 -07001655 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1656 }
1657
1658 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1659 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1660 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1661 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1662 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1663 }
Jaewan Kim49117872016-01-19 17:24:08 +09001664
1665 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_NOTHING;
1666 if (mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)) {
1667 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE;
1668 }
Jeff Brownf71343d2013-05-31 17:59:11 -07001669 }
1670
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001671 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001672 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001673 // This method might be called before the policy has been fully initialized
1674 // or for other displays we don't care about.
1675 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1676 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001677 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001678 mDisplay = display;
1679
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001680 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001681 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001682 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001683 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001684 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001685 mLandscapeRotation = Surface.ROTATION_0;
1686 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001687 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001688 mPortraitRotation = Surface.ROTATION_90;
1689 mUpsideDownRotation = Surface.ROTATION_270;
1690 } else {
1691 mPortraitRotation = Surface.ROTATION_270;
1692 mUpsideDownRotation = Surface.ROTATION_90;
1693 }
1694 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001695 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001696 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001697 mPortraitRotation = Surface.ROTATION_0;
1698 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001699 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001700 mLandscapeRotation = Surface.ROTATION_270;
1701 mSeascapeRotation = Surface.ROTATION_90;
1702 } else {
1703 mLandscapeRotation = Surface.ROTATION_90;
1704 mSeascapeRotation = Surface.ROTATION_270;
1705 }
1706 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001707
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001708 mStatusBarHeight =
1709 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001710
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001711 // Height of the navigation bar when presented horizontally at bottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001712 mNavigationBarHeightForRotationDefault[mPortraitRotation] =
1713 mNavigationBarHeightForRotationDefault[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001714 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001715 mNavigationBarHeightForRotationDefault[mLandscapeRotation] =
1716 mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize(
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001717 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001718
1719 // Width of the navigation bar when presented vertically along one side
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001720 mNavigationBarWidthForRotationDefault[mPortraitRotation] =
1721 mNavigationBarWidthForRotationDefault[mUpsideDownRotation] =
1722 mNavigationBarWidthForRotationDefault[mLandscapeRotation] =
1723 mNavigationBarWidthForRotationDefault[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001724 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001725
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001726 // Height of the navigation bar when presented horizontally at bottom
1727 mNavigationBarHeightForRotationInCarMode[mPortraitRotation] =
1728 mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] =
1729 res.getDimensionPixelSize(
1730 com.android.internal.R.dimen.navigation_bar_height_car_mode);
1731 mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] =
1732 mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize(
1733 com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode);
1734
1735 // Width of the navigation bar when presented vertically along one side
1736 mNavigationBarWidthForRotationInCarMode[mPortraitRotation] =
1737 mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] =
1738 mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] =
1739 mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] =
1740 res.getDimensionPixelSize(
1741 com.android.internal.R.dimen.navigation_bar_width_car_mode);
1742
Daniel Sandler4a066c52012-04-20 14:49:13 -04001743 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001744 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001745 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001746
Devin Kimd7b12b42014-05-05 14:34:58 -07001747 // Allow the navigation bar to move on non-square small devices (phones).
1748 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001749
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001750 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001751 // Allow a system property to override this. Used by the emulator.
1752 // See also hasNavigationBar().
1753 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1754 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001755 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001756 } else if ("0".equals(navBarOverride)) {
1757 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001758 }
1759
Jeff Brown27f1d672012-10-17 18:32:34 -07001760 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1761 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001762 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001763 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001764 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001765 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001766 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001767 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001768
Chong Zhangae6119ff2014-11-11 18:54:39 -08001769 // For demo purposes, allow the rotation of the remote display to be controlled.
1770 // By default, remote display locks rotation to landscape.
1771 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1772 mDemoRotation = mPortraitRotation;
1773 } else {
1774 mDemoRotation = mLandscapeRotation;
1775 }
1776 mDemoRotationLock = SystemProperties.getBoolean(
1777 "persist.demo.rotationlock", false);
1778
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001779 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1780 // http://developer.android.com/guide/practices/screens_support.html#range
1781 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1782 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1783 // For debug purposes the next line turns this feature off with:
1784 // $ adb shell setprop config.override_forced_orient true
1785 // $ adb shell wm size reset
1786 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1787 }
1788
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001789 /**
1790 * @return whether the navigation bar can be hidden, e.g. the device has a
1791 * navigation bar and touch exploration is not enabled
1792 */
1793 private boolean canHideNavigationBar() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04001794 return mHasNavigationBar;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001795 }
1796
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001797 @Override
1798 public boolean isDefaultOrientationForced() {
1799 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001800 }
1801
Dianne Hackbornc652de82013-02-15 16:32:56 -08001802 @Override
1803 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1804 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1805 mOverscanLeft = left;
1806 mOverscanTop = top;
1807 mOverscanRight = right;
1808 mOverscanBottom = bottom;
1809 }
1810 }
1811
Dianne Hackbornc777e072010-02-12 13:07:59 -08001812 public void updateSettings() {
1813 ContentResolver resolver = mContext.getContentResolver();
1814 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001815 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001816 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001817 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001818 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1819 UserHandle.USER_CURRENT);
1820 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001821 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001822 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1823 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001824
Jeff Browna20dda42014-05-27 20:57:24 -07001825 // Configure wake gesture.
1826 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1827 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1828 UserHandle.USER_CURRENT) != 0;
1829 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1830 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1831 updateWakeGestureListenerLp();
1832 }
1833
Jeff Brown207673cd2012-06-05 17:47:11 -07001834 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001835 int userRotation = Settings.System.getIntForUser(resolver,
1836 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1837 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001838 if (mUserRotation != userRotation) {
1839 mUserRotation = userRotation;
1840 updateRotation = true;
1841 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001842 int userRotationMode = Settings.System.getIntForUser(resolver,
1843 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001844 WindowManagerPolicy.USER_ROTATION_FREE :
1845 WindowManagerPolicy.USER_ROTATION_LOCKED;
1846 if (mUserRotationMode != userRotationMode) {
1847 mUserRotationMode = userRotationMode;
1848 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001849 updateOrientationListenerLp();
1850 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001851
Dianne Hackbornc777e072010-02-12 13:07:59 -08001852 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001853 int pointerLocation = Settings.System.getIntForUser(resolver,
1854 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001855 if (mPointerLocationMode != pointerLocation) {
1856 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001857 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1858 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001859 }
1860 }
1861 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001862 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1863 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1864 String imId = Settings.Secure.getStringForUser(resolver,
1865 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001866 boolean hasSoftInput = imId != null && imId.length() > 0;
1867 if (mHasSoftInput != hasSoftInput) {
1868 mHasSoftInput = hasSoftInput;
1869 updateRotation = true;
1870 }
John Spurlockf1a36642013-10-12 17:50:42 -04001871 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001872 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001873 }
tiger_huangcc6366d2015-06-29 17:17:30 +08001874 }
1875 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05001876 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001877 }
1878 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001879 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001880 }
Jeff Brown70825162012-03-28 17:27:48 -07001881 }
1882
Jeff Browna20dda42014-05-27 20:57:24 -07001883 private void updateWakeGestureListenerLp() {
1884 if (shouldEnableWakeGestureLp()) {
1885 mWakeGestureListener.requestWakeUpTrigger();
1886 } else {
1887 mWakeGestureListener.cancelWakeUpTrigger();
1888 }
1889 }
1890
1891 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001892 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001893 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1894 && mWakeGestureListener.isSupported();
1895 }
1896
Jeff Brown70825162012-03-28 17:27:48 -07001897 private void enablePointerLocation() {
1898 if (mPointerLocationView == null) {
1899 mPointerLocationView = new PointerLocationView(mContext);
1900 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001901 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1902 WindowManager.LayoutParams.MATCH_PARENT,
1903 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001904 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001905 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1906 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1907 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1908 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001909 if (ActivityManager.isHighEndGfx()) {
1910 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1911 lp.privateFlags |=
1912 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1913 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001914 lp.format = PixelFormat.TRANSLUCENT;
1915 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001916 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001917 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001918 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001919 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001920 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001921 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001922 }
Jeff Brown70825162012-03-28 17:27:48 -07001923
1924 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001925 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001926 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1927 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001928 wm.removeView(mPointerLocationView);
1929 mPointerLocationView = null;
1930 }
1931 }
1932
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001933 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001934 try {
1935 int rotation = mContext.getResources().getInteger(resID);
1936 switch (rotation) {
1937 case 0:
1938 return Surface.ROTATION_0;
1939 case 90:
1940 return Surface.ROTATION_90;
1941 case 180:
1942 return Surface.ROTATION_180;
1943 case 270:
1944 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001945 }
1946 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001947 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001948 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001949 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001950 }
1951
1952 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001953 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001954 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001955 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001956
1957 outAppOp[0] = AppOpsManager.OP_NONE;
1958
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001959 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1960 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1961 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1962 return WindowManagerGlobal.ADD_INVALID_TYPE;
1963 }
1964
1965 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1966 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001967 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001968 }
1969 String permission = null;
1970 switch (type) {
1971 case TYPE_TOAST:
1972 // XXX right now the app process has complete control over
1973 // this... should introduce a token to let the system
1974 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001975 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001976 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001977 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001978 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001979 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001980 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001981 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001982 case TYPE_ACCESSIBILITY_OVERLAY:
Jason Monk8f7f3182015-11-18 16:35:14 -05001983 case TYPE_QS_DIALOG:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001984 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001985 break;
1986 case TYPE_PHONE:
1987 case TYPE_PRIORITY_PHONE:
1988 case TYPE_SYSTEM_ALERT:
1989 case TYPE_SYSTEM_ERROR:
1990 case TYPE_SYSTEM_OVERLAY:
1991 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001992 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001993 break;
1994 default:
1995 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1996 }
1997 if (permission != null) {
Billy Laucbe540f2015-06-25 01:51:44 +01001998 if (permission == android.Manifest.permission.SYSTEM_ALERT_WINDOW) {
1999 final int callingUid = Binder.getCallingUid();
Billy Lau060275f2015-07-15 22:29:19 +01002000 // system processes will be automatically allowed privilege to draw
Billy Laucbe540f2015-06-25 01:51:44 +01002001 if (callingUid == Process.SYSTEM_UID) {
2002 return WindowManagerGlobal.ADD_OKAY;
2003 }
2004
Billy Lau060275f2015-07-15 22:29:19 +01002005 // check if user has enabled this operation. SecurityException will be thrown if
2006 // this app has not been allowed by the user
Billy Laucbe540f2015-06-25 01:51:44 +01002007 final int mode = mAppOpsManager.checkOp(outAppOp[0], callingUid,
2008 attrs.packageName);
Billy Lau060275f2015-07-15 22:29:19 +01002009 switch (mode) {
2010 case AppOpsManager.MODE_ALLOWED:
2011 case AppOpsManager.MODE_IGNORED:
2012 // although we return ADD_OKAY for MODE_IGNORED, the added window will
2013 // actually be hidden in WindowManagerService
2014 return WindowManagerGlobal.ADD_OKAY;
2015 case AppOpsManager.MODE_ERRORED:
Billy Laucbe540f2015-06-25 01:51:44 +01002016 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
Billy Lau060275f2015-07-15 22:29:19 +01002017 default:
2018 // in the default mode, we will make a decision here based on
2019 // checkCallingPermission()
2020 if (mContext.checkCallingPermission(permission) !=
2021 PackageManager.PERMISSION_GRANTED) {
2022 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
2023 } else {
2024 return WindowManagerGlobal.ADD_OKAY;
2025 }
Billy Laucbe540f2015-06-25 01:51:44 +01002026 }
Billy Laucbe540f2015-06-25 01:51:44 +01002027 }
2028
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002029 if (mContext.checkCallingOrSelfPermission(permission)
2030 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07002031 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002032 }
2033 }
Jeff Brown98365d72012-08-19 20:30:52 -07002034 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002035 }
Craig Mautner88400d32012-09-30 12:35:45 -07002036
2037 @Override
2038 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
2039
2040 // If this switch statement is modified, modify the comment in the declarations of
2041 // the type in {@link WindowManager.LayoutParams} as well.
2042 switch (attrs.type) {
2043 default:
2044 // These are the windows that by default are shown only to the user that created
2045 // them. If this needs to be overridden, set
2046 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
2047 // {@link WindowManager.LayoutParams}. Note that permission
2048 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
2049 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
2050 return true;
2051 }
2052 break;
2053
2054 // These are the windows that by default are shown to all users. However, to
2055 // protect against spoofing, check permissions below.
2056 case TYPE_APPLICATION_STARTING:
2057 case TYPE_BOOT_PROGRESS:
2058 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07002059 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08002060 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07002061 case TYPE_KEYGUARD_DIALOG:
2062 case TYPE_MAGNIFICATION_OVERLAY:
2063 case TYPE_NAVIGATION_BAR:
2064 case TYPE_NAVIGATION_BAR_PANEL:
2065 case TYPE_PHONE:
2066 case TYPE_POINTER:
2067 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07002068 case TYPE_SEARCH_BAR:
2069 case TYPE_STATUS_BAR:
2070 case TYPE_STATUS_BAR_PANEL:
2071 case TYPE_STATUS_BAR_SUB_PANEL:
2072 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07002073 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07002074 case TYPE_PRIVATE_PRESENTATION:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002075 case TYPE_DOCK_DIVIDER:
Craig Mautner88400d32012-09-30 12:35:45 -07002076 break;
2077 }
2078
2079 // Check if third party app has set window to system window type.
2080 return mContext.checkCallingOrSelfPermission(
2081 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
2082 != PackageManager.PERMISSION_GRANTED;
2083 }
2084
Craig Mautner967212c2013-04-13 21:10:58 -07002085 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002086 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
2087 switch (attrs.type) {
2088 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07002089 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002090 // These types of windows can't receive input events.
2091 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2092 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002093 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002094 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002095 case TYPE_STATUS_BAR:
2096
2097 // If the Keyguard is in a hidden state (occluded by another window), we force to
2098 // remove the wallpaper and keyguard flag so that any change in-flight after setting
2099 // the keyguard as occluded wouldn't set these flags again.
2100 // See {@link #processKeyguardSetHiddenResultLw}.
2101 if (mKeyguardHidden) {
2102 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2103 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2104 }
2105 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002106 }
Adrian Roos38502112014-04-09 21:04:11 +02002107
2108 if (attrs.type != TYPE_STATUS_BAR) {
2109 // The status bar is the only window allowed to exhibit keyguard behavior.
2110 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2111 }
Adrian Roosea562512014-05-05 13:33:03 +02002112
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002113 if (ActivityManager.isHighEndGfx()) {
2114 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
2115 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
2116 }
2117 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0
Jorim Jaggi406585a2015-12-21 10:58:56 +01002118 || (mForceWindowDrawsStatusBarBackground
2119 && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT)) {
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002120 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
2121 }
Adrian Roosea562512014-05-05 13:33:03 +02002122 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002123 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002124
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002125 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07002126 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002127 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002128
Michael Wright3818c922014-09-02 13:59:07 -07002129 private void readCameraLensCoverState() {
2130 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
2131 }
2132
Jeff Browndaa37532012-05-01 15:54:03 -07002133 private boolean isHidden(int accessibilityMode) {
2134 switch (accessibilityMode) {
2135 case 1:
2136 return mLidState == LID_CLOSED;
2137 case 2:
2138 return mLidState == LID_OPEN;
2139 default:
2140 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002141 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002142 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002143
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002144 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002145 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07002146 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
2147 int navigationPresence) {
2148 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
2149
Jeff Brownf71343d2013-05-31 17:59:11 -07002150 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002151 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07002152 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08002153
Jeff Browndaa37532012-05-01 15:54:03 -07002154 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
2155 || (keyboardPresence == PRESENCE_INTERNAL
2156 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002157 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07002158 if (!mHasSoftInput) {
2159 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
2160 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002161 }
2162
Jeff Browndaa37532012-05-01 15:54:03 -07002163 if (config.navigation == Configuration.NAVIGATION_NONAV
2164 || (navigationPresence == PRESENCE_INTERNAL
2165 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002166 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08002167 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002168 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002169
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002170 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002171 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002172 public int windowTypeToLayerLw(int type) {
2173 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002174 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002175 }
2176 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07002177 case TYPE_PRIVATE_PRESENTATION:
2178 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002179 case TYPE_WALLPAPER:
2180 // wallpaper is at the bottom, though the window manager may move it.
2181 return 2;
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002182 case TYPE_DOCK_DIVIDER:
2183 return 2;
Jason Monk8f7f3182015-11-18 16:35:14 -05002184 case TYPE_QS_DIALOG:
2185 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002186 case TYPE_PHONE:
2187 return 3;
2188 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002189 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002190 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002191 case TYPE_VOICE_INTERACTION:
2192 // voice interaction layer is almost immediately above apps.
2193 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07002194 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002195 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07002196 case TYPE_SYSTEM_DIALOG:
2197 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002198 case TYPE_TOAST:
2199 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07002200 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002201 case TYPE_PRIORITY_PHONE:
2202 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07002203 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002204 case TYPE_DREAM:
2205 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07002206 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002207 case TYPE_SYSTEM_ALERT:
2208 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002209 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002210 case TYPE_INPUT_METHOD:
2211 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002212 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002213 case TYPE_INPUT_METHOD_DIALOG:
2214 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002215 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08002216 case TYPE_KEYGUARD_SCRIM:
2217 // the safety window that shows behind keyguard while keyguard is starting
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002218 return 14;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002219 case TYPE_STATUS_BAR_SUB_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002220 return 15;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002221 case TYPE_STATUS_BAR:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002222 return 16;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002223 case TYPE_STATUS_BAR_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002224 return 17;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002225 case TYPE_KEYGUARD_DIALOG:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002226 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002227 case TYPE_VOLUME_OVERLAY:
2228 // the on-screen volume indicator and controller shown when the user
2229 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002230 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002231 case TYPE_SYSTEM_OVERLAY:
2232 // the on-screen volume indicator and controller shown when the user
2233 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002234 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002235 case TYPE_NAVIGATION_BAR:
2236 // the navigation bar, if available, shows atop most things
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002237 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002238 case TYPE_NAVIGATION_BAR_PANEL:
2239 // some panels (e.g. search) need to show on top of the navigation bar
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002240 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002241 case TYPE_SYSTEM_ERROR:
2242 // system-level error dialogs
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002243 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002244 case TYPE_MAGNIFICATION_OVERLAY:
2245 // used to highlight the magnified portion of a display
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002246 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002247 case TYPE_DISPLAY_OVERLAY:
2248 // used to simulate secondary display devices
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002249 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002250 case TYPE_DRAG:
2251 // the drag layer: input for drag-and-drop is associated with this window,
2252 // which sits above all other focusable windows
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002253 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002254 case TYPE_ACCESSIBILITY_OVERLAY:
2255 // overlay put by accessibility services to intercept user interaction
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002256 return 27;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002257 case TYPE_SECURE_SYSTEM_OVERLAY:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002258 return 28;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002259 case TYPE_BOOT_PROGRESS:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002260 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002261 case TYPE_POINTER:
2262 // the (mouse) pointer layer
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002263 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002264 }
2265 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002266 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002267 }
2268
2269 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002270 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002271 public int subWindowTypeToLayerLw(int type) {
2272 switch (type) {
2273 case TYPE_APPLICATION_PANEL:
2274 case TYPE_APPLICATION_ATTACHED_DIALOG:
2275 return APPLICATION_PANEL_SUBLAYER;
2276 case TYPE_APPLICATION_MEDIA:
2277 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002278 case TYPE_APPLICATION_MEDIA_OVERLAY:
2279 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002280 case TYPE_APPLICATION_SUB_PANEL:
2281 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002282 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2283 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002284 }
2285 Log.e(TAG, "Unknown sub-window type: " + type);
2286 return 0;
2287 }
2288
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002289 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002290 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002291 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002292 }
2293
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002294 private int getNavigationBarWidth(int rotation, int uiMode) {
2295 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2296 return mNavigationBarWidthForRotationInCarMode[rotation];
2297 } else {
2298 return mNavigationBarWidthForRotationDefault[rotation];
2299 }
2300 }
2301
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002302 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002303 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation,
2304 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002305 if (mHasNavigationBar) {
2306 // For a basic navigation bar, when we are in landscape mode we place
2307 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002308 if (mNavigationBarCanMove && fullWidth > fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002309 return fullWidth - getNavigationBarWidth(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002310 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002311 }
2312 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002313 }
2314
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002315 private int getNavigationBarHeight(int rotation, int uiMode) {
2316 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2317 return mNavigationBarHeightForRotationInCarMode[rotation];
2318 } else {
2319 return mNavigationBarHeightForRotationDefault[rotation];
2320 }
2321 }
2322
Jose Lima9546b202014-07-02 17:21:51 -07002323 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002324 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation,
2325 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002326 if (mHasNavigationBar) {
2327 // For a basic navigation bar, when we are in portrait mode we place
2328 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002329 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002330 return fullHeight - getNavigationBarHeight(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002331 }
2332 }
2333 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002334 }
2335
Jose Lima9546b202014-07-02 17:21:51 -07002336 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002337 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode) {
2338 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002339 }
2340
Jose Lima9546b202014-07-02 17:21:51 -07002341 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002342 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode) {
John Spurlock80f00c12013-06-13 11:10:51 -04002343 // There is a separate status bar at the top of the display. We don't count that as part
2344 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002345 // we do want to exclude it since applications can't generally use that part
2346 // of the screen.
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002347 return getNonDecorDisplayHeight(
2348 fullWidth, fullHeight, rotation, uiMode) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002349 }
2350
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002351 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002352 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2353 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002354 (isKeyguardHostWindow(attrs) &&
2355 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002356 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002357 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002358
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002359 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002360 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2361 return attrs.type == TYPE_STATUS_BAR;
2362 }
2363
2364 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002365 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002366 switch (attrs.type) {
2367 case TYPE_STATUS_BAR:
2368 case TYPE_NAVIGATION_BAR:
2369 case TYPE_WALLPAPER:
2370 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002371 case TYPE_KEYGUARD_SCRIM:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002372 case TYPE_DOCK_DIVIDER:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002373 return false;
2374 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002375 // Hide only windows below the keyguard host window.
2376 return windowTypeToLayerLw(win.getBaseType())
2377 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002378 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002379 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002380
Craig Mautner7d7808f2014-09-11 18:02:38 -07002381 @Override
2382 public WindowState getWinShowWhenLockedLw() {
2383 return mWinShowWhenLocked;
2384 }
2385
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002386 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002387 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002388 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2389 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002390 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002391 if (!SHOW_STARTING_ANIMATIONS) {
2392 return null;
2393 }
2394 if (packageName == null) {
2395 return null;
2396 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002397
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002398 WindowManager wm = null;
2399 View view = null;
2400
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002401 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002402 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002403 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2404 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2405 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002406 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002407 try {
2408 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002409 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002410 } catch (PackageManager.NameNotFoundException e) {
2411 // Ignore
2412 }
2413 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002414
Jorim Jaggia16cc152015-06-01 16:55:05 -07002415 PhoneWindow win = new PhoneWindow(context);
2416 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002417
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002418 Resources r = context.getResources();
2419 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002420
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002421 win.setType(
2422 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002423
2424 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2425 // Assumes it's safe to show starting windows of launched apps while
2426 // the keyguard is being hidden. This is okay because starting windows never show
2427 // secret information.
2428 if (mKeyguardHidden) {
2429 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2430 }
2431 }
2432
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002433 // Force the window flags: this is a fake window, so it is not really
2434 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2435 // flag because we do know that the next window will take input
2436 // focus, so we want to get the IME window up on top of us right away.
2437 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002438 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002439 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2440 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2441 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002442 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002443 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2444 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2445 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002446
Adam Powell04fe6eb2013-05-31 14:39:48 -07002447 win.setDefaultIcon(icon);
2448 win.setDefaultLogo(logo);
2449
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002450 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002451 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002452
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002453 final WindowManager.LayoutParams params = win.getAttributes();
2454 params.token = appToken;
2455 params.packageName = packageName;
2456 params.windowAnimations = win.getWindowStyle().getResourceId(
2457 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002458 params.privateFlags |=
2459 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002460 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002461
2462 if (!compatInfo.supportsScreen()) {
2463 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2464 }
2465
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002466 params.setTitle("Starting " + packageName);
2467
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002468 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2469 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002470
Craig Mautner6fbda632012-07-03 09:26:39 -07002471 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002472 TAG, "Adding starting window for " + packageName
2473 + " / " + appToken + ": "
2474 + (view.getParent() != null ? view : null));
2475
2476 wm.addView(view, params);
2477
2478 // Only return the view if it was successfully added to the
2479 // window manager... which we can tell by it having a parent.
2480 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002481 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002482 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002483 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2484 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002485 } catch (RuntimeException e) {
2486 // don't crash if something else bad happens, for example a
2487 // failure loading resources because we are loading from an app
2488 // on external storage that has been unmounted.
2489 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002490 } finally {
2491 if (view != null && view.getParent() == null) {
2492 Log.w(TAG, "view not successfully added to wm, removing view");
2493 wm.removeViewImmediate(view);
2494 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002495 }
2496
2497 return null;
2498 }
2499
2500 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002501 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002502 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002503 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2504 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002505
2506 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002507 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002508 wm.removeView(window);
2509 }
2510 }
2511
2512 /**
2513 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002514 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002515 * Currently enforces that three window types are singletons:
2516 * <ul>
2517 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002518 * <li>KEYGUARD_TYPE</li>
2519 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002520 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002521 * @param win The window to be added
2522 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002523 *
Jeff Brown98365d72012-08-19 20:30:52 -07002524 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2525 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002526 */
Jose Lima9546b202014-07-02 17:21:51 -07002527 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002528 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2529 switch (attrs.type) {
2530 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002531 mContext.enforceCallingOrSelfPermission(
2532 android.Manifest.permission.STATUS_BAR_SERVICE,
2533 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002534 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002535 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002536 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002537 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002538 }
2539 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002540 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002541 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002542 case TYPE_NAVIGATION_BAR:
2543 mContext.enforceCallingOrSelfPermission(
2544 android.Manifest.permission.STATUS_BAR_SERVICE,
2545 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002546 if (mNavigationBar != null) {
2547 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002548 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002549 }
2550 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002551 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002552 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002553 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002554 break;
Jim Millere898ac52012-04-06 17:10:57 -07002555 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002556 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002557 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002558 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002559 mContext.enforceCallingOrSelfPermission(
2560 android.Manifest.permission.STATUS_BAR_SERVICE,
2561 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002562 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002563 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002564 if (mKeyguardScrim != null) {
2565 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2566 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002567 mKeyguardScrim = win;
2568 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002569 }
Jeff Brown98365d72012-08-19 20:30:52 -07002570 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002571 }
2572
2573 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002574 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002575 public void removeWindowLw(WindowState win) {
2576 if (mStatusBar == win) {
2577 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002578 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002579 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002580 } else if (mKeyguardScrim == win) {
2581 Log.v(TAG, "Removing keyguard scrim");
2582 mKeyguardScrim = null;
2583 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002584 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002585 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002586 }
2587 }
2588
2589 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002590
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002591 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002592 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002593 public int selectAnimationLw(WindowState win, int transit) {
2594 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2595 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002596 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002597 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002598 if (transit == TRANSIT_EXIT
2599 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002600 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002601 } else if (transit == TRANSIT_ENTER
2602 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002603 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002604 }
2605 } else if (win == mNavigationBar) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002606 if (win.getAttrs().windowAnimations != 0) {
2607 return 0;
2608 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002609 // This can be on either the bottom or the right.
2610 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002611 if (transit == TRANSIT_EXIT
2612 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002613 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002614 } else if (transit == TRANSIT_ENTER
2615 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002616 return R.anim.dock_bottom_enter;
2617 }
2618 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002619 if (transit == TRANSIT_EXIT
2620 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002621 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002622 } else if (transit == TRANSIT_ENTER
2623 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002624 return R.anim.dock_right_enter;
2625 }
2626 }
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08002627 } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -08002628 if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08002629 return R.anim.fade_in;
2630 } else if (transit == TRANSIT_EXIT) {
2631 return R.anim.fade_out;
2632 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002633 }
2634
2635 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002636 if (win.hasAppShownWindows()) {
2637 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2638 return com.android.internal.R.anim.app_starting_exit;
2639 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002640 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002641 && transit == TRANSIT_ENTER) {
2642 // Special case: we are animating in a dream, while the keyguard
2643 // is shown. We don't want an animation on the dream, because
2644 // we need it shown immediately with the keyguard animating away
2645 // to reveal it.
2646 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002647 }
2648
2649 return 0;
2650 }
2651
Craig Mautner3c174372013-02-21 17:54:37 -08002652 @Override
2653 public void selectRotationAnimationLw(int anim[]) {
2654 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2655 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2656 + (mTopFullscreenOpaqueWindowState == null ?
2657 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2658 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2659 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2660 case ROTATION_ANIMATION_CROSSFADE:
2661 anim[0] = R.anim.rotation_animation_xfade_exit;
2662 anim[1] = R.anim.rotation_animation_enter;
2663 break;
2664 case ROTATION_ANIMATION_JUMPCUT:
2665 anim[0] = R.anim.rotation_animation_jump_exit;
2666 anim[1] = R.anim.rotation_animation_enter;
2667 break;
2668 case ROTATION_ANIMATION_ROTATE:
2669 default:
2670 anim[0] = anim[1] = 0;
2671 break;
2672 }
2673 } else {
2674 anim[0] = anim[1] = 0;
2675 }
2676 }
2677
2678 @Override
2679 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2680 boolean forceDefault) {
2681 switch (exitAnimId) {
2682 case R.anim.rotation_animation_xfade_exit:
2683 case R.anim.rotation_animation_jump_exit:
2684 // These are the only cases that matter.
2685 if (forceDefault) {
2686 return false;
2687 }
2688 int anim[] = new int[2];
2689 selectRotationAnimationLw(anim);
2690 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2691 default:
2692 return true;
2693 }
2694 }
2695
2696 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002697 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2698 boolean goingToNotificationShade) {
2699 if (goingToNotificationShade) {
2700 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002701 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002702
2703 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2704 R.anim.lock_screen_behind_enter_wallpaper :
2705 R.anim.lock_screen_behind_enter);
2706
2707 // TODO: Use XML interpolators when we have log interpolators available in XML.
2708 final List<Animation> animations = set.getAnimations();
2709 for (int i = animations.size() - 1; i >= 0; --i) {
2710 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2711 }
2712
2713 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002714 }
2715
2716
2717 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002718 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2719 if (goingToNotificationShade) {
2720 return null;
2721 } else {
2722 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2723 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002724 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002725
2726 private static void awakenDreams() {
2727 IDreamManager dreamManager = getDreamManager();
2728 if (dreamManager != null) {
2729 try {
2730 dreamManager.awaken();
2731 } catch (RemoteException e) {
2732 // fine, stay asleep then
2733 }
2734 }
2735 }
2736
2737 static IDreamManager getDreamManager() {
2738 return IDreamManager.Stub.asInterface(
2739 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2740 }
2741
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002742 TelecomManager getTelecommService() {
2743 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002744 }
2745
Jeff Brown4d396052010-10-29 21:50:21 -07002746 static IAudioService getAudioService() {
2747 IAudioService audioService = IAudioService.Stub.asInterface(
2748 ServiceManager.checkService(Context.AUDIO_SERVICE));
2749 if (audioService == null) {
2750 Log.w(TAG, "Unable to find IAudioService interface.");
2751 }
2752 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002753 }
2754
2755 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002756 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002757 }
2758
2759 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2760 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2761 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2762 };
2763
2764 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002765 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002766 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002767 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002768 final int keyCode = event.getKeyCode();
2769 final int repeatCount = event.getRepeatCount();
2770 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002771 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002772 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2773 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002774
Jeff Brown40013652012-05-16 21:22:36 -07002775 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002776 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002777 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2778 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002779 }
2780
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002781 // If we think we might have a volume down & power key chord on the way
2782 // but we're not sure, then tell the dispatcher to wait a little while and
2783 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002784 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002785 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002786 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002787 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2788 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002789 if (now < timeoutTime) {
2790 return timeoutTime - now;
2791 }
2792 }
2793 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002794 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002795 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002796 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002797 }
2798 return -1;
2799 }
2800 }
2801
Michael Wright6a62e552014-06-03 19:19:48 -07002802 // Cancel any pending meta actions if we see any other keys being pressed between the down
2803 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002804 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002805 mPendingMetaAction = false;
2806 }
2807
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002808 // First we always handle the home key here, so applications
2809 // can never break it, although if keyguard is on, we do let
2810 // it handle it, because that gives us the correct 5 second
2811 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002812 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002813
Jeff Brown49ed71d2010-12-06 17:13:33 -08002814 // If we have released the home key, and didn't do anything else
2815 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002816 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002817 cancelPreloadRecentApps();
2818
Jeff Brown49ed71d2010-12-06 17:13:33 -08002819 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002820 if (mHomeConsumed) {
2821 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002822 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002823 }
Jeff Browncaca8812013-05-09 13:34:33 -07002824
2825 if (canceled) {
2826 Log.i(TAG, "Ignoring HOME; event canceled.");
2827 return -1;
2828 }
2829
Yorke Lee4f803242014-12-15 23:22:06 +00002830 // If an incoming call is ringing, HOME is totally disabled.
2831 // (The user is already on the InCallUI at this point,
2832 // and his ONLY options are to answer or reject the call.)
2833 TelecomManager telecomManager = getTelecommService();
2834 if (telecomManager != null && telecomManager.isRinging()) {
2835 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2836 return -1;
2837 }
2838
Jeff Browncaca8812013-05-09 13:34:33 -07002839 // Delay handling home if a double-tap is possible.
2840 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2841 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2842 mHomeDoubleTapPending = true;
2843 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2844 ViewConfiguration.getDoubleTapTimeout());
2845 return -1;
2846 }
2847
Jeff Brown13f00f02014-10-31 14:45:50 -07002848 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002849 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002850 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002851
2852 // If a system window has focus, then it doesn't make sense
2853 // right now to interact with applications.
2854 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2855 if (attrs != null) {
2856 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002857 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2858 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2859 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002860 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002861 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002862 }
2863 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2864 for (int i=0; i<typeCount; i++) {
2865 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2866 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002867 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002868 }
2869 }
2870 }
Jeff Browncaca8812013-05-09 13:34:33 -07002871
2872 // Remember that home is pressed and handle special actions.
2873 if (repeatCount == 0) {
2874 mHomePressed = true;
2875 if (mHomeDoubleTapPending) {
2876 mHomeDoubleTapPending = false;
2877 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2878 handleDoubleTapOnHome();
2879 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2880 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2881 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002882 }
Jeff Browncaca8812013-05-09 13:34:33 -07002883 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2884 if (!keyguardOn) {
Jaewan Kim52632e22016-01-14 18:01:52 +09002885 handleLongPressOnHome(event.getDeviceId(), event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002886 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002887 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002888 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002889 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002890 // Hijack modified menu keys for debugging features
2891 final int chordBug = KeyEvent.META_SHIFT_ON;
2892
2893 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002894 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002895 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002896 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2897 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002898 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002899 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002900 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002901 Intent service = new Intent();
2902 service.setClassName(mContext, "com.android.server.LoadAverageService");
2903 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002904 boolean shown = Settings.Global.getInt(
2905 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002906 if (!shown) {
2907 mContext.startService(service);
2908 } else {
2909 mContext.stopService(service);
2910 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002911 Settings.Global.putInt(
2912 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002913 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002914 }
2915 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002916 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002917 if (down) {
2918 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002919 mSearchKeyShortcutPending = true;
2920 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002921 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002922 } else {
2923 mSearchKeyShortcutPending = false;
2924 if (mConsumeSearchKeyUp) {
2925 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002926 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002927 }
2928 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002929 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002930 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002931 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002932 if (down && repeatCount == 0) {
2933 preloadRecentApps();
2934 } else if (!down) {
2935 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002936 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002937 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002938 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002939 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2940 if (down) {
2941 IStatusBarService service = getStatusBarService();
2942 if (service != null) {
2943 try {
2944 service.expandNotificationsPanel();
2945 } catch (RemoteException e) {
2946 // do nothing.
2947 }
2948 }
2949 }
Clara Bayarrif2debb12015-07-10 14:47:17 +01002950 } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) {
2951 if (down) {
2952 if (repeatCount == 0) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00002953 toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01002954 }
2955 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002956 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2957 if (down) {
2958 if (repeatCount == 0) {
2959 mAssistKeyLongPressed = false;
2960 } else if (repeatCount == 1) {
2961 mAssistKeyLongPressed = true;
2962 if (!keyguardOn) {
2963 launchAssistLongPressAction();
2964 }
2965 }
2966 } else {
2967 if (mAssistKeyLongPressed) {
2968 mAssistKeyLongPressed = false;
2969 } else {
2970 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002971 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002972 }
2973 }
2974 }
2975 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002976 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2977 if (!down) {
2978 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002979 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002980 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2981 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07002982 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
2983 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
2984 if (dic != null) {
2985 try {
2986 dic.exitIdle("voice-search");
2987 } catch (RemoteException e) {
2988 }
2989 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002990 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002991 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002992 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002993 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002994 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002995 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2996 if (down && repeatCount == 0) {
2997 mHandler.post(mScreenshotRunnable);
2998 }
2999 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08003000 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
3001 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
3002 if (down) {
3003 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
3004
3005 // Disable autobrightness if it's on
3006 int auto = Settings.System.getIntForUser(
3007 mContext.getContentResolver(),
3008 Settings.System.SCREEN_BRIGHTNESS_MODE,
3009 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3010 UserHandle.USER_CURRENT_OR_SELF);
3011 if (auto != 0) {
3012 Settings.System.putIntForUser(mContext.getContentResolver(),
3013 Settings.System.SCREEN_BRIGHTNESS_MODE,
3014 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3015 UserHandle.USER_CURRENT_OR_SELF);
3016 }
3017
3018 int min = mPowerManager.getMinimumScreenBrightnessSetting();
3019 int max = mPowerManager.getMaximumScreenBrightnessSetting();
3020 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
3021 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
3022 Settings.System.SCREEN_BRIGHTNESS,
3023 mPowerManager.getDefaultScreenBrightnessSetting(),
3024 UserHandle.USER_CURRENT_OR_SELF);
3025 brightness += step;
3026 // Make sure we don't go beyond the limits.
3027 brightness = Math.min(max, brightness);
3028 brightness = Math.max(min, brightness);
3029
3030 Settings.System.putIntForUser(mContext.getContentResolver(),
3031 Settings.System.SCREEN_BRIGHTNESS, brightness,
3032 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00003033 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07003034 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08003035 }
3036 return -1;
Jaewan Kim765487f2016-01-12 14:45:42 +09003037 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
3038 || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
3039 || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
3040 if (mUseTvRouting) {
3041 // On TVs volume keys never go to the foreground app.
3042 dispatchDirectAudioEvent(event);
3043 return -1;
3044 }
Michael Wrightce0c13a2014-07-30 10:49:21 -07003045 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07003046 if (down) {
3047 mPendingMetaAction = true;
3048 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003049 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07003050 }
3051 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003052 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003053
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003054 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08003055 // Any printing key that is chorded with Search should be consumed
3056 // even if no shortcut was invoked. This prevents text from being
3057 // inadvertently inserted when using a keyboard that has built-in macro
3058 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003059 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08003060 final KeyCharacterMap kcm = event.getKeyCharacterMap();
3061 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003062 mConsumeSearchKeyUp = true;
3063 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08003064 if (down && repeatCount == 0 && !keyguardOn) {
3065 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
3066 if (shortcutIntent != null) {
3067 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003068 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003069 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003070 } catch (ActivityNotFoundException ex) {
3071 Slog.w(TAG, "Dropping shortcut key combination because "
3072 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003073 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003074 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003075 } else {
3076 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003077 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003078 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003079 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003080 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003081 }
3082 }
3083
Jeff Brown68b909d2011-12-07 16:36:01 -08003084 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07003085 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08003086 && (metaState & KeyEvent.META_META_ON) != 0) {
3087 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07003088 if (kcm.isPrintingKey(keyCode)) {
3089 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
3090 metaState & ~(KeyEvent.META_META_ON
3091 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
3092 if (shortcutIntent != null) {
3093 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3094 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003095 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07003096 } catch (ActivityNotFoundException ex) {
3097 Slog.w(TAG, "Dropping shortcut key combination because "
3098 + "the activity to which it is registered was not found: "
3099 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
3100 }
3101 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08003102 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003103 }
3104 }
3105
Jeff Brown6651a632011-11-28 12:59:11 -08003106 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07003107 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08003108 String category = sApplicationLaunchKeyCategories.get(keyCode);
3109 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08003110 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08003111 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3112 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003113 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08003114 } catch (ActivityNotFoundException ex) {
3115 Slog.w(TAG, "Dropping application launch key because "
3116 + "the activity to which it is registered was not found: "
3117 + "keyCode=" + keyCode + ", category=" + category, ex);
3118 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003119 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08003120 }
3121 }
3122
Michael Wright61c46752014-08-21 16:57:33 -07003123 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08003124 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Michael Wrightd847ad52015-10-24 13:24:15 +01003125 if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) {
Jeff Brown68b909d2011-12-07 16:36:01 -08003126 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07003127 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003128 mRecentAppsHeldModifiers = shiftlessModifiers;
3129 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08003130 return -1;
3131 }
3132 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07003133 } else if (!down && mRecentAppsHeldModifiers != 0
3134 && (metaState & mRecentAppsHeldModifiers) == 0) {
3135 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07003136 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003137 }
3138
Yohei Yukawaae61f712015-12-09 13:00:10 -08003139 // Handle keyboard layout switching.
3140 // TODO: Deprecate this behavior when we fully migrate to IME subtype-based layout rotation.
3141 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_SPACE
3142 && ((metaState & KeyEvent.META_CTRL_MASK) != 0)) {
3143 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
3144 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
3145 return -1;
3146 }
3147
3148 // Handle input method switching.
Jeff Browncf39bdf2012-05-18 14:41:19 -07003149 if (down && repeatCount == 0
3150 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3151 || (keyCode == KeyEvent.KEYCODE_SPACE
Yohei Yukawaae61f712015-12-09 13:00:10 -08003152 && (metaState & KeyEvent.META_META_MASK) != 0))) {
3153 final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0;
3154 mWindowManagerFuncs.switchInputMethod(forwardDirection);
Jeff Browncf39bdf2012-05-18 14:41:19 -07003155 return -1;
3156 }
3157 if (mLanguageSwitchKeyPressed && !down
3158 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3159 || keyCode == KeyEvent.KEYCODE_SPACE)) {
3160 mLanguageSwitchKeyPressed = false;
3161 return -1;
3162 }
3163
Jeff Brown13f00f02014-10-31 14:45:50 -07003164 if (isValidGlobalKey(keyCode)
3165 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07003166 return -1;
3167 }
3168
Michael Wright6a62e552014-06-03 19:19:48 -07003169 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07003170 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07003171 return -1;
3172 }
3173
Jeff Brown68b909d2011-12-07 16:36:01 -08003174 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003175 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003176 }
3177
Jeff Brown3915bb82010-11-05 15:02:16 -07003178 /** {@inheritDoc} */
3179 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08003180 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07003181 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07003182 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08003183 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
3184 + ", flags=" + event.getFlags()
3185 + ", keyCode=" + event.getKeyCode()
3186 + ", scanCode=" + event.getScanCode()
3187 + ", metaState=" + event.getMetaState()
3188 + ", repeatCount=" + event.getRepeatCount()
3189 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07003190 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003191
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003192 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003193 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3194 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003195 final int keyCode = event.getKeyCode();
3196 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003197 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
3198 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003199
Jeff Brown54875002011-04-06 15:33:01 -07003200 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003201 final FallbackAction fallbackAction;
3202 if (initialDown) {
3203 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
3204 } else {
3205 fallbackAction = mFallbackActions.get(keyCode);
3206 }
3207
3208 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07003209 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003210 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
3211 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003212 }
3213
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003214 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
3215 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08003216 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003217 event.getAction(), fallbackAction.keyCode,
3218 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08003219 event.getDeviceId(), event.getScanCode(),
3220 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003221
3222 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
3223 fallbackEvent.recycle();
3224 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003225 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003226
3227 if (initialDown) {
3228 mFallbackActions.put(keyCode, fallbackAction);
3229 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3230 mFallbackActions.remove(keyCode);
3231 fallbackAction.recycle();
3232 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003233 }
3234 }
3235
Jeff Brown40013652012-05-16 21:22:36 -07003236 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003237 if (fallbackEvent == null) {
3238 Slog.d(TAG, "No fallback.");
3239 } else {
3240 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3241 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003242 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003243 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003244 }
3245
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003246 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003247 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003248 if ((actions & ACTION_PASS_TO_USER) != 0) {
3249 long delayMillis = interceptKeyBeforeDispatching(
3250 win, fallbackEvent, policyFlags);
3251 if (delayMillis == 0) {
3252 return true;
3253 }
3254 }
3255 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003256 }
3257
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003258 private void launchAssistLongPressAction() {
3259 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3260 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3261
3262 // launch the search activity
3263 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3264 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3265 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003266 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003267 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003268 SearchManager searchManager = getSearchManager();
3269 if (searchManager != null) {
3270 searchManager.stopSearch();
3271 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003272 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003273 } catch (ActivityNotFoundException e) {
3274 Slog.w(TAG, "No activity to handle assist long press action.", e);
3275 }
3276 }
3277
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003278 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003279 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Maurice Lam39d13812015-07-23 20:49:20 -07003280 if (!isUserSetupComplete()) {
3281 // Disable opening assist window during setup
3282 return;
3283 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003284 Bundle args = null;
3285 if (deviceId > Integer.MIN_VALUE) {
3286 args = new Bundle();
3287 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003288 }
Jorim Jaggi165ce062015-07-06 16:18:11 -07003289 if ((mContext.getResources().getConfiguration().uiMode
3290 & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
3291 // On TV, use legacy handling until assistants are implemented in the proper way.
3292 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3293 .launchLegacyAssist(hint, UserHandle.myUserId(), args);
3294 } else {
3295 try {
3296 if (hint != null) {
3297 if (args == null) {
3298 args = new Bundle();
3299 }
3300 args.putBoolean(hint, true);
3301 }
3302 IStatusBarService statusbar = getStatusBarService();
3303 if (statusbar != null) {
3304 statusbar.startAssist(args);
3305 }
3306 } catch (RemoteException e) {
3307 Slog.e(TAG, "RemoteException when starting assist", e);
3308 // re-acquire status bar service next time it is needed.
3309 mStatusBarService = null;
3310 }
3311 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003312 }
3313
Bart Sears8b1c27c2015-03-18 23:51:02 +00003314 private void startActivityAsUser(Intent intent, UserHandle handle) {
3315 if (isUserSetupComplete()) {
3316 mContext.startActivityAsUser(intent, handle);
3317 } else {
3318 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3319 }
3320 }
3321
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003322 private SearchManager getSearchManager() {
3323 if (mSearchManager == null) {
3324 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3325 }
3326 return mSearchManager;
3327 }
3328
Jeff Browncaca8812013-05-09 13:34:33 -07003329 private void preloadRecentApps() {
3330 mPreloadedRecentApps = true;
3331 try {
3332 IStatusBarService statusbar = getStatusBarService();
3333 if (statusbar != null) {
3334 statusbar.preloadRecentApps();
3335 }
3336 } catch (RemoteException e) {
3337 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3338 // re-acquire status bar service next time it is needed.
3339 mStatusBarService = null;
3340 }
3341 }
3342
3343 private void cancelPreloadRecentApps() {
3344 if (mPreloadedRecentApps) {
3345 mPreloadedRecentApps = false;
3346 try {
3347 IStatusBarService statusbar = getStatusBarService();
3348 if (statusbar != null) {
3349 statusbar.cancelPreloadRecentApps();
3350 }
3351 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003352 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003353 // re-acquire status bar service next time it is needed.
3354 mStatusBarService = null;
3355 }
3356 }
3357 }
3358
3359 private void toggleRecentApps() {
3360 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003361 try {
3362 IStatusBarService statusbar = getStatusBarService();
3363 if (statusbar != null) {
3364 statusbar.toggleRecentApps();
3365 }
3366 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003367 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3368 // re-acquire status bar service next time it is needed.
3369 mStatusBarService = null;
3370 }
3371 }
3372
Craig Mautner84984fa2014-06-19 11:19:20 -07003373 @Override
3374 public void showRecentApps() {
3375 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3376 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3377 }
3378
Winson Chung1e8d71b2014-05-16 17:05:22 -07003379 private void showRecentApps(boolean triggeredFromAltTab) {
3380 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3381 try {
3382 IStatusBarService statusbar = getStatusBarService();
3383 if (statusbar != null) {
3384 statusbar.showRecentApps(triggeredFromAltTab);
3385 }
3386 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003387 Slog.e(TAG, "RemoteException when showing recent apps", e);
3388 // re-acquire status bar service next time it is needed.
3389 mStatusBarService = null;
3390 }
3391 }
3392
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003393 private void toggleKeyboardShortcutsMenu() {
Clara Bayarrif2debb12015-07-10 14:47:17 +01003394 try {
3395 IStatusBarService statusbar = getStatusBarService();
3396 if (statusbar != null) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003397 statusbar.toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01003398 }
3399 } catch (RemoteException e) {
3400 Slog.e(TAG, "RemoteException when showing keyboard shortcuts menu", e);
3401 }
3402 }
3403
Winson Chungcdcd4872014-08-05 18:00:13 -07003404 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003405 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3406 try {
3407 IStatusBarService statusbar = getStatusBarService();
3408 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003409 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003410 }
3411 } catch (RemoteException e) {
3412 Slog.e(TAG, "RemoteException when closing recent apps", e);
3413 // re-acquire status bar service next time it is needed.
3414 mStatusBarService = null;
3415 }
3416 }
3417
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003418 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003419 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003420 }
3421
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003422 /**
3423 * A home key -> launch home action was detected. Take the appropriate action
3424 * given the situation with the keyguard.
3425 */
Bryce Lee662ed802015-04-10 20:11:39 +00003426 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3427 if (respectKeyguard) {
3428 if (isKeyguardShowingAndNotOccluded()) {
3429 // don't launch home if keyguard showing
3430 return;
3431 }
3432
3433 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3434 // when in keyguard restricted mode, must first verify unlock
3435 // before launching home
3436 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3437 @Override
3438 public void onKeyguardExitResult(boolean success) {
3439 if (success) {
3440 try {
3441 ActivityManagerNative.getDefault().stopAppSwitches();
3442 } catch (RemoteException e) {
3443 }
3444 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3445 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003446 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003447 }
Bryce Lee662ed802015-04-10 20:11:39 +00003448 });
3449 return;
3450 }
3451 }
3452
3453 // no keyguard stuff to worry about, just launch home!
3454 try {
3455 ActivityManagerNative.getDefault().stopAppSwitches();
3456 } catch (RemoteException e) {
3457 }
3458 if (mRecentsVisible) {
3459 // Hide Recents and notify it to launch Home
3460 if (awakenFromDreams) {
3461 awakenDreams();
3462 }
Bryce Lee662ed802015-04-10 20:11:39 +00003463 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003464 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003465 // Otherwise, just launch Home
3466 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3467 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003468 }
3469 }
3470
John Spurlock04db1762013-05-13 12:46:41 -04003471 private final Runnable mClearHideNavigationFlag = new Runnable() {
3472 @Override
3473 public void run() {
3474 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3475 // Clear flags.
3476 mForceClearedSystemUiFlags &=
3477 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3478 }
3479 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003480 }
3481 };
3482
3483 /**
3484 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3485 * to determine when the nav bar should be shown and prevent applications from
3486 * receiving those touches.
3487 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003488 final class HideNavInputEventReceiver extends InputEventReceiver {
3489 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3490 super(inputChannel, looper);
3491 }
3492
Dianne Hackborndf89e652011-10-06 22:35:11 -07003493 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003494 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003495 boolean handled = false;
3496 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003497 if (event instanceof MotionEvent
3498 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3499 final MotionEvent motionEvent = (MotionEvent)event;
3500 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003501 // When the user taps down, we re-show the nav bar.
3502 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003503 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003504 // Any user activity always causes us to show the
3505 // navigation controls, if they had been hidden.
3506 // We also clear the low profile and only content
3507 // flags so that tapping on the screen will atomically
3508 // restore all currently hidden screen decorations.
3509 int newVal = mResettingSystemUiFlags |
3510 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3511 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3512 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003513 if (mResettingSystemUiFlags != newVal) {
3514 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003515 changed = true;
3516 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003517 // We don't allow the system's nav bar to be hidden
3518 // again for 1 second, to prevent applications from
3519 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003520 newVal = mForceClearedSystemUiFlags |
3521 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003522 if (mForceClearedSystemUiFlags != newVal) {
3523 mForceClearedSystemUiFlags = newVal;
3524 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003525 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003526 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003527 }
3528 if (changed) {
3529 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3530 }
3531 }
3532 }
3533 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003534 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003535 }
3536 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003537 }
3538 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3539 new InputEventReceiver.Factory() {
3540 @Override
3541 public InputEventReceiver createInputEventReceiver(
3542 InputChannel inputChannel, Looper looper) {
3543 return new HideNavInputEventReceiver(inputChannel, looper);
3544 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003545 };
3546
3547 @Override
3548 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003549 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3550 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003551 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003552
Dianne Hackborndf89e652011-10-06 22:35:11 -07003553 // Reset any bits in mForceClearingStatusBarVisibility that
3554 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003555 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003556 // Clear any bits in the new visibility that are currently being
3557 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003558 return visibility & ~mResettingSystemUiFlags
3559 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003560 }
3561
Craig Mautner69b08182012-09-05 13:07:13 -07003562 @Override
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003563 public void getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation,
3564 Rect outContentInsets, Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003565 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003566 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3567 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003568
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003569 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
3570 if (useOutsets) {
3571 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
3572 if (outset > 0) {
3573 if (displayRotation == Surface.ROTATION_0) {
3574 outOutsets.bottom += outset;
3575 } else if (displayRotation == Surface.ROTATION_90) {
3576 outOutsets.right += outset;
3577 } else if (displayRotation == Surface.ROTATION_180) {
3578 outOutsets.top += outset;
3579 } else if (displayRotation == Surface.ROTATION_270) {
3580 outOutsets.left += outset;
3581 }
3582 }
3583 }
3584
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003585 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003586 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003587 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003588 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003589 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003590 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3591 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3592 } else {
3593 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3594 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3595 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003596 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3597 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003598 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003599 availRight - mStableFullscreenRight,
3600 availBottom - mStableFullscreenBottom);
3601 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003602 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003603 availRight - mStableRight, availBottom - mStableBottom);
3604 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003605 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003606 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003607 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003608 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003609 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003610 availRight - mCurRight, availBottom - mCurBottom);
3611 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003612 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003613 availRight - mCurRight, availBottom - mCurBottom);
3614 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003615
3616 outStableInsets.set(mStableLeft, mStableTop,
3617 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003618 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003619 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003620 outContentInsets.setEmpty();
3621 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003622 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003623
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003624 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
3625 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
3626 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
3627 }
3628
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003629 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003630 @Override
3631 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003632 int displayRotation, int uiMode) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003633 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003634 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3635 if (isDefaultDisplay) {
3636 switch (displayRotation) {
3637 case Surface.ROTATION_90:
3638 overscanLeft = mOverscanTop;
3639 overscanTop = mOverscanRight;
3640 overscanRight = mOverscanBottom;
3641 overscanBottom = mOverscanLeft;
3642 break;
3643 case Surface.ROTATION_180:
3644 overscanLeft = mOverscanRight;
3645 overscanTop = mOverscanBottom;
3646 overscanRight = mOverscanLeft;
3647 overscanBottom = mOverscanTop;
3648 break;
3649 case Surface.ROTATION_270:
3650 overscanLeft = mOverscanBottom;
3651 overscanTop = mOverscanLeft;
3652 overscanRight = mOverscanTop;
3653 overscanBottom = mOverscanRight;
3654 break;
3655 default:
3656 overscanLeft = mOverscanLeft;
3657 overscanTop = mOverscanTop;
3658 overscanRight = mOverscanRight;
3659 overscanBottom = mOverscanBottom;
3660 break;
3661 }
3662 } else {
3663 overscanLeft = 0;
3664 overscanTop = 0;
3665 overscanRight = 0;
3666 overscanBottom = 0;
3667 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003668 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3669 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3670 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3671 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003672 mSystemLeft = 0;
3673 mSystemTop = 0;
3674 mSystemRight = displayWidth;
3675 mSystemBottom = displayHeight;
3676 mUnrestrictedScreenLeft = overscanLeft;
3677 mUnrestrictedScreenTop = overscanTop;
3678 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3679 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3680 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3681 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003682 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3683 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003684 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003685 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003686 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003687 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003688 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003689 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003690 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003691 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003692 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003693 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003694
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003695 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3696 final Rect pf = mTmpParentFrame;
3697 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003698 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003699 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003700 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003701 pf.left = df.left = of.left = vf.left = mDockLeft;
3702 pf.top = df.top = of.top = vf.top = mDockTop;
3703 pf.right = df.right = of.right = vf.right = mDockRight;
3704 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003705 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003706
Craig Mautner69b08182012-09-05 13:07:13 -07003707 if (isDefaultDisplay) {
3708 // For purposes of putting out fake window up to steal focus, we will
3709 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003710 final int sysui = mLastSystemUiFlags;
3711 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003712 boolean navTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003713 & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003714 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3715 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3716 boolean navAllowedHidden = immersive || immersiveSticky;
3717 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003718 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3719 if (!isKeyguardShowing) {
3720 navTranslucent &= areTranslucentBarsAllowed();
3721 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003722
Craig Mautner69b08182012-09-05 13:07:13 -07003723 // When the navigation bar isn't visible, we put up a fake
3724 // input window to catch all touch events. This way we can
3725 // detect when the user presses anywhere to bring back the nav
3726 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003727 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003728 if (mInputConsumer != null) {
3729 mInputConsumer.dismiss();
3730 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003731 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003732 } else if (mInputConsumer == null) {
3733 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3734 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003735 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003736
Craig Mautner69b08182012-09-05 13:07:13 -07003737 // For purposes of positioning and showing the nav bar, if we have
3738 // decided that it can't be hidden (because of the screen aspect ratio),
3739 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003740 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003741
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003742 boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003743 displayRotation, uiMode, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003744 navAllowedHidden);
Craig Mautnereda67292013-04-28 13:50:14 -07003745 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003746 mDockLeft, mDockTop, mDockRight, mDockBottom));
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003747 updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003748 if (updateSysUiVisibility) {
3749 updateSystemUiVisibilityLw();
3750 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003751 }
3752 }
3753
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003754 private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui,
3755 boolean isKeyguardShowing) {
3756 // decide where the status bar goes ahead of time
3757 if (mStatusBar != null) {
3758 // apply any navigation bar insets
3759 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3760 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3761 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3762 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3763 + mUnrestrictedScreenTop;
3764 vf.left = mStableLeft;
3765 vf.top = mStableTop;
3766 vf.right = mStableRight;
3767 vf.bottom = mStableBottom;
3768
3769 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3770
3771 // Let the status bar determine its size.
3772 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3773 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3774 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
3775
3776 // For layout, the status bar is always at the top with our fixed height.
3777 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3778
3779 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
3780 boolean statusBarTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003781 & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0;
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003782 if (!isKeyguardShowing) {
3783 statusBarTranslucent &= areTranslucentBarsAllowed();
3784 }
3785
3786 // If the status bar is hidden, we don't want to cause
3787 // windows behind it to scroll.
3788 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
3789 // Status bar may go away, so the screen area it occupies
3790 // is available to apps but just covering them when the
3791 // status bar is visible.
3792 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3793
3794 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3795 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3796 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3797 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3798
3799 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
3800 String.format(
3801 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3802 mDockLeft, mDockTop, mDockRight, mDockBottom,
3803 mContentLeft, mContentTop, mContentRight, mContentBottom,
3804 mCurLeft, mCurTop, mCurRight, mCurBottom));
3805 }
3806 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
3807 && !statusBarTransient && !statusBarTranslucent
3808 && !mStatusBarController.wasRecentlyTranslucent()) {
3809 // If the opaque status bar is currently requested to be visible,
3810 // and not in the process of animating on or off, then
3811 // we can tell the app that it is covered by it.
3812 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3813 }
3814 if (mStatusBarController.checkHiddenLw()) {
3815 return true;
3816 }
3817 }
3818 return false;
3819 }
3820
3821 private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003822 int uiMode, int overscanRight, int overscanBottom, Rect dcf, boolean navVisible,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003823 boolean navTranslucent, boolean navAllowedHidden) {
3824 if (mNavigationBar != null) {
3825 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
3826 // Force the navigation bar to its appropriate place and
3827 // size. We need to do this directly, instead of relying on
3828 // it to bubble up from the nav bar, because this needs to
3829 // change atomically with screen rotations.
Jorim Jaggi737af722015-12-31 10:42:27 +01003830 mNavigationBarOnBottom = isNavigationBarOnBottom(displayWidth, displayHeight);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003831 if (mNavigationBarOnBottom) {
3832 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
3833 int top = displayHeight - overscanBottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003834 - getNavigationBarHeight(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003835 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
3836 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
3837 if (transientNavBarShowing) {
3838 mNavigationBarController.setBarShowingLw(true);
3839 } else if (navVisible) {
3840 mNavigationBarController.setBarShowingLw(true);
3841 mDockBottom = mTmpNavigationFrame.top;
3842 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3843 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
3844 } else {
3845 // We currently want to hide the navigation UI.
3846 mNavigationBarController.setBarShowingLw(false);
3847 }
3848 if (navVisible && !navTranslucent && !navAllowedHidden
3849 && !mNavigationBar.isAnimatingLw()
3850 && !mNavigationBarController.wasRecentlyTranslucent()) {
3851 // If the opaque nav bar is currently requested to be visible,
3852 // and not in the process of animating on or off, then
3853 // we can tell the app that it is covered by it.
3854 mSystemBottom = mTmpNavigationFrame.top;
3855 }
3856 } else {
3857 // Landscape screen; nav bar goes to the right.
3858 int left = displayWidth - overscanRight
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003859 - getNavigationBarWidth(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003860 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
3861 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
3862 if (transientNavBarShowing) {
3863 mNavigationBarController.setBarShowingLw(true);
3864 } else if (navVisible) {
3865 mNavigationBarController.setBarShowingLw(true);
3866 mDockRight = mTmpNavigationFrame.left;
3867 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3868 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
3869 } else {
3870 // We currently want to hide the navigation UI.
3871 mNavigationBarController.setBarShowingLw(false);
3872 }
3873 if (navVisible && !navTranslucent && !navAllowedHidden
3874 && !mNavigationBar.isAnimatingLw()
3875 && !mNavigationBarController.wasRecentlyTranslucent()) {
3876 // If the nav bar is currently requested to be visible,
3877 // and not in the process of animating on or off, then
3878 // we can tell the app that it is covered by it.
3879 mSystemRight = mTmpNavigationFrame.left;
3880 }
3881 }
3882 // Make sure the content and current rectangles are updated to
3883 // account for the restrictions from the navigation bar.
3884 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3885 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3886 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3887 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3888 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3889 // And compute the final frame.
3890 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
3891 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3892 mTmpNavigationFrame, mTmpNavigationFrame);
3893 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
3894 if (mNavigationBarController.checkHiddenLw()) {
3895 return true;
3896 }
3897 }
3898 return false;
3899 }
3900
Jorim Jaggi737af722015-12-31 10:42:27 +01003901 private boolean isNavigationBarOnBottom(int displayWidth, int displayHeight) {
3902 return !mNavigationBarCanMove || displayWidth < displayHeight;
3903 }
3904
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003905 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003906 @Override
John Spurlock46646232013-09-30 22:32:42 -04003907 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003908 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3909 return mStatusBar.getSurfaceLayer();
3910 }
3911
3912 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3913 return mNavigationBar.getSurfaceLayer();
3914 }
3915
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003916 return 0;
3917 }
3918
Craig Mautner967212c2013-04-13 21:10:58 -07003919 @Override
3920 public void getContentRectLw(Rect r) {
3921 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3922 }
3923
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003924 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3925 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003926 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3927 // Here's a special case: if this attached window is a panel that is
3928 // above the dock window, and the window it is attached to is below
3929 // the dock window, then the frames we computed for the window it is
3930 // attached to can not be used because the dock is effectively part
3931 // of the underlying window and the attached window is floating on top
3932 // of the whole thing. So, we ignore the attached window and explicitly
3933 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003934 df.left = of.left = cf.left = vf.left = mDockLeft;
3935 df.top = of.top = cf.top = vf.top = mDockTop;
3936 df.right = of.right = cf.right = vf.right = mDockRight;
3937 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003938 } else {
3939 // The effective display frame of the attached window depends on
3940 // whether it is taking care of insetting its content. If not,
3941 // we need to use the parent's content frame so that the entire
3942 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003943 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003944 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003945 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003946 // Set the content frame of the attached window to the parent's decor frame
3947 // (same as content frame when IME isn't present) if specifically requested by
3948 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3949 // Otherwise, use the overscan frame.
3950 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3951 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003952 } else {
3953 // If the window is resizing, then we want to base the content
3954 // frame on our attached content frame to resize... however,
3955 // things can be tricky if the attached window is NOT in resize
3956 // mode, in which case its content frame will be larger.
3957 // Ungh. So to deal with that, make sure the content frame
3958 // we end up using is not covering the IM dock.
3959 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003960 if (attached.isVoiceInteraction()) {
3961 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3962 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3963 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3964 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3965 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003966 if (cf.left < mContentLeft) cf.left = mContentLeft;
3967 if (cf.top < mContentTop) cf.top = mContentTop;
3968 if (cf.right > mContentRight) cf.right = mContentRight;
3969 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3970 }
3971 }
3972 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003973 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003974 vf.set(attached.getVisibleFrameLw());
3975 }
3976 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3977 // window should be positioned relative to its parent or the entire
3978 // screen.
3979 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3980 ? attached.getFrameLw() : df);
3981 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003982
3983 private void applyStableConstraints(int sysui, int fl, Rect r) {
3984 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3985 // If app is requesting a stable layout, don't let the
3986 // content insets go below the stable values.
3987 if ((fl & FLAG_FULLSCREEN) != 0) {
3988 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3989 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3990 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3991 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3992 } else {
3993 if (r.left < mStableLeft) r.left = mStableLeft;
3994 if (r.top < mStableTop) r.top = mStableTop;
3995 if (r.right > mStableRight) r.right = mStableRight;
3996 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3997 }
3998 }
3999 }
4000
Jorim Jaggiaa806142015-05-20 18:04:16 -07004001 private boolean canReceiveInput(WindowState win) {
4002 boolean notFocusable =
4003 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
4004 boolean altFocusableIm =
4005 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
4006 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
4007 return !notFocusableForIm;
4008 }
4009
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004010 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07004011 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004012 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07004013 // We've already done the navigation bar and status bar. If the status bar can receive
4014 // input, we need to layout it again to accomodate for the IME window.
4015 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004016 return;
4017 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07004018 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07004019 final boolean isDefaultDisplay = win.isDefaultDisplay();
4020 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09004021 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
4022 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07004023 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09004024 offsetInputMethodWindowLw(mLastInputMethodWindow);
4025 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004026
John Spurlockc6d1c602014-01-17 15:22:06 -05004027 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004028 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05004029 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004030
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004031 final Rect pf = mTmpParentFrame;
4032 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004033 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004034 final Rect cf = mTmpContentFrame;
4035 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04004036 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07004037 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004038 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04004039 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07004040
4041 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04004042 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004043
Craig Mautnerf683b562012-10-02 11:10:57 -07004044 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
4045
Adrian Roosfa104232014-06-20 16:10:14 -07004046 if (isDefaultDisplay) {
4047 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
4048 } else {
4049 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
4050 }
4051
Craig Mautner69b08182012-09-05 13:07:13 -07004052 if (!isDefaultDisplay) {
4053 if (attached != null) {
4054 // If this window is attached to another, our display
4055 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004056 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07004057 } else {
4058 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004059 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4060 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4061 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004062 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004063 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004064 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07004065 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004066 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004067 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
4068 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
4069 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04004070 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04004071 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04004072 // ...with content insets above the nav bar
4073 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004074 // IM dock windows always go to the bottom of the screen.
4075 attrs.gravity = Gravity.BOTTOM;
4076 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004077 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004078 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004079 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004080 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4081 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004082 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004083 // Note: In Phone landscape mode, the button bar should also be excluded.
4084 cf.right = vf.right = mStableRight;
4085 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004086 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07004087 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02004088 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4089 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4090 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
4091 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
4092 cf.left = vf.left = mStableLeft;
4093 cf.top = vf.top = mStableTop;
4094 cf.right = vf.right = mStableRight;
4095 vf.bottom = mStableBottom;
Adrian Roosdc5b4532016-01-06 20:49:41 +01004096
4097 if (adjust == SOFT_INPUT_ADJUST_RESIZE) {
4098 cf.bottom = mContentBottom;
4099 } else {
4100 cf.bottom = mDockBottom;
4101 vf.bottom = mContentBottom;
4102 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004103 } else {
John Spurlock46646232013-09-30 22:32:42 -04004104
4105 // Default policy decor for the default display
4106 dcf.left = mSystemLeft;
4107 dcf.top = mSystemTop;
4108 dcf.right = mSystemRight;
4109 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04004110 final boolean inheritTranslucentDecor = (attrs.privateFlags
4111 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04004112 final boolean isAppWindow =
4113 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
4114 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
4115 final boolean topAtRest =
4116 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
4117 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04004118 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
4119 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004120 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
4121 && (fl & WindowManager.LayoutParams.
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004122 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0
4123 && !mForceWindowDrawsStatusBarBackground) {
John Spurlock46646232013-09-30 22:32:42 -04004124 // Ensure policy decor includes status bar
4125 dcf.top = mStableTop;
4126 }
John Spurlockbd957402013-10-03 11:38:39 -04004127 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004128 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
4129 && (fl & WindowManager.LayoutParams.
4130 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004131 // Ensure policy decor includes navigation bar
4132 dcf.bottom = mStableBottom;
4133 dcf.right = mStableRight;
4134 }
4135 }
4136
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004137 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
4138 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07004139 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004140 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004141 // This is the case for a normal activity window: we want it
4142 // to cover all of the screen space, and it can take care of
4143 // moving its contents to account for screen decorations that
4144 // intrude into that space.
4145 if (attached != null) {
4146 // If this window is attached to another, our display
4147 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004148 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004149 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004150 if (attrs.type == TYPE_STATUS_BAR_PANEL
4151 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08004152 // Status bar panels are the only windows who can go on top of
4153 // the status bar. They are protected by the STATUS_BAR_SERVICE
4154 // permission, so they have the same privileges as the status
4155 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004156 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004157 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004158
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004159 pf.left = df.left = of.left = hasNavBar
4160 ? mDockLeft : mUnrestrictedScreenLeft;
4161 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4162 pf.right = df.right = of.right = hasNavBar
4163 ? mRestrictedScreenLeft+mRestrictedScreenWidth
4164 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4165 pf.bottom = df.bottom = of.bottom = hasNavBar
4166 ? mRestrictedScreenTop+mRestrictedScreenHeight
4167 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004168
Craig Mautnereda67292013-04-28 13:50:14 -07004169 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004170 "Laying out status bar window: (%d,%d - %d,%d)",
4171 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04004172 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004173 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4174 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4175 // Asking to layout into the overscan region, so give it that pure
4176 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004177 pf.left = df.left = of.left = mOverscanScreenLeft;
4178 pf.top = df.top = of.top = mOverscanScreenTop;
4179 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
4180 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
4181 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004182 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004183 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004184 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4185 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004186 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08004187 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004188 // only do this for application windows to ensure no window that
4189 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08004190 pf.left = df.left = mOverscanScreenLeft;
4191 pf.top = df.top = mOverscanScreenTop;
4192 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4193 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004194 // We need to tell the app about where the frame inside the overscan
4195 // is, so it can inset its content by that amount -- it didn't ask
4196 // to actually extend itself into the overscan region.
4197 of.left = mUnrestrictedScreenLeft;
4198 of.top = mUnrestrictedScreenTop;
4199 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4200 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004201 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08004202 pf.left = df.left = mRestrictedOverscanScreenLeft;
4203 pf.top = df.top = mRestrictedOverscanScreenTop;
4204 pf.right = df.right = mRestrictedOverscanScreenLeft
4205 + mRestrictedOverscanScreenWidth;
4206 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
4207 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004208 // We need to tell the app about where the frame inside the overscan
4209 // is, so it can inset its content by that amount -- it didn't ask
4210 // to actually extend itself into the overscan region.
4211 of.left = mUnrestrictedScreenLeft;
4212 of.top = mUnrestrictedScreenTop;
4213 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4214 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004215 }
Craig Mautner69b08182012-09-05 13:07:13 -07004216
John Spurlock46646232013-09-30 22:32:42 -04004217 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004218 if (win.isVoiceInteraction()) {
4219 cf.left = mVoiceContentLeft;
4220 cf.top = mVoiceContentTop;
4221 cf.right = mVoiceContentRight;
4222 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004223 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004224 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4225 cf.left = mDockLeft;
4226 cf.top = mDockTop;
4227 cf.right = mDockRight;
4228 cf.bottom = mDockBottom;
4229 } else {
4230 cf.left = mContentLeft;
4231 cf.top = mContentTop;
4232 cf.right = mContentRight;
4233 cf.bottom = mContentBottom;
4234 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004235 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004236 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004237 // Full screen windows are always given a layout that is as if the
4238 // status bar and other transient decors are gone. This is to avoid
4239 // bad states when moving from a window that is not hding the
4240 // status bar to one that is.
4241 cf.left = mRestrictedScreenLeft;
4242 cf.top = mRestrictedScreenTop;
4243 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4244 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004245 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004246 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004247 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4248 vf.left = mCurLeft;
4249 vf.top = mCurTop;
4250 vf.right = mCurRight;
4251 vf.bottom = mCurBottom;
4252 } else {
4253 vf.set(cf);
4254 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004255 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004256 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
4257 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
4258 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07004259 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4260 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004261 // A window that has requested to fill the entire screen just
4262 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004263 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04004264 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
4265 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004266 pf.left = df.left = of.left = cf.left = hasNavBar
4267 ? mDockLeft : mUnrestrictedScreenLeft;
4268 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4269 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004270 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08004271 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004272 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004273 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004274 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004275 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04004276 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
4277 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07004278 } else if (attrs.type == TYPE_NAVIGATION_BAR
4279 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004280 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004281 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4282 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4283 pf.right = df.right = of.right = mUnrestrictedScreenLeft
4284 + mUnrestrictedScreenWidth;
4285 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
4286 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004287 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004288 "Laying out navigation bar window: (%d,%d - %d,%d)",
4289 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08004290 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
4291 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07004292 && ((fl & FLAG_FULLSCREEN) != 0)) {
4293 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004294 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4295 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4296 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4297 + mOverscanScreenWidth;
4298 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4299 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08004300 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08004301 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004302 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4303 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4304 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4305 + mOverscanScreenWidth;
4306 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4307 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04004308 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004309 // The wallpaper also has Real Ultimate Power, but we want to tell
4310 // it about the overscan area.
4311 pf.left = df.left = mOverscanScreenLeft;
4312 pf.top = df.top = mOverscanScreenTop;
4313 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4314 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4315 of.left = cf.left = mUnrestrictedScreenLeft;
4316 of.top = cf.top = mUnrestrictedScreenTop;
4317 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4318 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004319 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004320 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4321 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4322 // Asking to layout into the overscan region, so give it that pure
4323 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004324 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4325 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4326 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004327 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004328 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004329 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004330 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004331 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004332 && (attrs.type == TYPE_STATUS_BAR
4333 || attrs.type == TYPE_TOAST
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01004334 || attrs.type == TYPE_DOCK_DIVIDER
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004335 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004336 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4337 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004338 // Asking for layout as if the nav bar is hidden, lets the
4339 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004340 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004341 // can be above the nav bar can do this.
4342 // XXX This assumes that an app asking for this will also
4343 // ask for layout in only content. We can't currently figure out
4344 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004345 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4346 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4347 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4348 + mUnrestrictedScreenWidth;
4349 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4350 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004351 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004352 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4353 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4354 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4355 + mRestrictedScreenWidth;
4356 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4357 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004358 }
Craig Mautner69b08182012-09-05 13:07:13 -07004359
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004360 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004361
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004362 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4363 vf.left = mCurLeft;
4364 vf.top = mCurTop;
4365 vf.right = mCurRight;
4366 vf.bottom = mCurBottom;
4367 } else {
4368 vf.set(cf);
4369 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004370 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004371 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4372 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004373 // A child window should be placed inside of the same visible
4374 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004375 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004376 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004377 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4378 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004379 // Otherwise, a normal window must be placed inside the content
4380 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004381 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4382 // Status bar panels and the volume dialog are the only windows who can go on
4383 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004384 // permission, so they have the same privileges as the status
4385 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004386 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4387 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4388 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4389 + mRestrictedScreenWidth;
4390 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4391 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004392 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004393 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004394 pf.left = df.left = of.left = cf.left = mStableLeft;
4395 pf.top = df.top = of.top = cf.top = mStableTop;
4396 pf.right = df.right = of.right = cf.right = mStableRight;
4397 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004398 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004399 pf.left = mContentLeft;
4400 pf.top = mContentTop;
4401 pf.right = mContentRight;
4402 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004403 if (win.isVoiceInteraction()) {
4404 df.left = of.left = cf.left = mVoiceContentLeft;
4405 df.top = of.top = cf.top = mVoiceContentTop;
4406 df.right = of.right = cf.right = mVoiceContentRight;
4407 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4408 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004409 df.left = of.left = cf.left = mDockLeft;
4410 df.top = of.top = cf.top = mDockTop;
4411 df.right = of.right = cf.right = mDockRight;
4412 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004413 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004414 df.left = of.left = cf.left = mContentLeft;
4415 df.top = of.top = cf.top = mContentTop;
4416 df.right = of.right = cf.right = mContentRight;
4417 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004418 }
4419 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4420 vf.left = mCurLeft;
4421 vf.top = mCurTop;
4422 vf.right = mCurRight;
4423 vf.bottom = mCurBottom;
4424 } else {
4425 vf.set(cf);
4426 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004427 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004428 }
4429 }
Craig Mautner69b08182012-09-05 13:07:13 -07004430
Craig Mautnerb816bed2013-07-23 10:26:17 -07004431 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4432 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004433 df.left = df.top = -10000;
4434 df.right = df.bottom = 10000;
4435 if (attrs.type != TYPE_WALLPAPER) {
4436 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4437 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4438 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004439 }
4440
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004441 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4442 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004443 // We only want to apply outsets to certain types of windows. For example, we never want to
4444 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004445 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004446 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004447 osf = mTmpOutsetFrame;
4448 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4449 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4450 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004451 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004452 if (rotation == Surface.ROTATION_0) {
4453 osf.bottom += outset;
4454 } else if (rotation == Surface.ROTATION_90) {
4455 osf.right += outset;
4456 } else if (rotation == Surface.ROTATION_180) {
4457 osf.top -= outset;
4458 } else if (rotation == Surface.ROTATION_270) {
4459 osf.left -= outset;
4460 }
4461 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4462 + " with rotation " + rotation + ", result: " + osf);
4463 }
4464 }
4465
Craig Mautnereda67292013-04-28 13:50:14 -07004466 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004467 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004468 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004469 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004470 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004471 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004472 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004473 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004474 + " sf=" + sf.toShortString()
4475 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004476
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004477 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004478
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004479 // Dock windows carve out the bottom of the screen, so normal windows
4480 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004481 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4482 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004483 setLastInputMethodWindowLw(null, null);
4484 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004485 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004486 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4487 && !win.getGivenInsetsPendingLw()) {
4488 offsetVoiceInputWindowLw(win);
4489 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004490 }
4491
satok1bc0a492012-04-25 22:47:12 +09004492 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004493 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004494 top += win.getGivenContentInsetsLw().top;
4495 if (mContentBottom > top) {
4496 mContentBottom = top;
4497 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004498 if (mVoiceContentBottom > top) {
4499 mVoiceContentBottom = top;
4500 }
satok1bc0a492012-04-25 22:47:12 +09004501 top = win.getVisibleFrameLw().top;
4502 top += win.getGivenVisibleInsetsLw().top;
4503 if (mCurBottom > top) {
4504 mCurBottom = top;
4505 }
Craig Mautnereda67292013-04-28 13:50:14 -07004506 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004507 + mDockBottom + " mContentBottom="
4508 + mContentBottom + " mCurBottom=" + mCurBottom);
4509 }
4510
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004511 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004512 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004513 top += win.getGivenContentInsetsLw().top;
4514 if (mVoiceContentBottom > top) {
4515 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004516 }
4517 }
4518
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004519 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004520 @Override
4521 public void finishLayoutLw() {
4522 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004523 }
4524
4525 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004526 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004527 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004528 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004529 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004530 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004531 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004532 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004533 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004534 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004535 mForcingShowNavBar = false;
4536 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004537
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004538 mHideLockScreen = false;
4539 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004540 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004541 mShowingLockscreen = false;
4542 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004543 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004544 mKeyguardSecure = isKeyguardSecure();
4545 mKeyguardSecureIncludingHidden = mKeyguardSecure
4546 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004547 }
4548
4549 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004550 @Override
Yohei Yukawad1a09222015-06-30 16:22:05 -07004551 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,
4552 WindowState attached) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004553 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4554 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004555 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004556 if (mTopFullscreenOpaqueWindowState == null
4557 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4558 mForcingShowNavBar = true;
4559 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004560 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004561 if (attrs.type == TYPE_STATUS_BAR) {
4562 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4563 mForceStatusBarFromKeyguard = true;
Jorim Jaggie1de9f62015-09-23 14:59:50 -07004564 mShowingLockscreen = true;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004565 }
4566 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4567 mForceStatusBarTransparent = true;
4568 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004569 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004570
4571 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4572 && attrs.type < FIRST_SYSTEM_WINDOW;
4573 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4574 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4575
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004576 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004577 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004578 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004579 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004580 mForceStatusBarFromKeyguard = true;
4581 } else {
4582 mForceStatusBar = true;
4583 }
4584 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004585 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004586 // If the lockscreen was showing when the dream started then wait
4587 // for the dream to draw before hiding the lockscreen.
4588 if (!mDreamingLockscreen
4589 || (win.isVisibleLw() && win.hasDrawnLw())) {
4590 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004591 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004592 }
4593 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004594
Yohei Yukawad1a09222015-06-30 16:22:05 -07004595 final IApplicationToken appToken = win.getAppToken();
4596
4597 // For app windows that are not attached, we decide if all windows in the app they
4598 // represent should be hidden or if we should hide the lockscreen. For attached app
4599 // windows we defer the decision to the window it is attached to.
4600 if (appWindow && attached == null) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004601 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004602 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004603 mAppsToBeHidden.remove(appToken);
4604 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004605 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004606 if (dismissKeyguard && !mKeyguardSecure) {
4607 mAppsThatDismissKeyguard.add(appToken);
Selim Cinek90b5e072015-08-28 17:05:56 -07004608 } else if (win.isDrawnLw() || win.hasAppShownWindows()) {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004609 mWinShowWhenLocked = win;
4610 mHideLockScreen = true;
4611 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004612 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004613 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004614 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004615 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004616 mAppsToBeHidden.add(appToken);
4617 } else {
4618 mAppsToBeHidden.remove(appToken);
4619 }
4620 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004621 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004622 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004623 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004624 if (attrs.x == 0 && attrs.y == 0
4625 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4626 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4627 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4628 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004629 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4630 mTopFullscreenOpaqueOrDimmingWindowState = win;
4631 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004632 if (!mAppsThatDismissKeyguard.isEmpty() &&
4633 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4634 if (DEBUG_LAYOUT) Slog.v(TAG,
4635 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004636 mDismissKeyguard = (mWinDismissingKeyguard == win
4637 && mSecureDismissingKeyguard == mKeyguardSecure)
4638 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004639 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004640 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004641 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Selim Cinek90b5e072015-08-28 17:05:56 -07004642 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked
4643 && (win.isDrawnLw() || win.hasAppShownWindows())) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004644 if (DEBUG_LAYOUT) Slog.v(TAG,
4645 "Setting mHideLockScreen to true by win " + win);
4646 mHideLockScreen = true;
4647 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004648 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004649 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004650 mAllowLockscreenWhenOn = true;
4651 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004652 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004653
4654 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004655 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4656 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004657 win.hideLw(false);
4658 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004659 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004660 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4661 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4662 // that is being hidden in an animation - keep the
4663 // keyguard hidden until the new window shows up and
4664 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004665 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004666 mHideLockScreen = true;
4667 mWinShowWhenLocked = win;
4668 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004669 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004670 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4671 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4672 && win.isDimming()) {
4673 mTopFullscreenOpaqueOrDimmingWindowState = win;
4674 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004675 }
4676
4677 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004678 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004679 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004680 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4681 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4682 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004683 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4684 // fullscreen window.
4685 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4686 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4687 mTopFullscreenOpaqueWindowState.hideLw(false);
4688 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4689 }
4690
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004691 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004692 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004693
4694 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4695 ? mTopFullscreenOpaqueWindowState.getAttrs()
4696 : null;
4697
Jeff Brownc8018eb2012-10-29 21:33:27 -07004698 // If we are not currently showing a dream then remember the current
4699 // lockscreen state. We will use this to determine whether the dream
4700 // started while the lockscreen was showing and remember this state
4701 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004702 if (!mShowingDream) {
4703 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004704 if (mDreamingSleepTokenNeeded) {
4705 mDreamingSleepTokenNeeded = false;
4706 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4707 }
4708 } else {
4709 if (!mDreamingSleepTokenNeeded) {
4710 mDreamingSleepTokenNeeded = true;
4711 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4712 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004713 }
4714
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004715 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004716 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004717 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004718 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004719 boolean shouldBeTransparent = mForceStatusBarTransparent
4720 && !mForceStatusBar
4721 && !mForceStatusBarFromKeyguard;
4722 if (!shouldBeTransparent) {
4723 mStatusBarController.setShowTransparent(false /* transparent */);
4724 } else if (!mStatusBar.isVisibleLw()) {
4725 mStatusBarController.setShowTransparent(true /* transparent */);
4726 }
4727 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004728 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004729 if (mStatusBarController.setBarShowingLw(true)) {
4730 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4731 }
Craig Mautner81defc72013-10-29 11:10:42 -07004732 // Maintain fullscreen layout until incoming animation is complete.
4733 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004734 // Transient status bar on the lockscreen is not allowed
4735 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4736 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4737 mLastSystemUiFlags, mLastSystemUiFlags);
4738 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004739 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004740 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004741 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004742 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07004743 + " shown position: "
4744 + mTopFullscreenOpaqueWindowState.getShownPositionLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004745 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004746 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004747 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004748 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004749 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004750 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004751 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004752 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4753 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004754 if (mStatusBarController.isTransientShowing()) {
4755 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004756 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4757 }
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07004758 } else if (topIsFullscreen
4759 && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID)
4760 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) {
Craig Mautnereda67292013-04-28 13:50:14 -07004761 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004762 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004763 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004764 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004765 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004766 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004767 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004768 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004769 if (mStatusBarController.setBarShowingLw(true)) {
4770 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4771 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004772 }
4773 }
4774 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004775
Craig Mautner81defc72013-10-29 11:10:42 -07004776 if (mTopIsFullscreen != topIsFullscreen) {
4777 if (!topIsFullscreen) {
4778 // Force another layout when status bar becomes fully shown.
4779 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4780 }
4781 mTopIsFullscreen = topIsFullscreen;
4782 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004783
Craig Mautner39834192012-09-02 07:47:24 -07004784 // Hide the key guard if a visible window explicitly specifies that it wants to be
4785 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004786 if (mKeyguardDelegate != null && mStatusBar != null) {
4787 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4788 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004789 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004790 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004791 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004792 changes |= FINISH_LAYOUT_REDO_LAYOUT
4793 | FINISH_LAYOUT_REDO_CONFIG
4794 | FINISH_LAYOUT_REDO_WALLPAPER;
4795 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004796 if (mKeyguardDelegate.isShowing()) {
4797 mHandler.post(new Runnable() {
4798 @Override
4799 public void run() {
4800 mKeyguardDelegate.keyguardDone(false, false);
4801 }
4802 });
4803 }
4804 } else if (mHideLockScreen) {
4805 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004806 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004807 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004808 changes |= FINISH_LAYOUT_REDO_LAYOUT
4809 | FINISH_LAYOUT_REDO_CONFIG
4810 | FINISH_LAYOUT_REDO_WALLPAPER;
4811 }
4812 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004813 mKeyguardHidden = false;
4814 if (setKeyguardOccludedLw(false)) {
4815 changes |= FINISH_LAYOUT_REDO_LAYOUT
4816 | FINISH_LAYOUT_REDO_CONFIG
4817 | FINISH_LAYOUT_REDO_WALLPAPER;
4818 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004819 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4820 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004821 mHandler.post(new Runnable() {
4822 @Override
4823 public void run() {
4824 mKeyguardDelegate.dismiss();
4825 }
4826 });
4827 }
4828 } else {
4829 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004830 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004831 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004832 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004833 changes |= FINISH_LAYOUT_REDO_LAYOUT
4834 | FINISH_LAYOUT_REDO_CONFIG
4835 | FINISH_LAYOUT_REDO_WALLPAPER;
4836 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004837 }
4838 }
Joe Onorato664644d2011-01-23 17:53:23 -08004839
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004840 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004841 // If the navigation bar has been hidden or shown, we need to do another
4842 // layout pass to update that window.
4843 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4844 }
Joe Onorato664644d2011-01-23 17:53:23 -08004845
Mike Lockwood28569302010-01-28 11:54:40 -05004846 // update since mAllowLockscreenWhenOn might have changed
4847 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004848 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004849 }
4850
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004851 /**
Jim Millerab954542014-10-10 18:21:49 -07004852 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004853 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004854 * @return Whether the flags have changed and we have to redo the layout.
4855 */
Jim Millerab954542014-10-10 18:21:49 -07004856 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4857 boolean wasOccluded = mKeyguardOccluded;
4858 boolean showing = mKeyguardDelegate.isShowing();
4859 if (wasOccluded && !isOccluded && showing) {
4860 mKeyguardOccluded = false;
4861 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004862 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4863 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4864 return true;
Jim Millerab954542014-10-10 18:21:49 -07004865 } else if (!wasOccluded && isOccluded && showing) {
4866 mKeyguardOccluded = true;
4867 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004868 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4869 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4870 return true;
4871 } else {
4872 return false;
4873 }
4874 }
4875
4876 private boolean isStatusBarKeyguard() {
4877 return mStatusBar != null
4878 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4879 }
4880
Jose Lima9546b202014-07-02 17:21:51 -07004881 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004882 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004883 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004884 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004885 return false;
4886 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004887 return true;
4888 }
4889
Jose Lima9546b202014-07-02 17:21:51 -07004890 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004891 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004892 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004893 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004894 // If the navigation bar has been hidden or shown, we need to do another
4895 // layout pass to update that window.
4896 return FINISH_LAYOUT_REDO_LAYOUT;
4897 }
4898 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004899 }
4900
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004901 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004902 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004903 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4904 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004905 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4906 if (newLidState == mLidState) {
4907 return;
4908 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004909
Jeff Brownc458ce92012-04-30 14:58:40 -07004910 mLidState = newLidState;
4911 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004912 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004913
4914 if (lidOpen) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07004915 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch,
4916 "android.policy:LID");
Jeff Brownc458ce92012-04-30 14:58:40 -07004917 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004918 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004919 }
4920 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004921
Michael Wright3818c922014-09-02 13:59:07 -07004922 @Override
4923 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4924 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4925 if (mCameraLensCoverState == lensCoverState) {
4926 return;
4927 }
4928 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4929 lensCoverState == CAMERA_LENS_UNCOVERED) {
4930 Intent intent;
4931 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4932 mKeyguardDelegate.isShowing();
4933 if (keyguardActive) {
4934 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4935 } else {
4936 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4937 }
Dianne Hackborn280a64e2015-07-13 14:48:08 -07004938 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens,
4939 "android.policy:CAMERA_COVER");
Bart Sears8b1c27c2015-03-18 23:51:02 +00004940 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004941 }
4942 mCameraLensCoverState = lensCoverState;
4943 }
4944
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004945 void setHdmiPlugged(boolean plugged) {
4946 if (mHdmiPlugged != plugged) {
4947 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004948 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004949 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004950 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004951 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004952 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004953 }
4954 }
4955
Joe Onoratoea495d42011-04-06 11:41:11 -07004956 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004957 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004958 // watch for HDMI plug messages if the hdmi switch exists
4959 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4960 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4961
Joe Onoratoea495d42011-04-06 11:41:11 -07004962 final String filename = "/sys/class/switch/hdmi/state";
4963 FileReader reader = null;
4964 try {
4965 reader = new FileReader(filename);
4966 char[] buf = new char[15];
4967 int n = reader.read(buf);
4968 if (n > 1) {
4969 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4970 }
4971 } catch (IOException ex) {
4972 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4973 } catch (NumberFormatException ex) {
4974 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4975 } finally {
4976 if (reader != null) {
4977 try {
4978 reader.close();
4979 } catch (IOException ex) {
4980 }
Joe Onoratodc100302011-01-11 17:07:41 -08004981 }
4982 }
4983 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004984 // This dance forces the code in setHdmiPlugged to run.
4985 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4986 mHdmiPlugged = !plugged;
4987 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004988 }
4989
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004990 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004991 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004992
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004993 final Runnable mScreenshotTimeout = new Runnable() {
4994 @Override public void run() {
4995 synchronized (mScreenshotLock) {
4996 if (mScreenshotConnection != null) {
4997 mContext.unbindService(mScreenshotConnection);
4998 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004999 }
Winson Chung9112ec32011-06-27 13:15:32 -07005000 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005001 }
5002 };
5003
5004 // Assume this is called from the Handler thread.
5005 private void takeScreenshot() {
5006 synchronized (mScreenshotLock) {
5007 if (mScreenshotConnection != null) {
5008 return;
5009 }
5010 ComponentName cn = new ComponentName("com.android.systemui",
5011 "com.android.systemui.screenshot.TakeScreenshotService");
5012 Intent intent = new Intent();
5013 intent.setComponent(cn);
5014 ServiceConnection conn = new ServiceConnection() {
5015 @Override
5016 public void onServiceConnected(ComponentName name, IBinder service) {
5017 synchronized (mScreenshotLock) {
5018 if (mScreenshotConnection != this) {
5019 return;
5020 }
5021 Messenger messenger = new Messenger(service);
5022 Message msg = Message.obtain(null, 1);
5023 final ServiceConnection myConn = this;
5024 Handler h = new Handler(mHandler.getLooper()) {
5025 @Override
5026 public void handleMessage(Message msg) {
5027 synchronized (mScreenshotLock) {
5028 if (mScreenshotConnection == myConn) {
5029 mContext.unbindService(mScreenshotConnection);
5030 mScreenshotConnection = null;
5031 mHandler.removeCallbacks(mScreenshotTimeout);
5032 }
5033 }
5034 }
5035 };
5036 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07005037 msg.arg1 = msg.arg2 = 0;
5038 if (mStatusBar != null && mStatusBar.isVisibleLw())
5039 msg.arg1 = 1;
5040 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
5041 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005042 try {
5043 messenger.send(msg);
5044 } catch (RemoteException e) {
5045 }
5046 }
5047 }
5048 @Override
5049 public void onServiceDisconnected(ComponentName name) {}
5050 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08005051 if (mContext.bindServiceAsUser(
5052 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005053 mScreenshotConnection = conn;
5054 mHandler.postDelayed(mScreenshotTimeout, 10000);
5055 }
5056 }
Winson Chung9112ec32011-06-27 13:15:32 -07005057 }
5058
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005059 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005060 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07005061 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07005062 if (!mSystemBooted) {
5063 // If we have not yet booted, don't let key events do anything.
5064 return 0;
5065 }
5066
Jeff Brown037c33e2014-04-09 00:31:55 -07005067 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08005068 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
5069 final boolean canceled = event.isCanceled();
5070 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07005071
Jeff Brown3122e442010-10-11 23:32:49 -07005072 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07005073
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05005074 // If screen is off then we treat the case where the keyguard is open but hidden
5075 // the same as if it were open and in front.
5076 // This will prevent any keys other than the power button from waking the screen
5077 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08005078 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07005079 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07005080 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08005081 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005082
Jeff Brown40013652012-05-16 21:22:36 -07005083 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005084 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07005085 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08005086 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005087 }
5088
Jeff Brown037c33e2014-04-09 00:31:55 -07005089 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07005090 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07005091 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
5092 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07005093 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07005094 // When the device is interactive or the key is injected pass the
5095 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07005096 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005097 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07005098 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
5099 // If we're currently dozing with the screen on and the keyguard showing, pass the key
5100 // to the application but preserve its wake key status to make sure we still move
5101 // from dozing to fully interactive if we would normally go from off to fully
5102 // interactive.
5103 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07005104 } else {
5105 // When the screen is off and the key is not injected, determine whether
5106 // to wake the device but don't pass the key to the application.
5107 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08005108 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
5109 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005110 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005111 }
5112
Justin Kohd378ad72013-04-01 12:18:26 -07005113 // If the key would be handled globally, just return the result, don't worry about special
5114 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07005115 if (isValidGlobalKey(keyCode)
5116 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07005117 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005118 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Michael Wright85b1af62014-06-04 14:51:58 -07005119 }
Justin Kohd378ad72013-04-01 12:18:26 -07005120 return result;
5121 }
5122
Jeff Brownbae8e772014-06-12 19:59:45 -07005123 boolean useHapticFeedback = down
5124 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
5125 && event.getRepeatCount() == 0;
5126
Jeff Brown4d396052010-10-29 21:50:21 -07005127 // Handle special keys.
5128 switch (keyCode) {
5129 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07005130 case KeyEvent.KEYCODE_VOLUME_UP:
5131 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005132 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
5133 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005134 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005135 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005136 mScreenshotChordVolumeDownKeyTriggered = true;
5137 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
5138 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005139 cancelPendingPowerKeyAction();
5140 interceptScreenshotChord();
5141 }
5142 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005143 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005144 cancelPendingScreenshotChordAction();
5145 }
5146 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
5147 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005148 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005149 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005150 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005151 cancelPendingPowerKeyAction();
5152 cancelPendingScreenshotChordAction();
5153 }
5154 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005155 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005156 cancelPendingScreenshotChordAction();
5157 }
5158 }
Jeff Brown4d396052010-10-29 21:50:21 -07005159 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005160 TelecomManager telecomManager = getTelecommService();
5161 if (telecomManager != null) {
5162 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005163 // If an incoming call is ringing, either VOLUME key means
5164 // "silence ringer". We handle these keys here, rather than
5165 // in the InCallScreen, to make sure we'll respond to them
5166 // even if the InCallScreen hasn't come to the foreground yet.
5167 // Look for the DOWN event here, to agree with the "fallback"
5168 // behavior in the InCallScreen.
5169 Log.i(TAG, "interceptKeyBeforeQueueing:"
5170 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07005171
Santos Cordon6848f722014-05-21 15:22:12 -07005172 // Silence the ringer. (It's safe to call this
5173 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005174 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07005175
Santos Cordon6848f722014-05-21 15:22:12 -07005176 // And *don't* pass this key thru to the current activity
5177 // (which is probably the InCallScreen.)
5178 result &= ~ACTION_PASS_TO_USER;
5179 break;
5180 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005181 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07005182 && (result & ACTION_PASS_TO_USER) == 0) {
5183 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07005184 // the application, just pass it to the session service.
5185
5186 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07005187 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07005188 break;
Jeff Brown4d396052010-10-29 21:50:21 -07005189 }
5190 }
Jaewan Kim765487f2016-01-12 14:45:42 +09005191 }
5192 if (mUseTvRouting) {
5193 // On TVs, defer special key handlings to
5194 // {@link interceptKeyBeforeDispatching()}.
5195 result |= ACTION_PASS_TO_USER;
5196 } else if ((result & ACTION_PASS_TO_USER) == 0) {
5197 // If we aren't passing to the user and no one else
5198 // handled it send it to the session manager to
5199 // figure out.
5200 MediaSessionLegacyHelper.getHelper(mContext)
5201 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07005202 }
5203 break;
5204 }
5205
5206 case KeyEvent.KEYCODE_ENDCALL: {
5207 result &= ~ACTION_PASS_TO_USER;
5208 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005209 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07005210 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005211 if (telecomManager != null) {
5212 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07005213 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005214 if (interactive && !hungUp) {
5215 mEndCallKeyHandled = false;
5216 mHandler.postDelayed(mEndCallLongPress,
5217 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
5218 } else {
5219 mEndCallKeyHandled = true;
5220 }
Jeff Brown4d396052010-10-29 21:50:21 -07005221 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005222 if (!mEndCallKeyHandled) {
5223 mHandler.removeCallbacks(mEndCallLongPress);
5224 if (!canceled) {
5225 if ((mEndcallBehavior
5226 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
5227 if (goHome()) {
5228 break;
5229 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07005230 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005231 if ((mEndcallBehavior
5232 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
5233 mPowerManager.goToSleep(event.getEventTime(),
5234 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
5235 isWakeKey = false;
5236 }
Jeff Brown4d396052010-10-29 21:50:21 -07005237 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005238 }
Jeff Brown4d396052010-10-29 21:50:21 -07005239 }
5240 break;
5241 }
5242
5243 case KeyEvent.KEYCODE_POWER: {
5244 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07005245 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07005246 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005247 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005248 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005249 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07005250 }
5251 break;
5252 }
5253
Jeff Brown6212a492014-03-07 13:58:47 -08005254 case KeyEvent.KEYCODE_SLEEP: {
5255 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005256 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07005257 if (!mPowerManager.isInteractive()) {
5258 useHapticFeedback = false; // suppress feedback if already non-interactive
5259 }
Nick Vaccarob593a812015-05-15 11:23:05 -07005260 if (down) {
5261 sleepPress(event.getEventTime());
5262 } else {
5263 sleepRelease(event.getEventTime());
5264 }
Jeff Brown6212a492014-03-07 13:58:47 -08005265 break;
5266 }
5267
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -07005268 case KeyEvent.KEYCODE_SOFT_SLEEP: {
5269 result &= ~ACTION_PASS_TO_USER;
5270 isWakeKey = false;
5271 if (!down) {
5272 mPowerManagerInternal.setUserInactiveOverrideFromWindowManager();
5273 }
5274 break;
5275 }
5276
Jeff Brown6212a492014-03-07 13:58:47 -08005277 case KeyEvent.KEYCODE_WAKEUP: {
5278 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005279 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08005280 break;
5281 }
5282
Jeff Brown4d396052010-10-29 21:50:21 -07005283 case KeyEvent.KEYCODE_MEDIA_PLAY:
5284 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5285 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07005286 case KeyEvent.KEYCODE_HEADSETHOOK:
5287 case KeyEvent.KEYCODE_MUTE:
5288 case KeyEvent.KEYCODE_MEDIA_STOP:
5289 case KeyEvent.KEYCODE_MEDIA_NEXT:
5290 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5291 case KeyEvent.KEYCODE_MEDIA_REWIND:
5292 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005293 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
5294 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07005295 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
5296 // If the global session is active pass all media keys to it
5297 // instead of the active window.
5298 result &= ~ACTION_PASS_TO_USER;
5299 }
Jeff Brown4d396052010-10-29 21:50:21 -07005300 if ((result & ACTION_PASS_TO_USER) == 0) {
5301 // Only do this if we would otherwise not pass it to the user. In that
5302 // case, the PhoneWindow class will do the same thing, except it will
5303 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07005304 // Note that we need to make a copy of the key event here because the
5305 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07005306 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07005307 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
5308 new KeyEvent(event));
5309 msg.setAsynchronous(true);
5310 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005311 }
5312 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005313 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005314
Jeff Brown4d396052010-10-29 21:50:21 -07005315 case KeyEvent.KEYCODE_CALL: {
5316 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005317 TelecomManager telecomManager = getTelecommService();
5318 if (telecomManager != null) {
5319 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005320 Log.i(TAG, "interceptKeyBeforeQueueing:"
5321 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005322 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005323
Santos Cordon6848f722014-05-21 15:22:12 -07005324 // And *don't* pass this key thru to the current activity
5325 // (which is presumably the InCallScreen.)
5326 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005327 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005328 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005329 }
Jeff Brown4d396052010-10-29 21:50:21 -07005330 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005331 }
Michael Wright869a67c2014-08-26 19:33:06 -07005332 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5333 // Only do this if we would otherwise not pass it to the user. In that case,
5334 // interceptKeyBeforeDispatching would apply a similar but different policy in
5335 // order to invoke voice assist actions. Note that we need to make a copy of the
5336 // key event here because the original key event will be recycled when we return.
5337 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5338 mBroadcastWakeLock.acquire();
5339 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5340 keyguardActive ? 1 : 0, 0);
5341 msg.setAsynchronous(true);
5342 msg.sendToTarget();
5343 }
Jaewan Kim49117872016-01-19 17:24:08 +09005344 break;
5345 }
5346 case KeyEvent.KEYCODE_WINDOW: {
5347 if (mShortPressWindowBehavior == SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE) {
5348 if (!down) {
5349 handlePipKey(event);
5350 }
5351 result &= ~ACTION_PASS_TO_USER;
5352 }
5353 break;
Michael Wright869a67c2014-08-26 19:33:06 -07005354 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005355 }
Jeff Brown26875502014-01-30 21:47:47 -08005356
Jeff Brownbae8e772014-06-12 19:59:45 -07005357 if (useHapticFeedback) {
5358 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5359 }
5360
Jeff Brown26875502014-01-30 21:47:47 -08005361 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005362 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Jeff Brown26875502014-01-30 21:47:47 -08005363 }
Bryce Lee584a4452014-10-21 15:55:55 -07005364
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005365 return result;
5366 }
5367
Jeff Brown1c2e4942012-11-06 16:32:01 -08005368 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005369 * Returns true if the key can have global actions attached to it.
5370 * We reserve all power management keys for the system since they require
5371 * very careful handling.
5372 */
5373 private static boolean isValidGlobalKey(int keyCode) {
5374 switch (keyCode) {
5375 case KeyEvent.KEYCODE_POWER:
5376 case KeyEvent.KEYCODE_WAKEUP:
5377 case KeyEvent.KEYCODE_SLEEP:
5378 return false;
5379 default:
5380 return true;
5381 }
5382 }
5383
5384 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005385 * When the screen is off we ignore some keys that might otherwise typically
5386 * be considered wake keys. We filter them out here.
5387 *
5388 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5389 * is always considered a wake key.
5390 */
5391 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5392 switch (keyCode) {
5393 // ignore volume keys unless docked
5394 case KeyEvent.KEYCODE_VOLUME_UP:
5395 case KeyEvent.KEYCODE_VOLUME_DOWN:
5396 case KeyEvent.KEYCODE_VOLUME_MUTE:
5397 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5398
5399 // ignore media and camera keys
5400 case KeyEvent.KEYCODE_MUTE:
5401 case KeyEvent.KEYCODE_HEADSETHOOK:
5402 case KeyEvent.KEYCODE_MEDIA_PLAY:
5403 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5404 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5405 case KeyEvent.KEYCODE_MEDIA_STOP:
5406 case KeyEvent.KEYCODE_MEDIA_NEXT:
5407 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5408 case KeyEvent.KEYCODE_MEDIA_REWIND:
5409 case KeyEvent.KEYCODE_MEDIA_RECORD:
5410 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005411 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005412 case KeyEvent.KEYCODE_CAMERA:
5413 return false;
5414 }
5415 return true;
5416 }
5417
5418
Jeff Brown56194eb2011-03-02 19:23:13 -08005419 /** {@inheritDoc} */
5420 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005421 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5422 if ((policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005423 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion,
5424 "android.policy:MOTION")) {
Bryce Lee5c138322014-11-03 08:26:09 -08005425 return 0;
5426 }
Michael Wright70af00a2014-09-03 19:30:20 -07005427 }
Bryce Lee5c138322014-11-03 08:26:09 -08005428
Michael Wright70af00a2014-09-03 19:30:20 -07005429 if (shouldDispatchInputWhenNonInteractive()) {
5430 return ACTION_PASS_TO_USER;
5431 }
Bryce Lee5c138322014-11-03 08:26:09 -08005432
Bryce Lee812d7022014-11-10 13:33:28 -08005433 // If we have not passed the action up and we are in theater mode without dreaming,
5434 // there will be no dream to intercept the touch and wake into ambient. The device should
5435 // wake up in this case.
5436 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005437 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming,
5438 "android.policy:MOTION");
Bryce Lee812d7022014-11-10 13:33:28 -08005439 }
5440
Jeff Brown037c33e2014-04-09 00:31:55 -07005441 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005442 }
5443
Michael Wright70af00a2014-09-03 19:30:20 -07005444 private boolean shouldDispatchInputWhenNonInteractive() {
Joe LaPennaf2b9b2d2015-11-17 22:22:37 +00005445 // Send events to keyguard while the screen is on.
5446 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5447 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005448 return true;
5449 }
5450
5451 // Send events to a dozing dream even if the screen is off since the dream
5452 // is in control of the state of the screen.
5453 IDreamManager dreamManager = getDreamManager();
5454
5455 try {
5456 if (dreamManager != null && dreamManager.isDreaming()) {
5457 return true;
5458 }
5459 } catch (RemoteException e) {
5460 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5461 }
5462
5463 // Otherwise, consume events since the user can't see what is being
5464 // interacted with.
5465 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005466 }
5467
RoboErik001c59c2015-01-26 15:53:51 -08005468 private void dispatchDirectAudioEvent(KeyEvent event) {
5469 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5470 return;
5471 }
5472 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005473 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5474 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005475 String pkgName = mContext.getOpPackageName();
5476 switch (keyCode) {
5477 case KeyEvent.KEYCODE_VOLUME_UP:
5478 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005479 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005480 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005481 } catch (RemoteException e) {
5482 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5483 }
5484 break;
5485 case KeyEvent.KEYCODE_VOLUME_DOWN:
5486 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005487 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005488 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005489 } catch (RemoteException e) {
5490 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5491 }
5492 break;
5493 case KeyEvent.KEYCODE_VOLUME_MUTE:
5494 try {
5495 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005496 getAudioService().adjustSuggestedStreamVolume(
5497 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005498 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005499 }
5500 } catch (RemoteException e) {
5501 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5502 }
5503 break;
5504 }
5505 }
5506
Jeff Brown40013652012-05-16 21:22:36 -07005507 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5508 if (DEBUG_INPUT) {
5509 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005510 }
5511
Jeff Brown40013652012-05-16 21:22:36 -07005512 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5513 if (DEBUG_INPUT) {
5514 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5515 }
5516
5517 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5518 mHavePendingMediaKeyRepeatWithWakeLock = false;
5519 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5520 }
5521
5522 dispatchMediaKeyWithWakeLockToAudioService(event);
5523
5524 if (event.getAction() == KeyEvent.ACTION_DOWN
5525 && event.getRepeatCount() == 0) {
5526 mHavePendingMediaKeyRepeatWithWakeLock = true;
5527
5528 Message msg = mHandler.obtainMessage(
5529 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5530 msg.setAsynchronous(true);
5531 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5532 } else {
5533 mBroadcastWakeLock.release();
5534 }
5535 }
5536
5537 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5538 mHavePendingMediaKeyRepeatWithWakeLock = false;
5539
5540 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5541 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5542 if (DEBUG_INPUT) {
5543 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5544 }
5545
5546 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5547 mBroadcastWakeLock.release();
5548 }
5549
5550 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5551 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005552 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005553 }
5554 }
5555
Michael Wright869a67c2014-08-26 19:33:06 -07005556 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005557 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5558 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5559 if (dic != null) {
5560 try {
5561 dic.exitIdle("voice-search");
5562 } catch (RemoteException e) {
5563 }
5564 }
Michael Wright869a67c2014-08-26 19:33:06 -07005565 Intent voiceIntent =
5566 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5567 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005568 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005569 mBroadcastWakeLock.release();
5570 }
5571
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005572 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005573 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005574 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005575 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5576 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5577 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005578 } else {
5579 try {
5580 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5581 ServiceManager.getService(Context.UI_MODE_SERVICE));
5582 mUiMode = uiModeService.getCurrentModeType();
5583 } catch (RemoteException e) {
5584 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005585 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005586 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005587 synchronized (mLock) {
5588 updateOrientationListenerLp();
5589 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005590 }
5591 };
5592
Jeff Brown6aaf2952012-10-05 16:01:08 -07005593 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5594 @Override
5595 public void onReceive(Context context, Intent intent) {
5596 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005597 if (mKeyguardDelegate != null) {
5598 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005599 }
5600 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005601 if (mKeyguardDelegate != null) {
5602 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005603 }
5604 }
5605 }
5606 };
5607
Christopher Tate5e08af02012-09-21 17:17:22 -07005608 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5609 @Override
5610 public void onReceive(Context context, Intent intent) {
5611 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5612 // tickle the settings observer: this first ensures that we're
5613 // observing the relevant settings for the newly-active user,
5614 // and then updates our own bookkeeping based on the now-
5615 // current user.
5616 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005617
5618 // force a re-application of focused window sysui visibility.
5619 // the window may never have been shown for this user
5620 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005621 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005622 mLastSystemUiFlags = 0;
5623 updateSystemUiVisibilityLw();
5624 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005625 }
5626 }
5627 };
5628
Adrian Roosddc8b272015-05-21 16:28:27 -07005629 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005630 @Override
5631 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005632 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5633 if (!isUserSetupComplete()) {
5634 // Swipe-up for navigation bar is disabled during setup
5635 return;
5636 }
5637 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5638 mNavigationBarController.showTransient();
5639 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005640 }
5641 };
5642
John Spurlocke1f366f2013-08-05 12:22:40 -04005643 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005644 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005645 if (!isUserSetupComplete()) {
5646 // Swipe-up for navigation bar is disabled during setup
5647 return;
5648 }
John Spurlock27735a42013-08-14 17:57:38 -04005649 boolean sb = mStatusBarController.checkShowTransientBarLw();
5650 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005651 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005652 // Don't show status bar when swiping on already visible navigation bar
5653 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005654 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005655 return;
5656 }
John Spurlock27735a42013-08-14 17:57:38 -04005657 if (sb) mStatusBarController.showTransient();
5658 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005659 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005660 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005661 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005662 }
5663 }
5664
Jeff Brown3ee549c2014-09-22 20:14:39 -07005665 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005666 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005667 public void startedGoingToSleep(int why) {
5668 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005669 if (mKeyguardDelegate != null) {
5670 mKeyguardDelegate.onStartedGoingToSleep(why);
5671 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005672 }
5673
5674 // Called on the PowerManager's Notifier thread.
5675 @Override
5676 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005677 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005678 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04005679 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005680
5681 // We must get this work done here because the power manager will drop
5682 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005683 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005684 mAwake = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005685 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005686 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005687 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005688 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005689 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005690 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005691 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005692 }
5693
Jeff Brown3ee549c2014-09-22 20:14:39 -07005694 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005695 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005696 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005697 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005698 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005699
Jeff Brown3ee549c2014-09-22 20:14:39 -07005700 // Since goToSleep performs these functions synchronously, we must
5701 // do the same here. We cannot post this work to a handler because
5702 // that might cause it to become reordered with respect to what
5703 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005704 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005705 mAwake = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005706
Jeff Browna20dda42014-05-27 20:57:24 -07005707 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005708 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005709 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005710 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005711
Jim Miller5ecd8112013-01-09 18:50:26 -08005712 if (mKeyguardDelegate != null) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005713 mKeyguardDelegate.onStartedWakingUp();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005714 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005715 }
5716
Jeff Brown416c49c2015-05-26 19:50:18 -07005717 // Called on the PowerManager's Notifier thread.
5718 @Override
5719 public void finishedWakingUp() {
5720 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5721 }
5722
5723 private void wakeUpFromPowerKey(long eventTime) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005724 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER");
Jeff Brown416c49c2015-05-26 19:50:18 -07005725 }
5726
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005727 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) {
Bryce Leed3896842015-06-23 17:06:51 -07005728 final boolean theaterModeEnabled = isTheaterModeEnabled();
5729 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07005730 return false;
5731 }
5732
Bryce Leed3896842015-06-23 17:06:51 -07005733 if (theaterModeEnabled) {
5734 Settings.Global.putInt(mContext.getContentResolver(),
5735 Settings.Global.THEATER_MODE_ON, 0);
5736 }
5737
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005738 mPowerManager.wakeUp(wakeTime, reason);
Jeff Brown416c49c2015-05-26 19:50:18 -07005739 return true;
5740 }
5741
Jeff Brown36c4db82014-09-19 12:05:31 -07005742 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005743 synchronized (mLock) {
Jorim Jaggif3255482015-07-24 12:32:42 -07005744 if (!mScreenOnEarly || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005745 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005746 }
5747
Jeff Brown36c4db82014-09-19 12:05:31 -07005748 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005749 if (mKeyguardDelegate != null) {
5750 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5751 }
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005752 mWindowManagerDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005753 }
5754
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005755 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
5756 // as well as enabling the orientation change logic/sensor.
5757 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5758 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005759 }
5760
5761 // Called on the DisplayManager's DisplayPowerController thread.
5762 @Override
5763 public void screenTurnedOff() {
5764 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5765
Jeff Brown48d1b142015-06-10 16:36:03 -07005766 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005767 synchronized (mLock) {
5768 mScreenOnEarly = false;
5769 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005770 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005771 mWindowManagerDrawComplete = false;
5772 mScreenOnListener = null;
5773 updateOrientationListenerLp();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005774
5775 if (mKeyguardDelegate != null) {
5776 mKeyguardDelegate.onScreenTurnedOff();
5777 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005778 }
5779 }
5780
Jeff Brown3ee549c2014-09-22 20:14:39 -07005781 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005782 @Override
5783 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005784 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005785
Jeff Brown48d1b142015-06-10 16:36:03 -07005786 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005787 synchronized (mLock) {
5788 mScreenOnEarly = true;
5789 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005790 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005791 mWindowManagerDrawComplete = false;
5792 mScreenOnListener = screenOnListener;
Jeff Brown36c4db82014-09-19 12:05:31 -07005793
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005794 if (mKeyguardDelegate != null) {
Jorim Jaggia4b51bc2015-08-10 18:20:43 -07005795 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5796 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005797 mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback);
5798 } else {
5799 if (DEBUG_WAKEUP) Slog.d(TAG,
5800 "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
5801 finishKeyguardDrawn();
5802 }
5803 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005804 }
5805
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005806 // Called on the DisplayManager's DisplayPowerController thread.
5807 @Override
5808 public void screenTurnedOn() {
5809 synchronized (mLock) {
5810 if (mKeyguardDelegate != null) {
5811 mKeyguardDelegate.onScreenTurnedOn();
5812 }
5813 }
5814 }
5815
Jeff Brown36c4db82014-09-19 12:05:31 -07005816 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005817 synchronized (mLock) {
5818 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005819 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005820 }
5821
Jeff Brown36c4db82014-09-19 12:05:31 -07005822 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005823 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005824
5825 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005826 }
5827
Craig Mautner8a0da012014-05-31 15:13:37 -07005828 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005829 synchronized (mLock) {
5830 // We have just finished drawing screen content. Since the orientation listener
5831 // gets only installed when all windows are drawn, we try to install it again.
5832 updateOrientationListenerLp();
5833 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005834 final ScreenOnListener listener;
5835 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005836 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005837 if (DEBUG_WAKEUP) Slog.d(TAG,
5838 "finishScreenTurningOn: mAwake=" + mAwake
5839 + ", mScreenOnEarly=" + mScreenOnEarly
5840 + ", mScreenOnFully=" + mScreenOnFully
5841 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5842 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5843
5844 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5845 || (mAwake && !mKeyguardDrawComplete)) {
5846 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005847 }
5848
Jeff Brown3ee549c2014-09-22 20:14:39 -07005849 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5850 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005851 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005852 mScreenOnFully = true;
5853
5854 // Remember the first time we draw the keyguard so we know when we're done with
5855 // the main part of booting and can enable the screen and hide boot messages.
5856 if (!mKeyguardDrawnOnce && mAwake) {
5857 mKeyguardDrawnOnce = true;
5858 enableScreen = true;
5859 if (mBootMessageNeedsHiding) {
5860 mBootMessageNeedsHiding = false;
5861 hideBootMessages();
5862 }
5863 } else {
5864 enableScreen = false;
5865 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005866 }
5867
Jeff Brown3ee549c2014-09-22 20:14:39 -07005868 if (listener != null) {
5869 listener.onScreenOn();
5870 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005871
Jeff Brown3ee549c2014-09-22 20:14:39 -07005872 if (enableScreen) {
5873 try {
5874 mWindowManager.enableScreenIfNeeded();
5875 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005876 }
Craig Mautnera631d492014-08-05 15:16:01 -07005877 }
5878 }
5879
5880 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005881 synchronized (mLock) {
5882 if (!mKeyguardDrawnOnce) {
5883 mBootMessageNeedsHiding = true;
5884 return; // keyguard hasn't drawn the first time yet, not done booting
5885 }
Craig Mautnera631d492014-08-05 15:16:01 -07005886 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005887
5888 if (mBootMsgDialog != null) {
5889 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5890 mBootMsgDialog.dismiss();
5891 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005892 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005893 }
5894
5895 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005896 public boolean isScreenOn() {
5897 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005898 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005899
Dianne Hackborn08743722009-12-21 12:16:51 -08005900 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005901 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005902 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005903 if (mKeyguardDelegate != null) {
5904 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005905 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005906 }
5907
5908 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005909 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005910 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005911 if (mKeyguardDelegate != null) {
5912 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005913 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005914 }
5915
Jim Millerab954542014-10-10 18:21:49 -07005916 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005917 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005918 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005919 }
5920
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005921 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005922 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005923 public boolean isKeyguardLocked() {
5924 return keyguardOn();
5925 }
5926
5927 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005928 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005929 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005930 if (mKeyguardDelegate == null) return false;
5931 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005932 }
5933
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005934 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005935 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07005936 public boolean isKeyguardShowingOrOccluded() {
5937 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
5938 }
5939
5940 /** {@inheritDoc} */
5941 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005942 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005943 if (mKeyguardDelegate == null) return false;
5944 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005945 }
5946
Jose Lima9546b202014-07-02 17:21:51 -07005947 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005948 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005949 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005950 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005951 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005952 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005953 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005954 // ask the keyguard to prompt the user to authenticate if necessary
5955 mKeyguardDelegate.dismiss();
5956 }
5957 });
5958 }
5959 }
5960
5961 public void notifyActivityDrawnForKeyguardLw() {
5962 if (mKeyguardDelegate != null) {
5963 mHandler.post(new Runnable() {
5964 @Override
5965 public void run() {
5966 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005967 }
5968 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005969 }
5970 }
5971
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005972 @Override
5973 public boolean isKeyguardDrawnLw() {
5974 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005975 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005976 }
5977 }
5978
Jorim Jaggi0d674622014-05-21 01:34:15 +02005979 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005980 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005981 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005982 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005983 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005984 }
5985 }
5986
Jorim Jaggi737af722015-12-31 10:42:27 +01005987 @Override
5988 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
5989 Rect outInsets) {
5990 outInsets.setEmpty();
5991 if (mStatusBar != null) {
5992 outInsets.top = mStatusBarHeight;
5993 }
5994 if (mNavigationBar != null) {
5995 if (isNavigationBarOnBottom(displayWidth, displayHeight)) {
5996 outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode);
5997 } else {
5998 outInsets.right = getNavigationBarWidth(displayRotation, mUiMode);
5999 }
6000 }
6001 }
6002
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006003 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006004 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006005 }
6006
6007 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006008 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006009 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07006010
Jeff Brown01a98dd2011-09-20 15:08:29 -07006011 @Override
6012 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006013 if (false) {
6014 Slog.v(TAG, "rotationForOrientationLw(orient="
6015 + orientation + ", last=" + lastRotation
6016 + "); user=" + mUserRotation + " "
6017 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
6018 ? "USER_ROTATION_LOCKED" : "")
6019 );
6020 }
6021
Craig Mautner46ac6fa2013-08-01 10:06:34 -07006022 if (mForceDefaultOrientation) {
6023 return Surface.ROTATION_0;
6024 }
6025
The Android Open Source Project0727d222009-03-11 12:11:58 -07006026 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07006027 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
6028 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07006029 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07006030 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006031
Jeff Browndec6cf42011-11-15 14:08:20 -08006032 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07006033 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006034 // Ignore sensor when lid switch is open and rotation is forced.
6035 preferredRotation = mLidOpenRotation;
6036 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07006037 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006038 // Ignore sensor when in car dock unless explicitly enabled.
6039 // This case can override the behavior of NOSENSOR, and can also
6040 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006041 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006042 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08006043 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6044 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
6045 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07006046 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006047 // Ignore sensor when in desk dock unless explicitly enabled.
6048 // This case can override the behavior of NOSENSOR, and can also
6049 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006050 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006051 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006052 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
6053 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08006054 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006055 preferredRotation = mDemoHdmiRotation;
6056 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
6057 && mUndockedHdmiRotation >= 0) {
6058 // Ignore sensor when plugged into HDMI and an undocked orientation has
6059 // been specified in the configuration (only for legacy devices without
6060 // full multi-display support).
6061 // Note that the dock orientation overrides the HDMI orientation.
6062 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08006063 } else if (mDemoRotationLock) {
6064 // Ignore sensor when demo rotation lock is enabled.
6065 // Note that the dock orientation and HDMI rotation lock override this.
6066 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006067 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
6068 // Application just wants to remain locked in the last rotation.
6069 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08006070 } else if (!mSupportAutoRotation) {
6071 // If we don't support auto-rotation then bail out here and ignore
6072 // the sensor and any rotation lock settings.
6073 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07006074 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07006075 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006076 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
6077 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
6078 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
6079 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07006080 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
6081 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6082 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
6083 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
6084 // Otherwise, use sensor only if requested by the application or enabled
6085 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07006086 if (mAllowAllRotations < 0) {
6087 // Can't read this during init() because the context doesn't
6088 // have display metrics at that time so we cannot determine
6089 // tablet vs. phone then.
6090 mAllowAllRotations = mContext.getResources().getBoolean(
6091 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
6092 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006093 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07006094 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006095 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6096 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006097 preferredRotation = sensorRotation;
6098 } else {
6099 preferredRotation = lastRotation;
6100 }
Jeff Brown207673cd2012-06-05 17:47:11 -07006101 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
6102 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
6103 // Apply rotation lock. Does not apply to NOSENSOR.
6104 // The idea is that the user rotation expresses a weak preference for the direction
6105 // of gravity and as NOSENSOR is never affected by gravity, then neither should
6106 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07006107 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08006108 } else {
6109 // No overriding preference.
6110 // We will do exactly what the application asked us to do.
6111 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07006112 }
6113
Dianne Hackborne5439f22010-10-02 16:53:50 -07006114 switch (orientation) {
6115 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006116 // Return portrait unless overridden.
6117 if (isAnyPortrait(preferredRotation)) {
6118 return preferredRotation;
6119 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07006120 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006121
Jeff Brown01a98dd2011-09-20 15:08:29 -07006122 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006123 // Return landscape unless overridden.
6124 if (isLandscapeOrSeascape(preferredRotation)) {
6125 return preferredRotation;
6126 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006127 return mLandscapeRotation;
6128
6129 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006130 // Return reverse portrait unless overridden.
6131 if (isAnyPortrait(preferredRotation)) {
6132 return preferredRotation;
6133 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006134 return mUpsideDownRotation;
6135
6136 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006137 // Return seascape unless overridden.
6138 if (isLandscapeOrSeascape(preferredRotation)) {
6139 return preferredRotation;
6140 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006141 return mSeascapeRotation;
6142
6143 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006144 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006145 // Return either landscape rotation.
6146 if (isLandscapeOrSeascape(preferredRotation)) {
6147 return preferredRotation;
6148 }
6149 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08006150 return lastRotation;
6151 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006152 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006153
Jeff Brown01a98dd2011-09-20 15:08:29 -07006154 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006155 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006156 // Return either portrait rotation.
6157 if (isAnyPortrait(preferredRotation)) {
6158 return preferredRotation;
6159 }
6160 if (isAnyPortrait(lastRotation)) {
6161 return lastRotation;
6162 }
6163 return mPortraitRotation;
6164
6165 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07006166 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
6167 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07006168 if (preferredRotation >= 0) {
6169 return preferredRotation;
6170 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07006171 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05006172 }
6173 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006174 }
6175
Jeff Brown01a98dd2011-09-20 15:08:29 -07006176 @Override
6177 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
6178 switch (orientation) {
6179 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
6180 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
6181 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
6182 return isAnyPortrait(rotation);
6183
6184 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
6185 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
6186 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
6187 return isLandscapeOrSeascape(rotation);
6188
6189 default:
6190 return true;
6191 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006192 }
6193
Jeff Brownc0347aa2011-09-23 17:26:09 -07006194 @Override
6195 public void setRotationLw(int rotation) {
6196 mOrientationListener.setCurrentRotation(rotation);
6197 }
6198
Jeff Brown01a98dd2011-09-20 15:08:29 -07006199 private boolean isLandscapeOrSeascape(int rotation) {
6200 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006201 }
6202
Jeff Brown01a98dd2011-09-20 15:08:29 -07006203 private boolean isAnyPortrait(int rotation) {
6204 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006205 }
6206
Jose Lima9546b202014-07-02 17:21:51 -07006207 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006208 public int getUserRotationMode() {
6209 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07006210 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
6211 WindowManagerPolicy.USER_ROTATION_FREE :
6212 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006213 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006214
6215 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07006216 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006217 public void setUserRotationMode(int mode, int rot) {
6218 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006219
6220 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006221 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07006222 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006223 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006224 rot,
6225 UserHandle.USER_CURRENT);
6226 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006227 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006228 0,
6229 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006230 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07006231 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006232 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006233 1,
6234 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006235 }
6236 }
6237
Jose Lima9546b202014-07-02 17:21:51 -07006238 @Override
Jeff Brownac143512012-04-05 18:57:33 -07006239 public void setSafeMode(boolean safeMode) {
6240 mSafeMode = safeMode;
6241 performHapticFeedbackLw(null, safeMode
6242 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
6243 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006244 }
Craig Mautnereda67292013-04-28 13:50:14 -07006245
Dianne Hackborn181ceb52009-08-27 22:16:40 -07006246 static long[] getLongIntArray(Resources r, int resid) {
6247 int[] ar = r.getIntArray(resid);
6248 if (ar == null) {
6249 return null;
6250 }
6251 long[] out = new long[ar.length];
6252 for (int i=0; i<ar.length; i++) {
6253 out[i] = ar[i];
6254 }
6255 return out;
6256 }
Craig Mautnereda67292013-04-28 13:50:14 -07006257
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006258 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006259 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006260 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07006261 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08006262 mKeyguardDelegate.onSystemReady();
6263
Michael Wright3818c922014-09-02 13:59:07 -07006264 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07006265 updateUiMode();
Adrian Roos3542f7d2015-07-13 15:57:53 -07006266 boolean bindKeyguardNow;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006267 synchronized (mLock) {
6268 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08006269 mSystemReady = true;
6270 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006271 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08006272 public void run() {
6273 updateSettings();
6274 }
6275 });
Adrian Roos3542f7d2015-07-13 15:57:53 -07006276
6277 bindKeyguardNow = mDeferBindKeyguard;
6278 if (bindKeyguardNow) {
6279 // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now.
6280 mDeferBindKeyguard = false;
6281 }
6282 }
6283
6284 if (bindKeyguardNow) {
6285 mKeyguardDelegate.bindService(mContext);
6286 mKeyguardDelegate.onBootCompleted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006287 }
Michael Wrighta4d22d72015-09-16 23:19:26 +01006288 mSystemGestures.systemReady();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006289 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006290
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006291 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006292 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006293 public void systemBooted() {
Adrian Roos3542f7d2015-07-13 15:57:53 -07006294 boolean bindKeyguardNow = false;
6295 synchronized (mLock) {
6296 // Time to bind Keyguard; take care to only bind it once, either here if ready or
6297 // in systemReady if not.
6298 if (mKeyguardDelegate != null) {
6299 bindKeyguardNow = true;
6300 } else {
6301 // Because mKeyguardDelegate is null, we know that the synchronized block in
6302 // systemReady didn't run yet and setting this will actually have an effect.
6303 mDeferBindKeyguard = true;
6304 }
6305 }
6306 if (bindKeyguardNow) {
Jason Monk5eeebf52014-09-26 12:36:51 -04006307 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07006308 mKeyguardDelegate.onBootCompleted();
6309 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006310 synchronized (mLock) {
6311 mSystemBooted = true;
6312 }
Jeff Brown416c49c2015-05-26 19:50:18 -07006313 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07006314 screenTurningOn(null);
Jorim Jaggic0496072015-08-19 15:14:52 -07006315 screenTurnedOn();
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006316 }
6317
Dianne Hackborn661cd522011-08-22 00:26:20 -07006318 ProgressDialog mBootMsgDialog = null;
6319
6320 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006321 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006322 public void showBootMessage(final CharSequence msg, final boolean always) {
6323 mHandler.post(new Runnable() {
6324 @Override public void run() {
6325 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006326 int theme;
Jaewan Kim49117872016-01-19 17:24:08 +09006327 if (mContext.getPackageManager().hasSystemFeature(FEATURE_WATCH)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006328 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
Jaewan Kim49117872016-01-19 17:24:08 +09006329 } else if (mContext.getPackageManager().hasSystemFeature(FEATURE_TELEVISION)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006330 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
6331 } else {
6332 theme = 0;
6333 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07006334
6335 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07006336 // This dialog will consume all events coming in to
6337 // it, to avoid it trying to do things too early in boot.
6338 @Override public boolean dispatchKeyEvent(KeyEvent event) {
6339 return true;
6340 }
6341 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
6342 return true;
6343 }
6344 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
6345 return true;
6346 }
6347 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
6348 return true;
6349 }
6350 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
6351 return true;
6352 }
6353 @Override public boolean dispatchPopulateAccessibilityEvent(
6354 AccessibilityEvent event) {
6355 return true;
6356 }
6357 };
Jeff Hao9f60c082014-10-28 18:51:07 -07006358 if (mContext.getPackageManager().isUpgrade()) {
6359 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
6360 } else {
6361 mBootMsgDialog.setTitle(R.string.android_start_title);
6362 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006363 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
6364 mBootMsgDialog.setIndeterminate(true);
6365 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07006366 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006367 mBootMsgDialog.getWindow().addFlags(
6368 WindowManager.LayoutParams.FLAG_DIM_BEHIND
6369 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
6370 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08006371 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
6372 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
6373 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006374 mBootMsgDialog.setCancelable(false);
6375 mBootMsgDialog.show();
6376 }
6377 mBootMsgDialog.setMessage(msg);
6378 }
6379 });
6380 }
6381
6382 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006383 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006384 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07006385 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006386 }
6387
Mike Lockwood28569302010-01-28 11:54:40 -05006388 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006389 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006390 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006391 // ***************************************
6392 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
6393 // ***************************************
6394 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
6395 // WITH ITS LOCKS HELD.
6396 //
6397 // This code must be VERY careful about the locks
6398 // it acquires.
6399 // In fact, the current code acquires way too many,
6400 // and probably has lurking deadlocks.
6401
Mike Lockwood28569302010-01-28 11:54:40 -05006402 synchronized (mScreenLockTimeout) {
6403 if (mLockScreenTimerActive) {
6404 // reset the timer
6405 mHandler.removeCallbacks(mScreenLockTimeout);
6406 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6407 }
6408 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006409 }
6410
Adam Cohenf7522022012-10-03 20:03:18 -07006411 class ScreenLockTimeout implements Runnable {
6412 Bundle options;
6413
6414 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006415 public void run() {
6416 synchronized (this) {
6417 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006418 if (mKeyguardDelegate != null) {
6419 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006420 }
Mike Lockwood28569302010-01-28 11:54:40 -05006421 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006422 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006423 }
6424 }
Mike Lockwood28569302010-01-28 11:54:40 -05006425
Adam Cohenf7522022012-10-03 20:03:18 -07006426 public void setLockOptions(Bundle options) {
6427 this.options = options;
6428 }
6429 }
6430
6431 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6432
Jose Lima9546b202014-07-02 17:21:51 -07006433 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006434 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006435 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6436 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006437 if (options != null) {
6438 // In case multiple calls are made to lockNow, we don't wipe out the options
6439 // until the runnable actually executes.
6440 mScreenLockTimeout.setLockOptions(options);
6441 }
Jim Miller93c518e2012-01-17 15:55:31 -08006442 mHandler.post(mScreenLockTimeout);
6443 }
6444
Mike Lockwood28569302010-01-28 11:54:40 -05006445 private void updateLockScreenTimeout() {
6446 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006447 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006448 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006449 if (mLockScreenTimerActive != enable) {
6450 if (enable) {
6451 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
Jim Miller2967f482016-01-07 15:05:32 -08006452 mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests
Mike Lockwood28569302010-01-28 11:54:40 -05006453 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6454 } else {
6455 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6456 mHandler.removeCallbacks(mScreenLockTimeout);
6457 }
6458 mLockScreenTimerActive = enable;
6459 }
6460 }
6461 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006462
Jeff Brown061ea992015-04-17 19:55:47 -07006463 private void updateDreamingSleepToken(boolean acquire) {
6464 if (acquire) {
6465 if (mDreamingSleepToken == null) {
6466 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6467 }
6468 } else {
6469 if (mDreamingSleepToken != null) {
6470 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006471 mDreamingSleepToken = null;
6472 }
6473 }
6474 }
6475
6476 private void updateScreenOffSleepToken(boolean acquire) {
6477 if (acquire) {
6478 if (mScreenOffSleepToken == null) {
6479 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6480 }
6481 } else {
6482 if (mScreenOffSleepToken != null) {
6483 mScreenOffSleepToken.release();
6484 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006485 }
6486 }
6487 }
6488
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006489 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006490 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006491 public void enableScreenAfterBoot() {
6492 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006493 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006494 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006495 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006496
Jeff Brownc458ce92012-04-30 14:58:40 -07006497 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006498 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006499 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006500 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006501 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01006502 } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) {
6503 mWindowManagerFuncs.lockDeviceNow();
Jeff Brownc458ce92012-04-30 14:58:40 -07006504 }
Jeff Browna20dda42014-05-27 20:57:24 -07006505
6506 synchronized (mLock) {
6507 updateWakeGestureListenerLp();
6508 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006509 }
6510
Jeff Brown4f5fa282014-06-12 19:19:15 -07006511 void updateUiMode() {
6512 if (mUiModeManager == null) {
6513 mUiModeManager = IUiModeManager.Stub.asInterface(
6514 ServiceManager.getService(Context.UI_MODE_SERVICE));
6515 }
6516 try {
6517 mUiMode = mUiModeManager.getCurrentModeType();
6518 } catch (RemoteException e) {
6519 }
6520 }
6521
Jeff Brown01a98dd2011-09-20 15:08:29 -07006522 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006523 try {
6524 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006525 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6526 } catch (RemoteException e) {
6527 // Ignore
6528 }
6529 }
6530
6531 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6532 try {
6533 //set orientation on WindowManager
6534 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006535 } catch (RemoteException e) {
6536 // Ignore
6537 }
6538 }
6539
Daniel Sandler6396c722013-04-16 20:19:09 -04006540 /**
6541 * Return an Intent to launch the currently active dock app as home. Returns
6542 * null if the standard home should be launched, which is the case if any of the following is
6543 * true:
6544 * <ul>
6545 * <li>The device is not in either car mode or desk mode
keunyounga7710492015-09-23 11:33:58 -07006546 * <li>The device is in car mode but mEnableCarDockHomeCapture is false
Daniel Sandler6396c722013-04-16 20:19:09 -04006547 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6548 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6549 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6550 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006551 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006552 */
6553 Intent createHomeDockIntent() {
6554 Intent intent = null;
6555
6556 // What home does is based on the mode, not the dock state. That
6557 // is, when in car mode you should be taken to car home regardless
6558 // of whether we are actually in a car dock.
6559 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
keunyounga7710492015-09-23 11:33:58 -07006560 if (mEnableCarDockHomeCapture) {
Daniel Sandler6396c722013-04-16 20:19:09 -04006561 intent = mCarDockIntent;
6562 }
6563 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6564 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6565 intent = mDeskDockIntent;
6566 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006567 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6568 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6569 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6570 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6571 // Always launch dock home from home when watch is docked, if it exists.
6572 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006573 }
6574
6575 if (intent == null) {
6576 return null;
6577 }
6578
6579 ActivityInfo ai = null;
6580 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6581 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006582 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006583 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006584 if (info != null) {
6585 ai = info.activityInfo;
6586 }
6587 if (ai != null
6588 && ai.metaData != null
6589 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6590 intent = new Intent(intent);
6591 intent.setClassName(ai.packageName, ai.name);
6592 return intent;
6593 }
6594
6595 return null;
6596 }
6597
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006598 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6599 if (awakenFromDreams) {
6600 awakenDreams();
6601 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006602
6603 Intent dock = createHomeDockIntent();
6604 if (dock != null) {
6605 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006606 if (fromHomeKey) {
6607 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6608 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006609 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006610 return;
6611 } catch (ActivityNotFoundException e) {
6612 }
6613 }
6614
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006615 Intent intent;
6616
6617 if (fromHomeKey) {
6618 intent = new Intent(mHomeIntent);
6619 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6620 } else {
6621 intent = mHomeIntent;
6622 }
6623
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006624 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006625 }
Craig Mautnereda67292013-04-28 13:50:14 -07006626
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006627 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006628 * goes to the home screen
6629 * @return whether it did anything
6630 */
6631 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006632 if (!isUserSetupComplete()) {
6633 Slog.i(TAG, "Not going home because user setup is in progress.");
6634 return false;
6635 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006636 if (false) {
6637 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006638 try {
6639 ActivityManagerNative.getDefault().stopAppSwitches();
6640 } catch (RemoteException e) {
6641 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006642 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006643 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006644 } else {
6645 // This code brings home to the front or, if it is already
6646 // at the front, puts the device to sleep.
6647 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006648 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6649 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6650 Log.d(TAG, "UTS-TEST-MODE");
6651 } else {
6652 ActivityManagerNative.getDefault().stopAppSwitches();
6653 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006654 Intent dock = createHomeDockIntent();
6655 if (dock != null) {
6656 int result = ActivityManagerNative.getDefault()
6657 .startActivityAsUser(null, null, dock,
6658 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6659 null, null, 0,
6660 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006661 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006662 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6663 return false;
6664 }
6665 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006666 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006667 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006668 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006669 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006670 null, null, 0,
6671 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006672 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006673 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006674 return false;
6675 }
6676 } catch (RemoteException ex) {
6677 // bummer, the activity manager, which is in this process, is dead
6678 }
6679 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006680 return true;
6681 }
Craig Mautnereda67292013-04-28 13:50:14 -07006682
6683 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006684 public void setCurrentOrientationLw(int newOrientation) {
6685 synchronized (mLock) {
6686 if (newOrientation != mCurrentAppOrientation) {
6687 mCurrentAppOrientation = newOrientation;
6688 updateOrientationListenerLp();
6689 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006690 }
6691 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006692
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006693 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6694 if (!isGlobalAccessibilityGestureEnabled()) {
6695 return;
6696 }
6697 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6698 Context.AUDIO_SERVICE);
6699 if (audioManager.isSilentMode()) {
6700 return;
6701 }
6702 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6703 Settings.System.DEFAULT_NOTIFICATION_URI);
6704 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6705 ringTone.play();
6706 }
Craig Mautnereda67292013-04-28 13:50:14 -07006707
Bryce Lee584a4452014-10-21 15:55:55 -07006708 private boolean isTheaterModeEnabled() {
6709 return Settings.Global.getInt(mContext.getContentResolver(),
6710 Settings.Global.THEATER_MODE_ON, 0) == 1;
6711 }
6712
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006713 private boolean isGlobalAccessibilityGestureEnabled() {
6714 return Settings.Global.getInt(mContext.getContentResolver(),
6715 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6716 }
6717
Craig Mautnereda67292013-04-28 13:50:14 -07006718 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006719 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006720 if (!mVibrator.hasVibrator()) {
6721 return false;
6722 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006723 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6724 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006725 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006726 return false;
6727 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006728 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006729 switch (effectId) {
6730 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006731 pattern = mLongPressVibePattern;
6732 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006733 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006734 pattern = mVirtualKeyVibePattern;
6735 break;
6736 case HapticFeedbackConstants.KEYBOARD_TAP:
6737 pattern = mKeyboardTapVibePattern;
6738 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006739 case HapticFeedbackConstants.CLOCK_TICK:
6740 pattern = mClockTickVibePattern;
6741 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006742 case HapticFeedbackConstants.CALENDAR_DATE:
6743 pattern = mCalendarDateVibePattern;
6744 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006745 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006746 pattern = mSafeModeDisabledVibePattern;
6747 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006748 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006749 pattern = mSafeModeEnabledVibePattern;
6750 break;
Mady Mellore8608912015-06-05 09:02:55 -07006751 case HapticFeedbackConstants.CONTEXT_CLICK:
6752 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006753 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006754 default:
6755 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006756 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006757 int owningUid;
6758 String owningPackage;
6759 if (win != null) {
6760 owningUid = win.getOwningUid();
6761 owningPackage = win.getOwningPackage();
6762 } else {
6763 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006764 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006765 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006766 if (pattern.length == 1) {
6767 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006768 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006769 } else {
6770 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006771 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006772 }
6773 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006774 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006775
6776 @Override
6777 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006778 }
6779
Jeff Brownc38c9be2012-10-04 13:16:19 -07006780 @Override
6781 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006782 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006783 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006784 }
6785 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006786
Dianne Hackborndf89e652011-10-06 22:35:11 -07006787 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006788 // If there is no window focused, there will be nobody to handle the events
6789 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006790 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6791 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006792 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006793 return 0;
6794 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006795 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006796 // We are updating at a point where the keyguard has gotten
6797 // focus, but we were last in a state where the top window is
6798 // hiding it. This is probably because the keyguard as been
6799 // shown while the top window was displayed, so we want to ignore
6800 // it here because this is just a very transient change and it
6801 // will quickly lose focus once it correctly gets hidden.
6802 return 0;
6803 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006804
John Spurlock1db8b682014-02-18 11:18:59 -05006805 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006806 & ~mResettingSystemUiFlags
6807 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006808 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006809 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006810 }
Thanh Hai Mai6c009f52015-09-01 16:27:32 -07006811
6812 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6813 tmpVisibility |= StatusBarManager.DISABLE_RECENT;
6814 }
6815
Adrian Rooscd3884d2015-02-18 17:25:23 +01006816 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006817 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006818 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006819 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006820 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006821 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006822 return 0;
6823 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006824 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006825 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006826 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006827 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006828 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006829 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006830 try {
6831 IStatusBarService statusbar = getStatusBarService();
6832 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006833 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006834 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006835 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006836 } catch (RemoteException e) {
6837 // re-acquire status bar service next time it is needed.
6838 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006839 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006840 }
6841 });
6842 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006843 }
6844
Adrian Rooscd3884d2015-02-18 17:25:23 +01006845 private int updateLightStatusBarLw(int vis) {
6846 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6847 ? mStatusBar
6848 : mTopFullscreenOpaqueOrDimmingWindowState;
6849
6850 if (statusColorWin != null) {
6851 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6852 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6853 // its light flag.
6854 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6855 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6856 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6857 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6858 // Otherwise if it's dimming, clear the light flag.
6859 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6860 }
6861 }
6862 return vis;
6863 }
6864
John Spurlock79da8332013-09-20 12:04:47 -04006865 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006866 final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
6867 final boolean freeformStackVisible =
6868 mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID);
6869 final boolean forceShowSystemBars = dockedStackVisible || freeformStackVisible;
Jorim Jaggi4fa78922015-11-30 17:13:56 -08006870 final boolean forceOpaqueSystemBars = forceShowSystemBars && !mForceStatusBarFromKeyguard;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006871
John Spurlockbd957402013-10-03 11:38:39 -04006872 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006873 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6874 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006875 : mTopFullscreenOpaqueWindowState;
6876 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6877 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6878
John Spurlock27735a42013-08-14 17:57:38 -04006879 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006880 int type = win.getAttrs().type;
6881 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006882 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006883 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6884 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006885 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006886 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6887 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006888 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006889 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6890 }
John Spurlockbd957402013-10-03 11:38:39 -04006891 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006892 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006893
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006894 if ((!areTranslucentBarsAllowed() && transWin != mStatusBar)
6895 || forceOpaqueSystemBars) {
Adrian Roosea562512014-05-05 13:33:03 +02006896 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6897 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006898 }
6899
Jorim Jaggi4fa78922015-11-30 17:13:56 -08006900 if (mForceWindowDrawsStatusBarBackground) {
6901 vis |= View.STATUS_BAR_TRANSPARENT;
6902 vis &= ~View.STATUS_BAR_TRANSLUCENT;
6903 }
6904
John Spurlock27735a42013-08-14 17:57:38 -04006905 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006906 boolean immersiveSticky =
6907 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006908 final boolean hideStatusBarWM =
6909 mTopFullscreenOpaqueWindowState != null
6910 && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006911 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006912 final boolean hideStatusBarSysui =
John Spurlock27735a42013-08-14 17:57:38 -04006913 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006914 final boolean hideNavBarSysui =
John Spurlockf1a36642013-10-12 17:50:42 -04006915 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006916
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006917 final boolean transientStatusBarAllowed = mStatusBar != null
6918 && (statusBarHasFocus || (!forceShowSystemBars
6919 && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky))));
John Spurlock27735a42013-08-14 17:57:38 -04006920
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006921 final boolean transientNavBarAllowed = mNavigationBar != null
6922 && !forceShowSystemBars && hideNavBarSysui && immersiveSticky;
John Spurlockf1a36642013-10-12 17:50:42 -04006923
Adrian Roosddc8b272015-05-21 16:28:27 -07006924 final long now = SystemClock.uptimeMillis();
6925 final boolean pendingPanic = mPendingPanicGestureUptime != 0
6926 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
6927 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
6928 // The user performed the panic gesture recently, we're about to hide the bars,
6929 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
6930 mPendingPanicGestureUptime = 0;
6931 mStatusBarController.showTransient();
6932 mNavigationBarController.showTransient();
6933 }
6934
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006935 final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006936 && !transientStatusBarAllowed && hideStatusBarSysui;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006937 final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006938 && !transientNavBarAllowed;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006939 if (denyTransientStatus || denyTransientNav || forceShowSystemBars) {
John Spurlock27735a42013-08-14 17:57:38 -04006940 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006941 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006942 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006943 }
John Spurlock27735a42013-08-14 17:57:38 -04006944
Selim Cinekf98702e2015-05-20 22:48:40 -07006945 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
6946 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
6947 final boolean navAllowedHidden = immersive || immersiveSticky;
6948
Selim Cinekd6623612015-05-22 18:56:22 -07006949 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
6950 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07006951 // We can't hide the navbar from this window otherwise the input consumer would not get
6952 // the input events.
6953 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
6954 }
6955
John Spurlock27735a42013-08-14 17:57:38 -04006956 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6957
6958 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006959 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6960 boolean newImmersiveMode = isImmersiveMode(vis);
6961 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006962 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006963 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6964 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006965 }
John Spurlock27735a42013-08-14 17:57:38 -04006966
John Spurlockf1a36642013-10-12 17:50:42 -04006967 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6968
John Spurlocke1f366f2013-08-05 12:22:40 -04006969 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006970 }
6971
John Spurlockf1a36642013-10-12 17:50:42 -04006972 private void clearClearableFlagsLw() {
6973 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6974 if (newVal != mResettingSystemUiFlags) {
6975 mResettingSystemUiFlags = newVal;
6976 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6977 }
6978 }
6979
6980 private boolean isImmersiveMode(int vis) {
6981 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006982 return mNavigationBar != null
6983 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006984 && (vis & flags) != 0
6985 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006986 }
6987
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006988 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006989 * @return whether the navigation or status bar can be made translucent
6990 *
6991 * This should return true unless touch exploration is not enabled or
6992 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006993 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006994 private boolean areTranslucentBarsAllowed() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04006995 return mTranslucentDecorEnabled;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006996 }
6997
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006998 // Use this instead of checking config_showNavigationBar so that it can be consistently
6999 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07007000 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007001 public boolean hasNavigationBar() {
7002 return mHasNavigationBar;
7003 }
7004
satok1bc0a492012-04-25 22:47:12 +09007005 @Override
7006 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
7007 mLastInputMethodWindow = ime;
7008 mLastInputMethodTargetWindow = target;
7009 }
7010
Craig Mautnerf1b67412012-09-19 13:18:29 -07007011 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09007012 public int getInputMethodWindowVisibleHeightLw() {
7013 return mDockBottom - mCurBottom;
7014 }
7015
7016 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07007017 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07007018 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08007019 if (mKeyguardDelegate != null) {
7020 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007021 }
John Spurlock13451a22012-09-28 14:40:41 -04007022 if (mStatusBarService != null) {
7023 try {
7024 mStatusBarService.setCurrentUser(newUserId);
7025 } catch (RemoteException e) {
7026 // oh well
7027 }
7028 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007029 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007030 }
7031
7032 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08007033 public boolean canMagnifyWindow(int windowType) {
7034 switch (windowType) {
7035 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
7036 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
7037 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
7038 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
7039 return false;
7040 }
7041 }
7042 return true;
7043 }
7044
7045 @Override
7046 public boolean isTopLevelWindow(int windowType) {
7047 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
7048 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
7049 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
7050 }
7051 return true;
7052 }
7053
Jim Miller4eeb4f62012-11-08 00:04:29 -08007054 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07007055 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007056 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007057 pw.print(" mSystemReady="); pw.print(mSystemReady);
7058 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07007059 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007060 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07007061 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007062 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07007063 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
7064 || mForceClearedSystemUiFlags != 0) {
7065 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
7066 pw.print(Integer.toHexString(mLastSystemUiFlags));
7067 pw.print(" mResettingSystemUiFlags=0x");
7068 pw.print(Integer.toHexString(mResettingSystemUiFlags));
7069 pw.print(" mForceClearedSystemUiFlags=0x");
7070 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07007071 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007072 if (mLastFocusNeedsMenu) {
7073 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
7074 pw.println(mLastFocusNeedsMenu);
7075 }
Jeff Browna20dda42014-05-27 20:57:24 -07007076 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
7077 pw.println(mWakeGestureEnabledSetting);
7078
Jeff Brownbcdfc622014-03-06 19:13:04 -08007079 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04007080 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
7081 pw.print(" mDockMode="); pw.print(mDockMode);
keunyounga7710492015-09-23 11:33:58 -07007082 pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007083 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
7084 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
7085 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
7086 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05007087 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007088 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007089 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
7090 pw.print(mCarDockEnablesAccelerometer);
7091 pw.print(" mDeskDockEnablesAccelerometer=");
7092 pw.println(mDeskDockEnablesAccelerometer);
7093 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
7094 pw.print(mLidKeyboardAccessibility);
7095 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01007096 pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007097 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007098 pw.print(prefix);
7099 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
7100 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07007101 pw.print(prefix);
7102 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
7103 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007104 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07007105 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
7106 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
7107 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
7108 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
7109 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
7110 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
7111 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08007112 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
7113 pw.print(","); pw.print(mOverscanScreenTop);
7114 pw.print(") "); pw.print(mOverscanScreenWidth);
7115 pw.print("x"); pw.println(mOverscanScreenHeight);
7116 if (mOverscanLeft != 0 || mOverscanTop != 0
7117 || mOverscanRight != 0 || mOverscanBottom != 0) {
7118 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
7119 pw.print(" top="); pw.print(mOverscanTop);
7120 pw.print(" right="); pw.print(mOverscanRight);
7121 pw.print(" bottom="); pw.println(mOverscanBottom);
7122 }
Dianne Hackborn313440842013-02-19 19:22:59 -08007123 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
7124 pw.print(mRestrictedOverscanScreenLeft);
7125 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
7126 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
7127 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007128 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
7129 pw.print(","); pw.print(mUnrestrictedScreenTop);
7130 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
7131 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
7132 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
7133 pw.print(","); pw.print(mRestrictedScreenTop);
7134 pw.print(") "); pw.print(mRestrictedScreenWidth);
7135 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07007136 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
7137 pw.print(","); pw.print(mStableFullscreenTop);
7138 pw.print(")-("); pw.print(mStableFullscreenRight);
7139 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07007140 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
7141 pw.print(","); pw.print(mStableTop);
7142 pw.print(")-("); pw.print(mStableRight);
7143 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007144 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
7145 pw.print(","); pw.print(mSystemTop);
7146 pw.print(")-("); pw.print(mSystemRight);
7147 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007148 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
7149 pw.print(","); pw.print(mCurTop);
7150 pw.print(")-("); pw.print(mCurRight);
7151 pw.print(","); pw.print(mCurBottom); pw.println(")");
7152 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
7153 pw.print(","); pw.print(mContentTop);
7154 pw.print(")-("); pw.print(mContentRight);
7155 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07007156 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
7157 pw.print(","); pw.print(mVoiceContentTop);
7158 pw.print(")-("); pw.print(mVoiceContentRight);
7159 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007160 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
7161 pw.print(","); pw.print(mDockTop);
7162 pw.print(")-("); pw.print(mDockRight);
7163 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007164 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
7165 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007166 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
7167 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07007168 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
7169 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007170 if (mLastInputMethodWindow != null) {
7171 pw.print(prefix); pw.print("mLastInputMethodWindow=");
7172 pw.println(mLastInputMethodWindow);
7173 }
7174 if (mLastInputMethodTargetWindow != null) {
7175 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
7176 pw.println(mLastInputMethodTargetWindow);
7177 }
7178 if (mStatusBar != null) {
7179 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08007180 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
7181 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007182 }
7183 if (mNavigationBar != null) {
7184 pw.print(prefix); pw.print("mNavigationBar=");
7185 pw.println(mNavigationBar);
7186 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007187 if (mFocusedWindow != null) {
7188 pw.print(prefix); pw.print("mFocusedWindow=");
7189 pw.println(mFocusedWindow);
7190 }
7191 if (mFocusedApp != null) {
7192 pw.print(prefix); pw.print("mFocusedApp=");
7193 pw.println(mFocusedApp);
7194 }
7195 if (mWinDismissingKeyguard != null) {
7196 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
7197 pw.println(mWinDismissingKeyguard);
7198 }
7199 if (mTopFullscreenOpaqueWindowState != null) {
7200 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
7201 pw.println(mTopFullscreenOpaqueWindowState);
7202 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01007203 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
7204 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
7205 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
7206 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007207 if (mForcingShowNavBar) {
7208 pw.print(prefix); pw.print("mForcingShowNavBar=");
7209 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
7210 pw.println(mForcingShowNavBarLayer);
7211 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007212 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007213 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007214 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
7215 pw.print(" mForceStatusBarFromKeyguard=");
7216 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007217 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07007218 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007219 pw.print(" mHomePressed="); pw.println(mHomePressed);
7220 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
7221 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
7222 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
7223 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
7224 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
7225 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
7226 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
7227 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
7228 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
7229 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07007230 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
7231 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
7232 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07007233
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07007234 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04007235 mStatusBarController.dump(pw, prefix);
7236 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05007237 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07007238
Jeff Browna20dda42014-05-27 20:57:24 -07007239 if (mWakeGestureListener != null) {
7240 mWakeGestureListener.dump(pw, prefix);
7241 }
Jeff Brown600f0032014-05-22 17:06:00 -07007242 if (mOrientationListener != null) {
7243 mOrientationListener.dump(pw, prefix);
7244 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00007245 if (mBurnInProtectionHelper != null) {
7246 mBurnInProtectionHelper.dump(prefix, pw);
7247 }
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07007248 if (mKeyguardDelegate != null) {
7249 mKeyguardDelegate.dump(prefix, pw);
7250 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007251 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007252}