blob: ad85b599730125fc569d8e7f252fca71f91d0e65 [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
Dianne Hackborna4972e92012-03-14 10:38:05 -070019import android.app.ActivityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080020import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080021import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040022import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070023import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070024import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040025import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080026import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070027import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080028import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040029import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080030import android.content.ContentResolver;
31import android.content.Context;
32import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070033import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070034import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080035import android.content.pm.ActivityInfo;
36import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040037import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070038import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080039import android.content.res.Configuration;
40import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070041import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080042import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080043import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080044import android.graphics.Rect;
John Spurlock7b414672014-07-18 13:02:39 -040045import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080046import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050047import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080048import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070049import android.media.Ringtone;
50import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070051import android.media.session.MediaSessionLegacyHelper;
Mark Renoufc1256912015-03-11 14:38:23 -040052import android.os.Build;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070053import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080054import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070055import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080056import android.os.Handler;
57import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080058import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070059import android.os.Message;
60import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080061import android.os.PowerManager;
62import android.os.RemoteException;
63import android.os.ServiceManager;
64import android.os.SystemClock;
65import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080066import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070067import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080068import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070069import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080070import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070071import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040072import android.service.dreams.DreamService;
73import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070074import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070075import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070076import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080077import android.util.EventLog;
78import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070079import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080080import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070081import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080082import android.view.Gravity;
83import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080084import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080085import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070086import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070087import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080088import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080089import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080090import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080091import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080092import android.view.KeyEvent;
93import android.view.MotionEvent;
Jorim Jaggib10e33f2015-02-04 21:57:40 +010094import android.view.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080095import android.view.Surface;
96import android.view.View;
97import android.view.ViewConfiguration;
Mark Renoufc1256912015-03-11 14:38:23 -040098import android.view.ViewRootImpl;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080099import android.view.Window;
100import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800101import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700102import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800103import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800104import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800105import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800106import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200107import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800108import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800109import com.android.internal.R;
Craig Mautnerae446592012-12-06 19:05:05 -0800110import com.android.internal.statusbar.IStatusBarService;
Craig Mautnerae446592012-12-06 19:05:05 -0800111import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700112import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100113import com.android.server.policy.keyguard.KeyguardServiceDelegate;
114import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800115
116import java.io.File;
117import java.io.FileReader;
118import java.io.IOException;
119import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700120import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800121import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800122
Dianne Hackbornc652de82013-02-15 16:32:56 -0800123import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700124import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
125import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
126import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700127import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
128import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
129import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800130
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800131/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700132 * WindowManagerPolicy implementation for the Android phone UI. This
133 * introduces a new method suffix, Lp, for an internal lock of the
134 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400135 * 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 -0700136 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800137 */
138public class PhoneWindowManager implements WindowManagerPolicy {
139 static final String TAG = "WindowManager";
140 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700141 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700142 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700143 static final boolean DEBUG_KEYGUARD = false;
144 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700145 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700146 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800147 static final boolean SHOW_STARTING_ANIMATIONS = true;
148 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400149
Daniel Sandler6396c722013-04-16 20:19:09 -0400150 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
151 // No longer recommended for desk docks; still useful in car docks.
152 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
153 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
154
Jeff Brown6d8fd272014-05-20 21:24:38 -0700155 static final int SHORT_PRESS_POWER_NOTHING = 0;
156 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
157 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
158 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800159 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700160
Joe Onoratod208e702010-10-08 16:22:43 -0400161 static final int LONG_PRESS_POWER_NOTHING = 0;
162 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
163 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700164 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700165
Jeff Brown13f00f02014-10-31 14:45:50 -0700166 static final int MULTI_PRESS_POWER_NOTHING = 0;
167 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
168 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
169
Michael Jurka3b1fc472011-06-13 10:54:40 -0700170 // These need to match the documentation/constant in
171 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800172 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800173 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700174 static final int LONG_PRESS_HOME_ASSIST = 2;
175
176 static final int DOUBLE_TAP_HOME_NOTHING = 0;
177 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800178
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000179 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
180 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
181
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700182 static final int APPLICATION_MEDIA_SUBLAYER = -2;
183 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800184 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800185 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700186 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700187
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800188 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
189 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
190 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500191 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700192 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800193
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700194 /**
195 * These are the system UI flags that, when changing, can cause the layout
196 * of the screen to change.
197 */
198 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400199 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400200 | View.SYSTEM_UI_FLAG_FULLSCREEN
201 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200202 | View.NAVIGATION_BAR_TRANSLUCENT
203 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700204
John Spurlock7b414672014-07-18 13:02:39 -0400205 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
206 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
207 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
208 .build();
209
Jim Miller5ecd8112013-01-09 18:50:26 -0800210 /**
211 * Keyguard stuff
212 */
213 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100214 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700215 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800216
Jeff Brown6651a632011-11-28 12:59:11 -0800217 /* Table of Application Launch keys. Maps from key codes to intent categories.
218 *
219 * These are special keys that are used to launch particular kinds of applications,
220 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
221 * usage page. We don't support quite that many yet...
222 */
223 static SparseArray<String> sApplicationLaunchKeyCategories;
224 static {
225 sApplicationLaunchKeyCategories = new SparseArray<String>();
226 sApplicationLaunchKeyCategories.append(
227 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
228 sApplicationLaunchKeyCategories.append(
229 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
230 sApplicationLaunchKeyCategories.append(
231 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
232 sApplicationLaunchKeyCategories.append(
233 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
234 sApplicationLaunchKeyCategories.append(
235 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
236 sApplicationLaunchKeyCategories.append(
237 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
238 }
239
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700240 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
241 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
242
Dianne Hackborndf89e652011-10-06 22:35:11 -0700243 /**
244 * Lock protecting internal state. Must not call out into window
245 * manager with lock held. (This lock will be acquired in places
246 * where the window manager is calling in with its own lock held.)
247 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800248 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700249
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800250 Context mContext;
251 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700252 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700253 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700254 PowerManager mPowerManager;
Jose Lima9546b202014-07-02 17:21:51 -0700255 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400256 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700257 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700258 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800259 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700260 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800261 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000262 BurnInProtectionHelper mBurnInProtectionHelper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800263
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700264 // Vibrator pattern for haptic feedback of a long press.
265 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700266
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700267 // Vibrator pattern for haptic feedback of virtual key press.
268 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700269
Amith Yamasanic33cb712010-02-10 15:21:49 -0800270 // Vibrator pattern for a short vibration.
271 long[] mKeyboardTapVibePattern;
272
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700273 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
274 long[] mClockTickVibePattern;
275
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700276 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
277 long[] mCalendarDateVibePattern;
278
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700279 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
280 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700281
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700282 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
283 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700284
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800285 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
286 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400287
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800288 boolean mSafeMode;
289 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700290 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400291 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400292 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700293 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400294 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
295 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
296 int[] mNavigationBarHeightForRotation = new int[4];
297 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400298
Craig Mautnera631d492014-08-05 15:16:01 -0700299 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800300 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700301 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700302 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700303 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700304 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
305 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
306 }
307 };
308 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
309 @Override
310 public void onShown(IBinder windowToken) {
311 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
312 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
313 }
314 };
315
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800316 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800317 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900318 WindowState mLastInputMethodWindow = null;
319 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800320
Jeff Brown13f00f02014-10-31 14:45:50 -0700321 // FIXME This state is shared between the input reader and handler thread.
322 // Technically it's broken and buggy but it has been like this for many years
323 // and we have not yet seen any problems. Someday we'll rewrite this logic
324 // so that only one thread is involved in handling input policy. Unfortunately
325 // it's on a critical path for power management so we can't just post the work to the
326 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
327 // to hold wakelocks during dispatch and eliminating the critical path.
328 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800329 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700330 volatile int mPowerKeyPressCounter;
331 volatile boolean mEndCallKeyHandled;
332
Winson Chungd42a6cf2014-06-03 16:24:04 -0700333 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700334 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700335 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800336
Jeff Brown2e7760e2012-04-11 15:14:55 -0700337 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700338 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700339 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800340
Dianne Hackbornc777e072010-02-12 13:07:59 -0800341 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700342 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800343 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700344 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400345 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700346 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700347 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400348 int mCarDockRotation;
349 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700350 int mUndockedHdmiRotation;
351 int mDemoHdmiRotation;
352 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800353 int mDemoRotation;
354 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400355
Jeff Browna20dda42014-05-27 20:57:24 -0700356 boolean mWakeGestureEnabledSetting;
357 MyWakeGestureListener mWakeGestureListener;
358
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700359 // Default display does not rotate, apps that require non-default orientation will have to
360 // have the orientation emulated.
361 private boolean mForceDefaultOrientation = false;
362
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400363 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
364 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700365 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400366
Jeff Brownbcdfc622014-03-06 19:13:04 -0800367 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700368 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400369 boolean mCarDockEnablesAccelerometer;
370 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700371 int mLidKeyboardAccessibility;
372 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700373 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700374 int mShortPressOnPowerBehavior;
375 int mLongPressOnPowerBehavior;
376 int mDoublePressOnPowerBehavior;
377 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000378 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700379 boolean mAwake;
380 boolean mScreenOnEarly;
381 boolean mScreenOnFully;
382 ScreenOnListener mScreenOnListener;
383 boolean mKeyguardDrawComplete;
384 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800385 boolean mOrientationSensorEnabled = false;
386 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800387 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400388 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800389 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700390
Jeff Brown70825162012-03-28 17:27:48 -0700391 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800392
393 // The last window we were told about in focusChanged.
394 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800395 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800396
Jeff Brown70825162012-03-28 17:27:48 -0700397 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800398
Dianne Hackbornc652de82013-02-15 16:32:56 -0800399 // The current size of the screen; really; extends into the overscan area of
400 // the screen and doesn't account for any system elements like the status bar.
401 int mOverscanScreenLeft, mOverscanScreenTop;
402 int mOverscanScreenWidth, mOverscanScreenHeight;
403 // The current visible size of the screen; really; (ir)regardless of whether the status
404 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800405 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
406 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800407 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
408 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
409 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700410 // The current size of the screen; these may be different than (0,0)-(dw,dh)
411 // if the status bar can't be hidden; in that case it effectively carves out
412 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800413 int mRestrictedScreenLeft, mRestrictedScreenTop;
414 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700415 // During layout, the current screen borders accounting for any currently
416 // visible system UI elements.
417 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700418 // For applications requesting stable content insets, these are them.
419 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700420 // For applications requesting stable content insets but have also set the
421 // fullscreen window flag, these are the stable dimensions without the status bar.
422 int mStableFullscreenLeft, mStableFullscreenTop;
423 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800424 // During layout, the current screen borders with all outer decoration
425 // (status bar, input method dock) accounted for.
426 int mCurLeft, mCurTop, mCurRight, mCurBottom;
427 // During layout, the frame in which content should be displayed
428 // to the user, accounting for all screen decoration except for any
429 // space they deem as available for other content. This is usually
430 // the same as mCur*, but may be larger if the screen decor has supplied
431 // content insets.
432 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700433 // During layout, the frame in which voice content should be displayed
434 // to the user, accounting for all screen decoration except for any
435 // space they deem as available for other content.
436 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800437 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800438 // windows are placed.
439 int mDockLeft, mDockTop, mDockRight, mDockBottom;
440 // During layout, the layer at which the doc window is placed.
441 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700442 // During layout, this is the layer of the status bar.
443 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700444 int mLastSystemUiFlags;
445 // Bits that we are in the process of clearing, so we want to prevent
446 // them from being set by applications until everything has been updated
447 // to have them clear.
448 int mResettingSystemUiFlags = 0;
449 // Bits that we are currently always keeping cleared.
450 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800451 // What we last reported to system UI about whether the compatibility
452 // menu needs to be displayed.
453 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700454
455 FakeWindow mHideNavFakeWindow = null;
456
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800457 static final Rect mTmpParentFrame = new Rect();
458 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800459 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800460 static final Rect mTmpContentFrame = new Rect();
461 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400462 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700463 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700464 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700465
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800466 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100467 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700468 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200469 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400470 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800471 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700472 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700473 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800474 boolean mForcingShowNavBar;
475 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700476
477 // States of keyguard dismiss.
478 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
479 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
480 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
481 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
482
483 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
484 * be done once per window. */
485 private WindowState mWinDismissingKeyguard;
486
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700487 /** The window that is currently showing "over" the keyguard. If there is an app window
488 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
489 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
490 * the wallpaper. */
491 private WindowState mWinShowWhenLocked;
492
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700493 boolean mShowingLockscreen;
494 boolean mShowingDream;
495 boolean mDreamingLockscreen;
Jim Millerab954542014-10-10 18:21:49 -0700496 boolean mKeyguardSecure;
497 boolean mKeyguardSecureIncludingHidden;
498 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800499 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700500 boolean mHomeConsumed;
501 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800502 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700503 Intent mCarDockIntent;
504 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700505 boolean mSearchKeyShortcutPending;
506 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700507 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700508 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800509
Mike Lockwood28569302010-01-28 11:54:40 -0500510 // support for activating the lock screen while the screen is on
511 boolean mAllowLockscreenWhenOn;
512 int mLockScreenTimeout;
513 boolean mLockScreenTimerActive;
514
David Brownbaf8d092010-03-08 21:52:59 -0800515 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800516 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800517
518 // Behavior of POWER button while in-call and screen on.
519 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
520 int mIncallPowerBehavior;
521
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700522 Display mDisplay;
523
Dianne Hackborn9d132642011-04-21 17:26:39 -0700524 int mLandscapeRotation = 0; // default landscape rotation
525 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
526 int mPortraitRotation = 0; // default portrait rotation
527 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700528
Dianne Hackbornc652de82013-02-15 16:32:56 -0800529 int mOverscanLeft = 0;
530 int mOverscanTop = 0;
531 int mOverscanRight = 0;
532 int mOverscanBottom = 0;
533
Joe Onorato46b0d682010-11-22 17:37:27 -0800534 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700535 private int mLongPressOnHomeBehavior;
536
537 // What we do when the user double-taps on home
538 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800539
Bryce Lee584a4452014-10-21 15:55:55 -0700540 // Allowed theater mode wake actions
541 private boolean mAllowTheaterModeWakeFromKey;
542 private boolean mAllowTheaterModeWakeFromPowerKey;
543 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800544 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700545 private boolean mAllowTheaterModeWakeFromCameraLens;
546 private boolean mAllowTheaterModeWakeFromLidSwitch;
547 private boolean mAllowTheaterModeWakeFromWakeGesture;
548
Bryce Leed3b28402015-03-09 15:49:13 +0000549 // Whether to support long press from power button in non-interactive mode
550 private boolean mSupportLongPressPowerWhenNonInteractive;
551
Bryce Lee55e846d2014-11-04 12:43:44 -0800552 // Whether to go to sleep entering theater mode from power button
553 private boolean mGoToSleepOnButtonPressTheaterMode;
554
Winson Chung9112ec32011-06-27 13:15:32 -0700555 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700556 // Time to volume and power must be pressed within this interval of each other.
557 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700558 // Increase the chord delay when taking a screenshot from the keyguard
559 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800560 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700561 private boolean mScreenshotChordVolumeDownKeyTriggered;
562 private long mScreenshotChordVolumeDownKeyTime;
563 private boolean mScreenshotChordVolumeDownKeyConsumed;
564 private boolean mScreenshotChordVolumeUpKeyTriggered;
565 private boolean mScreenshotChordPowerKeyTriggered;
566 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700567
Michael Wrightb854e242013-02-05 17:54:02 -0800568 /* The number of steps between min and max brightness */
569 private static final int BRIGHTNESS_STEPS = 10;
570
Christopher Tate5e08af02012-09-21 17:17:22 -0700571 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800572 ShortcutManager mShortcutManager;
573 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700574 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700575 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800576
Craig Mautnerd625ab22013-09-06 13:40:31 -0700577 private int mCurrentUserId;
578
Justin Kohd378ad72013-04-01 12:18:26 -0700579 // Maps global key codes to the components that will handle them.
580 private GlobalKeyManager mGlobalKeyManager;
581
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700582 // Fallback actions by key code.
583 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
584 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800585
Jorim Jaggi76a16232014-08-08 17:00:47 +0200586 private final LogDecelerateInterpolator mLogDecelerateInterpolator
587 = new LogDecelerateInterpolator(100, 0);
588
Jeff Brown70825162012-03-28 17:27:48 -0700589 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
590 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700591 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
592 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700593 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
594 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
595 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700596 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700597 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700598 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700599 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700600 private static final int MSG_POWER_DELAYED_PRESS = 13;
601 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown70825162012-03-28 17:27:48 -0700602
603 private class PolicyHandler extends Handler {
604 @Override
605 public void handleMessage(Message msg) {
606 switch (msg.what) {
607 case MSG_ENABLE_POINTER_LOCATION:
608 enablePointerLocation();
609 break;
610 case MSG_DISABLE_POINTER_LOCATION:
611 disablePointerLocation();
612 break;
Jeff Brown40013652012-05-16 21:22:36 -0700613 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
614 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
615 break;
616 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
617 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
618 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700619 case MSG_DISPATCH_SHOW_RECENTS:
620 showRecentApps(false);
621 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700622 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
623 showGlobalActionsInternal();
624 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700625 case MSG_KEYGUARD_DRAWN_COMPLETE:
626 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700627 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700628 break;
629 case MSG_KEYGUARD_DRAWN_TIMEOUT:
630 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700631 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700632 break;
633 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
634 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700635 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700636 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700637 case MSG_HIDE_BOOT_MESSAGE:
638 handleHideBootMessage();
639 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700640 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
641 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
642 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700643 case MSG_POWER_DELAYED_PRESS:
644 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
645 finishPowerKeyPress();
646 break;
647 case MSG_POWER_LONG_PRESS:
648 powerLongPress();
649 break;
Jeff Brown70825162012-03-28 17:27:48 -0700650 }
651 }
652 }
653
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800654 private UEventObserver mHDMIObserver = new UEventObserver() {
655 @Override
656 public void onUEvent(UEventObserver.UEvent event) {
657 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
658 }
659 };
660
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800661 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800662 SettingsObserver(Handler handler) {
663 super(handler);
664 }
David Brownbaf8d092010-03-08 21:52:59 -0800665
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800666 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700667 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800668 ContentResolver resolver = mContext.getContentResolver();
669 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700670 Settings.System.END_BUTTON_BEHAVIOR), false, this,
671 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800672 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700673 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
674 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700675 resolver.registerContentObserver(Settings.Secure.getUriFor(
676 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
677 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800678 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700679 Settings.System.ACCELEROMETER_ROTATION), false, this,
680 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500681 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700682 Settings.System.USER_ROTATION), false, this,
683 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400684 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700685 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
686 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800687 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700688 Settings.System.POINTER_LOCATION), false, this,
689 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800690 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700691 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
692 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500693 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400694 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700695 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500696 resolver.registerContentObserver(Settings.Global.getUriFor(
697 Settings.Global.POLICY_CONTROL), false, this,
698 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800699 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800700 }
701
702 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800703 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700704 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800705 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800706 }
Craig Mautner967212c2013-04-13 21:10:58 -0700707
Jeff Browna20dda42014-05-27 20:57:24 -0700708 class MyWakeGestureListener extends WakeGestureListener {
709 MyWakeGestureListener(Context context, Handler handler) {
710 super(context, handler);
711 }
712
713 @Override
714 public void onWakeUp() {
715 synchronized (mLock) {
716 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700717 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700718 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700719 }
720 }
721 }
722 }
723
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800724 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800725 MyOrientationListener(Context context, Handler handler) {
726 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800727 }
Craig Mautner967212c2013-04-13 21:10:58 -0700728
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800729 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700730 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700731 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700732 updateRotation(false);
733 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800734 }
735 MyOrientationListener mOrientationListener;
736
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100737 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400738
John Spurlock27735a42013-08-14 17:57:38 -0400739 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400740 View.NAVIGATION_BAR_TRANSIENT,
741 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400742 View.NAVIGATION_BAR_TRANSLUCENT,
743 StatusBarManager.WINDOW_NAVIGATION_BAR,
744 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400745
John Spurlockf1a36642013-10-12 17:50:42 -0400746 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400747
Craig Mautner037aa8d2013-06-07 10:35:44 -0700748 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400749
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700750 IStatusBarService getStatusBarService() {
751 synchronized (mServiceAquireLock) {
752 if (mStatusBarService == null) {
753 mStatusBarService = IStatusBarService.Stub.asInterface(
754 ServiceManager.getService("statusbar"));
755 }
756 return mStatusBarService;
757 }
758 }
759
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700760 /*
761 * We always let the sensor be switched on by default except when
762 * the user has explicitly disabled sensor based rotation or when the
763 * screen is switched off.
764 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700765 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800766 if (mSupportAutoRotation) {
767 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
768 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
769 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
770 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
771 // If the application has explicitly requested to follow the
772 // orientation, then we need to turn the sensor on.
773 return true;
774 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800775 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700776 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800777 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
778 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
779 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400780 // enable accelerometer if we are docked in a dock that enables accelerometer
781 // orientation management,
782 return true;
783 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700784 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800785 // If the setting for using the sensor by default is enabled, then
786 // we will always leave it on. Note that the user could go to
787 // a window that forces an orientation that does not use the
788 // sensor and in theory we could turn it off... however, when next
789 // turning it on we won't have a good value for the current
790 // orientation for a little bit, which can cause orientation
791 // changes to lag, so we'd like to keep it always on. (It will
792 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700793 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800794 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800795 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800796 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700797
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800798 /*
799 * Various use cases for invoking this function
800 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700801 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800802 * if not already enabled
803 * screen turned on and current app does not have sensor orientation, disable listeners if
804 * already enabled
805 * screen turning on and current app has sensor based orientation, enable listeners if needed
806 * screen turning on and current app has nosensor based orientation, do nothing
807 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700808 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800809 if (!mOrientationListener.canDetectOrientation()) {
810 // If sensor is turned off or nonexistent for some reason
811 return;
812 }
813 //Could have been invoked due to screen turning on or off or
814 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700815 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
816 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
817 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800818 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700819 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700820 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800821 disable = false;
822 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700823 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800824 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700825 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800826 mOrientationSensorEnabled = true;
827 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700828 }
829 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800830 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700831 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800832 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700833 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800834 mOrientationSensorEnabled = false;
835 }
836 }
837
Jeff Brown13f00f02014-10-31 14:45:50 -0700838 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
839 // Hold a wake lock until the power key is released.
840 if (!mPowerKeyWakeLock.isHeld()) {
841 mPowerKeyWakeLock.acquire();
842 }
843
844 // Cancel multi-press detection timeout.
845 if (mPowerKeyPressCounter != 0) {
846 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
847 }
848
849 // Detect user pressing the power button in panic when an application has
850 // taken over the whole screen.
851 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800852 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700853 if (panic) {
854 mHandler.post(mRequestTransientNav);
855 }
856
857 // Latch power key state to detect screenshot chord.
858 if (interactive && !mScreenshotChordPowerKeyTriggered
859 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
860 mScreenshotChordPowerKeyTriggered = true;
861 mScreenshotChordPowerKeyTime = event.getDownTime();
862 interceptScreenshotChord();
863 }
864
865 // Stop ringing or end call if configured to do so when power is pressed.
866 TelecomManager telecomManager = getTelecommService();
867 boolean hungUp = false;
868 if (telecomManager != null) {
869 if (telecomManager.isRinging()) {
870 // Pressing Power while there's a ringing incoming
871 // call should silence the ringer.
872 telecomManager.silenceRinger();
873 } else if ((mIncallPowerBehavior
874 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
875 && telecomManager.isInCall() && interactive) {
876 // Otherwise, if "Power button ends call" is enabled,
877 // the Power button will hang up any current active call.
878 hungUp = telecomManager.endCall();
879 }
880 }
881
882 // If the power key has still not yet been handled, then detect short
883 // press, long press, or multi press and decide what to do.
884 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
885 || mScreenshotChordVolumeUpKeyTriggered;
886 if (!mPowerKeyHandled) {
887 if (interactive) {
888 // When interactive, we're already awake.
889 // Wait for a long press or for the button to be released to decide what to do.
890 if (hasLongPressOnPowerBehavior()) {
891 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
892 msg.setAsynchronous(true);
893 mHandler.sendMessageDelayed(msg,
894 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
895 }
896 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800897 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800898
Bryce Leed3b28402015-03-09 15:49:13 +0000899 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
900 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
901 msg.setAsynchronous(true);
902 mHandler.sendMessageDelayed(msg,
903 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800904 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000905 } else {
906 final int maxCount = getMaxMultiPressPowerCount();
907
908 if (maxCount <= 1) {
909 mPowerKeyHandled = true;
910 } else {
911 mBeganFromNonInteractive = true;
912 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700913 }
914 }
Jeff Brown4d396052010-10-29 21:50:21 -0700915 }
916 }
917
Jeff Brown13f00f02014-10-31 14:45:50 -0700918 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
919 final boolean handled = canceled || mPowerKeyHandled;
920 mScreenshotChordPowerKeyTriggered = false;
921 cancelPendingScreenshotChordAction();
922 cancelPendingPowerKeyAction();
923
924 if (!handled) {
925 // Figure out how to handle the key now that it has been released.
926 mPowerKeyPressCounter += 1;
927
928 final int maxCount = getMaxMultiPressPowerCount();
929 final long eventTime = event.getDownTime();
930 if (mPowerKeyPressCounter < maxCount) {
931 // This could be a multi-press. Wait a little bit longer to confirm.
932 // Continue holding the wake lock.
933 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
934 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
935 msg.setAsynchronous(true);
936 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
937 return;
938 }
939
940 // No other actions. Handle it immediately.
941 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700942 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700943
944 // Done. Reset our state.
945 finishPowerKeyPress();
946 }
947
948 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800949 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700950 mPowerKeyPressCounter = 0;
951 if (mPowerKeyWakeLock.isHeld()) {
952 mPowerKeyWakeLock.release();
953 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700954 }
955
956 private void cancelPendingPowerKeyAction() {
957 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700958 mPowerKeyHandled = true;
959 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700960 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700961 }
962
963 private void powerPress(long eventTime, boolean interactive, int count) {
964 if (mScreenOnEarly && !mScreenOnFully) {
965 Slog.i(TAG, "Suppressed redundant power key press while "
966 + "already in the process of turning the screen on.");
967 return;
Jeff Brownff204712011-10-25 21:27:54 -0700968 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700969
970 if (count == 2) {
971 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
972 } else if (count == 3) {
973 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -0800974 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700975 switch (mShortPressOnPowerBehavior) {
976 case SHORT_PRESS_POWER_NOTHING:
977 break;
978 case SHORT_PRESS_POWER_GO_TO_SLEEP:
979 mPowerManager.goToSleep(eventTime,
980 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
981 break;
982 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
983 mPowerManager.goToSleep(eventTime,
984 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
985 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
986 break;
987 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
988 mPowerManager.goToSleep(eventTime,
989 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
990 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
991 launchHomeFromHotKey();
992 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800993 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +0000994 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800995 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700996 }
997 }
998 }
999
1000 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1001 switch (behavior) {
1002 case MULTI_PRESS_POWER_NOTHING:
1003 break;
1004 case MULTI_PRESS_POWER_THEATER_MODE:
1005 if (isTheaterModeEnabled()) {
1006 Slog.i(TAG, "Toggling theater mode off.");
1007 Settings.Global.putInt(mContext.getContentResolver(),
1008 Settings.Global.THEATER_MODE_ON, 0);
1009 if (!interactive) {
1010 wakeUpFromPowerKey(eventTime);
1011 }
1012 } else {
1013 Slog.i(TAG, "Toggling theater mode on.");
1014 Settings.Global.putInt(mContext.getContentResolver(),
1015 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001016
1017 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001018 mPowerManager.goToSleep(eventTime,
1019 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1020 }
1021 }
1022 break;
1023 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001024 Slog.i(TAG, "Starting brightness boost.");
1025 if (!interactive) {
1026 wakeUpFromPowerKey(eventTime);
1027 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001028 mPowerManager.boostScreenBrightness(eventTime);
1029 break;
1030 }
1031 }
1032
1033 private int getMaxMultiPressPowerCount() {
1034 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1035 return 3;
1036 }
1037 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1038 return 2;
1039 }
1040 return 1;
1041 }
1042
1043 private void powerLongPress() {
1044 final int behavior = getResolvedLongPressOnPowerBehavior();
1045 switch (behavior) {
1046 case LONG_PRESS_POWER_NOTHING:
1047 break;
1048 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1049 mPowerKeyHandled = true;
1050 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1051 performAuditoryFeedbackForAccessibilityIfNeed();
1052 }
1053 showGlobalActionsInternal();
1054 break;
1055 case LONG_PRESS_POWER_SHUT_OFF:
1056 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1057 mPowerKeyHandled = true;
1058 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1059 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1060 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1061 break;
1062 }
1063 }
1064
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001065 private void sleepPress(KeyEvent event) {
1066 switch (mShortPressOnSleepBehavior) {
1067 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
1068 mPowerManager.goToSleep(event.getEventTime(),
1069 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1070 break;
1071 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001072 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001073 mPowerManager.goToSleep(event.getEventTime(),
1074 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1075 break;
1076 }
1077 }
1078
Jeff Brown13f00f02014-10-31 14:45:50 -07001079 private int getResolvedLongPressOnPowerBehavior() {
1080 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1081 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1082 }
1083 return mLongPressOnPowerBehavior;
1084 }
1085
1086 private boolean hasLongPressOnPowerBehavior() {
1087 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001088 }
1089
1090 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001091 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001092 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1093 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001094 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001095 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1096 && now <= mScreenshotChordPowerKeyTime
1097 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1098 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001099 cancelPendingPowerKeyAction();
1100
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001101 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001102 }
1103 }
1104 }
1105
Winson Chung1cea2f32012-10-08 20:42:01 -07001106 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001107 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001108 // Double the time it takes to take a screenshot from the keyguard
1109 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001110 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001111 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001112 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001113 }
1114
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001115 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001116 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001117 }
1118
Jeff Brown13f00f02014-10-31 14:45:50 -07001119 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001120 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001121 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001122 mEndCallKeyHandled = true;
1123 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1124 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001125 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001126 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001127 }
1128 };
1129
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001130 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001131 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001132 public void run() {
1133 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001134 }
1135 };
1136
Alan Viverettee34560b22014-07-10 14:50:06 -07001137 @Override
1138 public void showGlobalActions() {
1139 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1140 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1141 }
1142
1143 void showGlobalActionsInternal() {
1144 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001145 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001146 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001147 }
Jim Millerab954542014-10-10 18:21:49 -07001148 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001149 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1150 if (keyguardShowing) {
1151 // since it took two seconds of long press to bring this up,
1152 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001153 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001154 }
1155 }
1156
1157 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001158 return Settings.Global.getInt(
1159 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001160 }
1161
Maurice Lam99c6e072014-04-28 18:24:28 -07001162 boolean isUserSetupComplete() {
1163 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1164 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1165 }
1166
Jeff Brown13f00f02014-10-31 14:45:50 -07001167 private void handleShortPressOnHome() {
1168 // If there's a dream running then use home to escape the dream
1169 // but don't actually go home.
1170 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1171 mDreamManagerInternal.stopDream(false /*immediate*/);
1172 return;
1173 }
1174
1175 // Go home!
1176 launchHomeFromHotKey();
1177 }
1178
Patrick Dubroyece94522011-02-23 18:35:01 -08001179 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -08001180 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001181 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001182 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001183
Jeff Browncaca8812013-05-09 13:34:33 -07001184 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1185 toggleRecentApps();
1186 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1187 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -07001188 }
1189 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001190 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001191
Jeff Browncaca8812013-05-09 13:34:33 -07001192 private void handleDoubleTapOnHome() {
1193 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1194 mHomeConsumed = true;
1195 toggleRecentApps();
1196 }
1197 }
1198
1199 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1200 @Override
1201 public void run() {
1202 if (mHomeDoubleTapPending) {
1203 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001204 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001205 }
1206 }
1207 };
1208
Mark Renoufc1256912015-03-11 14:38:23 -04001209 private boolean isRoundWindow() {
1210 return mContext.getResources().getBoolean(com.android.internal.R.bool.config_windowIsRound)
1211 || (Build.HARDWARE.contains("goldfish")
1212 && SystemProperties.getBoolean(ViewRootImpl.PROPERTY_EMULATOR_CIRCULAR, false));
1213 }
1214
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001215 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001216 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001217 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001218 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001219 mContext = context;
1220 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001221 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001222 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001223 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Mark Renoufc1256912015-03-11 14:38:23 -04001224
1225 // Init display burn-in protection
1226 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1227 com.android.internal.R.bool.config_enableBurnInProtection);
1228 // Allow a system property to override this. Used by developer settings.
1229 boolean burnInProtectionDevMode =
1230 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1231 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1232 final int minHorizontal;
1233 final int maxHorizontal;
1234 final int minVertical;
1235 final int maxVertical;
1236 final int maxRadius;
1237 if (burnInProtectionDevMode) {
1238 minHorizontal = -8;
1239 maxHorizontal = 8;
1240 minVertical = -8;
1241 maxVertical = -4;
1242 maxRadius = (isRoundWindow()) ? 6 : -1;
1243 } else {
1244 Resources resources = context.getResources();
1245 minHorizontal = resources.getInteger(
1246 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1247 maxHorizontal = resources.getInteger(
1248 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1249 minVertical = resources.getInteger(
1250 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1251 maxVertical = resources.getInteger(
1252 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1253 maxRadius = resources.getInteger(
1254 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1255 }
1256 mBurnInProtectionHelper = new BurnInProtectionHelper(
1257 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001258 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001259
Jeff Brown70825162012-03-28 17:27:48 -07001260 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001261 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001262 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001263 try {
1264 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1265 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001266 mSettingsObserver = new SettingsObserver(mHandler);
1267 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001268 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001269 mUiMode = context.getResources().getInteger(
1270 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001271 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1272 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1273 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1274 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001275 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1276 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1277 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1278 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1279 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1280 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1281 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1282 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001283
Jeff Brown96307042012-07-27 15:51:34 -07001284 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1285 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001286 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001287 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1288 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001289 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001290 mSupportAutoRotation = mContext.getResources().getBoolean(
1291 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001292 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001293 com.android.internal.R.integer.config_lidOpenRotation);
1294 mCarDockRotation = readRotation(
1295 com.android.internal.R.integer.config_carDockRotation);
1296 mDeskDockRotation = readRotation(
1297 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001298 mUndockedHdmiRotation = readRotation(
1299 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001300 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1301 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1302 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1303 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001304 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1305 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1306 mLidNavigationAccessibility = mContext.getResources().getInteger(
1307 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001308 mLidControlsSleep = mContext.getResources().getBoolean(
1309 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001310 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1311 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001312
1313 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1314 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1315 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1316 || mContext.getResources().getBoolean(
1317 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1318 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1319 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001320 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1321 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001322 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1323 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1324 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1325 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1326 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1327 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1328
Bryce Lee55e846d2014-11-04 12:43:44 -08001329 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1330 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1331
Bryce Leed3b28402015-03-09 15:49:13 +00001332 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1333 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1334
Jeff Brown13f00f02014-10-31 14:45:50 -07001335 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1336 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1337 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1338 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1339 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1340 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1341 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1342 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001343 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1344 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001345
John Spurlock61560172015-02-06 19:46:04 -05001346 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001347
Jeff Brownf71343d2013-05-31 17:59:11 -07001348 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001349
Svetoslav8e3feb12014-02-24 13:46:47 -08001350 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1351 Context.ACCESSIBILITY_SERVICE);
1352
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001353 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001354 IntentFilter filter = new IntentFilter();
1355 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1356 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1357 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1358 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001359 filter.addAction(Intent.ACTION_DOCK_EVENT);
1360 Intent intent = context.registerReceiver(mDockReceiver, filter);
1361 if (intent != null) {
1362 // Retrieve current sticky dock event broadcast.
1363 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1364 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1365 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001366
Jeff Brown6aaf2952012-10-05 16:01:08 -07001367 // register for dream-related broadcasts
1368 filter = new IntentFilter();
1369 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1370 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1371 context.registerReceiver(mDreamReceiver, filter);
1372
Christopher Tate5e08af02012-09-21 17:17:22 -07001373 // register for multiuser-relevant broadcasts
1374 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1375 context.registerReceiver(mMultiuserReceiver, filter);
1376
John Spurlock57306e62013-04-22 09:48:49 -04001377 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001378 mSystemGestures = new SystemGesturesPointerEventListener(context,
1379 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001380 @Override
1381 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001382 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001383 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001384 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001385 }
1386 @Override
1387 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001388 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001389 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001390 }
1391 }
1392 @Override
1393 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001394 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001395 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001396 }
1397 }
1398 @Override
1399 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001400 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001401 }
Adrian Roos3595be42015-03-05 16:31:15 +01001402 @Override
1403 public void onDown() {
1404 mOrientationListener.onTouchStart();
1405 }
1406 @Override
1407 public void onUpOrCancel() {
1408 mOrientationListener.onTouchEnd();
1409 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001410 });
John Spurlockf1a36642013-10-12 17:50:42 -04001411 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001412 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001413
Jeff Brownc2346132012-04-13 01:55:38 -07001414 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001415 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1416 com.android.internal.R.array.config_longPressVibePattern);
1417 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1418 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001419 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1420 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001421 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1422 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001423 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1424 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001425 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1426 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1427 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1428 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001429
Christopher Tatee90585f2012-03-05 18:56:25 -08001430 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1431 com.android.internal.R.bool.config_enableScreenshotChord);
1432
Justin Kohd378ad72013-04-01 12:18:26 -07001433 mGlobalKeyManager = new GlobalKeyManager(mContext);
1434
Joe Onoratoea495d42011-04-06 11:41:11 -07001435 // Controls rotation and the like.
1436 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001437
1438 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001439 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001440 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001441 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001442
1443 mWindowManagerInternal.registerAppTransitionListener(
1444 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001445 }
1446
Jeff Brownf71343d2013-05-31 17:59:11 -07001447 /**
1448 * Read values from config.xml that may be overridden depending on
1449 * the configuration of the device.
1450 * eg. Disable long press on home goes to recents on sw600dp.
1451 */
1452 private void readConfigurationDependentBehaviors() {
1453 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1454 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1455 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1456 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1457 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1458 }
1459
1460 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1461 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1462 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1463 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1464 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1465 }
1466 }
1467
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001468 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001469 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001470 // This method might be called before the policy has been fully initialized
1471 // or for other displays we don't care about.
1472 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1473 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001474 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001475 mDisplay = display;
1476
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001477 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001478 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001479 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001480 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001481 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001482 mLandscapeRotation = Surface.ROTATION_0;
1483 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001484 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001485 mPortraitRotation = Surface.ROTATION_90;
1486 mUpsideDownRotation = Surface.ROTATION_270;
1487 } else {
1488 mPortraitRotation = Surface.ROTATION_270;
1489 mUpsideDownRotation = Surface.ROTATION_90;
1490 }
1491 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001492 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001493 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001494 mPortraitRotation = Surface.ROTATION_0;
1495 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001496 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001497 mLandscapeRotation = Surface.ROTATION_270;
1498 mSeascapeRotation = Surface.ROTATION_90;
1499 } else {
1500 mLandscapeRotation = Surface.ROTATION_90;
1501 mSeascapeRotation = Surface.ROTATION_270;
1502 }
1503 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001504
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001505 mStatusBarHeight =
1506 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001507
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001508 // Height of the navigation bar when presented horizontally at bottom
1509 mNavigationBarHeightForRotation[mPortraitRotation] =
1510 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001511 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001512 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001513 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1514 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001515
1516 // Width of the navigation bar when presented vertically along one side
1517 mNavigationBarWidthForRotation[mPortraitRotation] =
1518 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1519 mNavigationBarWidthForRotation[mLandscapeRotation] =
1520 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001521 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001522
1523 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001524 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001525 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001526
Devin Kimd7b12b42014-05-05 14:34:58 -07001527 // Allow the navigation bar to move on non-square small devices (phones).
1528 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001529
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001530 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001531 // Allow a system property to override this. Used by the emulator.
1532 // See also hasNavigationBar().
1533 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1534 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001535 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001536 } else if ("0".equals(navBarOverride)) {
1537 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001538 }
1539
Jeff Brown27f1d672012-10-17 18:32:34 -07001540 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1541 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001542 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001543 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001544 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001545 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001546 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001547 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001548
Chong Zhangae6119ff2014-11-11 18:54:39 -08001549 // For demo purposes, allow the rotation of the remote display to be controlled.
1550 // By default, remote display locks rotation to landscape.
1551 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1552 mDemoRotation = mPortraitRotation;
1553 } else {
1554 mDemoRotation = mLandscapeRotation;
1555 }
1556 mDemoRotationLock = SystemProperties.getBoolean(
1557 "persist.demo.rotationlock", false);
1558
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001559 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1560 // http://developer.android.com/guide/practices/screens_support.html#range
1561 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1562 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1563 // For debug purposes the next line turns this feature off with:
1564 // $ adb shell setprop config.override_forced_orient true
1565 // $ adb shell wm size reset
1566 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1567 }
1568
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001569 /**
1570 * @return whether the navigation bar can be hidden, e.g. the device has a
1571 * navigation bar and touch exploration is not enabled
1572 */
1573 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001574 return mHasNavigationBar
1575 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001576 }
1577
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001578 @Override
1579 public boolean isDefaultOrientationForced() {
1580 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001581 }
1582
Dianne Hackbornc652de82013-02-15 16:32:56 -08001583 @Override
1584 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1585 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1586 mOverscanLeft = left;
1587 mOverscanTop = top;
1588 mOverscanRight = right;
1589 mOverscanBottom = bottom;
1590 }
1591 }
1592
Dianne Hackbornc777e072010-02-12 13:07:59 -08001593 public void updateSettings() {
1594 ContentResolver resolver = mContext.getContentResolver();
1595 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001596 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001597 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001598 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001599 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1600 UserHandle.USER_CURRENT);
1601 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001602 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001603 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1604 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001605
Jeff Browna20dda42014-05-27 20:57:24 -07001606 // Configure wake gesture.
1607 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1608 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1609 UserHandle.USER_CURRENT) != 0;
1610 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1611 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1612 updateWakeGestureListenerLp();
1613 }
1614
Jeff Brown207673cd2012-06-05 17:47:11 -07001615 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001616 int userRotation = Settings.System.getIntForUser(resolver,
1617 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1618 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001619 if (mUserRotation != userRotation) {
1620 mUserRotation = userRotation;
1621 updateRotation = true;
1622 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001623 int userRotationMode = Settings.System.getIntForUser(resolver,
1624 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001625 WindowManagerPolicy.USER_ROTATION_FREE :
1626 WindowManagerPolicy.USER_ROTATION_LOCKED;
1627 if (mUserRotationMode != userRotationMode) {
1628 mUserRotationMode = userRotationMode;
1629 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001630 updateOrientationListenerLp();
1631 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001632
Dianne Hackbornc777e072010-02-12 13:07:59 -08001633 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001634 int pointerLocation = Settings.System.getIntForUser(resolver,
1635 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001636 if (mPointerLocationMode != pointerLocation) {
1637 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001638 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1639 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001640 }
1641 }
1642 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001643 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1644 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1645 String imId = Settings.Secure.getStringForUser(resolver,
1646 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001647 boolean hasSoftInput = imId != null && imId.length() > 0;
1648 if (mHasSoftInput != hasSoftInput) {
1649 mHasSoftInput = hasSoftInput;
1650 updateRotation = true;
1651 }
John Spurlockf1a36642013-10-12 17:50:42 -04001652 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001653 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001654 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001655 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001656 }
1657 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001658 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001659 }
Jeff Brown70825162012-03-28 17:27:48 -07001660 }
1661
Jeff Browna20dda42014-05-27 20:57:24 -07001662 private void updateWakeGestureListenerLp() {
1663 if (shouldEnableWakeGestureLp()) {
1664 mWakeGestureListener.requestWakeUpTrigger();
1665 } else {
1666 mWakeGestureListener.cancelWakeUpTrigger();
1667 }
1668 }
1669
1670 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001671 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001672 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1673 && mWakeGestureListener.isSupported();
1674 }
1675
Jeff Brown70825162012-03-28 17:27:48 -07001676 private void enablePointerLocation() {
1677 if (mPointerLocationView == null) {
1678 mPointerLocationView = new PointerLocationView(mContext);
1679 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001680 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1681 WindowManager.LayoutParams.MATCH_PARENT,
1682 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001683 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001684 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1685 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1686 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1687 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001688 if (ActivityManager.isHighEndGfx()) {
1689 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1690 lp.privateFlags |=
1691 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1692 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001693 lp.format = PixelFormat.TRANSLUCENT;
1694 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001695 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001696 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001697 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001698 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001699 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001700 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001701 }
Jeff Brown70825162012-03-28 17:27:48 -07001702
1703 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001704 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001705 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1706 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001707 wm.removeView(mPointerLocationView);
1708 mPointerLocationView = null;
1709 }
1710 }
1711
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001712 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001713 try {
1714 int rotation = mContext.getResources().getInteger(resID);
1715 switch (rotation) {
1716 case 0:
1717 return Surface.ROTATION_0;
1718 case 90:
1719 return Surface.ROTATION_90;
1720 case 180:
1721 return Surface.ROTATION_180;
1722 case 270:
1723 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001724 }
1725 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001726 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001727 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001728 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001729 }
1730
1731 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001732 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001733 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001734 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001735
1736 outAppOp[0] = AppOpsManager.OP_NONE;
1737
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001738 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1739 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1740 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1741 return WindowManagerGlobal.ADD_INVALID_TYPE;
1742 }
1743
1744 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1745 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001746 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001747 }
1748 String permission = null;
1749 switch (type) {
1750 case TYPE_TOAST:
1751 // XXX right now the app process has complete control over
1752 // this... should introduce a token to let the system
1753 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001754 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001755 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001756 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001757 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001758 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001759 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001760 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001761 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001762 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001763 break;
1764 case TYPE_PHONE:
1765 case TYPE_PRIORITY_PHONE:
1766 case TYPE_SYSTEM_ALERT:
1767 case TYPE_SYSTEM_ERROR:
1768 case TYPE_SYSTEM_OVERLAY:
1769 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001770 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001771 break;
1772 default:
1773 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1774 }
1775 if (permission != null) {
1776 if (mContext.checkCallingOrSelfPermission(permission)
1777 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001778 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001779 }
1780 }
Jeff Brown98365d72012-08-19 20:30:52 -07001781 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001782 }
Craig Mautner88400d32012-09-30 12:35:45 -07001783
1784 @Override
1785 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1786
1787 // If this switch statement is modified, modify the comment in the declarations of
1788 // the type in {@link WindowManager.LayoutParams} as well.
1789 switch (attrs.type) {
1790 default:
1791 // These are the windows that by default are shown only to the user that created
1792 // them. If this needs to be overridden, set
1793 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1794 // {@link WindowManager.LayoutParams}. Note that permission
1795 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1796 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1797 return true;
1798 }
1799 break;
1800
1801 // These are the windows that by default are shown to all users. However, to
1802 // protect against spoofing, check permissions below.
1803 case TYPE_APPLICATION_STARTING:
1804 case TYPE_BOOT_PROGRESS:
1805 case TYPE_DISPLAY_OVERLAY:
1806 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001807 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001808 case TYPE_KEYGUARD_DIALOG:
1809 case TYPE_MAGNIFICATION_OVERLAY:
1810 case TYPE_NAVIGATION_BAR:
1811 case TYPE_NAVIGATION_BAR_PANEL:
1812 case TYPE_PHONE:
1813 case TYPE_POINTER:
1814 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001815 case TYPE_SEARCH_BAR:
1816 case TYPE_STATUS_BAR:
1817 case TYPE_STATUS_BAR_PANEL:
1818 case TYPE_STATUS_BAR_SUB_PANEL:
1819 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001820 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001821 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001822 break;
1823 }
1824
1825 // Check if third party app has set window to system window type.
1826 return mContext.checkCallingOrSelfPermission(
1827 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1828 != PackageManager.PERMISSION_GRANTED;
1829 }
1830
Craig Mautner967212c2013-04-13 21:10:58 -07001831 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001832 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1833 switch (attrs.type) {
1834 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001835 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001836 // These types of windows can't receive input events.
1837 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1838 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001839 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001840 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001841 case TYPE_STATUS_BAR:
1842
1843 // If the Keyguard is in a hidden state (occluded by another window), we force to
1844 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1845 // the keyguard as occluded wouldn't set these flags again.
1846 // See {@link #processKeyguardSetHiddenResultLw}.
1847 if (mKeyguardHidden) {
1848 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1849 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1850 }
1851 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001852 }
Adrian Roos38502112014-04-09 21:04:11 +02001853
1854 if (attrs.type != TYPE_STATUS_BAR) {
1855 // The status bar is the only window allowed to exhibit keyguard behavior.
1856 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1857 }
Adrian Roosea562512014-05-05 13:33:03 +02001858
1859 if (ActivityManager.isHighEndGfx()
1860 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001861 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001862 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1863 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001864 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001865
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001866 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001867 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001868 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001869
Michael Wright3818c922014-09-02 13:59:07 -07001870 private void readCameraLensCoverState() {
1871 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1872 }
1873
Jeff Browndaa37532012-05-01 15:54:03 -07001874 private boolean isHidden(int accessibilityMode) {
1875 switch (accessibilityMode) {
1876 case 1:
1877 return mLidState == LID_CLOSED;
1878 case 2:
1879 return mLidState == LID_OPEN;
1880 default:
1881 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001882 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001883 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001884
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001885 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001886 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001887 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1888 int navigationPresence) {
1889 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1890
Jeff Brownf71343d2013-05-31 17:59:11 -07001891 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001892 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001893 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001894
Jeff Browndaa37532012-05-01 15:54:03 -07001895 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1896 || (keyboardPresence == PRESENCE_INTERNAL
1897 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001898 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001899 if (!mHasSoftInput) {
1900 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1901 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001902 }
1903
Jeff Browndaa37532012-05-01 15:54:03 -07001904 if (config.navigation == Configuration.NAVIGATION_NONAV
1905 || (navigationPresence == PRESENCE_INTERNAL
1906 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001907 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001908 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001909 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001910
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001911 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001912 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001913 public int windowTypeToLayerLw(int type) {
1914 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001915 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001916 }
1917 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001918 case TYPE_PRIVATE_PRESENTATION:
1919 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001920 case TYPE_WALLPAPER:
1921 // wallpaper is at the bottom, though the window manager may move it.
1922 return 2;
1923 case TYPE_PHONE:
1924 return 3;
1925 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07001926 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001927 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001928 case TYPE_VOICE_INTERACTION:
1929 // voice interaction layer is almost immediately above apps.
1930 return 5;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001931 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001932 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001933 case TYPE_TOAST:
1934 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001935 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001936 case TYPE_PRIORITY_PHONE:
1937 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001938 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001939 case TYPE_DREAM:
1940 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001941 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001942 case TYPE_SYSTEM_ALERT:
1943 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001944 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001945 case TYPE_INPUT_METHOD:
1946 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001947 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001948 case TYPE_INPUT_METHOD_DIALOG:
1949 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001950 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001951 case TYPE_KEYGUARD_SCRIM:
1952 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001953 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001954 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001955 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001956 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001957 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001958 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001959 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001960 case TYPE_KEYGUARD_DIALOG:
1961 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001962 case TYPE_VOLUME_OVERLAY:
1963 // the on-screen volume indicator and controller shown when the user
1964 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001965 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001966 case TYPE_SYSTEM_OVERLAY:
1967 // the on-screen volume indicator and controller shown when the user
1968 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001969 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001970 case TYPE_NAVIGATION_BAR:
1971 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001972 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001973 case TYPE_NAVIGATION_BAR_PANEL:
1974 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001975 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001976 case TYPE_SYSTEM_ERROR:
1977 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001978 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001979 case TYPE_MAGNIFICATION_OVERLAY:
1980 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001981 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001982 case TYPE_DISPLAY_OVERLAY:
1983 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001984 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001985 case TYPE_DRAG:
1986 // the drag layer: input for drag-and-drop is associated with this window,
1987 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001988 return 25;
Svetoslav3a5c7212014-10-14 09:54:26 -07001989 case TYPE_ACCESSIBILITY_OVERLAY:
1990 // overlay put by accessibility services to intercept user interaction
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001991 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07001992 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001993 return 27;
Svetoslav3a5c7212014-10-14 09:54:26 -07001994 case TYPE_BOOT_PROGRESS:
1995 return 28;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001996 case TYPE_POINTER:
1997 // the (mouse) pointer layer
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001998 return 29;
Svetoslav3a5c7212014-10-14 09:54:26 -07001999 case TYPE_HIDDEN_NAV_CONSUMER:
2000 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002001 }
2002 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002003 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002004 }
2005
2006 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002007 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002008 public int subWindowTypeToLayerLw(int type) {
2009 switch (type) {
2010 case TYPE_APPLICATION_PANEL:
2011 case TYPE_APPLICATION_ATTACHED_DIALOG:
2012 return APPLICATION_PANEL_SUBLAYER;
2013 case TYPE_APPLICATION_MEDIA:
2014 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002015 case TYPE_APPLICATION_MEDIA_OVERLAY:
2016 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002017 case TYPE_APPLICATION_SUB_PANEL:
2018 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002019 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2020 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002021 }
2022 Log.e(TAG, "Unknown sub-window type: " + type);
2023 return 0;
2024 }
2025
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002026 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002027 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002028 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002029 }
2030
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002031 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002032 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002033 if (mHasNavigationBar) {
2034 // For a basic navigation bar, when we are in landscape mode we place
2035 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002036 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2037 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002038 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002039 }
2040 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002041 }
2042
Jose Lima9546b202014-07-02 17:21:51 -07002043 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002044 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002045 if (mHasNavigationBar) {
2046 // For a basic navigation bar, when we are in portrait mode we place
2047 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002048 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2049 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002050 }
2051 }
2052 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002053 }
2054
Jose Lima9546b202014-07-02 17:21:51 -07002055 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002056 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2057 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002058 }
2059
Jose Lima9546b202014-07-02 17:21:51 -07002060 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002061 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002062 // There is a separate status bar at the top of the display. We don't count that as part
2063 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002064 // we do want to exclude it since applications can't generally use that part
2065 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002066 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002067 }
2068
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002069 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002070 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2071 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002072 (isKeyguardHostWindow(attrs) &&
2073 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002074 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002075 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002076
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002077 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002078 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2079 return attrs.type == TYPE_STATUS_BAR;
2080 }
2081
2082 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002083 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002084 switch (attrs.type) {
2085 case TYPE_STATUS_BAR:
2086 case TYPE_NAVIGATION_BAR:
2087 case TYPE_WALLPAPER:
2088 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002089 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002090 return false;
2091 default:
2092 return true;
2093 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002094 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002095
Craig Mautner7d7808f2014-09-11 18:02:38 -07002096 @Override
2097 public WindowState getWinShowWhenLockedLw() {
2098 return mWinShowWhenLocked;
2099 }
2100
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002101 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002102 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002103 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2104 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002105 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002106 if (!SHOW_STARTING_ANIMATIONS) {
2107 return null;
2108 }
2109 if (packageName == null) {
2110 return null;
2111 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002112
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002113 WindowManager wm = null;
2114 View view = null;
2115
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002116 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002117 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002118 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2119 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2120 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002121 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002122 try {
2123 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002124 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002125 } catch (PackageManager.NameNotFoundException e) {
2126 // Ignore
2127 }
2128 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002129
Jorim Jaggib10e33f2015-02-04 21:57:40 +01002130 Window win = new PhoneWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002131 final TypedArray ta = win.getWindowStyle();
2132 if (ta.getBoolean(
2133 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2134 || ta.getBoolean(
2135 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002136 return null;
2137 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002138
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002139 Resources r = context.getResources();
2140 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002141
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002142 win.setType(
2143 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
2144 // Force the window flags: this is a fake window, so it is not really
2145 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2146 // flag because we do know that the next window will take input
2147 // focus, so we want to get the IME window up on top of us right away.
2148 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002149 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002150 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2151 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2152 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002153 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002154 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2155 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2156 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002157
Adam Powell04fe6eb2013-05-31 14:39:48 -07002158 win.setDefaultIcon(icon);
2159 win.setDefaultLogo(logo);
2160
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002161 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002162 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002163
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002164 final WindowManager.LayoutParams params = win.getAttributes();
2165 params.token = appToken;
2166 params.packageName = packageName;
2167 params.windowAnimations = win.getWindowStyle().getResourceId(
2168 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002169 params.privateFlags |=
2170 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002171 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002172
2173 if (!compatInfo.supportsScreen()) {
2174 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2175 }
2176
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002177 params.setTitle("Starting " + packageName);
2178
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002179 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2180 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002181
2182 if (win.isFloating()) {
2183 // Whoops, there is no way to display an animation/preview
2184 // of such a thing! After all that work... let's skip it.
2185 // (Note that we must do this here because it is in
2186 // getDecorView() where the theme is evaluated... maybe
2187 // we should peek the floating attribute from the theme
2188 // earlier.)
2189 return null;
2190 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002191
Craig Mautner6fbda632012-07-03 09:26:39 -07002192 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002193 TAG, "Adding starting window for " + packageName
2194 + " / " + appToken + ": "
2195 + (view.getParent() != null ? view : null));
2196
2197 wm.addView(view, params);
2198
2199 // Only return the view if it was successfully added to the
2200 // window manager... which we can tell by it having a parent.
2201 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002202 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002203 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002204 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2205 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002206 } catch (RuntimeException e) {
2207 // don't crash if something else bad happens, for example a
2208 // failure loading resources because we are loading from an app
2209 // on external storage that has been unmounted.
2210 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002211 } finally {
2212 if (view != null && view.getParent() == null) {
2213 Log.w(TAG, "view not successfully added to wm, removing view");
2214 wm.removeViewImmediate(view);
2215 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002216 }
2217
2218 return null;
2219 }
2220
2221 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002222 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002223 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002224 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2225 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002226
2227 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002228 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002229 wm.removeView(window);
2230 }
2231 }
2232
2233 /**
2234 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002235 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002236 * Currently enforces that three window types are singletons:
2237 * <ul>
2238 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002239 * <li>KEYGUARD_TYPE</li>
2240 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002241 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002242 * @param win The window to be added
2243 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002244 *
Jeff Brown98365d72012-08-19 20:30:52 -07002245 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2246 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002247 */
Jose Lima9546b202014-07-02 17:21:51 -07002248 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002249 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2250 switch (attrs.type) {
2251 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002252 mContext.enforceCallingOrSelfPermission(
2253 android.Manifest.permission.STATUS_BAR_SERVICE,
2254 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002255 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002256 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002257 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002258 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002259 }
2260 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002261 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002262 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002263 case TYPE_NAVIGATION_BAR:
2264 mContext.enforceCallingOrSelfPermission(
2265 android.Manifest.permission.STATUS_BAR_SERVICE,
2266 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002267 if (mNavigationBar != null) {
2268 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002269 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002270 }
2271 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002272 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002273 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002274 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002275 break;
Jim Millere898ac52012-04-06 17:10:57 -07002276 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002277 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002278 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002279 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002280 mContext.enforceCallingOrSelfPermission(
2281 android.Manifest.permission.STATUS_BAR_SERVICE,
2282 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002283 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002284 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002285 if (mKeyguardScrim != null) {
2286 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2287 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002288 mKeyguardScrim = win;
2289 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002290 }
Jeff Brown98365d72012-08-19 20:30:52 -07002291 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002292 }
2293
2294 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002295 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002296 public void removeWindowLw(WindowState win) {
2297 if (mStatusBar == win) {
2298 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002299 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002300 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002301 } else if (mKeyguardScrim == win) {
2302 Log.v(TAG, "Removing keyguard scrim");
2303 mKeyguardScrim = null;
2304 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002305 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002306 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002307 }
2308 }
2309
2310 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002311
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002312 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002313 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002314 public int selectAnimationLw(WindowState win, int transit) {
2315 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2316 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002317 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002318 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002319 if (transit == TRANSIT_EXIT
2320 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002321 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002322 } else if (transit == TRANSIT_ENTER
2323 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002324 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002325 }
2326 } else if (win == mNavigationBar) {
2327 // This can be on either the bottom or the right.
2328 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002329 if (transit == TRANSIT_EXIT
2330 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002331 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002332 } else if (transit == TRANSIT_ENTER
2333 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002334 return R.anim.dock_bottom_enter;
2335 }
2336 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002337 if (transit == TRANSIT_EXIT
2338 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002339 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002340 } else if (transit == TRANSIT_ENTER
2341 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002342 return R.anim.dock_right_enter;
2343 }
2344 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002345 }
2346
2347 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002348 if (win.hasAppShownWindows()) {
2349 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2350 return com.android.internal.R.anim.app_starting_exit;
2351 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002352 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002353 && transit == TRANSIT_ENTER) {
2354 // Special case: we are animating in a dream, while the keyguard
2355 // is shown. We don't want an animation on the dream, because
2356 // we need it shown immediately with the keyguard animating away
2357 // to reveal it.
2358 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002359 }
2360
2361 return 0;
2362 }
2363
Craig Mautner3c174372013-02-21 17:54:37 -08002364 @Override
2365 public void selectRotationAnimationLw(int anim[]) {
2366 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2367 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2368 + (mTopFullscreenOpaqueWindowState == null ?
2369 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2370 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2371 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2372 case ROTATION_ANIMATION_CROSSFADE:
2373 anim[0] = R.anim.rotation_animation_xfade_exit;
2374 anim[1] = R.anim.rotation_animation_enter;
2375 break;
2376 case ROTATION_ANIMATION_JUMPCUT:
2377 anim[0] = R.anim.rotation_animation_jump_exit;
2378 anim[1] = R.anim.rotation_animation_enter;
2379 break;
2380 case ROTATION_ANIMATION_ROTATE:
2381 default:
2382 anim[0] = anim[1] = 0;
2383 break;
2384 }
2385 } else {
2386 anim[0] = anim[1] = 0;
2387 }
2388 }
2389
2390 @Override
2391 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2392 boolean forceDefault) {
2393 switch (exitAnimId) {
2394 case R.anim.rotation_animation_xfade_exit:
2395 case R.anim.rotation_animation_jump_exit:
2396 // These are the only cases that matter.
2397 if (forceDefault) {
2398 return false;
2399 }
2400 int anim[] = new int[2];
2401 selectRotationAnimationLw(anim);
2402 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2403 default:
2404 return true;
2405 }
2406 }
2407
2408 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002409 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2410 boolean goingToNotificationShade) {
2411 if (goingToNotificationShade) {
2412 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002413 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002414
2415 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2416 R.anim.lock_screen_behind_enter_wallpaper :
2417 R.anim.lock_screen_behind_enter);
2418
2419 // TODO: Use XML interpolators when we have log interpolators available in XML.
2420 final List<Animation> animations = set.getAnimations();
2421 for (int i = animations.size() - 1; i >= 0; --i) {
2422 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2423 }
2424
2425 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002426 }
2427
2428
2429 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002430 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2431 if (goingToNotificationShade) {
2432 return null;
2433 } else {
2434 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2435 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002436 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002437
2438 private static void awakenDreams() {
2439 IDreamManager dreamManager = getDreamManager();
2440 if (dreamManager != null) {
2441 try {
2442 dreamManager.awaken();
2443 } catch (RemoteException e) {
2444 // fine, stay asleep then
2445 }
2446 }
2447 }
2448
2449 static IDreamManager getDreamManager() {
2450 return IDreamManager.Stub.asInterface(
2451 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2452 }
2453
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002454 TelecomManager getTelecommService() {
2455 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002456 }
2457
Jeff Brown4d396052010-10-29 21:50:21 -07002458 static IAudioService getAudioService() {
2459 IAudioService audioService = IAudioService.Stub.asInterface(
2460 ServiceManager.checkService(Context.AUDIO_SERVICE));
2461 if (audioService == null) {
2462 Log.w(TAG, "Unable to find IAudioService interface.");
2463 }
2464 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002465 }
2466
2467 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002468 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002469 }
2470
2471 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2472 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2473 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2474 };
2475
2476 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002477 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002478 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002479 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002480 final int keyCode = event.getKeyCode();
2481 final int repeatCount = event.getRepeatCount();
2482 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002483 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002484 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2485 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002486
Jeff Brown40013652012-05-16 21:22:36 -07002487 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002488 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002489 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2490 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002491 }
2492
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002493 // If we think we might have a volume down & power key chord on the way
2494 // but we're not sure, then tell the dispatcher to wait a little while and
2495 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002496 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002497 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002498 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002499 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2500 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002501 if (now < timeoutTime) {
2502 return timeoutTime - now;
2503 }
2504 }
2505 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002506 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002507 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002508 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002509 }
2510 return -1;
2511 }
2512 }
2513
Michael Wright6a62e552014-06-03 19:19:48 -07002514 // Cancel any pending meta actions if we see any other keys being pressed between the down
2515 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002516 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002517 mPendingMetaAction = false;
2518 }
2519
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002520 // First we always handle the home key here, so applications
2521 // can never break it, although if keyguard is on, we do let
2522 // it handle it, because that gives us the correct 5 second
2523 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002524 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002525
Jeff Brown49ed71d2010-12-06 17:13:33 -08002526 // If we have released the home key, and didn't do anything else
2527 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002528 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002529 cancelPreloadRecentApps();
2530
Jeff Brown49ed71d2010-12-06 17:13:33 -08002531 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002532 if (mHomeConsumed) {
2533 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002534 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002535 }
Jeff Browncaca8812013-05-09 13:34:33 -07002536
2537 if (canceled) {
2538 Log.i(TAG, "Ignoring HOME; event canceled.");
2539 return -1;
2540 }
2541
Yorke Lee4f803242014-12-15 23:22:06 +00002542 // If an incoming call is ringing, HOME is totally disabled.
2543 // (The user is already on the InCallUI at this point,
2544 // and his ONLY options are to answer or reject the call.)
2545 TelecomManager telecomManager = getTelecommService();
2546 if (telecomManager != null && telecomManager.isRinging()) {
2547 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2548 return -1;
2549 }
2550
Jeff Browncaca8812013-05-09 13:34:33 -07002551 // Delay handling home if a double-tap is possible.
2552 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2553 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2554 mHomeDoubleTapPending = true;
2555 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2556 ViewConfiguration.getDoubleTapTimeout());
2557 return -1;
2558 }
2559
Jeff Brown13f00f02014-10-31 14:45:50 -07002560 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002561 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002562 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002563
2564 // If a system window has focus, then it doesn't make sense
2565 // right now to interact with applications.
2566 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2567 if (attrs != null) {
2568 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002569 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2570 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2571 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002572 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002573 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002574 }
2575 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2576 for (int i=0; i<typeCount; i++) {
2577 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2578 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002579 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002580 }
2581 }
2582 }
Jeff Browncaca8812013-05-09 13:34:33 -07002583
2584 // Remember that home is pressed and handle special actions.
2585 if (repeatCount == 0) {
2586 mHomePressed = true;
2587 if (mHomeDoubleTapPending) {
2588 mHomeDoubleTapPending = false;
2589 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2590 handleDoubleTapOnHome();
2591 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2592 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2593 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002594 }
Jeff Browncaca8812013-05-09 13:34:33 -07002595 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2596 if (!keyguardOn) {
2597 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002598 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002599 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002600 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002601 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002602 // Hijack modified menu keys for debugging features
2603 final int chordBug = KeyEvent.META_SHIFT_ON;
2604
2605 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002606 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002607 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002608 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2609 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002610 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002611 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002612 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002613 Intent service = new Intent();
2614 service.setClassName(mContext, "com.android.server.LoadAverageService");
2615 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002616 boolean shown = Settings.Global.getInt(
2617 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002618 if (!shown) {
2619 mContext.startService(service);
2620 } else {
2621 mContext.stopService(service);
2622 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002623 Settings.Global.putInt(
2624 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002625 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002626 }
2627 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002628 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002629 if (down) {
2630 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002631 mSearchKeyShortcutPending = true;
2632 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002633 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002634 } else {
2635 mSearchKeyShortcutPending = false;
2636 if (mConsumeSearchKeyUp) {
2637 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002638 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002639 }
2640 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002641 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002642 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002643 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002644 if (down && repeatCount == 0) {
2645 preloadRecentApps();
2646 } else if (!down) {
2647 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002648 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002649 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002650 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002651 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2652 if (down) {
2653 if (repeatCount == 0) {
2654 mAssistKeyLongPressed = false;
2655 } else if (repeatCount == 1) {
2656 mAssistKeyLongPressed = true;
2657 if (!keyguardOn) {
2658 launchAssistLongPressAction();
2659 }
2660 }
2661 } else {
2662 if (mAssistKeyLongPressed) {
2663 mAssistKeyLongPressed = false;
2664 } else {
2665 if (!keyguardOn) {
2666 launchAssistAction();
2667 }
2668 }
2669 }
2670 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002671 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2672 if (!down) {
2673 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002674 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002675 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2676 } else {
2677 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002678 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002679 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002680 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002681 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002682 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2683 if (down && repeatCount == 0) {
2684 mHandler.post(mScreenshotRunnable);
2685 }
2686 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002687 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2688 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2689 if (down) {
2690 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2691
2692 // Disable autobrightness if it's on
2693 int auto = Settings.System.getIntForUser(
2694 mContext.getContentResolver(),
2695 Settings.System.SCREEN_BRIGHTNESS_MODE,
2696 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2697 UserHandle.USER_CURRENT_OR_SELF);
2698 if (auto != 0) {
2699 Settings.System.putIntForUser(mContext.getContentResolver(),
2700 Settings.System.SCREEN_BRIGHTNESS_MODE,
2701 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2702 UserHandle.USER_CURRENT_OR_SELF);
2703 }
2704
2705 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2706 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2707 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2708 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2709 Settings.System.SCREEN_BRIGHTNESS,
2710 mPowerManager.getDefaultScreenBrightnessSetting(),
2711 UserHandle.USER_CURRENT_OR_SELF);
2712 brightness += step;
2713 // Make sure we don't go beyond the limits.
2714 brightness = Math.min(max, brightness);
2715 brightness = Math.max(min, brightness);
2716
2717 Settings.System.putIntForUser(mContext.getContentResolver(),
2718 Settings.System.SCREEN_BRIGHTNESS, brightness,
2719 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002720 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002721 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002722 }
2723 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002724 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002725 if (down) {
2726 mPendingMetaAction = true;
2727 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002728 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002729 }
2730 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002731 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002732
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002733 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002734 // Any printing key that is chorded with Search should be consumed
2735 // even if no shortcut was invoked. This prevents text from being
2736 // inadvertently inserted when using a keyboard that has built-in macro
2737 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002738 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002739 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2740 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002741 mConsumeSearchKeyUp = true;
2742 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002743 if (down && repeatCount == 0 && !keyguardOn) {
2744 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2745 if (shortcutIntent != null) {
2746 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002747 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002748 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002749 } catch (ActivityNotFoundException ex) {
2750 Slog.w(TAG, "Dropping shortcut key combination because "
2751 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002752 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002753 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002754 } else {
2755 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002756 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002757 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002758 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002759 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002760 }
2761 }
2762
Jeff Brown68b909d2011-12-07 16:36:01 -08002763 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002764 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002765 && (metaState & KeyEvent.META_META_ON) != 0) {
2766 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002767 if (kcm.isPrintingKey(keyCode)) {
2768 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2769 metaState & ~(KeyEvent.META_META_ON
2770 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2771 if (shortcutIntent != null) {
2772 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2773 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002774 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002775 } catch (ActivityNotFoundException ex) {
2776 Slog.w(TAG, "Dropping shortcut key combination because "
2777 + "the activity to which it is registered was not found: "
2778 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2779 }
2780 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002781 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002782 }
2783 }
2784
Jeff Brown6651a632011-11-28 12:59:11 -08002785 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002786 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002787 String category = sApplicationLaunchKeyCategories.get(keyCode);
2788 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002789 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002790 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2791 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002792 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002793 } catch (ActivityNotFoundException ex) {
2794 Slog.w(TAG, "Dropping application launch key because "
2795 + "the activity to which it is registered was not found: "
2796 + "keyCode=" + keyCode + ", category=" + category, ex);
2797 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002798 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002799 }
2800 }
2801
Michael Wright61c46752014-08-21 16:57:33 -07002802 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002803 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002804 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002805 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002806 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002807 mRecentAppsHeldModifiers = shiftlessModifiers;
2808 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002809 return -1;
2810 }
2811 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002812 } else if (!down && mRecentAppsHeldModifiers != 0
2813 && (metaState & mRecentAppsHeldModifiers) == 0) {
2814 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002815 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002816 }
2817
Jeff Browncf39bdf2012-05-18 14:41:19 -07002818 // Handle keyboard language switching.
2819 if (down && repeatCount == 0
2820 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2821 || (keyCode == KeyEvent.KEYCODE_SPACE
2822 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2823 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2824 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2825 return -1;
2826 }
2827 if (mLanguageSwitchKeyPressed && !down
2828 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2829 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2830 mLanguageSwitchKeyPressed = false;
2831 return -1;
2832 }
2833
Jeff Brown13f00f02014-10-31 14:45:50 -07002834 if (isValidGlobalKey(keyCode)
2835 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002836 return -1;
2837 }
2838
Michael Wright6a62e552014-06-03 19:19:48 -07002839 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002840 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002841 return -1;
2842 }
2843
Jeff Brown68b909d2011-12-07 16:36:01 -08002844 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002845 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002846 }
2847
Jeff Brown3915bb82010-11-05 15:02:16 -07002848 /** {@inheritDoc} */
2849 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002850 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002851 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002852 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002853 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2854 + ", flags=" + event.getFlags()
2855 + ", keyCode=" + event.getKeyCode()
2856 + ", scanCode=" + event.getScanCode()
2857 + ", metaState=" + event.getMetaState()
2858 + ", repeatCount=" + event.getRepeatCount()
2859 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002860 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002861
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002862 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002863 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2864 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002865 final int keyCode = event.getKeyCode();
2866 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002867 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2868 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002869
Jeff Brown54875002011-04-06 15:33:01 -07002870 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002871 final FallbackAction fallbackAction;
2872 if (initialDown) {
2873 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2874 } else {
2875 fallbackAction = mFallbackActions.get(keyCode);
2876 }
2877
2878 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002879 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002880 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2881 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002882 }
2883
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002884 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2885 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002886 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002887 event.getAction(), fallbackAction.keyCode,
2888 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002889 event.getDeviceId(), event.getScanCode(),
2890 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002891
2892 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2893 fallbackEvent.recycle();
2894 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002895 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002896
2897 if (initialDown) {
2898 mFallbackActions.put(keyCode, fallbackAction);
2899 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2900 mFallbackActions.remove(keyCode);
2901 fallbackAction.recycle();
2902 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002903 }
2904 }
2905
Jeff Brown40013652012-05-16 21:22:36 -07002906 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002907 if (fallbackEvent == null) {
2908 Slog.d(TAG, "No fallback.");
2909 } else {
2910 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2911 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002912 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002913 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002914 }
2915
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002916 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002917 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002918 if ((actions & ACTION_PASS_TO_USER) != 0) {
2919 long delayMillis = interceptKeyBeforeDispatching(
2920 win, fallbackEvent, policyFlags);
2921 if (delayMillis == 0) {
2922 return true;
2923 }
2924 }
2925 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002926 }
2927
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002928 private void launchAssistLongPressAction() {
2929 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2930 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2931
2932 // launch the search activity
2933 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2934 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2935 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002936 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002937 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002938 SearchManager searchManager = getSearchManager();
2939 if (searchManager != null) {
2940 searchManager.stopSearch();
2941 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002942 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002943 } catch (ActivityNotFoundException e) {
2944 Slog.w(TAG, "No activity to handle assist long press action.", e);
2945 }
2946 }
2947
2948 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002949 launchAssistAction(null);
2950 }
2951
2952 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002953 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002954 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002955 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002956 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002957 if (hint != null) {
2958 intent.putExtra(hint, true);
2959 }
Jim Miller45308b12012-06-18 19:23:39 -07002960 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2961 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2962 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2963 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002964 startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002965 } catch (ActivityNotFoundException e) {
2966 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002967 }
2968 }
2969 }
2970
Bart Sears8b1c27c2015-03-18 23:51:02 +00002971 private void startActivityAsUser(Intent intent, UserHandle handle) {
2972 if (isUserSetupComplete()) {
2973 mContext.startActivityAsUser(intent, handle);
2974 } else {
2975 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
2976 }
2977 }
2978
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002979 private SearchManager getSearchManager() {
2980 if (mSearchManager == null) {
2981 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2982 }
2983 return mSearchManager;
2984 }
2985
Jeff Browncaca8812013-05-09 13:34:33 -07002986 private void preloadRecentApps() {
2987 mPreloadedRecentApps = true;
2988 try {
2989 IStatusBarService statusbar = getStatusBarService();
2990 if (statusbar != null) {
2991 statusbar.preloadRecentApps();
2992 }
2993 } catch (RemoteException e) {
2994 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2995 // re-acquire status bar service next time it is needed.
2996 mStatusBarService = null;
2997 }
2998 }
2999
3000 private void cancelPreloadRecentApps() {
3001 if (mPreloadedRecentApps) {
3002 mPreloadedRecentApps = false;
3003 try {
3004 IStatusBarService statusbar = getStatusBarService();
3005 if (statusbar != null) {
3006 statusbar.cancelPreloadRecentApps();
3007 }
3008 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003009 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003010 // re-acquire status bar service next time it is needed.
3011 mStatusBarService = null;
3012 }
3013 }
3014 }
3015
3016 private void toggleRecentApps() {
3017 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003018 try {
3019 IStatusBarService statusbar = getStatusBarService();
3020 if (statusbar != null) {
3021 statusbar.toggleRecentApps();
3022 }
3023 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003024 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3025 // re-acquire status bar service next time it is needed.
3026 mStatusBarService = null;
3027 }
3028 }
3029
Craig Mautner84984fa2014-06-19 11:19:20 -07003030 @Override
3031 public void showRecentApps() {
3032 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3033 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3034 }
3035
Winson Chung1e8d71b2014-05-16 17:05:22 -07003036 private void showRecentApps(boolean triggeredFromAltTab) {
3037 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3038 try {
3039 IStatusBarService statusbar = getStatusBarService();
3040 if (statusbar != null) {
3041 statusbar.showRecentApps(triggeredFromAltTab);
3042 }
3043 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003044 Slog.e(TAG, "RemoteException when showing recent apps", e);
3045 // re-acquire status bar service next time it is needed.
3046 mStatusBarService = null;
3047 }
3048 }
3049
Winson Chungcdcd4872014-08-05 18:00:13 -07003050 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003051 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3052 try {
3053 IStatusBarService statusbar = getStatusBarService();
3054 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003055 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003056 }
3057 } catch (RemoteException e) {
3058 Slog.e(TAG, "RemoteException when closing recent apps", e);
3059 // re-acquire status bar service next time it is needed.
3060 mStatusBarService = null;
3061 }
3062 }
3063
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003064 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003065 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003066 }
3067
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003068 /**
3069 * A home key -> launch home action was detected. Take the appropriate action
3070 * given the situation with the keyguard.
3071 */
Bryce Lee662ed802015-04-10 20:11:39 +00003072 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3073 if (respectKeyguard) {
3074 if (isKeyguardShowingAndNotOccluded()) {
3075 // don't launch home if keyguard showing
3076 return;
3077 }
3078
3079 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3080 // when in keyguard restricted mode, must first verify unlock
3081 // before launching home
3082 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3083 @Override
3084 public void onKeyguardExitResult(boolean success) {
3085 if (success) {
3086 try {
3087 ActivityManagerNative.getDefault().stopAppSwitches();
3088 } catch (RemoteException e) {
3089 }
3090 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3091 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003092 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003093 }
Bryce Lee662ed802015-04-10 20:11:39 +00003094 });
3095 return;
3096 }
3097 }
3098
3099 // no keyguard stuff to worry about, just launch home!
3100 try {
3101 ActivityManagerNative.getDefault().stopAppSwitches();
3102 } catch (RemoteException e) {
3103 }
3104 if (mRecentsVisible) {
3105 // Hide Recents and notify it to launch Home
3106 if (awakenFromDreams) {
3107 awakenDreams();
3108 }
3109 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3110 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003111 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003112 // Otherwise, just launch Home
3113 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3114 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003115 }
3116 }
3117
John Spurlock04db1762013-05-13 12:46:41 -04003118 private final Runnable mClearHideNavigationFlag = new Runnable() {
3119 @Override
3120 public void run() {
3121 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3122 // Clear flags.
3123 mForceClearedSystemUiFlags &=
3124 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3125 }
3126 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003127 }
3128 };
3129
3130 /**
3131 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3132 * to determine when the nav bar should be shown and prevent applications from
3133 * receiving those touches.
3134 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003135 final class HideNavInputEventReceiver extends InputEventReceiver {
3136 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3137 super(inputChannel, looper);
3138 }
3139
Dianne Hackborndf89e652011-10-06 22:35:11 -07003140 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003141 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003142 boolean handled = false;
3143 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003144 if (event instanceof MotionEvent
3145 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3146 final MotionEvent motionEvent = (MotionEvent)event;
3147 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003148 // When the user taps down, we re-show the nav bar.
3149 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003150 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003151 // Any user activity always causes us to show the
3152 // navigation controls, if they had been hidden.
3153 // We also clear the low profile and only content
3154 // flags so that tapping on the screen will atomically
3155 // restore all currently hidden screen decorations.
3156 int newVal = mResettingSystemUiFlags |
3157 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3158 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3159 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003160 if (mResettingSystemUiFlags != newVal) {
3161 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003162 changed = true;
3163 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003164 // We don't allow the system's nav bar to be hidden
3165 // again for 1 second, to prevent applications from
3166 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003167 newVal = mForceClearedSystemUiFlags |
3168 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003169 if (mForceClearedSystemUiFlags != newVal) {
3170 mForceClearedSystemUiFlags = newVal;
3171 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003172 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003173 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003174 }
3175 if (changed) {
3176 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3177 }
3178 }
3179 }
3180 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003181 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003182 }
3183 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003184 }
3185 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3186 new InputEventReceiver.Factory() {
3187 @Override
3188 public InputEventReceiver createInputEventReceiver(
3189 InputChannel inputChannel, Looper looper) {
3190 return new HideNavInputEventReceiver(inputChannel, looper);
3191 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003192 };
3193
3194 @Override
3195 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003196 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3197 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003198 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003199
Dianne Hackborndf89e652011-10-06 22:35:11 -07003200 // Reset any bits in mForceClearingStatusBarVisibility that
3201 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003202 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003203 // Clear any bits in the new visibility that are currently being
3204 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003205 return visibility & ~mResettingSystemUiFlags
3206 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003207 }
3208
Craig Mautner69b08182012-09-05 13:07:13 -07003209 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003210 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3211 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003212 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003213 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3214 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003215
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003216 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003217 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003218 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003219 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003220 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003221 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3222 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3223 } else {
3224 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3225 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3226 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003227 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3228 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003229 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003230 availRight - mStableFullscreenRight,
3231 availBottom - mStableFullscreenBottom);
3232 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003233 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003234 availRight - mStableRight, availBottom - mStableBottom);
3235 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003236 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003237 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003238 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003239 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003240 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003241 availRight - mCurRight, availBottom - mCurBottom);
3242 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003243 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003244 availRight - mCurRight, availBottom - mCurBottom);
3245 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003246
3247 outStableInsets.set(mStableLeft, mStableTop,
3248 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003249 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003250 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003251 outContentInsets.setEmpty();
3252 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003253 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003254
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003255 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003256 @Override
3257 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3258 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003259 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3260 if (isDefaultDisplay) {
3261 switch (displayRotation) {
3262 case Surface.ROTATION_90:
3263 overscanLeft = mOverscanTop;
3264 overscanTop = mOverscanRight;
3265 overscanRight = mOverscanBottom;
3266 overscanBottom = mOverscanLeft;
3267 break;
3268 case Surface.ROTATION_180:
3269 overscanLeft = mOverscanRight;
3270 overscanTop = mOverscanBottom;
3271 overscanRight = mOverscanLeft;
3272 overscanBottom = mOverscanTop;
3273 break;
3274 case Surface.ROTATION_270:
3275 overscanLeft = mOverscanBottom;
3276 overscanTop = mOverscanLeft;
3277 overscanRight = mOverscanTop;
3278 overscanBottom = mOverscanRight;
3279 break;
3280 default:
3281 overscanLeft = mOverscanLeft;
3282 overscanTop = mOverscanTop;
3283 overscanRight = mOverscanRight;
3284 overscanBottom = mOverscanBottom;
3285 break;
3286 }
3287 } else {
3288 overscanLeft = 0;
3289 overscanTop = 0;
3290 overscanRight = 0;
3291 overscanBottom = 0;
3292 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003293 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3294 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3295 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3296 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003297 mSystemLeft = 0;
3298 mSystemTop = 0;
3299 mSystemRight = displayWidth;
3300 mSystemBottom = displayHeight;
3301 mUnrestrictedScreenLeft = overscanLeft;
3302 mUnrestrictedScreenTop = overscanTop;
3303 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3304 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3305 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3306 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003307 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3308 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003309 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003310 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003311 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003312 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003313 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003314 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003315 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003316 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003317 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003318 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003319
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003320 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3321 final Rect pf = mTmpParentFrame;
3322 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003323 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003324 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003325 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003326 pf.left = df.left = of.left = vf.left = mDockLeft;
3327 pf.top = df.top = of.top = vf.top = mDockTop;
3328 pf.right = df.right = of.right = vf.right = mDockRight;
3329 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003330 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003331
Craig Mautner69b08182012-09-05 13:07:13 -07003332 if (isDefaultDisplay) {
3333 // For purposes of putting out fake window up to steal focus, we will
3334 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003335 final int sysui = mLastSystemUiFlags;
3336 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003337 boolean navTranslucent = (sysui
3338 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003339 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3340 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3341 boolean navAllowedHidden = immersive || immersiveSticky;
3342 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003343 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3344 if (!isKeyguardShowing) {
3345 navTranslucent &= areTranslucentBarsAllowed();
3346 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003347
Craig Mautner69b08182012-09-05 13:07:13 -07003348 // When the navigation bar isn't visible, we put up a fake
3349 // input window to catch all touch events. This way we can
3350 // detect when the user presses anywhere to bring back the nav
3351 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003352 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07003353 if (mHideNavFakeWindow != null) {
3354 mHideNavFakeWindow.dismiss();
3355 mHideNavFakeWindow = null;
3356 }
3357 } else if (mHideNavFakeWindow == null) {
3358 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
3359 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07003360 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07003361 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003362 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003363
Craig Mautner69b08182012-09-05 13:07:13 -07003364 // For purposes of positioning and showing the nav bar, if we have
3365 // decided that it can't be hidden (because of the screen aspect ratio),
3366 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003367 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003368
John Spurlockad3e6cb2013-04-30 08:47:43 -04003369 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003370 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003371 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003372 // Force the navigation bar to its appropriate place and
3373 // size. We need to do this directly, instead of relying on
3374 // it to bubble up from the nav bar, because this needs to
3375 // change atomically with screen rotations.
3376 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3377 if (mNavigationBarOnBottom) {
3378 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003379 int top = displayHeight - overscanBottom
3380 - mNavigationBarHeightForRotation[displayRotation];
3381 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003382 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003383 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003384 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003385 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003386 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003387 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003388 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3389 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003390 } else {
3391 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003392 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003393 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003394 if (navVisible && !navTranslucent && !navAllowedHidden
3395 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003396 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003397 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003398 // and not in the process of animating on or off, then
3399 // we can tell the app that it is covered by it.
3400 mSystemBottom = mTmpNavigationFrame.top;
3401 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003402 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003403 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003404 int left = displayWidth - overscanRight
3405 - mNavigationBarWidthForRotation[displayRotation];
3406 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003407 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003408 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003409 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003410 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003411 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003412 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003413 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3414 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003415 } else {
3416 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003417 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003418 }
John Spurlockbd957402013-10-03 11:38:39 -04003419 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3420 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003421 // If the nav bar is currently requested to be visible,
3422 // and not in the process of animating on or off, then
3423 // we can tell the app that it is covered by it.
3424 mSystemRight = mTmpNavigationFrame.left;
3425 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003426 }
Craig Mautner69b08182012-09-05 13:07:13 -07003427 // Make sure the content and current rectangles are updated to
3428 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003429 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3430 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3431 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3432 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003433 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3434 // And compute the final frame.
3435 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003436 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3437 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003438 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003439 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003440 updateSysUiVisibility = true;
3441 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003442 }
Craig Mautnereda67292013-04-28 13:50:14 -07003443 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003444 mDockLeft, mDockTop, mDockRight, mDockBottom));
3445
3446 // decide where the status bar goes ahead of time
3447 if (mStatusBar != null) {
3448 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003449 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3450 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3451 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3452 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3453 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003454 vf.left = mStableLeft;
3455 vf.top = mStableTop;
3456 vf.right = mStableRight;
3457 vf.bottom = mStableBottom;
3458
3459 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3460
3461 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003462 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003463
3464 // For layout, the status bar is always at the top with our fixed height.
3465 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3466
John Spurlocke1f366f2013-08-05 12:22:40 -04003467 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003468 boolean statusBarTranslucent = (sysui
3469 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003470 if (!isKeyguardShowing) {
3471 statusBarTranslucent &= areTranslucentBarsAllowed();
3472 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003473
Craig Mautner69b08182012-09-05 13:07:13 -07003474 // If the status bar is hidden, we don't want to cause
3475 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003476 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003477 // Status bar may go away, so the screen area it occupies
3478 // is available to apps but just covering them when the
3479 // status bar is visible.
3480 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3481
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003482 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3483 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3484 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3485 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003486
Craig Mautnereda67292013-04-28 13:50:14 -07003487 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003488 String.format(
3489 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3490 mDockLeft, mDockTop, mDockRight, mDockBottom,
3491 mContentLeft, mContentTop, mContentRight, mContentBottom,
3492 mCurLeft, mCurTop, mCurRight, mCurBottom));
3493 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003494 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003495 && !statusBarTransient && !statusBarTranslucent
3496 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003497 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003498 // and not in the process of animating on or off, then
3499 // we can tell the app that it is covered by it.
3500 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3501 }
John Spurlock27735a42013-08-14 17:57:38 -04003502 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003503 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003504 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003505 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003506 if (updateSysUiVisibility) {
3507 updateSystemUiVisibilityLw();
3508 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003509 }
3510 }
3511
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003512 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003513 @Override
John Spurlock46646232013-09-30 22:32:42 -04003514 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003515 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3516 return mStatusBar.getSurfaceLayer();
3517 }
3518
3519 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3520 return mNavigationBar.getSurfaceLayer();
3521 }
3522
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003523 return 0;
3524 }
3525
Craig Mautner967212c2013-04-13 21:10:58 -07003526 @Override
3527 public void getContentRectLw(Rect r) {
3528 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3529 }
3530
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003531 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3532 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003533 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3534 // Here's a special case: if this attached window is a panel that is
3535 // above the dock window, and the window it is attached to is below
3536 // the dock window, then the frames we computed for the window it is
3537 // attached to can not be used because the dock is effectively part
3538 // of the underlying window and the attached window is floating on top
3539 // of the whole thing. So, we ignore the attached window and explicitly
3540 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003541 df.left = of.left = cf.left = vf.left = mDockLeft;
3542 df.top = of.top = cf.top = vf.top = mDockTop;
3543 df.right = of.right = cf.right = vf.right = mDockRight;
3544 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003545 } else {
3546 // The effective display frame of the attached window depends on
3547 // whether it is taking care of insetting its content. If not,
3548 // we need to use the parent's content frame so that the entire
3549 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003550 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003551 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003552 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003553 // Set the content frame of the attached window to the parent's decor frame
3554 // (same as content frame when IME isn't present) if specifically requested by
3555 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3556 // Otherwise, use the overscan frame.
3557 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3558 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003559 } else {
3560 // If the window is resizing, then we want to base the content
3561 // frame on our attached content frame to resize... however,
3562 // things can be tricky if the attached window is NOT in resize
3563 // mode, in which case its content frame will be larger.
3564 // Ungh. So to deal with that, make sure the content frame
3565 // we end up using is not covering the IM dock.
3566 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003567 if (attached.isVoiceInteraction()) {
3568 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3569 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3570 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3571 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3572 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003573 if (cf.left < mContentLeft) cf.left = mContentLeft;
3574 if (cf.top < mContentTop) cf.top = mContentTop;
3575 if (cf.right > mContentRight) cf.right = mContentRight;
3576 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3577 }
3578 }
3579 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003580 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003581 vf.set(attached.getVisibleFrameLw());
3582 }
3583 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3584 // window should be positioned relative to its parent or the entire
3585 // screen.
3586 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3587 ? attached.getFrameLw() : df);
3588 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003589
3590 private void applyStableConstraints(int sysui, int fl, Rect r) {
3591 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3592 // If app is requesting a stable layout, don't let the
3593 // content insets go below the stable values.
3594 if ((fl & FLAG_FULLSCREEN) != 0) {
3595 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3596 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3597 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3598 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3599 } else {
3600 if (r.left < mStableLeft) r.left = mStableLeft;
3601 if (r.top < mStableTop) r.top = mStableTop;
3602 if (r.right > mStableRight) r.right = mStableRight;
3603 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3604 }
3605 }
3606 }
3607
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003608 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003609 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003610 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003611 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003612 final WindowManager.LayoutParams attrs = win.getAttrs();
3613 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3614 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003615 return;
3616 }
Craig Mautner69b08182012-09-05 13:07:13 -07003617 final boolean isDefaultDisplay = win.isDefaultDisplay();
3618 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003619 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3620 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003621 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003622 offsetInputMethodWindowLw(mLastInputMethodWindow);
3623 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003624
John Spurlockc6d1c602014-01-17 15:22:06 -05003625 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003626 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003627 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003628
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003629 final Rect pf = mTmpParentFrame;
3630 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003631 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003632 final Rect cf = mTmpContentFrame;
3633 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003634 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003635 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003636 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003637
3638 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003639 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003640
Craig Mautnerf683b562012-10-02 11:10:57 -07003641 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3642
Adrian Roosfa104232014-06-20 16:10:14 -07003643 if (isDefaultDisplay) {
3644 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3645 } else {
3646 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3647 }
3648
Craig Mautner69b08182012-09-05 13:07:13 -07003649 if (!isDefaultDisplay) {
3650 if (attached != null) {
3651 // If this window is attached to another, our display
3652 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003653 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003654 } else {
3655 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003656 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3657 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3658 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003659 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003660 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003661 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003662 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003663 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003664 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3665 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3666 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003667 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003668 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003669 // ...with content insets above the nav bar
3670 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003671 // IM dock windows always go to the bottom of the screen.
3672 attrs.gravity = Gravity.BOTTOM;
3673 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003674 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
3675 pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft;
3676 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3677 pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft
3678 + mUnrestrictedScreenWidth;
3679 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3680 + mUnrestrictedScreenHeight;
3681 cf.bottom = vf.bottom = mStableBottom;
3682 cf.top = vf.top = mStableTop;
Jorim Jaggie0700182014-08-21 01:12:37 +02003683 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3684 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3685 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3686 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3687 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3688 cf.left = vf.left = mStableLeft;
3689 cf.top = vf.top = mStableTop;
3690 cf.right = vf.right = mStableRight;
3691 vf.bottom = mStableBottom;
3692 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003693 } else {
John Spurlock46646232013-09-30 22:32:42 -04003694
3695 // Default policy decor for the default display
3696 dcf.left = mSystemLeft;
3697 dcf.top = mSystemTop;
3698 dcf.right = mSystemRight;
3699 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003700 final boolean inheritTranslucentDecor = (attrs.privateFlags
3701 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003702 final boolean isAppWindow =
3703 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3704 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3705 final boolean topAtRest =
3706 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3707 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003708 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3709 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003710 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3711 && (fl & WindowManager.LayoutParams.
3712 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003713 // Ensure policy decor includes status bar
3714 dcf.top = mStableTop;
3715 }
John Spurlockbd957402013-10-03 11:38:39 -04003716 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003717 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3718 && (fl & WindowManager.LayoutParams.
3719 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003720 // Ensure policy decor includes navigation bar
3721 dcf.bottom = mStableBottom;
3722 dcf.right = mStableRight;
3723 }
3724 }
3725
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003726 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3727 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003728 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003729 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003730 // This is the case for a normal activity window: we want it
3731 // to cover all of the screen space, and it can take care of
3732 // moving its contents to account for screen decorations that
3733 // intrude into that space.
3734 if (attached != null) {
3735 // If this window is attached to another, our display
3736 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003737 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003738 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003739 if (attrs.type == TYPE_STATUS_BAR_PANEL
3740 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003741 // Status bar panels are the only windows who can go on top of
3742 // the status bar. They are protected by the STATUS_BAR_SERVICE
3743 // permission, so they have the same privileges as the status
3744 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003745 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003746 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003747
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003748 pf.left = df.left = of.left = hasNavBar
3749 ? mDockLeft : mUnrestrictedScreenLeft;
3750 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3751 pf.right = df.right = of.right = hasNavBar
3752 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3753 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3754 pf.bottom = df.bottom = of.bottom = hasNavBar
3755 ? mRestrictedScreenTop+mRestrictedScreenHeight
3756 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003757
Craig Mautnereda67292013-04-28 13:50:14 -07003758 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003759 "Laying out status bar window: (%d,%d - %d,%d)",
3760 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003761 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003762 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3763 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3764 // Asking to layout into the overscan region, so give it that pure
3765 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003766 pf.left = df.left = of.left = mOverscanScreenLeft;
3767 pf.top = df.top = of.top = mOverscanScreenTop;
3768 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3769 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3770 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003771 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003772 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003773 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3774 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003775 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003776 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003777 // only do this for application windows to ensure no window that
3778 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003779 pf.left = df.left = mOverscanScreenLeft;
3780 pf.top = df.top = mOverscanScreenTop;
3781 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3782 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003783 // We need to tell the app about where the frame inside the overscan
3784 // is, so it can inset its content by that amount -- it didn't ask
3785 // to actually extend itself into the overscan region.
3786 of.left = mUnrestrictedScreenLeft;
3787 of.top = mUnrestrictedScreenTop;
3788 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3789 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003790 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003791 pf.left = df.left = mRestrictedOverscanScreenLeft;
3792 pf.top = df.top = mRestrictedOverscanScreenTop;
3793 pf.right = df.right = mRestrictedOverscanScreenLeft
3794 + mRestrictedOverscanScreenWidth;
3795 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3796 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003797 // We need to tell the app about where the frame inside the overscan
3798 // is, so it can inset its content by that amount -- it didn't ask
3799 // to actually extend itself into the overscan region.
3800 of.left = mUnrestrictedScreenLeft;
3801 of.top = mUnrestrictedScreenTop;
3802 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3803 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003804 }
Craig Mautner69b08182012-09-05 13:07:13 -07003805
John Spurlock46646232013-09-30 22:32:42 -04003806 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003807 if (win.isVoiceInteraction()) {
3808 cf.left = mVoiceContentLeft;
3809 cf.top = mVoiceContentTop;
3810 cf.right = mVoiceContentRight;
3811 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003812 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003813 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3814 cf.left = mDockLeft;
3815 cf.top = mDockTop;
3816 cf.right = mDockRight;
3817 cf.bottom = mDockBottom;
3818 } else {
3819 cf.left = mContentLeft;
3820 cf.top = mContentTop;
3821 cf.right = mContentRight;
3822 cf.bottom = mContentBottom;
3823 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003824 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003825 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003826 // Full screen windows are always given a layout that is as if the
3827 // status bar and other transient decors are gone. This is to avoid
3828 // bad states when moving from a window that is not hding the
3829 // status bar to one that is.
3830 cf.left = mRestrictedScreenLeft;
3831 cf.top = mRestrictedScreenTop;
3832 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3833 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003834 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003835 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003836 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3837 vf.left = mCurLeft;
3838 vf.top = mCurTop;
3839 vf.right = mCurRight;
3840 vf.bottom = mCurBottom;
3841 } else {
3842 vf.set(cf);
3843 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003844 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003845 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3846 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3847 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003848 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3849 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003850 // A window that has requested to fill the entire screen just
3851 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003852 if (attrs.type == TYPE_STATUS_BAR_PANEL
3853 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003854 pf.left = df.left = of.left = cf.left = hasNavBar
3855 ? mDockLeft : mUnrestrictedScreenLeft;
3856 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3857 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003858 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003859 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003860 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003861 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003862 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003863 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003864 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3865 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003866 } else if (attrs.type == TYPE_NAVIGATION_BAR
3867 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003868 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003869 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3870 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3871 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3872 + mUnrestrictedScreenWidth;
3873 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3874 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003875 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003876 "Laying out navigation bar window: (%d,%d - %d,%d)",
3877 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003878 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3879 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003880 && ((fl & FLAG_FULLSCREEN) != 0)) {
3881 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003882 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3883 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3884 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3885 + mOverscanScreenWidth;
3886 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3887 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003888 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003889 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003890 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3891 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3892 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3893 + mOverscanScreenWidth;
3894 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3895 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003896 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003897 // The wallpaper also has Real Ultimate Power, but we want to tell
3898 // it about the overscan area.
3899 pf.left = df.left = mOverscanScreenLeft;
3900 pf.top = df.top = mOverscanScreenTop;
3901 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3902 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3903 of.left = cf.left = mUnrestrictedScreenLeft;
3904 of.top = cf.top = mUnrestrictedScreenTop;
3905 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3906 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003907 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003908 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3909 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3910 // Asking to layout into the overscan region, so give it that pure
3911 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003912 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3913 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3914 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003915 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003916 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003917 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003918 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003919 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003920 && (attrs.type == TYPE_STATUS_BAR
3921 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07003922 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04003923 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3924 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003925 // Asking for layout as if the nav bar is hidden, lets the
3926 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003927 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003928 // can be above the nav bar can do this.
3929 // XXX This assumes that an app asking for this will also
3930 // ask for layout in only content. We can't currently figure out
3931 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003932 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3933 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3934 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3935 + mUnrestrictedScreenWidth;
3936 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3937 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003938 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003939 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3940 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3941 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3942 + mRestrictedScreenWidth;
3943 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3944 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003945 }
Craig Mautner69b08182012-09-05 13:07:13 -07003946
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003947 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003948
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003949 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3950 vf.left = mCurLeft;
3951 vf.top = mCurTop;
3952 vf.right = mCurRight;
3953 vf.bottom = mCurBottom;
3954 } else {
3955 vf.set(cf);
3956 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003957 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003958 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3959 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003960 // A child window should be placed inside of the same visible
3961 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003962 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003963 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003964 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3965 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003966 // Otherwise, a normal window must be placed inside the content
3967 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003968 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3969 // Status bar panels are the only windows who can go on top of
3970 // the status bar. They are protected by the STATUS_BAR_SERVICE
3971 // permission, so they have the same privileges as the status
3972 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003973 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3974 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3975 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3976 + mRestrictedScreenWidth;
3977 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3978 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003979 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3980 || attrs.type == TYPE_VOLUME_OVERLAY) {
3981 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003982 pf.left = df.left = of.left = cf.left = mStableLeft;
3983 pf.top = df.top = of.top = cf.top = mStableTop;
3984 pf.right = df.right = of.right = cf.right = mStableRight;
3985 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003986 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003987 pf.left = mContentLeft;
3988 pf.top = mContentTop;
3989 pf.right = mContentRight;
3990 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003991 if (win.isVoiceInteraction()) {
3992 df.left = of.left = cf.left = mVoiceContentLeft;
3993 df.top = of.top = cf.top = mVoiceContentTop;
3994 df.right = of.right = cf.right = mVoiceContentRight;
3995 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3996 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003997 df.left = of.left = cf.left = mDockLeft;
3998 df.top = of.top = cf.top = mDockTop;
3999 df.right = of.right = cf.right = mDockRight;
4000 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004001 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004002 df.left = of.left = cf.left = mContentLeft;
4003 df.top = of.top = cf.top = mContentTop;
4004 df.right = of.right = cf.right = mContentRight;
4005 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004006 }
4007 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4008 vf.left = mCurLeft;
4009 vf.top = mCurTop;
4010 vf.right = mCurRight;
4011 vf.bottom = mCurBottom;
4012 } else {
4013 vf.set(cf);
4014 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004015 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004016 }
4017 }
Craig Mautner69b08182012-09-05 13:07:13 -07004018
Craig Mautnerb816bed2013-07-23 10:26:17 -07004019 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4020 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004021 df.left = df.top = -10000;
4022 df.right = df.bottom = 10000;
4023 if (attrs.type != TYPE_WALLPAPER) {
4024 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4025 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4026 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004027 }
4028
Craig Mautnereda67292013-04-28 13:50:14 -07004029 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004030 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004031 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004032 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004033 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004034 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004035 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004036 + " dcf=" + dcf.toShortString()
4037 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07004038
Adrian Roosfa104232014-06-20 16:10:14 -07004039 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07004040
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004041 // Dock windows carve out the bottom of the screen, so normal windows
4042 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004043 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4044 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004045 setLastInputMethodWindowLw(null, null);
4046 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004047 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004048 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4049 && !win.getGivenInsetsPendingLw()) {
4050 offsetVoiceInputWindowLw(win);
4051 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004052 }
4053
satok1bc0a492012-04-25 22:47:12 +09004054 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004055 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004056 top += win.getGivenContentInsetsLw().top;
4057 if (mContentBottom > top) {
4058 mContentBottom = top;
4059 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004060 if (mVoiceContentBottom > top) {
4061 mVoiceContentBottom = top;
4062 }
satok1bc0a492012-04-25 22:47:12 +09004063 top = win.getVisibleFrameLw().top;
4064 top += win.getGivenVisibleInsetsLw().top;
4065 if (mCurBottom > top) {
4066 mCurBottom = top;
4067 }
Craig Mautnereda67292013-04-28 13:50:14 -07004068 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004069 + mDockBottom + " mContentBottom="
4070 + mContentBottom + " mCurBottom=" + mCurBottom);
4071 }
4072
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004073 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004074 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004075 top += win.getGivenContentInsetsLw().top;
4076 if (mVoiceContentBottom > top) {
4077 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004078 }
4079 }
4080
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004081 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004082 @Override
4083 public void finishLayoutLw() {
4084 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004085 }
4086
4087 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004088 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004089 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004090 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004091 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004092 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004093 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004094 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004095 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004096 mForcingShowNavBar = false;
4097 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004098
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004099 mHideLockScreen = false;
4100 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004101 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004102 mShowingLockscreen = false;
4103 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004104 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004105 mKeyguardSecure = isKeyguardSecure();
4106 mKeyguardSecureIncludingHidden = mKeyguardSecure
4107 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004108 }
4109
4110 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004111 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004112 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004113 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4114 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004115 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004116 if (mTopFullscreenOpaqueWindowState == null
4117 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4118 mForcingShowNavBar = true;
4119 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004120 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004121 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004122 mForceStatusBarFromKeyguard = true;
4123 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004124 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004125 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004126 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004127 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004128 mForceStatusBarFromKeyguard = true;
4129 } else {
4130 mForceStatusBar = true;
4131 }
4132 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004133 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004134 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004135 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004136 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Craig Mautner7d7808f2014-09-11 18:02:38 -07004137 && attrs.type < FIRST_SYSTEM_WINDOW;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004138 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004139 // If the lockscreen was showing when the dream started then wait
4140 // for the dream to draw before hiding the lockscreen.
4141 if (!mDreamingLockscreen
4142 || (win.isVisibleLw() && win.hasDrawnLw())) {
4143 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004144 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004145 }
4146 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004147
Craig Mautner00156ec2014-03-06 22:29:02 -08004148 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07004149 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerab55e522014-03-03 13:26:03 -08004150 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004151 final IApplicationToken appToken = win.getAppToken();
4152 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004153 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004154 mAppsToBeHidden.remove(appToken);
4155 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004156 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004157 if (dismissKeyguard && !mKeyguardSecure) {
4158 mAppsThatDismissKeyguard.add(appToken);
4159 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004160 mWinShowWhenLocked = win;
4161 mHideLockScreen = true;
4162 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004163 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004164 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004165 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004166 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004167 mAppsToBeHidden.add(appToken);
4168 } else {
4169 mAppsToBeHidden.remove(appToken);
4170 }
4171 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004172 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004173 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004174 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004175 if (attrs.x == 0 && attrs.y == 0
4176 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4177 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4178 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4179 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004180 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4181 mTopFullscreenOpaqueOrDimmingWindowState = win;
4182 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004183 if (!mAppsThatDismissKeyguard.isEmpty() &&
4184 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4185 if (DEBUG_LAYOUT) Slog.v(TAG,
4186 "Setting mDismissKeyguard true by win " + win);
4187 mDismissKeyguard = mWinDismissingKeyguard == win ?
4188 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
4189 mWinDismissingKeyguard = win;
Jim Millerab954542014-10-10 18:21:49 -07004190 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004191 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4192 if (DEBUG_LAYOUT) Slog.v(TAG,
4193 "Setting mHideLockScreen to true by win " + win);
4194 mHideLockScreen = true;
4195 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004196 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004197 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004198 mAllowLockscreenWhenOn = true;
4199 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004200 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004201
4202 if (mWinShowWhenLocked != null &&
4203 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
4204 win.hideLw(false);
4205 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004206 }
4207 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004208 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4209 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4210 && win.isDimming()) {
4211 mTopFullscreenOpaqueOrDimmingWindowState = win;
4212 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004213 }
4214
4215 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004216 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004217 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004218 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4219 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4220 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004221 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4222 // fullscreen window.
4223 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4224 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4225 mTopFullscreenOpaqueWindowState.hideLw(false);
4226 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4227 }
4228
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004229 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004230 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004231
4232 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4233 ? mTopFullscreenOpaqueWindowState.getAttrs()
4234 : null;
4235
Jeff Brownc8018eb2012-10-29 21:33:27 -07004236 // If we are not currently showing a dream then remember the current
4237 // lockscreen state. We will use this to determine whether the dream
4238 // started while the lockscreen was showing and remember this state
4239 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004240 if (!mShowingDream) {
4241 mDreamingLockscreen = mShowingLockscreen;
4242 }
4243
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004244 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004245 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004246 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004247 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004248 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07004249 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004250 if (mStatusBarController.setBarShowingLw(true)) {
4251 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4252 }
Craig Mautner81defc72013-10-29 11:10:42 -07004253 // Maintain fullscreen layout until incoming animation is complete.
4254 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004255 // Transient status bar on the lockscreen is not allowed
4256 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4257 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4258 mLastSystemUiFlags, mLastSystemUiFlags);
4259 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004260 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004261 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004262 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004263 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004264 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004265 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004266 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004267 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004268 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004269 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004270 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004271 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004272 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4273 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004274 if (mStatusBarController.isTransientShowing()) {
4275 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004276 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4277 }
4278 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004279 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004280 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004281 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004282 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004283 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004284 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004285 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004286 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004287 if (mStatusBarController.setBarShowingLw(true)) {
4288 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4289 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004290 }
4291 }
4292 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004293
Craig Mautner81defc72013-10-29 11:10:42 -07004294 if (mTopIsFullscreen != topIsFullscreen) {
4295 if (!topIsFullscreen) {
4296 // Force another layout when status bar becomes fully shown.
4297 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4298 }
4299 mTopIsFullscreen = topIsFullscreen;
4300 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004301
Craig Mautner39834192012-09-02 07:47:24 -07004302 // Hide the key guard if a visible window explicitly specifies that it wants to be
4303 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004304 if (mKeyguardDelegate != null && mStatusBar != null) {
4305 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4306 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004307 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004308 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004309 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004310 changes |= FINISH_LAYOUT_REDO_LAYOUT
4311 | FINISH_LAYOUT_REDO_CONFIG
4312 | FINISH_LAYOUT_REDO_WALLPAPER;
4313 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004314 if (mKeyguardDelegate.isShowing()) {
4315 mHandler.post(new Runnable() {
4316 @Override
4317 public void run() {
4318 mKeyguardDelegate.keyguardDone(false, false);
4319 }
4320 });
4321 }
4322 } else if (mHideLockScreen) {
4323 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004324 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004325 changes |= FINISH_LAYOUT_REDO_LAYOUT
4326 | FINISH_LAYOUT_REDO_CONFIG
4327 | FINISH_LAYOUT_REDO_WALLPAPER;
4328 }
4329 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
4330 // This is the case of keyguard isSecure() and not mHideLockScreen.
4331 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4332 // Only launch the next keyguard unlock window once per window.
4333 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004334 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004335 changes |= FINISH_LAYOUT_REDO_LAYOUT
4336 | FINISH_LAYOUT_REDO_CONFIG
4337 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004338 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004339 mHandler.post(new Runnable() {
4340 @Override
4341 public void run() {
4342 mKeyguardDelegate.dismiss();
4343 }
4344 });
4345 }
4346 } else {
4347 mWinDismissingKeyguard = null;
4348 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004349 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004350 changes |= FINISH_LAYOUT_REDO_LAYOUT
4351 | FINISH_LAYOUT_REDO_CONFIG
4352 | FINISH_LAYOUT_REDO_WALLPAPER;
4353 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004354 }
4355 }
Joe Onorato664644d2011-01-23 17:53:23 -08004356
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004357 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004358 // If the navigation bar has been hidden or shown, we need to do another
4359 // layout pass to update that window.
4360 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4361 }
Joe Onorato664644d2011-01-23 17:53:23 -08004362
Mike Lockwood28569302010-01-28 11:54:40 -05004363 // update since mAllowLockscreenWhenOn might have changed
4364 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004365 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004366 }
4367
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004368 /**
Jim Millerab954542014-10-10 18:21:49 -07004369 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004370 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004371 * @return Whether the flags have changed and we have to redo the layout.
4372 */
Jim Millerab954542014-10-10 18:21:49 -07004373 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4374 boolean wasOccluded = mKeyguardOccluded;
4375 boolean showing = mKeyguardDelegate.isShowing();
4376 if (wasOccluded && !isOccluded && showing) {
4377 mKeyguardOccluded = false;
4378 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004379 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4380 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4381 return true;
Jim Millerab954542014-10-10 18:21:49 -07004382 } else if (!wasOccluded && isOccluded && showing) {
4383 mKeyguardOccluded = true;
4384 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004385 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4386 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4387 return true;
4388 } else {
4389 return false;
4390 }
4391 }
4392
4393 private boolean isStatusBarKeyguard() {
4394 return mStatusBar != null
4395 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4396 }
4397
Jose Lima9546b202014-07-02 17:21:51 -07004398 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004399 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004400 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004401 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004402 return false;
4403 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004404 return true;
4405 }
4406
Jose Lima9546b202014-07-02 17:21:51 -07004407 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004408 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004409 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004410 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004411 // If the navigation bar has been hidden or shown, we need to do another
4412 // layout pass to update that window.
4413 return FINISH_LAYOUT_REDO_LAYOUT;
4414 }
4415 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004416 }
4417
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004418 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004419 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004420 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4421 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004422 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4423 if (newLidState == mLidState) {
4424 return;
4425 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004426
Jeff Brownc458ce92012-04-30 14:58:40 -07004427 mLidState = newLidState;
4428 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004429 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004430
4431 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004432 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004433 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004434 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004435 }
4436 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004437
Michael Wright3818c922014-09-02 13:59:07 -07004438 @Override
4439 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4440 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4441 if (mCameraLensCoverState == lensCoverState) {
4442 return;
4443 }
4444 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4445 lensCoverState == CAMERA_LENS_UNCOVERED) {
4446 Intent intent;
4447 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4448 mKeyguardDelegate.isShowing();
4449 if (keyguardActive) {
4450 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4451 } else {
4452 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4453 }
Bryce Lee584a4452014-10-21 15:55:55 -07004454 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004455 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004456 }
4457 mCameraLensCoverState = lensCoverState;
4458 }
4459
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004460 void setHdmiPlugged(boolean plugged) {
4461 if (mHdmiPlugged != plugged) {
4462 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004463 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004464 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004465 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004466 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004467 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004468 }
4469 }
4470
Joe Onoratoea495d42011-04-06 11:41:11 -07004471 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004472 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004473 // watch for HDMI plug messages if the hdmi switch exists
4474 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4475 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4476
Joe Onoratoea495d42011-04-06 11:41:11 -07004477 final String filename = "/sys/class/switch/hdmi/state";
4478 FileReader reader = null;
4479 try {
4480 reader = new FileReader(filename);
4481 char[] buf = new char[15];
4482 int n = reader.read(buf);
4483 if (n > 1) {
4484 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4485 }
4486 } catch (IOException ex) {
4487 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4488 } catch (NumberFormatException ex) {
4489 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4490 } finally {
4491 if (reader != null) {
4492 try {
4493 reader.close();
4494 } catch (IOException ex) {
4495 }
Joe Onoratodc100302011-01-11 17:07:41 -08004496 }
4497 }
4498 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004499 // This dance forces the code in setHdmiPlugged to run.
4500 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4501 mHdmiPlugged = !plugged;
4502 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004503 }
4504
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004505 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004506 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004507
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004508 final Runnable mScreenshotTimeout = new Runnable() {
4509 @Override public void run() {
4510 synchronized (mScreenshotLock) {
4511 if (mScreenshotConnection != null) {
4512 mContext.unbindService(mScreenshotConnection);
4513 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004514 }
Winson Chung9112ec32011-06-27 13:15:32 -07004515 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004516 }
4517 };
4518
4519 // Assume this is called from the Handler thread.
4520 private void takeScreenshot() {
4521 synchronized (mScreenshotLock) {
4522 if (mScreenshotConnection != null) {
4523 return;
4524 }
4525 ComponentName cn = new ComponentName("com.android.systemui",
4526 "com.android.systemui.screenshot.TakeScreenshotService");
4527 Intent intent = new Intent();
4528 intent.setComponent(cn);
4529 ServiceConnection conn = new ServiceConnection() {
4530 @Override
4531 public void onServiceConnected(ComponentName name, IBinder service) {
4532 synchronized (mScreenshotLock) {
4533 if (mScreenshotConnection != this) {
4534 return;
4535 }
4536 Messenger messenger = new Messenger(service);
4537 Message msg = Message.obtain(null, 1);
4538 final ServiceConnection myConn = this;
4539 Handler h = new Handler(mHandler.getLooper()) {
4540 @Override
4541 public void handleMessage(Message msg) {
4542 synchronized (mScreenshotLock) {
4543 if (mScreenshotConnection == myConn) {
4544 mContext.unbindService(mScreenshotConnection);
4545 mScreenshotConnection = null;
4546 mHandler.removeCallbacks(mScreenshotTimeout);
4547 }
4548 }
4549 }
4550 };
4551 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004552 msg.arg1 = msg.arg2 = 0;
4553 if (mStatusBar != null && mStatusBar.isVisibleLw())
4554 msg.arg1 = 1;
4555 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4556 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004557 try {
4558 messenger.send(msg);
4559 } catch (RemoteException e) {
4560 }
4561 }
4562 }
4563 @Override
4564 public void onServiceDisconnected(ComponentName name) {}
4565 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004566 if (mContext.bindServiceAsUser(
4567 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004568 mScreenshotConnection = conn;
4569 mHandler.postDelayed(mScreenshotTimeout, 10000);
4570 }
4571 }
Winson Chung9112ec32011-06-27 13:15:32 -07004572 }
4573
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004574 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004575 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004576 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004577 if (!mSystemBooted) {
4578 // If we have not yet booted, don't let key events do anything.
4579 return 0;
4580 }
4581
Jeff Brown037c33e2014-04-09 00:31:55 -07004582 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004583 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4584 final boolean canceled = event.isCanceled();
4585 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004586
Jeff Brown3122e442010-10-11 23:32:49 -07004587 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004588
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004589 // If screen is off then we treat the case where the keyguard is open but hidden
4590 // the same as if it were open and in front.
4591 // This will prevent any keys other than the power button from waking the screen
4592 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004593 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004594 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004595 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004596 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004597
Jeff Brown40013652012-05-16 21:22:36 -07004598 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004599 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004600 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004601 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004602 }
4603
Jeff Brown037c33e2014-04-09 00:31:55 -07004604 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004605 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004606 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4607 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004608 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004609 // When the device is interactive or the key is injected pass the
4610 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004611 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004612 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004613 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4614 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4615 // to the application but preserve its wake key status to make sure we still move
4616 // from dozing to fully interactive if we would normally go from off to fully
4617 // interactive.
4618 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004619 } else {
4620 // When the screen is off and the key is not injected, determine whether
4621 // to wake the device but don't pass the key to the application.
4622 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004623 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4624 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004625 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004626 }
4627
Justin Kohd378ad72013-04-01 12:18:26 -07004628 // If the key would be handled globally, just return the result, don't worry about special
4629 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004630 if (isValidGlobalKey(keyCode)
4631 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004632 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004633 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004634 }
Justin Kohd378ad72013-04-01 12:18:26 -07004635 return result;
4636 }
4637
Jeff Brownbae8e772014-06-12 19:59:45 -07004638 boolean useHapticFeedback = down
4639 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4640 && event.getRepeatCount() == 0;
4641
Jeff Brown4d396052010-10-29 21:50:21 -07004642 // Handle special keys.
4643 switch (keyCode) {
4644 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004645 case KeyEvent.KEYCODE_VOLUME_UP:
4646 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004647 if (mUseTvRouting) {
4648 // On TVs volume keys never go to the foreground app
4649 result &= ~ACTION_PASS_TO_USER;
4650 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004651 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4652 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004653 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004654 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004655 mScreenshotChordVolumeDownKeyTriggered = true;
4656 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4657 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004658 cancelPendingPowerKeyAction();
4659 interceptScreenshotChord();
4660 }
4661 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004662 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004663 cancelPendingScreenshotChordAction();
4664 }
4665 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4666 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004667 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004668 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004669 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004670 cancelPendingPowerKeyAction();
4671 cancelPendingScreenshotChordAction();
4672 }
4673 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004674 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004675 cancelPendingScreenshotChordAction();
4676 }
4677 }
Jeff Brown4d396052010-10-29 21:50:21 -07004678 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004679 TelecomManager telecomManager = getTelecommService();
4680 if (telecomManager != null) {
4681 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004682 // If an incoming call is ringing, either VOLUME key means
4683 // "silence ringer". We handle these keys here, rather than
4684 // in the InCallScreen, to make sure we'll respond to them
4685 // even if the InCallScreen hasn't come to the foreground yet.
4686 // Look for the DOWN event here, to agree with the "fallback"
4687 // behavior in the InCallScreen.
4688 Log.i(TAG, "interceptKeyBeforeQueueing:"
4689 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004690
Santos Cordon6848f722014-05-21 15:22:12 -07004691 // Silence the ringer. (It's safe to call this
4692 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004693 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004694
Santos Cordon6848f722014-05-21 15:22:12 -07004695 // And *don't* pass this key thru to the current activity
4696 // (which is probably the InCallScreen.)
4697 result &= ~ACTION_PASS_TO_USER;
4698 break;
4699 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004700 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004701 && (result & ACTION_PASS_TO_USER) == 0) {
4702 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004703 // the application, just pass it to the session service.
4704
4705 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004706 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004707 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004708 }
4709 }
4710
RoboErik430fc482014-06-12 15:49:20 -07004711 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004712 if (mUseTvRouting) {
4713 dispatchDirectAudioEvent(event);
4714 } else {
4715 // If we aren't passing to the user and no one else
4716 // handled it send it to the session manager to
4717 // figure out.
4718 MediaSessionLegacyHelper.getHelper(mContext)
4719 .sendVolumeKeyEvent(event, true);
4720 }
Jeff Brown4d396052010-10-29 21:50:21 -07004721 break;
4722 }
4723 }
4724 break;
4725 }
4726
4727 case KeyEvent.KEYCODE_ENDCALL: {
4728 result &= ~ACTION_PASS_TO_USER;
4729 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004730 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004731 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004732 if (telecomManager != null) {
4733 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004734 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004735 if (interactive && !hungUp) {
4736 mEndCallKeyHandled = false;
4737 mHandler.postDelayed(mEndCallLongPress,
4738 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4739 } else {
4740 mEndCallKeyHandled = true;
4741 }
Jeff Brown4d396052010-10-29 21:50:21 -07004742 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004743 if (!mEndCallKeyHandled) {
4744 mHandler.removeCallbacks(mEndCallLongPress);
4745 if (!canceled) {
4746 if ((mEndcallBehavior
4747 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4748 if (goHome()) {
4749 break;
4750 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004751 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004752 if ((mEndcallBehavior
4753 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4754 mPowerManager.goToSleep(event.getEventTime(),
4755 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4756 isWakeKey = false;
4757 }
Jeff Brown4d396052010-10-29 21:50:21 -07004758 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004759 }
Jeff Brown4d396052010-10-29 21:50:21 -07004760 }
4761 break;
4762 }
4763
4764 case KeyEvent.KEYCODE_POWER: {
4765 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004766 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004767 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004768 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004769 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004770 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004771 }
4772 break;
4773 }
4774
Jeff Brown6212a492014-03-07 13:58:47 -08004775 case KeyEvent.KEYCODE_SLEEP: {
4776 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004777 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004778 if (!mPowerManager.isInteractive()) {
4779 useHapticFeedback = false; // suppress feedback if already non-interactive
4780 }
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004781 sleepPress(event);
Jeff Brown6212a492014-03-07 13:58:47 -08004782 break;
4783 }
4784
4785 case KeyEvent.KEYCODE_WAKEUP: {
4786 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004787 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004788 break;
4789 }
4790
Jeff Brown4d396052010-10-29 21:50:21 -07004791 case KeyEvent.KEYCODE_MEDIA_PLAY:
4792 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4793 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004794 case KeyEvent.KEYCODE_HEADSETHOOK:
4795 case KeyEvent.KEYCODE_MUTE:
4796 case KeyEvent.KEYCODE_MEDIA_STOP:
4797 case KeyEvent.KEYCODE_MEDIA_NEXT:
4798 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4799 case KeyEvent.KEYCODE_MEDIA_REWIND:
4800 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004801 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4802 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004803 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4804 // If the global session is active pass all media keys to it
4805 // instead of the active window.
4806 result &= ~ACTION_PASS_TO_USER;
4807 }
Jeff Brown4d396052010-10-29 21:50:21 -07004808 if ((result & ACTION_PASS_TO_USER) == 0) {
4809 // Only do this if we would otherwise not pass it to the user. In that
4810 // case, the PhoneWindow class will do the same thing, except it will
4811 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004812 // Note that we need to make a copy of the key event here because the
4813 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004814 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004815 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4816 new KeyEvent(event));
4817 msg.setAsynchronous(true);
4818 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004819 }
4820 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004821 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004822
Jeff Brown4d396052010-10-29 21:50:21 -07004823 case KeyEvent.KEYCODE_CALL: {
4824 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004825 TelecomManager telecomManager = getTelecommService();
4826 if (telecomManager != null) {
4827 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004828 Log.i(TAG, "interceptKeyBeforeQueueing:"
4829 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004830 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004831
Santos Cordon6848f722014-05-21 15:22:12 -07004832 // And *don't* pass this key thru to the current activity
4833 // (which is presumably the InCallScreen.)
4834 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004835 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004836 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004837 }
Jeff Brown4d396052010-10-29 21:50:21 -07004838 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004839 }
Michael Wright869a67c2014-08-26 19:33:06 -07004840 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4841 // Only do this if we would otherwise not pass it to the user. In that case,
4842 // interceptKeyBeforeDispatching would apply a similar but different policy in
4843 // order to invoke voice assist actions. Note that we need to make a copy of the
4844 // key event here because the original key event will be recycled when we return.
4845 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4846 mBroadcastWakeLock.acquire();
4847 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4848 keyguardActive ? 1 : 0, 0);
4849 msg.setAsynchronous(true);
4850 msg.sendToTarget();
4851 }
4852 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004853 }
Jeff Brown26875502014-01-30 21:47:47 -08004854
Jeff Brownbae8e772014-06-12 19:59:45 -07004855 if (useHapticFeedback) {
4856 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4857 }
4858
Jeff Brown26875502014-01-30 21:47:47 -08004859 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004860 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004861 }
Bryce Lee584a4452014-10-21 15:55:55 -07004862
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004863 return result;
4864 }
4865
Jeff Brown1c2e4942012-11-06 16:32:01 -08004866 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004867 * Returns true if the key can have global actions attached to it.
4868 * We reserve all power management keys for the system since they require
4869 * very careful handling.
4870 */
4871 private static boolean isValidGlobalKey(int keyCode) {
4872 switch (keyCode) {
4873 case KeyEvent.KEYCODE_POWER:
4874 case KeyEvent.KEYCODE_WAKEUP:
4875 case KeyEvent.KEYCODE_SLEEP:
4876 return false;
4877 default:
4878 return true;
4879 }
4880 }
4881
4882 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08004883 * When the screen is off we ignore some keys that might otherwise typically
4884 * be considered wake keys. We filter them out here.
4885 *
4886 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4887 * is always considered a wake key.
4888 */
4889 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4890 switch (keyCode) {
4891 // ignore volume keys unless docked
4892 case KeyEvent.KEYCODE_VOLUME_UP:
4893 case KeyEvent.KEYCODE_VOLUME_DOWN:
4894 case KeyEvent.KEYCODE_VOLUME_MUTE:
4895 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4896
4897 // ignore media and camera keys
4898 case KeyEvent.KEYCODE_MUTE:
4899 case KeyEvent.KEYCODE_HEADSETHOOK:
4900 case KeyEvent.KEYCODE_MEDIA_PLAY:
4901 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4902 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4903 case KeyEvent.KEYCODE_MEDIA_STOP:
4904 case KeyEvent.KEYCODE_MEDIA_NEXT:
4905 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4906 case KeyEvent.KEYCODE_MEDIA_REWIND:
4907 case KeyEvent.KEYCODE_MEDIA_RECORD:
4908 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004909 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004910 case KeyEvent.KEYCODE_CAMERA:
4911 return false;
4912 }
4913 return true;
4914 }
4915
4916
Jeff Brown56194eb2011-03-02 19:23:13 -08004917 /** {@inheritDoc} */
4918 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004919 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4920 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08004921 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
4922 return 0;
4923 }
Michael Wright70af00a2014-09-03 19:30:20 -07004924 }
Bryce Lee5c138322014-11-03 08:26:09 -08004925
Michael Wright70af00a2014-09-03 19:30:20 -07004926 if (shouldDispatchInputWhenNonInteractive()) {
4927 return ACTION_PASS_TO_USER;
4928 }
Bryce Lee5c138322014-11-03 08:26:09 -08004929
Bryce Lee812d7022014-11-10 13:33:28 -08004930 // If we have not passed the action up and we are in theater mode without dreaming,
4931 // there will be no dream to intercept the touch and wake into ambient. The device should
4932 // wake up in this case.
4933 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
4934 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
4935 }
4936
Jeff Brown037c33e2014-04-09 00:31:55 -07004937 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004938 }
4939
Michael Wright70af00a2014-09-03 19:30:20 -07004940 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08004941 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07004942 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
4943 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08004944 return true;
4945 }
4946
4947 // Send events to a dozing dream even if the screen is off since the dream
4948 // is in control of the state of the screen.
4949 IDreamManager dreamManager = getDreamManager();
4950
4951 try {
4952 if (dreamManager != null && dreamManager.isDreaming()) {
4953 return true;
4954 }
4955 } catch (RemoteException e) {
4956 Slog.e(TAG, "RemoteException when checking if dreaming", e);
4957 }
4958
4959 // Otherwise, consume events since the user can't see what is being
4960 // interacted with.
4961 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07004962 }
4963
RoboErik001c59c2015-01-26 15:53:51 -08004964 private void dispatchDirectAudioEvent(KeyEvent event) {
4965 if (event.getAction() != KeyEvent.ACTION_DOWN) {
4966 return;
4967 }
4968 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04004969 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
4970 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08004971 String pkgName = mContext.getOpPackageName();
4972 switch (keyCode) {
4973 case KeyEvent.KEYCODE_VOLUME_UP:
4974 try {
John Spurlockee5ad722015-03-03 16:17:21 -05004975 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04004976 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08004977 } catch (RemoteException e) {
4978 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
4979 }
4980 break;
4981 case KeyEvent.KEYCODE_VOLUME_DOWN:
4982 try {
John Spurlockee5ad722015-03-03 16:17:21 -05004983 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04004984 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08004985 } catch (RemoteException e) {
4986 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
4987 }
4988 break;
4989 case KeyEvent.KEYCODE_VOLUME_MUTE:
4990 try {
4991 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05004992 getAudioService().adjustSuggestedStreamVolume(
4993 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04004994 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08004995 }
4996 } catch (RemoteException e) {
4997 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
4998 }
4999 break;
5000 }
5001 }
5002
Jeff Brown40013652012-05-16 21:22:36 -07005003 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5004 if (DEBUG_INPUT) {
5005 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005006 }
5007
Jeff Brown40013652012-05-16 21:22:36 -07005008 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5009 if (DEBUG_INPUT) {
5010 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5011 }
5012
5013 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5014 mHavePendingMediaKeyRepeatWithWakeLock = false;
5015 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5016 }
5017
5018 dispatchMediaKeyWithWakeLockToAudioService(event);
5019
5020 if (event.getAction() == KeyEvent.ACTION_DOWN
5021 && event.getRepeatCount() == 0) {
5022 mHavePendingMediaKeyRepeatWithWakeLock = true;
5023
5024 Message msg = mHandler.obtainMessage(
5025 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5026 msg.setAsynchronous(true);
5027 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5028 } else {
5029 mBroadcastWakeLock.release();
5030 }
5031 }
5032
5033 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5034 mHavePendingMediaKeyRepeatWithWakeLock = false;
5035
5036 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5037 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5038 if (DEBUG_INPUT) {
5039 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5040 }
5041
5042 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5043 mBroadcastWakeLock.release();
5044 }
5045
5046 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5047 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005048 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005049 }
5050 }
5051
Michael Wright869a67c2014-08-26 19:33:06 -07005052 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
5053 Intent voiceIntent =
5054 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5055 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005056 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005057 mBroadcastWakeLock.release();
5058 }
5059
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005060 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005061 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005062 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005063 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5064 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5065 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005066 } else {
5067 try {
5068 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5069 ServiceManager.getService(Context.UI_MODE_SERVICE));
5070 mUiMode = uiModeService.getCurrentModeType();
5071 } catch (RemoteException e) {
5072 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005073 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005074 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005075 synchronized (mLock) {
5076 updateOrientationListenerLp();
5077 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005078 }
5079 };
5080
Jeff Brown6aaf2952012-10-05 16:01:08 -07005081 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5082 @Override
5083 public void onReceive(Context context, Intent intent) {
5084 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005085 if (mKeyguardDelegate != null) {
5086 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005087 }
5088 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005089 if (mKeyguardDelegate != null) {
5090 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005091 }
5092 }
5093 }
5094 };
5095
Christopher Tate5e08af02012-09-21 17:17:22 -07005096 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5097 @Override
5098 public void onReceive(Context context, Intent intent) {
5099 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5100 // tickle the settings observer: this first ensures that we're
5101 // observing the relevant settings for the newly-active user,
5102 // and then updates our own bookkeeping based on the now-
5103 // current user.
5104 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005105
5106 // force a re-application of focused window sysui visibility.
5107 // the window may never have been shown for this user
5108 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005109 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005110 mLastSystemUiFlags = 0;
5111 updateSystemUiVisibilityLw();
5112 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005113 }
5114 }
5115 };
5116
John Spurlockd9b70bd2014-02-06 17:02:44 -05005117 private final Runnable mRequestTransientNav = new Runnable() {
5118 @Override
5119 public void run() {
5120 requestTransientBars(mNavigationBar);
5121 }
5122 };
5123
John Spurlocke1f366f2013-08-05 12:22:40 -04005124 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005125 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005126 if (!isUserSetupComplete()) {
5127 // Swipe-up for navigation bar is disabled during setup
5128 return;
5129 }
John Spurlock27735a42013-08-14 17:57:38 -04005130 boolean sb = mStatusBarController.checkShowTransientBarLw();
5131 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005132 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005133 // Don't show status bar when swiping on already visible navigation bar
5134 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005135 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005136 return;
5137 }
John Spurlock27735a42013-08-14 17:57:38 -04005138 if (sb) mStatusBarController.showTransient();
5139 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005140 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005141 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005142 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005143 }
5144 }
5145
Jeff Brown3ee549c2014-09-22 20:14:39 -07005146 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005147 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07005148 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005149 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07005150 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005151
5152 // We must get this work done here because the power manager will drop
5153 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005154 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005155 mAwake = false;
5156 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005157 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005158 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005159 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005160 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005161
5162 if (mKeyguardDelegate != null) {
5163 mKeyguardDelegate.onScreenTurnedOff(why);
5164 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005165 }
5166
Jeff Brown13f00f02014-10-31 14:45:50 -07005167 private void wakeUpFromPowerKey(long eventTime) {
5168 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5169 }
5170
Bryce Lee5c138322014-11-03 08:26:09 -08005171 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Lee584a4452014-10-21 15:55:55 -07005172 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005173 return false;
Bryce Lee584a4452014-10-21 15:55:55 -07005174 }
5175
5176 mPowerManager.wakeUp(wakeTime);
Bryce Lee5c138322014-11-03 08:26:09 -08005177 return true;
Bryce Lee584a4452014-10-21 15:55:55 -07005178 }
5179
Jeff Brown3ee549c2014-09-22 20:14:39 -07005180 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005181 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07005182 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005183 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07005184 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005185
Jeff Brown3ee549c2014-09-22 20:14:39 -07005186 // Since goToSleep performs these functions synchronously, we must
5187 // do the same here. We cannot post this work to a handler because
5188 // that might cause it to become reordered with respect to what
5189 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005190 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005191 mAwake = true;
5192 mKeyguardDrawComplete = false;
5193 if (mKeyguardDelegate != null) {
5194 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5195 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5196 }
5197
Jeff Browna20dda42014-05-27 20:57:24 -07005198 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005199 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005200 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005201 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005202
Jim Miller5ecd8112013-01-09 18:50:26 -08005203 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07005204 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005205 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005206 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005207 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005208 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005209 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005210 }
5211
Jeff Brown36c4db82014-09-19 12:05:31 -07005212 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005213 synchronized (mLock) {
5214 if (!mAwake || mKeyguardDrawComplete) {
5215 return; // spurious
5216 }
5217
Jeff Brown36c4db82014-09-19 12:05:31 -07005218 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005219 if (mKeyguardDelegate != null) {
5220 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5221 }
5222 }
5223
5224 finishScreenTurningOn();
5225 }
5226
5227 // Called on the DisplayManager's DisplayPowerController thread.
5228 @Override
5229 public void screenTurnedOff() {
5230 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5231
5232 synchronized (mLock) {
5233 mScreenOnEarly = false;
5234 mScreenOnFully = false;
5235 mWindowManagerDrawComplete = false;
5236 mScreenOnListener = null;
5237 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005238 }
5239 }
5240
Jeff Brown3ee549c2014-09-22 20:14:39 -07005241 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005242 @Override
5243 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005244 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005245
Jeff Brown3ee549c2014-09-22 20:14:39 -07005246 synchronized (mLock) {
5247 mScreenOnEarly = true;
5248 mScreenOnFully = false;
5249 mWindowManagerDrawComplete = false;
5250 mScreenOnListener = screenOnListener;
5251 updateOrientationListenerLp();
5252 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005253
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005254 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5255 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005256 // ... eventually calls finishWindowsDrawn
5257 }
5258
Jeff Brown36c4db82014-09-19 12:05:31 -07005259 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005260 synchronized (mLock) {
5261 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5262 return; // spurious
5263 }
5264
Jeff Brown36c4db82014-09-19 12:05:31 -07005265 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005266 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005267
5268 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005269 }
5270
Craig Mautner8a0da012014-05-31 15:13:37 -07005271 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005272 final ScreenOnListener listener;
5273 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005274 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005275 if (DEBUG_WAKEUP) Slog.d(TAG,
5276 "finishScreenTurningOn: mAwake=" + mAwake
5277 + ", mScreenOnEarly=" + mScreenOnEarly
5278 + ", mScreenOnFully=" + mScreenOnFully
5279 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5280 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5281
5282 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5283 || (mAwake && !mKeyguardDrawComplete)) {
5284 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005285 }
5286
Jeff Brown3ee549c2014-09-22 20:14:39 -07005287 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5288 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005289 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005290 mScreenOnFully = true;
5291
5292 // Remember the first time we draw the keyguard so we know when we're done with
5293 // the main part of booting and can enable the screen and hide boot messages.
5294 if (!mKeyguardDrawnOnce && mAwake) {
5295 mKeyguardDrawnOnce = true;
5296 enableScreen = true;
5297 if (mBootMessageNeedsHiding) {
5298 mBootMessageNeedsHiding = false;
5299 hideBootMessages();
5300 }
5301 } else {
5302 enableScreen = false;
5303 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005304 }
5305
Jeff Brown3ee549c2014-09-22 20:14:39 -07005306 if (listener != null) {
5307 listener.onScreenOn();
5308 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005309
Jeff Brown3ee549c2014-09-22 20:14:39 -07005310 if (enableScreen) {
5311 try {
5312 mWindowManager.enableScreenIfNeeded();
5313 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005314 }
Craig Mautnera631d492014-08-05 15:16:01 -07005315 }
5316 }
5317
5318 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005319 synchronized (mLock) {
5320 if (!mKeyguardDrawnOnce) {
5321 mBootMessageNeedsHiding = true;
5322 return; // keyguard hasn't drawn the first time yet, not done booting
5323 }
Craig Mautnera631d492014-08-05 15:16:01 -07005324 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005325
5326 if (mBootMsgDialog != null) {
5327 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5328 mBootMsgDialog.dismiss();
5329 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005330 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005331 }
5332
5333 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005334 public boolean isScreenOn() {
5335 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005336 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005337
Dianne Hackborn08743722009-12-21 12:16:51 -08005338 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005339 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005340 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005341 if (mKeyguardDelegate != null) {
5342 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005343 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005344 }
5345
5346 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005347 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005348 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005349 if (mKeyguardDelegate != null) {
5350 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005351 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005352 }
5353
Jim Millerab954542014-10-10 18:21:49 -07005354 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005355 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005356 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005357 }
5358
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005359 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005360 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005361 public boolean isKeyguardLocked() {
5362 return keyguardOn();
5363 }
5364
5365 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005366 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005367 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005368 if (mKeyguardDelegate == null) return false;
5369 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005370 }
5371
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005372 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005373 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005374 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005375 if (mKeyguardDelegate == null) return false;
5376 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005377 }
5378
Jose Lima9546b202014-07-02 17:21:51 -07005379 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005380 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005381 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005382 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005383 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005384 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005385 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005386 // ask the keyguard to prompt the user to authenticate if necessary
5387 mKeyguardDelegate.dismiss();
5388 }
5389 });
5390 }
5391 }
5392
5393 public void notifyActivityDrawnForKeyguardLw() {
5394 if (mKeyguardDelegate != null) {
5395 mHandler.post(new Runnable() {
5396 @Override
5397 public void run() {
5398 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005399 }
5400 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005401 }
5402 }
5403
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005404 @Override
5405 public boolean isKeyguardDrawnLw() {
5406 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005407 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005408 }
5409 }
5410
Jorim Jaggi0d674622014-05-21 01:34:15 +02005411 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005412 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005413 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005414 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005415 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005416 }
5417 }
5418
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005419 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005420 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005421 }
5422
5423 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005424 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005425 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005426
Jeff Brown01a98dd2011-09-20 15:08:29 -07005427 @Override
5428 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005429 if (false) {
5430 Slog.v(TAG, "rotationForOrientationLw(orient="
5431 + orientation + ", last=" + lastRotation
5432 + "); user=" + mUserRotation + " "
5433 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5434 ? "USER_ROTATION_LOCKED" : "")
5435 );
5436 }
5437
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005438 if (mForceDefaultOrientation) {
5439 return Surface.ROTATION_0;
5440 }
5441
The Android Open Source Project0727d222009-03-11 12:11:58 -07005442 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005443 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5444 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005445 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005446 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005447
Jeff Browndec6cf42011-11-15 14:08:20 -08005448 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005449 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005450 // Ignore sensor when lid switch is open and rotation is forced.
5451 preferredRotation = mLidOpenRotation;
5452 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005453 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005454 // Ignore sensor when in car dock unless explicitly enabled.
5455 // This case can override the behavior of NOSENSOR, and can also
5456 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005457 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005458 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005459 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5460 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5461 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005462 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005463 // Ignore sensor when in desk dock unless explicitly enabled.
5464 // This case can override the behavior of NOSENSOR, and can also
5465 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005466 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005467 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005468 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5469 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005470 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005471 preferredRotation = mDemoHdmiRotation;
5472 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5473 && mUndockedHdmiRotation >= 0) {
5474 // Ignore sensor when plugged into HDMI and an undocked orientation has
5475 // been specified in the configuration (only for legacy devices without
5476 // full multi-display support).
5477 // Note that the dock orientation overrides the HDMI orientation.
5478 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005479 } else if (mDemoRotationLock) {
5480 // Ignore sensor when demo rotation lock is enabled.
5481 // Note that the dock orientation and HDMI rotation lock override this.
5482 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005483 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5484 // Application just wants to remain locked in the last rotation.
5485 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005486 } else if (!mSupportAutoRotation) {
5487 // If we don't support auto-rotation then bail out here and ignore
5488 // the sensor and any rotation lock settings.
5489 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005490 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005491 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005492 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5493 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5494 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5495 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005496 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5497 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5498 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5499 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5500 // Otherwise, use sensor only if requested by the application or enabled
5501 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005502 if (mAllowAllRotations < 0) {
5503 // Can't read this during init() because the context doesn't
5504 // have display metrics at that time so we cannot determine
5505 // tablet vs. phone then.
5506 mAllowAllRotations = mContext.getResources().getBoolean(
5507 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5508 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005509 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005510 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005511 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5512 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005513 preferredRotation = sensorRotation;
5514 } else {
5515 preferredRotation = lastRotation;
5516 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005517 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5518 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5519 // Apply rotation lock. Does not apply to NOSENSOR.
5520 // The idea is that the user rotation expresses a weak preference for the direction
5521 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5522 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005523 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005524 } else {
5525 // No overriding preference.
5526 // We will do exactly what the application asked us to do.
5527 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005528 }
5529
Dianne Hackborne5439f22010-10-02 16:53:50 -07005530 switch (orientation) {
5531 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005532 // Return portrait unless overridden.
5533 if (isAnyPortrait(preferredRotation)) {
5534 return preferredRotation;
5535 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005536 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005537
Jeff Brown01a98dd2011-09-20 15:08:29 -07005538 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005539 // Return landscape unless overridden.
5540 if (isLandscapeOrSeascape(preferredRotation)) {
5541 return preferredRotation;
5542 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005543 return mLandscapeRotation;
5544
5545 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005546 // Return reverse portrait unless overridden.
5547 if (isAnyPortrait(preferredRotation)) {
5548 return preferredRotation;
5549 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005550 return mUpsideDownRotation;
5551
5552 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005553 // Return seascape unless overridden.
5554 if (isLandscapeOrSeascape(preferredRotation)) {
5555 return preferredRotation;
5556 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005557 return mSeascapeRotation;
5558
5559 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005560 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005561 // Return either landscape rotation.
5562 if (isLandscapeOrSeascape(preferredRotation)) {
5563 return preferredRotation;
5564 }
5565 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005566 return lastRotation;
5567 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005568 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005569
Jeff Brown01a98dd2011-09-20 15:08:29 -07005570 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005571 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005572 // Return either portrait rotation.
5573 if (isAnyPortrait(preferredRotation)) {
5574 return preferredRotation;
5575 }
5576 if (isAnyPortrait(lastRotation)) {
5577 return lastRotation;
5578 }
5579 return mPortraitRotation;
5580
5581 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005582 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5583 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005584 if (preferredRotation >= 0) {
5585 return preferredRotation;
5586 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005587 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005588 }
5589 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005590 }
5591
Jeff Brown01a98dd2011-09-20 15:08:29 -07005592 @Override
5593 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5594 switch (orientation) {
5595 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5596 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5597 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5598 return isAnyPortrait(rotation);
5599
5600 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5601 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5602 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5603 return isLandscapeOrSeascape(rotation);
5604
5605 default:
5606 return true;
5607 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005608 }
5609
Jeff Brownc0347aa2011-09-23 17:26:09 -07005610 @Override
5611 public void setRotationLw(int rotation) {
5612 mOrientationListener.setCurrentRotation(rotation);
5613 }
5614
Jeff Brown01a98dd2011-09-20 15:08:29 -07005615 private boolean isLandscapeOrSeascape(int rotation) {
5616 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005617 }
5618
Jeff Brown01a98dd2011-09-20 15:08:29 -07005619 private boolean isAnyPortrait(int rotation) {
5620 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005621 }
5622
Jose Lima9546b202014-07-02 17:21:51 -07005623 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005624 public int getUserRotationMode() {
5625 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005626 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5627 WindowManagerPolicy.USER_ROTATION_FREE :
5628 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005629 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005630
5631 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005632 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005633 public void setUserRotationMode(int mode, int rot) {
5634 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005635
5636 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005637 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005638 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005639 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005640 rot,
5641 UserHandle.USER_CURRENT);
5642 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005643 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005644 0,
5645 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005646 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005647 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005648 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005649 1,
5650 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005651 }
5652 }
5653
Jose Lima9546b202014-07-02 17:21:51 -07005654 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005655 public void setSafeMode(boolean safeMode) {
5656 mSafeMode = safeMode;
5657 performHapticFeedbackLw(null, safeMode
5658 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5659 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005660 }
Craig Mautnereda67292013-04-28 13:50:14 -07005661
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005662 static long[] getLongIntArray(Resources r, int resid) {
5663 int[] ar = r.getIntArray(resid);
5664 if (ar == null) {
5665 return null;
5666 }
5667 long[] out = new long[ar.length];
5668 for (int i=0; i<ar.length; i++) {
5669 out[i] = ar[i];
5670 }
5671 return out;
5672 }
Craig Mautnereda67292013-04-28 13:50:14 -07005673
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005674 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005675 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005676 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005677 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005678 mKeyguardDelegate.onSystemReady();
5679
Michael Wright3818c922014-09-02 13:59:07 -07005680 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005681 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005682 synchronized (mLock) {
5683 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005684 mSystemReady = true;
5685 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005686 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005687 public void run() {
5688 updateSettings();
5689 }
5690 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005691 }
5692 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005693
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005694 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005695 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005696 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005697 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005698 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005699 mKeyguardDelegate.onBootCompleted();
5700 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005701 synchronized (mLock) {
5702 mSystemBooted = true;
5703 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005704 wakingUp();
5705 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005706 }
5707
Dianne Hackborn661cd522011-08-22 00:26:20 -07005708 ProgressDialog mBootMsgDialog = null;
5709
5710 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005711 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005712 public void showBootMessage(final CharSequence msg, final boolean always) {
5713 mHandler.post(new Runnable() {
5714 @Override public void run() {
5715 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005716 int theme;
5717 if (mContext.getPackageManager().hasSystemFeature(
5718 PackageManager.FEATURE_WATCH)) {
5719 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5720 } else if (mContext.getPackageManager().hasSystemFeature(
5721 PackageManager.FEATURE_TELEVISION)) {
5722 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5723 } else {
5724 theme = 0;
5725 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005726
5727 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005728 // This dialog will consume all events coming in to
5729 // it, to avoid it trying to do things too early in boot.
5730 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5731 return true;
5732 }
5733 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5734 return true;
5735 }
5736 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5737 return true;
5738 }
5739 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5740 return true;
5741 }
5742 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5743 return true;
5744 }
5745 @Override public boolean dispatchPopulateAccessibilityEvent(
5746 AccessibilityEvent event) {
5747 return true;
5748 }
5749 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005750 if (mContext.getPackageManager().isUpgrade()) {
5751 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5752 } else {
5753 mBootMsgDialog.setTitle(R.string.android_start_title);
5754 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005755 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5756 mBootMsgDialog.setIndeterminate(true);
5757 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005758 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005759 mBootMsgDialog.getWindow().addFlags(
5760 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5761 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5762 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005763 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5764 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5765 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005766 mBootMsgDialog.setCancelable(false);
5767 mBootMsgDialog.show();
5768 }
5769 mBootMsgDialog.setMessage(msg);
5770 }
5771 });
5772 }
5773
5774 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005775 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005776 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005777 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005778 }
5779
Mike Lockwood28569302010-01-28 11:54:40 -05005780 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005781 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005782 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005783 // ***************************************
5784 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5785 // ***************************************
5786 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5787 // WITH ITS LOCKS HELD.
5788 //
5789 // This code must be VERY careful about the locks
5790 // it acquires.
5791 // In fact, the current code acquires way too many,
5792 // and probably has lurking deadlocks.
5793
Mike Lockwood28569302010-01-28 11:54:40 -05005794 synchronized (mScreenLockTimeout) {
5795 if (mLockScreenTimerActive) {
5796 // reset the timer
5797 mHandler.removeCallbacks(mScreenLockTimeout);
5798 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5799 }
5800 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005801 }
5802
Adam Cohenf7522022012-10-03 20:03:18 -07005803 class ScreenLockTimeout implements Runnable {
5804 Bundle options;
5805
5806 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005807 public void run() {
5808 synchronized (this) {
5809 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005810 if (mKeyguardDelegate != null) {
5811 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005812 }
Mike Lockwood28569302010-01-28 11:54:40 -05005813 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005814 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005815 }
5816 }
Mike Lockwood28569302010-01-28 11:54:40 -05005817
Adam Cohenf7522022012-10-03 20:03:18 -07005818 public void setLockOptions(Bundle options) {
5819 this.options = options;
5820 }
5821 }
5822
5823 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5824
Jose Lima9546b202014-07-02 17:21:51 -07005825 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005826 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005827 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5828 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005829 if (options != null) {
5830 // In case multiple calls are made to lockNow, we don't wipe out the options
5831 // until the runnable actually executes.
5832 mScreenLockTimeout.setLockOptions(options);
5833 }
Jim Miller93c518e2012-01-17 15:55:31 -08005834 mHandler.post(mScreenLockTimeout);
5835 }
5836
Mike Lockwood28569302010-01-28 11:54:40 -05005837 private void updateLockScreenTimeout() {
5838 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005839 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005840 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005841 if (mLockScreenTimerActive != enable) {
5842 if (enable) {
5843 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5844 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5845 } else {
5846 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5847 mHandler.removeCallbacks(mScreenLockTimeout);
5848 }
5849 mLockScreenTimerActive = enable;
5850 }
5851 }
5852 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005853
5854 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005855 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005856 public void enableScreenAfterBoot() {
5857 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005858 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005859 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005860 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005861
Jeff Brownc458ce92012-04-30 14:58:40 -07005862 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005863 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005864 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005865 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005866 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005867 }
Jeff Browna20dda42014-05-27 20:57:24 -07005868
5869 synchronized (mLock) {
5870 updateWakeGestureListenerLp();
5871 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005872 }
5873
Jeff Brown4f5fa282014-06-12 19:19:15 -07005874 void updateUiMode() {
5875 if (mUiModeManager == null) {
5876 mUiModeManager = IUiModeManager.Stub.asInterface(
5877 ServiceManager.getService(Context.UI_MODE_SERVICE));
5878 }
5879 try {
5880 mUiMode = mUiModeManager.getCurrentModeType();
5881 } catch (RemoteException e) {
5882 }
5883 }
5884
Jeff Brown01a98dd2011-09-20 15:08:29 -07005885 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005886 try {
5887 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005888 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5889 } catch (RemoteException e) {
5890 // Ignore
5891 }
5892 }
5893
5894 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5895 try {
5896 //set orientation on WindowManager
5897 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005898 } catch (RemoteException e) {
5899 // Ignore
5900 }
5901 }
5902
Daniel Sandler6396c722013-04-16 20:19:09 -04005903 /**
5904 * Return an Intent to launch the currently active dock app as home. Returns
5905 * null if the standard home should be launched, which is the case if any of the following is
5906 * true:
5907 * <ul>
5908 * <li>The device is not in either car mode or desk mode
5909 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5910 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5911 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5912 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5913 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005914 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005915 */
5916 Intent createHomeDockIntent() {
5917 Intent intent = null;
5918
5919 // What home does is based on the mode, not the dock state. That
5920 // is, when in car mode you should be taken to car home regardless
5921 // of whether we are actually in a car dock.
5922 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5923 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5924 intent = mCarDockIntent;
5925 }
5926 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5927 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5928 intent = mDeskDockIntent;
5929 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005930 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5931 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5932 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5933 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5934 // Always launch dock home from home when watch is docked, if it exists.
5935 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005936 }
5937
5938 if (intent == null) {
5939 return null;
5940 }
5941
5942 ActivityInfo ai = null;
5943 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5944 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005945 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005946 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005947 if (info != null) {
5948 ai = info.activityInfo;
5949 }
5950 if (ai != null
5951 && ai.metaData != null
5952 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5953 intent = new Intent(intent);
5954 intent.setClassName(ai.packageName, ai.name);
5955 return intent;
5956 }
5957
5958 return null;
5959 }
5960
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005961 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
5962 if (awakenFromDreams) {
5963 awakenDreams();
5964 }
Daniel Sandler6396c722013-04-16 20:19:09 -04005965
5966 Intent dock = createHomeDockIntent();
5967 if (dock != null) {
5968 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005969 if (fromHomeKey) {
5970 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5971 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00005972 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04005973 return;
5974 } catch (ActivityNotFoundException e) {
5975 }
5976 }
5977
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005978 Intent intent;
5979
5980 if (fromHomeKey) {
5981 intent = new Intent(mHomeIntent);
5982 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5983 } else {
5984 intent = mHomeIntent;
5985 }
5986
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00005987 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005988 }
Craig Mautnereda67292013-04-28 13:50:14 -07005989
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005990 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005991 * goes to the home screen
5992 * @return whether it did anything
5993 */
5994 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00005995 if (!isUserSetupComplete()) {
5996 Slog.i(TAG, "Not going home because user setup is in progress.");
5997 return false;
5998 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005999 if (false) {
6000 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006001 try {
6002 ActivityManagerNative.getDefault().stopAppSwitches();
6003 } catch (RemoteException e) {
6004 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006005 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006006 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006007 } else {
6008 // This code brings home to the front or, if it is already
6009 // at the front, puts the device to sleep.
6010 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006011 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6012 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6013 Log.d(TAG, "UTS-TEST-MODE");
6014 } else {
6015 ActivityManagerNative.getDefault().stopAppSwitches();
6016 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006017 Intent dock = createHomeDockIntent();
6018 if (dock != null) {
6019 int result = ActivityManagerNative.getDefault()
6020 .startActivityAsUser(null, null, dock,
6021 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6022 null, null, 0,
6023 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006024 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006025 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6026 return false;
6027 }
6028 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006029 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006030 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006031 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006032 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006033 null, null, 0,
6034 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006035 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006036 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006037 return false;
6038 }
6039 } catch (RemoteException ex) {
6040 // bummer, the activity manager, which is in this process, is dead
6041 }
6042 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006043 return true;
6044 }
Craig Mautnereda67292013-04-28 13:50:14 -07006045
6046 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006047 public void setCurrentOrientationLw(int newOrientation) {
6048 synchronized (mLock) {
6049 if (newOrientation != mCurrentAppOrientation) {
6050 mCurrentAppOrientation = newOrientation;
6051 updateOrientationListenerLp();
6052 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006053 }
6054 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006055
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006056 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6057 if (!isGlobalAccessibilityGestureEnabled()) {
6058 return;
6059 }
6060 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6061 Context.AUDIO_SERVICE);
6062 if (audioManager.isSilentMode()) {
6063 return;
6064 }
6065 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6066 Settings.System.DEFAULT_NOTIFICATION_URI);
6067 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6068 ringTone.play();
6069 }
Craig Mautnereda67292013-04-28 13:50:14 -07006070
Bryce Lee584a4452014-10-21 15:55:55 -07006071 private boolean isTheaterModeEnabled() {
6072 return Settings.Global.getInt(mContext.getContentResolver(),
6073 Settings.Global.THEATER_MODE_ON, 0) == 1;
6074 }
6075
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006076 private boolean isGlobalAccessibilityGestureEnabled() {
6077 return Settings.Global.getInt(mContext.getContentResolver(),
6078 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6079 }
6080
Craig Mautnereda67292013-04-28 13:50:14 -07006081 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006082 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006083 if (!mVibrator.hasVibrator()) {
6084 return false;
6085 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006086 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6087 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006088 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006089 return false;
6090 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006091 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006092 switch (effectId) {
6093 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006094 pattern = mLongPressVibePattern;
6095 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006096 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006097 pattern = mVirtualKeyVibePattern;
6098 break;
6099 case HapticFeedbackConstants.KEYBOARD_TAP:
6100 pattern = mKeyboardTapVibePattern;
6101 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006102 case HapticFeedbackConstants.CLOCK_TICK:
6103 pattern = mClockTickVibePattern;
6104 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006105 case HapticFeedbackConstants.CALENDAR_DATE:
6106 pattern = mCalendarDateVibePattern;
6107 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006108 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006109 pattern = mSafeModeDisabledVibePattern;
6110 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006111 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006112 pattern = mSafeModeEnabledVibePattern;
6113 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006114 default:
6115 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006116 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006117 int owningUid;
6118 String owningPackage;
6119 if (win != null) {
6120 owningUid = win.getOwningUid();
6121 owningPackage = win.getOwningPackage();
6122 } else {
6123 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006124 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006125 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006126 if (pattern.length == 1) {
6127 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006128 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006129 } else {
6130 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006131 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006132 }
6133 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006134 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006135
6136 @Override
6137 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006138 }
6139
Jeff Brownc38c9be2012-10-04 13:16:19 -07006140 @Override
6141 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006142 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006143 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006144 }
6145 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006146
Dianne Hackborndf89e652011-10-06 22:35:11 -07006147 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006148 // If there is no window focused, there will be nobody to handle the events
6149 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006150 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6151 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006152 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006153 return 0;
6154 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006155 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006156 // We are updating at a point where the keyguard has gotten
6157 // focus, but we were last in a state where the top window is
6158 // hiding it. This is probably because the keyguard as been
6159 // shown while the top window was displayed, so we want to ignore
6160 // it here because this is just a very transient change and it
6161 // will quickly lose focus once it correctly gets hidden.
6162 return 0;
6163 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006164
John Spurlock1db8b682014-02-18 11:18:59 -05006165 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006166 & ~mResettingSystemUiFlags
6167 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006168 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006169 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006170 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006171 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006172 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006173 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006174 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006175 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006176 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006177 return 0;
6178 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006179 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006180 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006181 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006182 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006183 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006184 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006185 try {
6186 IStatusBarService statusbar = getStatusBarService();
6187 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006188 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006189 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006190 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006191 } catch (RemoteException e) {
6192 // re-acquire status bar service next time it is needed.
6193 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006194 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006195 }
6196 });
6197 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006198 }
6199
Adrian Rooscd3884d2015-02-18 17:25:23 +01006200 private int updateLightStatusBarLw(int vis) {
6201 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6202 ? mStatusBar
6203 : mTopFullscreenOpaqueOrDimmingWindowState;
6204
6205 if (statusColorWin != null) {
6206 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6207 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6208 // its light flag.
6209 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6210 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6211 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6212 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6213 // Otherwise if it's dimming, clear the light flag.
6214 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6215 }
6216 }
6217 return vis;
6218 }
6219
John Spurlock79da8332013-09-20 12:04:47 -04006220 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006221 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006222 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6223 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006224 : mTopFullscreenOpaqueWindowState;
6225 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6226 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6227
John Spurlock27735a42013-08-14 17:57:38 -04006228 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04006229 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006230 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006231 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6232 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006233 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006234 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6235 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006236 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006237 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6238 }
John Spurlockbd957402013-10-03 11:38:39 -04006239 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006240 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006241
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006242 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006243 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6244 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006245 }
6246
John Spurlock27735a42013-08-14 17:57:38 -04006247 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006248 boolean immersiveSticky =
6249 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006250 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006251 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006252 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006253 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6254 boolean hideStatusBarSysui =
6255 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006256 boolean hideNavBarSysui =
6257 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006258
John Spurlock27735a42013-08-14 17:57:38 -04006259 boolean transientStatusBarAllowed =
6260 mStatusBar != null && (
6261 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006262 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006263 || statusBarHasFocus);
6264
John Spurlockf1a36642013-10-12 17:50:42 -04006265 boolean transientNavBarAllowed =
6266 mNavigationBar != null &&
6267 hideNavBarSysui && immersiveSticky;
6268
John Spurlockf25706f2013-11-07 18:02:43 -05006269 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006270 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006271 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006272 && !transientNavBarAllowed;
6273 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006274 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006275 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006276 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006277 }
John Spurlock27735a42013-08-14 17:57:38 -04006278
6279 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6280
6281 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006282 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6283 boolean newImmersiveMode = isImmersiveMode(vis);
6284 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006285 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006286 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6287 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006288 }
John Spurlock27735a42013-08-14 17:57:38 -04006289
John Spurlockf1a36642013-10-12 17:50:42 -04006290 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6291
John Spurlocke1f366f2013-08-05 12:22:40 -04006292 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006293 }
6294
John Spurlockf1a36642013-10-12 17:50:42 -04006295 private void clearClearableFlagsLw() {
6296 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6297 if (newVal != mResettingSystemUiFlags) {
6298 mResettingSystemUiFlags = newVal;
6299 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6300 }
6301 }
6302
6303 private boolean isImmersiveMode(int vis) {
6304 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006305 return mNavigationBar != null
6306 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006307 && (vis & flags) != 0
6308 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006309 }
6310
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006311 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006312 * @return whether the navigation or status bar can be made translucent
6313 *
6314 * This should return true unless touch exploration is not enabled or
6315 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006316 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006317 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006318 return mTranslucentDecorEnabled
6319 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006320 }
6321
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006322 // Use this instead of checking config_showNavigationBar so that it can be consistently
6323 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006324 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006325 public boolean hasNavigationBar() {
6326 return mHasNavigationBar;
6327 }
6328
satok1bc0a492012-04-25 22:47:12 +09006329 @Override
6330 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6331 mLastInputMethodWindow = ime;
6332 mLastInputMethodTargetWindow = target;
6333 }
6334
Craig Mautnerf1b67412012-09-19 13:18:29 -07006335 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006336 public int getInputMethodWindowVisibleHeightLw() {
6337 return mDockBottom - mCurBottom;
6338 }
6339
6340 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006341 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006342 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006343 if (mKeyguardDelegate != null) {
6344 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006345 }
John Spurlock13451a22012-09-28 14:40:41 -04006346 if (mStatusBarService != null) {
6347 try {
6348 mStatusBarService.setCurrentUser(newUserId);
6349 } catch (RemoteException e) {
6350 // oh well
6351 }
6352 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006353 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006354 }
6355
6356 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006357 public boolean canMagnifyWindow(int windowType) {
6358 switch (windowType) {
6359 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6360 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6361 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6362 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6363 return false;
6364 }
6365 }
6366 return true;
6367 }
6368
6369 @Override
6370 public boolean isTopLevelWindow(int windowType) {
6371 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6372 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6373 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6374 }
6375 return true;
6376 }
6377
Jim Miller4eeb4f62012-11-08 00:04:29 -08006378 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006379 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006380 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006381 pw.print(" mSystemReady="); pw.print(mSystemReady);
6382 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006383 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006384 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006385 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006386 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006387 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6388 || mForceClearedSystemUiFlags != 0) {
6389 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6390 pw.print(Integer.toHexString(mLastSystemUiFlags));
6391 pw.print(" mResettingSystemUiFlags=0x");
6392 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6393 pw.print(" mForceClearedSystemUiFlags=0x");
6394 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006395 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006396 if (mLastFocusNeedsMenu) {
6397 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6398 pw.println(mLastFocusNeedsMenu);
6399 }
Jeff Browna20dda42014-05-27 20:57:24 -07006400 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6401 pw.println(mWakeGestureEnabledSetting);
6402
Jeff Brownbcdfc622014-03-06 19:13:04 -08006403 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006404 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6405 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006406 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6407 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6408 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6409 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006410 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006411 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006412 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6413 pw.print(mCarDockEnablesAccelerometer);
6414 pw.print(" mDeskDockEnablesAccelerometer=");
6415 pw.println(mDeskDockEnablesAccelerometer);
6416 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6417 pw.print(mLidKeyboardAccessibility);
6418 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006419 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006420 pw.print(prefix);
6421 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6422 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006423 pw.print(prefix);
6424 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6425 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006426 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006427 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6428 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6429 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6430 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6431 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6432 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6433 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006434 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6435 pw.print(","); pw.print(mOverscanScreenTop);
6436 pw.print(") "); pw.print(mOverscanScreenWidth);
6437 pw.print("x"); pw.println(mOverscanScreenHeight);
6438 if (mOverscanLeft != 0 || mOverscanTop != 0
6439 || mOverscanRight != 0 || mOverscanBottom != 0) {
6440 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6441 pw.print(" top="); pw.print(mOverscanTop);
6442 pw.print(" right="); pw.print(mOverscanRight);
6443 pw.print(" bottom="); pw.println(mOverscanBottom);
6444 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006445 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6446 pw.print(mRestrictedOverscanScreenLeft);
6447 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6448 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6449 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006450 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6451 pw.print(","); pw.print(mUnrestrictedScreenTop);
6452 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6453 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6454 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6455 pw.print(","); pw.print(mRestrictedScreenTop);
6456 pw.print(") "); pw.print(mRestrictedScreenWidth);
6457 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006458 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6459 pw.print(","); pw.print(mStableFullscreenTop);
6460 pw.print(")-("); pw.print(mStableFullscreenRight);
6461 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006462 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6463 pw.print(","); pw.print(mStableTop);
6464 pw.print(")-("); pw.print(mStableRight);
6465 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006466 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6467 pw.print(","); pw.print(mSystemTop);
6468 pw.print(")-("); pw.print(mSystemRight);
6469 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006470 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6471 pw.print(","); pw.print(mCurTop);
6472 pw.print(")-("); pw.print(mCurRight);
6473 pw.print(","); pw.print(mCurBottom); pw.println(")");
6474 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6475 pw.print(","); pw.print(mContentTop);
6476 pw.print(")-("); pw.print(mContentRight);
6477 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006478 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6479 pw.print(","); pw.print(mVoiceContentTop);
6480 pw.print(")-("); pw.print(mVoiceContentRight);
6481 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006482 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6483 pw.print(","); pw.print(mDockTop);
6484 pw.print(")-("); pw.print(mDockRight);
6485 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006486 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6487 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006488 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6489 pw.print(" mShowingDream="); pw.print(mShowingDream);
6490 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006491 if (mLastInputMethodWindow != null) {
6492 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6493 pw.println(mLastInputMethodWindow);
6494 }
6495 if (mLastInputMethodTargetWindow != null) {
6496 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6497 pw.println(mLastInputMethodTargetWindow);
6498 }
6499 if (mStatusBar != null) {
6500 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006501 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6502 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006503 }
6504 if (mNavigationBar != null) {
6505 pw.print(prefix); pw.print("mNavigationBar=");
6506 pw.println(mNavigationBar);
6507 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006508 if (mFocusedWindow != null) {
6509 pw.print(prefix); pw.print("mFocusedWindow=");
6510 pw.println(mFocusedWindow);
6511 }
6512 if (mFocusedApp != null) {
6513 pw.print(prefix); pw.print("mFocusedApp=");
6514 pw.println(mFocusedApp);
6515 }
6516 if (mWinDismissingKeyguard != null) {
6517 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6518 pw.println(mWinDismissingKeyguard);
6519 }
6520 if (mTopFullscreenOpaqueWindowState != null) {
6521 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6522 pw.println(mTopFullscreenOpaqueWindowState);
6523 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006524 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6525 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6526 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6527 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006528 if (mForcingShowNavBar) {
6529 pw.print(prefix); pw.print("mForcingShowNavBar=");
6530 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6531 pw.println(mForcingShowNavBarLayer);
6532 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006533 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006534 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006535 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6536 pw.print(" mForceStatusBarFromKeyguard=");
6537 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006538 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006539 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006540 pw.print(" mHomePressed="); pw.println(mHomePressed);
6541 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6542 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6543 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6544 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6545 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6546 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6547 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6548 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6549 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6550 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006551 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6552 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6553 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006554
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006555 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006556 mStatusBarController.dump(pw, prefix);
6557 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006558 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006559
Jeff Browna20dda42014-05-27 20:57:24 -07006560 if (mWakeGestureListener != null) {
6561 mWakeGestureListener.dump(pw, prefix);
6562 }
Jeff Brown600f0032014-05-22 17:06:00 -07006563 if (mOrientationListener != null) {
6564 mOrientationListener.dump(pw, prefix);
6565 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006566 if (mBurnInProtectionHelper != null) {
6567 mBurnInProtectionHelper.dump(prefix, pw);
6568 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006569 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006570}