blob: fce01e526389e6e03360278354b58623e0fc143a [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 Mautnerc9457fa2014-06-06 14:27:48 -07004218 if (mWinShowWhenLocked != null &&
4219 mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) {
4220 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4221 // fullscreen window.
4222 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4223 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4224 mTopFullscreenOpaqueWindowState.hideLw(false);
4225 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4226 }
4227
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004228 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004229 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004230
4231 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4232 ? mTopFullscreenOpaqueWindowState.getAttrs()
4233 : null;
4234
Jeff Brownc8018eb2012-10-29 21:33:27 -07004235 // If we are not currently showing a dream then remember the current
4236 // lockscreen state. We will use this to determine whether the dream
4237 // started while the lockscreen was showing and remember this state
4238 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004239 if (!mShowingDream) {
4240 mDreamingLockscreen = mShowingLockscreen;
4241 }
4242
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004243 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004244 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004245 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004246 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004247 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07004248 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004249 if (mStatusBarController.setBarShowingLw(true)) {
4250 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4251 }
Craig Mautner81defc72013-10-29 11:10:42 -07004252 // Maintain fullscreen layout until incoming animation is complete.
4253 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004254 // Transient status bar on the lockscreen is not allowed
4255 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4256 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4257 mLastSystemUiFlags, mLastSystemUiFlags);
4258 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004259 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004260 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004261 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004262 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004263 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004264 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004265 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004266 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004267 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004268 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004269 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004270 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004271 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4272 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004273 if (mStatusBarController.isTransientShowing()) {
4274 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004275 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4276 }
4277 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004278 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004279 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004280 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004281 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004282 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004283 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004284 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004285 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004286 if (mStatusBarController.setBarShowingLw(true)) {
4287 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4288 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004289 }
4290 }
4291 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004292
Craig Mautner81defc72013-10-29 11:10:42 -07004293 if (mTopIsFullscreen != topIsFullscreen) {
4294 if (!topIsFullscreen) {
4295 // Force another layout when status bar becomes fully shown.
4296 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4297 }
4298 mTopIsFullscreen = topIsFullscreen;
4299 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004300
Craig Mautner39834192012-09-02 07:47:24 -07004301 // Hide the key guard if a visible window explicitly specifies that it wants to be
4302 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004303 if (mKeyguardDelegate != null && mStatusBar != null) {
4304 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4305 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004306 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004307 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004308 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004309 changes |= FINISH_LAYOUT_REDO_LAYOUT
4310 | FINISH_LAYOUT_REDO_CONFIG
4311 | FINISH_LAYOUT_REDO_WALLPAPER;
4312 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004313 if (mKeyguardDelegate.isShowing()) {
4314 mHandler.post(new Runnable() {
4315 @Override
4316 public void run() {
4317 mKeyguardDelegate.keyguardDone(false, false);
4318 }
4319 });
4320 }
4321 } else if (mHideLockScreen) {
4322 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004323 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004324 changes |= FINISH_LAYOUT_REDO_LAYOUT
4325 | FINISH_LAYOUT_REDO_CONFIG
4326 | FINISH_LAYOUT_REDO_WALLPAPER;
4327 }
4328 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
4329 // This is the case of keyguard isSecure() and not mHideLockScreen.
4330 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4331 // Only launch the next keyguard unlock window once per window.
4332 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004333 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004334 changes |= FINISH_LAYOUT_REDO_LAYOUT
4335 | FINISH_LAYOUT_REDO_CONFIG
4336 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004337 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004338 mHandler.post(new Runnable() {
4339 @Override
4340 public void run() {
4341 mKeyguardDelegate.dismiss();
4342 }
4343 });
4344 }
4345 } else {
4346 mWinDismissingKeyguard = null;
4347 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004348 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004349 changes |= FINISH_LAYOUT_REDO_LAYOUT
4350 | FINISH_LAYOUT_REDO_CONFIG
4351 | FINISH_LAYOUT_REDO_WALLPAPER;
4352 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004353 }
4354 }
Joe Onorato664644d2011-01-23 17:53:23 -08004355
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004356 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004357 // If the navigation bar has been hidden or shown, we need to do another
4358 // layout pass to update that window.
4359 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4360 }
Joe Onorato664644d2011-01-23 17:53:23 -08004361
Mike Lockwood28569302010-01-28 11:54:40 -05004362 // update since mAllowLockscreenWhenOn might have changed
4363 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004364 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004365 }
4366
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004367 /**
Jim Millerab954542014-10-10 18:21:49 -07004368 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004369 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004370 * @return Whether the flags have changed and we have to redo the layout.
4371 */
Jim Millerab954542014-10-10 18:21:49 -07004372 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4373 boolean wasOccluded = mKeyguardOccluded;
4374 boolean showing = mKeyguardDelegate.isShowing();
4375 if (wasOccluded && !isOccluded && showing) {
4376 mKeyguardOccluded = false;
4377 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004378 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4379 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4380 return true;
Jim Millerab954542014-10-10 18:21:49 -07004381 } else if (!wasOccluded && isOccluded && showing) {
4382 mKeyguardOccluded = true;
4383 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004384 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4385 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4386 return true;
4387 } else {
4388 return false;
4389 }
4390 }
4391
4392 private boolean isStatusBarKeyguard() {
4393 return mStatusBar != null
4394 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4395 }
4396
Jose Lima9546b202014-07-02 17:21:51 -07004397 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004398 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004399 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004400 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004401 return false;
4402 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004403 return true;
4404 }
4405
Jose Lima9546b202014-07-02 17:21:51 -07004406 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004407 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004408 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004409 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004410 // If the navigation bar has been hidden or shown, we need to do another
4411 // layout pass to update that window.
4412 return FINISH_LAYOUT_REDO_LAYOUT;
4413 }
4414 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004415 }
4416
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004417 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004418 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004419 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4420 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004421 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4422 if (newLidState == mLidState) {
4423 return;
4424 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004425
Jeff Brownc458ce92012-04-30 14:58:40 -07004426 mLidState = newLidState;
4427 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004428 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004429
4430 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004431 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004432 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004433 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004434 }
4435 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004436
Michael Wright3818c922014-09-02 13:59:07 -07004437 @Override
4438 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4439 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4440 if (mCameraLensCoverState == lensCoverState) {
4441 return;
4442 }
4443 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4444 lensCoverState == CAMERA_LENS_UNCOVERED) {
4445 Intent intent;
4446 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4447 mKeyguardDelegate.isShowing();
4448 if (keyguardActive) {
4449 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4450 } else {
4451 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4452 }
Bryce Lee584a4452014-10-21 15:55:55 -07004453 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004454 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004455 }
4456 mCameraLensCoverState = lensCoverState;
4457 }
4458
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004459 void setHdmiPlugged(boolean plugged) {
4460 if (mHdmiPlugged != plugged) {
4461 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004462 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004463 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004464 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004465 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004466 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004467 }
4468 }
4469
Joe Onoratoea495d42011-04-06 11:41:11 -07004470 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004471 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004472 // watch for HDMI plug messages if the hdmi switch exists
4473 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4474 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4475
Joe Onoratoea495d42011-04-06 11:41:11 -07004476 final String filename = "/sys/class/switch/hdmi/state";
4477 FileReader reader = null;
4478 try {
4479 reader = new FileReader(filename);
4480 char[] buf = new char[15];
4481 int n = reader.read(buf);
4482 if (n > 1) {
4483 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4484 }
4485 } catch (IOException ex) {
4486 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4487 } catch (NumberFormatException ex) {
4488 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4489 } finally {
4490 if (reader != null) {
4491 try {
4492 reader.close();
4493 } catch (IOException ex) {
4494 }
Joe Onoratodc100302011-01-11 17:07:41 -08004495 }
4496 }
4497 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004498 // This dance forces the code in setHdmiPlugged to run.
4499 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4500 mHdmiPlugged = !plugged;
4501 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004502 }
4503
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004504 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004505 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004506
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004507 final Runnable mScreenshotTimeout = new Runnable() {
4508 @Override public void run() {
4509 synchronized (mScreenshotLock) {
4510 if (mScreenshotConnection != null) {
4511 mContext.unbindService(mScreenshotConnection);
4512 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004513 }
Winson Chung9112ec32011-06-27 13:15:32 -07004514 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004515 }
4516 };
4517
4518 // Assume this is called from the Handler thread.
4519 private void takeScreenshot() {
4520 synchronized (mScreenshotLock) {
4521 if (mScreenshotConnection != null) {
4522 return;
4523 }
4524 ComponentName cn = new ComponentName("com.android.systemui",
4525 "com.android.systemui.screenshot.TakeScreenshotService");
4526 Intent intent = new Intent();
4527 intent.setComponent(cn);
4528 ServiceConnection conn = new ServiceConnection() {
4529 @Override
4530 public void onServiceConnected(ComponentName name, IBinder service) {
4531 synchronized (mScreenshotLock) {
4532 if (mScreenshotConnection != this) {
4533 return;
4534 }
4535 Messenger messenger = new Messenger(service);
4536 Message msg = Message.obtain(null, 1);
4537 final ServiceConnection myConn = this;
4538 Handler h = new Handler(mHandler.getLooper()) {
4539 @Override
4540 public void handleMessage(Message msg) {
4541 synchronized (mScreenshotLock) {
4542 if (mScreenshotConnection == myConn) {
4543 mContext.unbindService(mScreenshotConnection);
4544 mScreenshotConnection = null;
4545 mHandler.removeCallbacks(mScreenshotTimeout);
4546 }
4547 }
4548 }
4549 };
4550 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004551 msg.arg1 = msg.arg2 = 0;
4552 if (mStatusBar != null && mStatusBar.isVisibleLw())
4553 msg.arg1 = 1;
4554 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4555 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004556 try {
4557 messenger.send(msg);
4558 } catch (RemoteException e) {
4559 }
4560 }
4561 }
4562 @Override
4563 public void onServiceDisconnected(ComponentName name) {}
4564 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004565 if (mContext.bindServiceAsUser(
4566 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004567 mScreenshotConnection = conn;
4568 mHandler.postDelayed(mScreenshotTimeout, 10000);
4569 }
4570 }
Winson Chung9112ec32011-06-27 13:15:32 -07004571 }
4572
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004573 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004574 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004575 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004576 if (!mSystemBooted) {
4577 // If we have not yet booted, don't let key events do anything.
4578 return 0;
4579 }
4580
Jeff Brown037c33e2014-04-09 00:31:55 -07004581 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004582 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4583 final boolean canceled = event.isCanceled();
4584 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004585
Jeff Brown3122e442010-10-11 23:32:49 -07004586 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004587
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004588 // If screen is off then we treat the case where the keyguard is open but hidden
4589 // the same as if it were open and in front.
4590 // This will prevent any keys other than the power button from waking the screen
4591 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004592 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004593 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004594 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004595 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004596
Jeff Brown40013652012-05-16 21:22:36 -07004597 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004598 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004599 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004600 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004601 }
4602
Jeff Brown037c33e2014-04-09 00:31:55 -07004603 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004604 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004605 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4606 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004607 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004608 // When the device is interactive or the key is injected pass the
4609 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004610 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004611 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004612 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4613 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4614 // to the application but preserve its wake key status to make sure we still move
4615 // from dozing to fully interactive if we would normally go from off to fully
4616 // interactive.
4617 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004618 } else {
4619 // When the screen is off and the key is not injected, determine whether
4620 // to wake the device but don't pass the key to the application.
4621 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004622 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4623 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004624 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004625 }
4626
Justin Kohd378ad72013-04-01 12:18:26 -07004627 // If the key would be handled globally, just return the result, don't worry about special
4628 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004629 if (isValidGlobalKey(keyCode)
4630 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004631 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004632 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004633 }
Justin Kohd378ad72013-04-01 12:18:26 -07004634 return result;
4635 }
4636
Jeff Brownbae8e772014-06-12 19:59:45 -07004637 boolean useHapticFeedback = down
4638 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4639 && event.getRepeatCount() == 0;
4640
Jeff Brown4d396052010-10-29 21:50:21 -07004641 // Handle special keys.
4642 switch (keyCode) {
4643 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004644 case KeyEvent.KEYCODE_VOLUME_UP:
4645 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004646 if (mUseTvRouting) {
4647 // On TVs volume keys never go to the foreground app
4648 result &= ~ACTION_PASS_TO_USER;
4649 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004650 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4651 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004652 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004653 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004654 mScreenshotChordVolumeDownKeyTriggered = true;
4655 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4656 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004657 cancelPendingPowerKeyAction();
4658 interceptScreenshotChord();
4659 }
4660 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004661 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004662 cancelPendingScreenshotChordAction();
4663 }
4664 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4665 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004666 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004667 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004668 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004669 cancelPendingPowerKeyAction();
4670 cancelPendingScreenshotChordAction();
4671 }
4672 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004673 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004674 cancelPendingScreenshotChordAction();
4675 }
4676 }
Jeff Brown4d396052010-10-29 21:50:21 -07004677 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004678 TelecomManager telecomManager = getTelecommService();
4679 if (telecomManager != null) {
4680 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004681 // If an incoming call is ringing, either VOLUME key means
4682 // "silence ringer". We handle these keys here, rather than
4683 // in the InCallScreen, to make sure we'll respond to them
4684 // even if the InCallScreen hasn't come to the foreground yet.
4685 // Look for the DOWN event here, to agree with the "fallback"
4686 // behavior in the InCallScreen.
4687 Log.i(TAG, "interceptKeyBeforeQueueing:"
4688 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004689
Santos Cordon6848f722014-05-21 15:22:12 -07004690 // Silence the ringer. (It's safe to call this
4691 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004692 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004693
Santos Cordon6848f722014-05-21 15:22:12 -07004694 // And *don't* pass this key thru to the current activity
4695 // (which is probably the InCallScreen.)
4696 result &= ~ACTION_PASS_TO_USER;
4697 break;
4698 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004699 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004700 && (result & ACTION_PASS_TO_USER) == 0) {
4701 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004702 // the application, just pass it to the session service.
4703
4704 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004705 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004706 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004707 }
4708 }
4709
RoboErik430fc482014-06-12 15:49:20 -07004710 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004711 if (mUseTvRouting) {
4712 dispatchDirectAudioEvent(event);
4713 } else {
4714 // If we aren't passing to the user and no one else
4715 // handled it send it to the session manager to
4716 // figure out.
4717 MediaSessionLegacyHelper.getHelper(mContext)
4718 .sendVolumeKeyEvent(event, true);
4719 }
Jeff Brown4d396052010-10-29 21:50:21 -07004720 break;
4721 }
4722 }
4723 break;
4724 }
4725
4726 case KeyEvent.KEYCODE_ENDCALL: {
4727 result &= ~ACTION_PASS_TO_USER;
4728 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004729 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004730 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004731 if (telecomManager != null) {
4732 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004733 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004734 if (interactive && !hungUp) {
4735 mEndCallKeyHandled = false;
4736 mHandler.postDelayed(mEndCallLongPress,
4737 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4738 } else {
4739 mEndCallKeyHandled = true;
4740 }
Jeff Brown4d396052010-10-29 21:50:21 -07004741 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004742 if (!mEndCallKeyHandled) {
4743 mHandler.removeCallbacks(mEndCallLongPress);
4744 if (!canceled) {
4745 if ((mEndcallBehavior
4746 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4747 if (goHome()) {
4748 break;
4749 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004750 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004751 if ((mEndcallBehavior
4752 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4753 mPowerManager.goToSleep(event.getEventTime(),
4754 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4755 isWakeKey = false;
4756 }
Jeff Brown4d396052010-10-29 21:50:21 -07004757 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004758 }
Jeff Brown4d396052010-10-29 21:50:21 -07004759 }
4760 break;
4761 }
4762
4763 case KeyEvent.KEYCODE_POWER: {
4764 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004765 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004766 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004767 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004768 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004769 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004770 }
4771 break;
4772 }
4773
Jeff Brown6212a492014-03-07 13:58:47 -08004774 case KeyEvent.KEYCODE_SLEEP: {
4775 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004776 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004777 if (!mPowerManager.isInteractive()) {
4778 useHapticFeedback = false; // suppress feedback if already non-interactive
4779 }
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004780 sleepPress(event);
Jeff Brown6212a492014-03-07 13:58:47 -08004781 break;
4782 }
4783
4784 case KeyEvent.KEYCODE_WAKEUP: {
4785 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004786 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004787 break;
4788 }
4789
Jeff Brown4d396052010-10-29 21:50:21 -07004790 case KeyEvent.KEYCODE_MEDIA_PLAY:
4791 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4792 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004793 case KeyEvent.KEYCODE_HEADSETHOOK:
4794 case KeyEvent.KEYCODE_MUTE:
4795 case KeyEvent.KEYCODE_MEDIA_STOP:
4796 case KeyEvent.KEYCODE_MEDIA_NEXT:
4797 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4798 case KeyEvent.KEYCODE_MEDIA_REWIND:
4799 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004800 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4801 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004802 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4803 // If the global session is active pass all media keys to it
4804 // instead of the active window.
4805 result &= ~ACTION_PASS_TO_USER;
4806 }
Jeff Brown4d396052010-10-29 21:50:21 -07004807 if ((result & ACTION_PASS_TO_USER) == 0) {
4808 // Only do this if we would otherwise not pass it to the user. In that
4809 // case, the PhoneWindow class will do the same thing, except it will
4810 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004811 // Note that we need to make a copy of the key event here because the
4812 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004813 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004814 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4815 new KeyEvent(event));
4816 msg.setAsynchronous(true);
4817 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004818 }
4819 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004820 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004821
Jeff Brown4d396052010-10-29 21:50:21 -07004822 case KeyEvent.KEYCODE_CALL: {
4823 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004824 TelecomManager telecomManager = getTelecommService();
4825 if (telecomManager != null) {
4826 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004827 Log.i(TAG, "interceptKeyBeforeQueueing:"
4828 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004829 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004830
Santos Cordon6848f722014-05-21 15:22:12 -07004831 // And *don't* pass this key thru to the current activity
4832 // (which is presumably the InCallScreen.)
4833 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004834 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004835 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004836 }
Jeff Brown4d396052010-10-29 21:50:21 -07004837 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004838 }
Michael Wright869a67c2014-08-26 19:33:06 -07004839 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4840 // Only do this if we would otherwise not pass it to the user. In that case,
4841 // interceptKeyBeforeDispatching would apply a similar but different policy in
4842 // order to invoke voice assist actions. Note that we need to make a copy of the
4843 // key event here because the original key event will be recycled when we return.
4844 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4845 mBroadcastWakeLock.acquire();
4846 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4847 keyguardActive ? 1 : 0, 0);
4848 msg.setAsynchronous(true);
4849 msg.sendToTarget();
4850 }
4851 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004852 }
Jeff Brown26875502014-01-30 21:47:47 -08004853
Jeff Brownbae8e772014-06-12 19:59:45 -07004854 if (useHapticFeedback) {
4855 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4856 }
4857
Jeff Brown26875502014-01-30 21:47:47 -08004858 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004859 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004860 }
Bryce Lee584a4452014-10-21 15:55:55 -07004861
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004862 return result;
4863 }
4864
Jeff Brown1c2e4942012-11-06 16:32:01 -08004865 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004866 * Returns true if the key can have global actions attached to it.
4867 * We reserve all power management keys for the system since they require
4868 * very careful handling.
4869 */
4870 private static boolean isValidGlobalKey(int keyCode) {
4871 switch (keyCode) {
4872 case KeyEvent.KEYCODE_POWER:
4873 case KeyEvent.KEYCODE_WAKEUP:
4874 case KeyEvent.KEYCODE_SLEEP:
4875 return false;
4876 default:
4877 return true;
4878 }
4879 }
4880
4881 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08004882 * When the screen is off we ignore some keys that might otherwise typically
4883 * be considered wake keys. We filter them out here.
4884 *
4885 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4886 * is always considered a wake key.
4887 */
4888 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4889 switch (keyCode) {
4890 // ignore volume keys unless docked
4891 case KeyEvent.KEYCODE_VOLUME_UP:
4892 case KeyEvent.KEYCODE_VOLUME_DOWN:
4893 case KeyEvent.KEYCODE_VOLUME_MUTE:
4894 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4895
4896 // ignore media and camera keys
4897 case KeyEvent.KEYCODE_MUTE:
4898 case KeyEvent.KEYCODE_HEADSETHOOK:
4899 case KeyEvent.KEYCODE_MEDIA_PLAY:
4900 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4901 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4902 case KeyEvent.KEYCODE_MEDIA_STOP:
4903 case KeyEvent.KEYCODE_MEDIA_NEXT:
4904 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4905 case KeyEvent.KEYCODE_MEDIA_REWIND:
4906 case KeyEvent.KEYCODE_MEDIA_RECORD:
4907 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004908 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004909 case KeyEvent.KEYCODE_CAMERA:
4910 return false;
4911 }
4912 return true;
4913 }
4914
4915
Jeff Brown56194eb2011-03-02 19:23:13 -08004916 /** {@inheritDoc} */
4917 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004918 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4919 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08004920 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
4921 return 0;
4922 }
Michael Wright70af00a2014-09-03 19:30:20 -07004923 }
Bryce Lee5c138322014-11-03 08:26:09 -08004924
Michael Wright70af00a2014-09-03 19:30:20 -07004925 if (shouldDispatchInputWhenNonInteractive()) {
4926 return ACTION_PASS_TO_USER;
4927 }
Bryce Lee5c138322014-11-03 08:26:09 -08004928
Bryce Lee812d7022014-11-10 13:33:28 -08004929 // If we have not passed the action up and we are in theater mode without dreaming,
4930 // there will be no dream to intercept the touch and wake into ambient. The device should
4931 // wake up in this case.
4932 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
4933 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
4934 }
4935
Jeff Brown037c33e2014-04-09 00:31:55 -07004936 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004937 }
4938
Michael Wright70af00a2014-09-03 19:30:20 -07004939 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08004940 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07004941 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
4942 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08004943 return true;
4944 }
4945
4946 // Send events to a dozing dream even if the screen is off since the dream
4947 // is in control of the state of the screen.
4948 IDreamManager dreamManager = getDreamManager();
4949
4950 try {
4951 if (dreamManager != null && dreamManager.isDreaming()) {
4952 return true;
4953 }
4954 } catch (RemoteException e) {
4955 Slog.e(TAG, "RemoteException when checking if dreaming", e);
4956 }
4957
4958 // Otherwise, consume events since the user can't see what is being
4959 // interacted with.
4960 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07004961 }
4962
RoboErik001c59c2015-01-26 15:53:51 -08004963 private void dispatchDirectAudioEvent(KeyEvent event) {
4964 if (event.getAction() != KeyEvent.ACTION_DOWN) {
4965 return;
4966 }
4967 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04004968 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
4969 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08004970 String pkgName = mContext.getOpPackageName();
4971 switch (keyCode) {
4972 case KeyEvent.KEYCODE_VOLUME_UP:
4973 try {
John Spurlockee5ad722015-03-03 16:17:21 -05004974 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04004975 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08004976 } catch (RemoteException e) {
4977 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
4978 }
4979 break;
4980 case KeyEvent.KEYCODE_VOLUME_DOWN:
4981 try {
John Spurlockee5ad722015-03-03 16:17:21 -05004982 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04004983 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08004984 } catch (RemoteException e) {
4985 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
4986 }
4987 break;
4988 case KeyEvent.KEYCODE_VOLUME_MUTE:
4989 try {
4990 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05004991 getAudioService().adjustSuggestedStreamVolume(
4992 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04004993 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08004994 }
4995 } catch (RemoteException e) {
4996 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
4997 }
4998 break;
4999 }
5000 }
5001
Jeff Brown40013652012-05-16 21:22:36 -07005002 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5003 if (DEBUG_INPUT) {
5004 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005005 }
5006
Jeff Brown40013652012-05-16 21:22:36 -07005007 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5008 if (DEBUG_INPUT) {
5009 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5010 }
5011
5012 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5013 mHavePendingMediaKeyRepeatWithWakeLock = false;
5014 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5015 }
5016
5017 dispatchMediaKeyWithWakeLockToAudioService(event);
5018
5019 if (event.getAction() == KeyEvent.ACTION_DOWN
5020 && event.getRepeatCount() == 0) {
5021 mHavePendingMediaKeyRepeatWithWakeLock = true;
5022
5023 Message msg = mHandler.obtainMessage(
5024 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5025 msg.setAsynchronous(true);
5026 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5027 } else {
5028 mBroadcastWakeLock.release();
5029 }
5030 }
5031
5032 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5033 mHavePendingMediaKeyRepeatWithWakeLock = false;
5034
5035 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5036 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5037 if (DEBUG_INPUT) {
5038 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5039 }
5040
5041 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5042 mBroadcastWakeLock.release();
5043 }
5044
5045 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5046 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005047 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005048 }
5049 }
5050
Michael Wright869a67c2014-08-26 19:33:06 -07005051 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
5052 Intent voiceIntent =
5053 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5054 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005055 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005056 mBroadcastWakeLock.release();
5057 }
5058
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005059 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005060 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005061 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005062 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5063 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5064 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005065 } else {
5066 try {
5067 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5068 ServiceManager.getService(Context.UI_MODE_SERVICE));
5069 mUiMode = uiModeService.getCurrentModeType();
5070 } catch (RemoteException e) {
5071 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005072 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005073 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005074 synchronized (mLock) {
5075 updateOrientationListenerLp();
5076 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005077 }
5078 };
5079
Jeff Brown6aaf2952012-10-05 16:01:08 -07005080 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5081 @Override
5082 public void onReceive(Context context, Intent intent) {
5083 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005084 if (mKeyguardDelegate != null) {
5085 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005086 }
5087 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005088 if (mKeyguardDelegate != null) {
5089 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005090 }
5091 }
5092 }
5093 };
5094
Christopher Tate5e08af02012-09-21 17:17:22 -07005095 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5096 @Override
5097 public void onReceive(Context context, Intent intent) {
5098 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5099 // tickle the settings observer: this first ensures that we're
5100 // observing the relevant settings for the newly-active user,
5101 // and then updates our own bookkeeping based on the now-
5102 // current user.
5103 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005104
5105 // force a re-application of focused window sysui visibility.
5106 // the window may never have been shown for this user
5107 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005108 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005109 mLastSystemUiFlags = 0;
5110 updateSystemUiVisibilityLw();
5111 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005112 }
5113 }
5114 };
5115
John Spurlockd9b70bd2014-02-06 17:02:44 -05005116 private final Runnable mRequestTransientNav = new Runnable() {
5117 @Override
5118 public void run() {
5119 requestTransientBars(mNavigationBar);
5120 }
5121 };
5122
John Spurlocke1f366f2013-08-05 12:22:40 -04005123 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005124 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005125 if (!isUserSetupComplete()) {
5126 // Swipe-up for navigation bar is disabled during setup
5127 return;
5128 }
John Spurlock27735a42013-08-14 17:57:38 -04005129 boolean sb = mStatusBarController.checkShowTransientBarLw();
5130 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005131 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005132 // Don't show status bar when swiping on already visible navigation bar
5133 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005134 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005135 return;
5136 }
John Spurlock27735a42013-08-14 17:57:38 -04005137 if (sb) mStatusBarController.showTransient();
5138 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005139 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005140 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005141 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005142 }
5143 }
5144
Jeff Brown3ee549c2014-09-22 20:14:39 -07005145 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005146 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07005147 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005148 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07005149 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005150
5151 // We must get this work done here because the power manager will drop
5152 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005153 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005154 mAwake = false;
5155 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005156 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005157 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005158 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005159 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005160
5161 if (mKeyguardDelegate != null) {
5162 mKeyguardDelegate.onScreenTurnedOff(why);
5163 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005164 }
5165
Jeff Brown13f00f02014-10-31 14:45:50 -07005166 private void wakeUpFromPowerKey(long eventTime) {
5167 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5168 }
5169
Bryce Lee5c138322014-11-03 08:26:09 -08005170 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Lee584a4452014-10-21 15:55:55 -07005171 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005172 return false;
Bryce Lee584a4452014-10-21 15:55:55 -07005173 }
5174
5175 mPowerManager.wakeUp(wakeTime);
Bryce Lee5c138322014-11-03 08:26:09 -08005176 return true;
Bryce Lee584a4452014-10-21 15:55:55 -07005177 }
5178
Jeff Brown3ee549c2014-09-22 20:14:39 -07005179 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005180 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07005181 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005182 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07005183 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005184
Jeff Brown3ee549c2014-09-22 20:14:39 -07005185 // Since goToSleep performs these functions synchronously, we must
5186 // do the same here. We cannot post this work to a handler because
5187 // that might cause it to become reordered with respect to what
5188 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005189 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005190 mAwake = true;
5191 mKeyguardDrawComplete = false;
5192 if (mKeyguardDelegate != null) {
5193 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5194 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5195 }
5196
Jeff Browna20dda42014-05-27 20:57:24 -07005197 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005198 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005199 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005200 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005201
Jim Miller5ecd8112013-01-09 18:50:26 -08005202 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07005203 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005204 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005205 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005206 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005207 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005208 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005209 }
5210
Jeff Brown36c4db82014-09-19 12:05:31 -07005211 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005212 synchronized (mLock) {
5213 if (!mAwake || mKeyguardDrawComplete) {
5214 return; // spurious
5215 }
5216
Jeff Brown36c4db82014-09-19 12:05:31 -07005217 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005218 if (mKeyguardDelegate != null) {
5219 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5220 }
5221 }
5222
5223 finishScreenTurningOn();
5224 }
5225
5226 // Called on the DisplayManager's DisplayPowerController thread.
5227 @Override
5228 public void screenTurnedOff() {
5229 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5230
5231 synchronized (mLock) {
5232 mScreenOnEarly = false;
5233 mScreenOnFully = false;
5234 mWindowManagerDrawComplete = false;
5235 mScreenOnListener = null;
5236 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005237 }
5238 }
5239
Jeff Brown3ee549c2014-09-22 20:14:39 -07005240 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005241 @Override
5242 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005243 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005244
Jeff Brown3ee549c2014-09-22 20:14:39 -07005245 synchronized (mLock) {
5246 mScreenOnEarly = true;
5247 mScreenOnFully = false;
5248 mWindowManagerDrawComplete = false;
5249 mScreenOnListener = screenOnListener;
5250 updateOrientationListenerLp();
5251 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005252
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005253 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5254 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005255 // ... eventually calls finishWindowsDrawn
5256 }
5257
Jeff Brown36c4db82014-09-19 12:05:31 -07005258 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005259 synchronized (mLock) {
5260 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5261 return; // spurious
5262 }
5263
Jeff Brown36c4db82014-09-19 12:05:31 -07005264 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005265 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005266
5267 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005268 }
5269
Craig Mautner8a0da012014-05-31 15:13:37 -07005270 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005271 final ScreenOnListener listener;
5272 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005273 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005274 if (DEBUG_WAKEUP) Slog.d(TAG,
5275 "finishScreenTurningOn: mAwake=" + mAwake
5276 + ", mScreenOnEarly=" + mScreenOnEarly
5277 + ", mScreenOnFully=" + mScreenOnFully
5278 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5279 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5280
5281 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5282 || (mAwake && !mKeyguardDrawComplete)) {
5283 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005284 }
5285
Jeff Brown3ee549c2014-09-22 20:14:39 -07005286 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5287 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005288 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005289 mScreenOnFully = true;
5290
5291 // Remember the first time we draw the keyguard so we know when we're done with
5292 // the main part of booting and can enable the screen and hide boot messages.
5293 if (!mKeyguardDrawnOnce && mAwake) {
5294 mKeyguardDrawnOnce = true;
5295 enableScreen = true;
5296 if (mBootMessageNeedsHiding) {
5297 mBootMessageNeedsHiding = false;
5298 hideBootMessages();
5299 }
5300 } else {
5301 enableScreen = false;
5302 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005303 }
5304
Jeff Brown3ee549c2014-09-22 20:14:39 -07005305 if (listener != null) {
5306 listener.onScreenOn();
5307 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005308
Jeff Brown3ee549c2014-09-22 20:14:39 -07005309 if (enableScreen) {
5310 try {
5311 mWindowManager.enableScreenIfNeeded();
5312 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005313 }
Craig Mautnera631d492014-08-05 15:16:01 -07005314 }
5315 }
5316
5317 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005318 synchronized (mLock) {
5319 if (!mKeyguardDrawnOnce) {
5320 mBootMessageNeedsHiding = true;
5321 return; // keyguard hasn't drawn the first time yet, not done booting
5322 }
Craig Mautnera631d492014-08-05 15:16:01 -07005323 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005324
5325 if (mBootMsgDialog != null) {
5326 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5327 mBootMsgDialog.dismiss();
5328 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005329 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005330 }
5331
5332 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005333 public boolean isScreenOn() {
5334 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005335 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005336
Dianne Hackborn08743722009-12-21 12:16:51 -08005337 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005338 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005339 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005340 if (mKeyguardDelegate != null) {
5341 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005342 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005343 }
5344
5345 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005346 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005347 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005348 if (mKeyguardDelegate != null) {
5349 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005350 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005351 }
5352
Jim Millerab954542014-10-10 18:21:49 -07005353 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005354 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005355 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005356 }
5357
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005358 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005359 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005360 public boolean isKeyguardLocked() {
5361 return keyguardOn();
5362 }
5363
5364 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005365 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005366 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005367 if (mKeyguardDelegate == null) return false;
5368 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005369 }
5370
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005371 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005372 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005373 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005374 if (mKeyguardDelegate == null) return false;
5375 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005376 }
5377
Jose Lima9546b202014-07-02 17:21:51 -07005378 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005379 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005380 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005381 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005382 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005383 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005384 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005385 // ask the keyguard to prompt the user to authenticate if necessary
5386 mKeyguardDelegate.dismiss();
5387 }
5388 });
5389 }
5390 }
5391
5392 public void notifyActivityDrawnForKeyguardLw() {
5393 if (mKeyguardDelegate != null) {
5394 mHandler.post(new Runnable() {
5395 @Override
5396 public void run() {
5397 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005398 }
5399 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005400 }
5401 }
5402
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005403 @Override
5404 public boolean isKeyguardDrawnLw() {
5405 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005406 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005407 }
5408 }
5409
Jorim Jaggi0d674622014-05-21 01:34:15 +02005410 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005411 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005412 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005413 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005414 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005415 }
5416 }
5417
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005418 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005419 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005420 }
5421
5422 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005423 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005424 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005425
Jeff Brown01a98dd2011-09-20 15:08:29 -07005426 @Override
5427 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005428 if (false) {
5429 Slog.v(TAG, "rotationForOrientationLw(orient="
5430 + orientation + ", last=" + lastRotation
5431 + "); user=" + mUserRotation + " "
5432 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5433 ? "USER_ROTATION_LOCKED" : "")
5434 );
5435 }
5436
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005437 if (mForceDefaultOrientation) {
5438 return Surface.ROTATION_0;
5439 }
5440
The Android Open Source Project0727d222009-03-11 12:11:58 -07005441 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005442 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5443 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005444 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005445 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005446
Jeff Browndec6cf42011-11-15 14:08:20 -08005447 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005448 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005449 // Ignore sensor when lid switch is open and rotation is forced.
5450 preferredRotation = mLidOpenRotation;
5451 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005452 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005453 // Ignore sensor when in car dock unless explicitly enabled.
5454 // This case can override the behavior of NOSENSOR, and can also
5455 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005456 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005457 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005458 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5459 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5460 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005461 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005462 // Ignore sensor when in desk dock unless explicitly enabled.
5463 // This case can override the behavior of NOSENSOR, and can also
5464 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005465 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005466 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005467 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5468 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005469 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005470 preferredRotation = mDemoHdmiRotation;
5471 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5472 && mUndockedHdmiRotation >= 0) {
5473 // Ignore sensor when plugged into HDMI and an undocked orientation has
5474 // been specified in the configuration (only for legacy devices without
5475 // full multi-display support).
5476 // Note that the dock orientation overrides the HDMI orientation.
5477 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005478 } else if (mDemoRotationLock) {
5479 // Ignore sensor when demo rotation lock is enabled.
5480 // Note that the dock orientation and HDMI rotation lock override this.
5481 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005482 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5483 // Application just wants to remain locked in the last rotation.
5484 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005485 } else if (!mSupportAutoRotation) {
5486 // If we don't support auto-rotation then bail out here and ignore
5487 // the sensor and any rotation lock settings.
5488 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005489 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005490 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005491 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5492 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5493 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5494 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005495 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5496 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5497 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5498 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5499 // Otherwise, use sensor only if requested by the application or enabled
5500 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005501 if (mAllowAllRotations < 0) {
5502 // Can't read this during init() because the context doesn't
5503 // have display metrics at that time so we cannot determine
5504 // tablet vs. phone then.
5505 mAllowAllRotations = mContext.getResources().getBoolean(
5506 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5507 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005508 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005509 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005510 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5511 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005512 preferredRotation = sensorRotation;
5513 } else {
5514 preferredRotation = lastRotation;
5515 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005516 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5517 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5518 // Apply rotation lock. Does not apply to NOSENSOR.
5519 // The idea is that the user rotation expresses a weak preference for the direction
5520 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5521 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005522 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005523 } else {
5524 // No overriding preference.
5525 // We will do exactly what the application asked us to do.
5526 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005527 }
5528
Dianne Hackborne5439f22010-10-02 16:53:50 -07005529 switch (orientation) {
5530 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005531 // Return portrait unless overridden.
5532 if (isAnyPortrait(preferredRotation)) {
5533 return preferredRotation;
5534 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005535 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005536
Jeff Brown01a98dd2011-09-20 15:08:29 -07005537 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005538 // Return landscape unless overridden.
5539 if (isLandscapeOrSeascape(preferredRotation)) {
5540 return preferredRotation;
5541 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005542 return mLandscapeRotation;
5543
5544 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005545 // Return reverse portrait unless overridden.
5546 if (isAnyPortrait(preferredRotation)) {
5547 return preferredRotation;
5548 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005549 return mUpsideDownRotation;
5550
5551 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005552 // Return seascape unless overridden.
5553 if (isLandscapeOrSeascape(preferredRotation)) {
5554 return preferredRotation;
5555 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005556 return mSeascapeRotation;
5557
5558 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005559 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005560 // Return either landscape rotation.
5561 if (isLandscapeOrSeascape(preferredRotation)) {
5562 return preferredRotation;
5563 }
5564 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005565 return lastRotation;
5566 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005567 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005568
Jeff Brown01a98dd2011-09-20 15:08:29 -07005569 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005570 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005571 // Return either portrait rotation.
5572 if (isAnyPortrait(preferredRotation)) {
5573 return preferredRotation;
5574 }
5575 if (isAnyPortrait(lastRotation)) {
5576 return lastRotation;
5577 }
5578 return mPortraitRotation;
5579
5580 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005581 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5582 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005583 if (preferredRotation >= 0) {
5584 return preferredRotation;
5585 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005586 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005587 }
5588 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005589 }
5590
Jeff Brown01a98dd2011-09-20 15:08:29 -07005591 @Override
5592 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5593 switch (orientation) {
5594 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5595 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5596 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5597 return isAnyPortrait(rotation);
5598
5599 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5600 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5601 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5602 return isLandscapeOrSeascape(rotation);
5603
5604 default:
5605 return true;
5606 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005607 }
5608
Jeff Brownc0347aa2011-09-23 17:26:09 -07005609 @Override
5610 public void setRotationLw(int rotation) {
5611 mOrientationListener.setCurrentRotation(rotation);
5612 }
5613
Jeff Brown01a98dd2011-09-20 15:08:29 -07005614 private boolean isLandscapeOrSeascape(int rotation) {
5615 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005616 }
5617
Jeff Brown01a98dd2011-09-20 15:08:29 -07005618 private boolean isAnyPortrait(int rotation) {
5619 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005620 }
5621
Jose Lima9546b202014-07-02 17:21:51 -07005622 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005623 public int getUserRotationMode() {
5624 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005625 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5626 WindowManagerPolicy.USER_ROTATION_FREE :
5627 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005628 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005629
5630 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005631 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005632 public void setUserRotationMode(int mode, int rot) {
5633 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005634
5635 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005636 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005637 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005638 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005639 rot,
5640 UserHandle.USER_CURRENT);
5641 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005642 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005643 0,
5644 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005645 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005646 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005647 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005648 1,
5649 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005650 }
5651 }
5652
Jose Lima9546b202014-07-02 17:21:51 -07005653 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005654 public void setSafeMode(boolean safeMode) {
5655 mSafeMode = safeMode;
5656 performHapticFeedbackLw(null, safeMode
5657 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5658 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005659 }
Craig Mautnereda67292013-04-28 13:50:14 -07005660
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005661 static long[] getLongIntArray(Resources r, int resid) {
5662 int[] ar = r.getIntArray(resid);
5663 if (ar == null) {
5664 return null;
5665 }
5666 long[] out = new long[ar.length];
5667 for (int i=0; i<ar.length; i++) {
5668 out[i] = ar[i];
5669 }
5670 return out;
5671 }
Craig Mautnereda67292013-04-28 13:50:14 -07005672
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005673 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005674 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005675 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005676 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005677 mKeyguardDelegate.onSystemReady();
5678
Michael Wright3818c922014-09-02 13:59:07 -07005679 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005680 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005681 synchronized (mLock) {
5682 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005683 mSystemReady = true;
5684 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005685 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005686 public void run() {
5687 updateSettings();
5688 }
5689 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005690 }
5691 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005692
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005693 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005694 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005695 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005696 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005697 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005698 mKeyguardDelegate.onBootCompleted();
5699 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005700 synchronized (mLock) {
5701 mSystemBooted = true;
5702 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005703 wakingUp();
5704 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005705 }
5706
Dianne Hackborn661cd522011-08-22 00:26:20 -07005707 ProgressDialog mBootMsgDialog = null;
5708
5709 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005710 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005711 public void showBootMessage(final CharSequence msg, final boolean always) {
5712 mHandler.post(new Runnable() {
5713 @Override public void run() {
5714 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005715 int theme;
5716 if (mContext.getPackageManager().hasSystemFeature(
5717 PackageManager.FEATURE_WATCH)) {
5718 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5719 } else if (mContext.getPackageManager().hasSystemFeature(
5720 PackageManager.FEATURE_TELEVISION)) {
5721 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5722 } else {
5723 theme = 0;
5724 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005725
5726 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005727 // This dialog will consume all events coming in to
5728 // it, to avoid it trying to do things too early in boot.
5729 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5730 return true;
5731 }
5732 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5733 return true;
5734 }
5735 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5736 return true;
5737 }
5738 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5739 return true;
5740 }
5741 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5742 return true;
5743 }
5744 @Override public boolean dispatchPopulateAccessibilityEvent(
5745 AccessibilityEvent event) {
5746 return true;
5747 }
5748 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005749 if (mContext.getPackageManager().isUpgrade()) {
5750 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5751 } else {
5752 mBootMsgDialog.setTitle(R.string.android_start_title);
5753 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005754 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5755 mBootMsgDialog.setIndeterminate(true);
5756 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005757 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005758 mBootMsgDialog.getWindow().addFlags(
5759 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5760 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5761 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005762 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5763 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5764 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005765 mBootMsgDialog.setCancelable(false);
5766 mBootMsgDialog.show();
5767 }
5768 mBootMsgDialog.setMessage(msg);
5769 }
5770 });
5771 }
5772
5773 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005774 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005775 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005776 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005777 }
5778
Mike Lockwood28569302010-01-28 11:54:40 -05005779 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005780 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005781 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005782 // ***************************************
5783 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5784 // ***************************************
5785 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5786 // WITH ITS LOCKS HELD.
5787 //
5788 // This code must be VERY careful about the locks
5789 // it acquires.
5790 // In fact, the current code acquires way too many,
5791 // and probably has lurking deadlocks.
5792
Mike Lockwood28569302010-01-28 11:54:40 -05005793 synchronized (mScreenLockTimeout) {
5794 if (mLockScreenTimerActive) {
5795 // reset the timer
5796 mHandler.removeCallbacks(mScreenLockTimeout);
5797 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5798 }
5799 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005800 }
5801
Adam Cohenf7522022012-10-03 20:03:18 -07005802 class ScreenLockTimeout implements Runnable {
5803 Bundle options;
5804
5805 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005806 public void run() {
5807 synchronized (this) {
5808 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005809 if (mKeyguardDelegate != null) {
5810 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005811 }
Mike Lockwood28569302010-01-28 11:54:40 -05005812 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005813 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005814 }
5815 }
Mike Lockwood28569302010-01-28 11:54:40 -05005816
Adam Cohenf7522022012-10-03 20:03:18 -07005817 public void setLockOptions(Bundle options) {
5818 this.options = options;
5819 }
5820 }
5821
5822 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5823
Jose Lima9546b202014-07-02 17:21:51 -07005824 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005825 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005826 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5827 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005828 if (options != null) {
5829 // In case multiple calls are made to lockNow, we don't wipe out the options
5830 // until the runnable actually executes.
5831 mScreenLockTimeout.setLockOptions(options);
5832 }
Jim Miller93c518e2012-01-17 15:55:31 -08005833 mHandler.post(mScreenLockTimeout);
5834 }
5835
Mike Lockwood28569302010-01-28 11:54:40 -05005836 private void updateLockScreenTimeout() {
5837 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005838 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005839 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005840 if (mLockScreenTimerActive != enable) {
5841 if (enable) {
5842 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5843 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5844 } else {
5845 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5846 mHandler.removeCallbacks(mScreenLockTimeout);
5847 }
5848 mLockScreenTimerActive = enable;
5849 }
5850 }
5851 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005852
5853 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005854 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005855 public void enableScreenAfterBoot() {
5856 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005857 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005858 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005859 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005860
Jeff Brownc458ce92012-04-30 14:58:40 -07005861 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005862 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005863 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005864 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005865 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005866 }
Jeff Browna20dda42014-05-27 20:57:24 -07005867
5868 synchronized (mLock) {
5869 updateWakeGestureListenerLp();
5870 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005871 }
5872
Jeff Brown4f5fa282014-06-12 19:19:15 -07005873 void updateUiMode() {
5874 if (mUiModeManager == null) {
5875 mUiModeManager = IUiModeManager.Stub.asInterface(
5876 ServiceManager.getService(Context.UI_MODE_SERVICE));
5877 }
5878 try {
5879 mUiMode = mUiModeManager.getCurrentModeType();
5880 } catch (RemoteException e) {
5881 }
5882 }
5883
Jeff Brown01a98dd2011-09-20 15:08:29 -07005884 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005885 try {
5886 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005887 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5888 } catch (RemoteException e) {
5889 // Ignore
5890 }
5891 }
5892
5893 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5894 try {
5895 //set orientation on WindowManager
5896 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005897 } catch (RemoteException e) {
5898 // Ignore
5899 }
5900 }
5901
Daniel Sandler6396c722013-04-16 20:19:09 -04005902 /**
5903 * Return an Intent to launch the currently active dock app as home. Returns
5904 * null if the standard home should be launched, which is the case if any of the following is
5905 * true:
5906 * <ul>
5907 * <li>The device is not in either car mode or desk mode
5908 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5909 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5910 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5911 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5912 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005913 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005914 */
5915 Intent createHomeDockIntent() {
5916 Intent intent = null;
5917
5918 // What home does is based on the mode, not the dock state. That
5919 // is, when in car mode you should be taken to car home regardless
5920 // of whether we are actually in a car dock.
5921 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5922 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5923 intent = mCarDockIntent;
5924 }
5925 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5926 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5927 intent = mDeskDockIntent;
5928 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005929 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5930 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5931 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5932 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5933 // Always launch dock home from home when watch is docked, if it exists.
5934 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005935 }
5936
5937 if (intent == null) {
5938 return null;
5939 }
5940
5941 ActivityInfo ai = null;
5942 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5943 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005944 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005945 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005946 if (info != null) {
5947 ai = info.activityInfo;
5948 }
5949 if (ai != null
5950 && ai.metaData != null
5951 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5952 intent = new Intent(intent);
5953 intent.setClassName(ai.packageName, ai.name);
5954 return intent;
5955 }
5956
5957 return null;
5958 }
5959
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005960 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
5961 if (awakenFromDreams) {
5962 awakenDreams();
5963 }
Daniel Sandler6396c722013-04-16 20:19:09 -04005964
5965 Intent dock = createHomeDockIntent();
5966 if (dock != null) {
5967 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005968 if (fromHomeKey) {
5969 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5970 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00005971 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04005972 return;
5973 } catch (ActivityNotFoundException e) {
5974 }
5975 }
5976
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005977 Intent intent;
5978
5979 if (fromHomeKey) {
5980 intent = new Intent(mHomeIntent);
5981 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5982 } else {
5983 intent = mHomeIntent;
5984 }
5985
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00005986 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005987 }
Craig Mautnereda67292013-04-28 13:50:14 -07005988
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005989 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005990 * goes to the home screen
5991 * @return whether it did anything
5992 */
5993 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00005994 if (!isUserSetupComplete()) {
5995 Slog.i(TAG, "Not going home because user setup is in progress.");
5996 return false;
5997 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005998 if (false) {
5999 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006000 try {
6001 ActivityManagerNative.getDefault().stopAppSwitches();
6002 } catch (RemoteException e) {
6003 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006004 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006005 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006006 } else {
6007 // This code brings home to the front or, if it is already
6008 // at the front, puts the device to sleep.
6009 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006010 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6011 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6012 Log.d(TAG, "UTS-TEST-MODE");
6013 } else {
6014 ActivityManagerNative.getDefault().stopAppSwitches();
6015 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006016 Intent dock = createHomeDockIntent();
6017 if (dock != null) {
6018 int result = ActivityManagerNative.getDefault()
6019 .startActivityAsUser(null, null, dock,
6020 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6021 null, null, 0,
6022 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006023 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006024 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6025 return false;
6026 }
6027 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006028 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006029 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006030 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006031 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006032 null, null, 0,
6033 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006034 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006035 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006036 return false;
6037 }
6038 } catch (RemoteException ex) {
6039 // bummer, the activity manager, which is in this process, is dead
6040 }
6041 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006042 return true;
6043 }
Craig Mautnereda67292013-04-28 13:50:14 -07006044
6045 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006046 public void setCurrentOrientationLw(int newOrientation) {
6047 synchronized (mLock) {
6048 if (newOrientation != mCurrentAppOrientation) {
6049 mCurrentAppOrientation = newOrientation;
6050 updateOrientationListenerLp();
6051 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006052 }
6053 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006054
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006055 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6056 if (!isGlobalAccessibilityGestureEnabled()) {
6057 return;
6058 }
6059 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6060 Context.AUDIO_SERVICE);
6061 if (audioManager.isSilentMode()) {
6062 return;
6063 }
6064 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6065 Settings.System.DEFAULT_NOTIFICATION_URI);
6066 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6067 ringTone.play();
6068 }
Craig Mautnereda67292013-04-28 13:50:14 -07006069
Bryce Lee584a4452014-10-21 15:55:55 -07006070 private boolean isTheaterModeEnabled() {
6071 return Settings.Global.getInt(mContext.getContentResolver(),
6072 Settings.Global.THEATER_MODE_ON, 0) == 1;
6073 }
6074
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006075 private boolean isGlobalAccessibilityGestureEnabled() {
6076 return Settings.Global.getInt(mContext.getContentResolver(),
6077 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6078 }
6079
Craig Mautnereda67292013-04-28 13:50:14 -07006080 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006081 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006082 if (!mVibrator.hasVibrator()) {
6083 return false;
6084 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006085 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6086 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006087 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006088 return false;
6089 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006090 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006091 switch (effectId) {
6092 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006093 pattern = mLongPressVibePattern;
6094 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006095 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006096 pattern = mVirtualKeyVibePattern;
6097 break;
6098 case HapticFeedbackConstants.KEYBOARD_TAP:
6099 pattern = mKeyboardTapVibePattern;
6100 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006101 case HapticFeedbackConstants.CLOCK_TICK:
6102 pattern = mClockTickVibePattern;
6103 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006104 case HapticFeedbackConstants.CALENDAR_DATE:
6105 pattern = mCalendarDateVibePattern;
6106 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006107 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006108 pattern = mSafeModeDisabledVibePattern;
6109 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006110 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006111 pattern = mSafeModeEnabledVibePattern;
6112 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006113 default:
6114 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006115 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006116 int owningUid;
6117 String owningPackage;
6118 if (win != null) {
6119 owningUid = win.getOwningUid();
6120 owningPackage = win.getOwningPackage();
6121 } else {
6122 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006123 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006124 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006125 if (pattern.length == 1) {
6126 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006127 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006128 } else {
6129 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006130 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006131 }
6132 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006133 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006134
6135 @Override
6136 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006137 }
6138
Jeff Brownc38c9be2012-10-04 13:16:19 -07006139 @Override
6140 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006141 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006142 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006143 }
6144 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006145
Dianne Hackborndf89e652011-10-06 22:35:11 -07006146 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006147 // If there is no window focused, there will be nobody to handle the events
6148 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006149 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6150 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006151 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006152 return 0;
6153 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006154 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006155 // We are updating at a point where the keyguard has gotten
6156 // focus, but we were last in a state where the top window is
6157 // hiding it. This is probably because the keyguard as been
6158 // shown while the top window was displayed, so we want to ignore
6159 // it here because this is just a very transient change and it
6160 // will quickly lose focus once it correctly gets hidden.
6161 return 0;
6162 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006163
John Spurlock1db8b682014-02-18 11:18:59 -05006164 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006165 & ~mResettingSystemUiFlags
6166 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006167 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006168 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006169 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006170 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006171 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006172 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006173 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006174 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006175 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006176 return 0;
6177 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006178 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006179 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006180 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006181 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006182 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006183 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006184 try {
6185 IStatusBarService statusbar = getStatusBarService();
6186 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006187 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006188 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006189 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006190 } catch (RemoteException e) {
6191 // re-acquire status bar service next time it is needed.
6192 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006193 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006194 }
6195 });
6196 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006197 }
6198
Adrian Rooscd3884d2015-02-18 17:25:23 +01006199 private int updateLightStatusBarLw(int vis) {
6200 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6201 ? mStatusBar
6202 : mTopFullscreenOpaqueOrDimmingWindowState;
6203
6204 if (statusColorWin != null) {
6205 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6206 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6207 // its light flag.
6208 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6209 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6210 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6211 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6212 // Otherwise if it's dimming, clear the light flag.
6213 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6214 }
6215 }
6216 return vis;
6217 }
6218
John Spurlock79da8332013-09-20 12:04:47 -04006219 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006220 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006221 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6222 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006223 : mTopFullscreenOpaqueWindowState;
6224 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6225 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6226
John Spurlock27735a42013-08-14 17:57:38 -04006227 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04006228 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006229 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006230 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6231 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006232 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006233 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6234 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006235 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006236 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6237 }
John Spurlockbd957402013-10-03 11:38:39 -04006238 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006239 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006240
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006241 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006242 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6243 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006244 }
6245
John Spurlock27735a42013-08-14 17:57:38 -04006246 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006247 boolean immersiveSticky =
6248 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006249 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006250 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006251 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006252 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6253 boolean hideStatusBarSysui =
6254 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006255 boolean hideNavBarSysui =
6256 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006257
John Spurlock27735a42013-08-14 17:57:38 -04006258 boolean transientStatusBarAllowed =
6259 mStatusBar != null && (
6260 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006261 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006262 || statusBarHasFocus);
6263
John Spurlockf1a36642013-10-12 17:50:42 -04006264 boolean transientNavBarAllowed =
6265 mNavigationBar != null &&
6266 hideNavBarSysui && immersiveSticky;
6267
John Spurlockf25706f2013-11-07 18:02:43 -05006268 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006269 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006270 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006271 && !transientNavBarAllowed;
6272 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006273 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006274 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006275 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006276 }
John Spurlock27735a42013-08-14 17:57:38 -04006277
6278 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6279
6280 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006281 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6282 boolean newImmersiveMode = isImmersiveMode(vis);
6283 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006284 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006285 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6286 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006287 }
John Spurlock27735a42013-08-14 17:57:38 -04006288
John Spurlockf1a36642013-10-12 17:50:42 -04006289 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6290
John Spurlocke1f366f2013-08-05 12:22:40 -04006291 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006292 }
6293
John Spurlockf1a36642013-10-12 17:50:42 -04006294 private void clearClearableFlagsLw() {
6295 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6296 if (newVal != mResettingSystemUiFlags) {
6297 mResettingSystemUiFlags = newVal;
6298 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6299 }
6300 }
6301
6302 private boolean isImmersiveMode(int vis) {
6303 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006304 return mNavigationBar != null
6305 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006306 && (vis & flags) != 0
6307 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006308 }
6309
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006310 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006311 * @return whether the navigation or status bar can be made translucent
6312 *
6313 * This should return true unless touch exploration is not enabled or
6314 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006315 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006316 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006317 return mTranslucentDecorEnabled
6318 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006319 }
6320
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006321 // Use this instead of checking config_showNavigationBar so that it can be consistently
6322 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006323 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006324 public boolean hasNavigationBar() {
6325 return mHasNavigationBar;
6326 }
6327
satok1bc0a492012-04-25 22:47:12 +09006328 @Override
6329 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6330 mLastInputMethodWindow = ime;
6331 mLastInputMethodTargetWindow = target;
6332 }
6333
Craig Mautnerf1b67412012-09-19 13:18:29 -07006334 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006335 public int getInputMethodWindowVisibleHeightLw() {
6336 return mDockBottom - mCurBottom;
6337 }
6338
6339 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006340 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006341 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006342 if (mKeyguardDelegate != null) {
6343 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006344 }
John Spurlock13451a22012-09-28 14:40:41 -04006345 if (mStatusBarService != null) {
6346 try {
6347 mStatusBarService.setCurrentUser(newUserId);
6348 } catch (RemoteException e) {
6349 // oh well
6350 }
6351 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006352 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006353 }
6354
6355 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006356 public boolean canMagnifyWindow(int windowType) {
6357 switch (windowType) {
6358 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6359 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6360 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6361 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6362 return false;
6363 }
6364 }
6365 return true;
6366 }
6367
6368 @Override
6369 public boolean isTopLevelWindow(int windowType) {
6370 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6371 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6372 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6373 }
6374 return true;
6375 }
6376
Jim Miller4eeb4f62012-11-08 00:04:29 -08006377 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006378 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006379 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006380 pw.print(" mSystemReady="); pw.print(mSystemReady);
6381 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006382 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006383 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006384 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006385 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006386 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6387 || mForceClearedSystemUiFlags != 0) {
6388 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6389 pw.print(Integer.toHexString(mLastSystemUiFlags));
6390 pw.print(" mResettingSystemUiFlags=0x");
6391 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6392 pw.print(" mForceClearedSystemUiFlags=0x");
6393 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006394 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006395 if (mLastFocusNeedsMenu) {
6396 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6397 pw.println(mLastFocusNeedsMenu);
6398 }
Jeff Browna20dda42014-05-27 20:57:24 -07006399 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6400 pw.println(mWakeGestureEnabledSetting);
6401
Jeff Brownbcdfc622014-03-06 19:13:04 -08006402 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006403 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6404 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006405 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6406 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6407 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6408 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006409 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006410 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006411 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6412 pw.print(mCarDockEnablesAccelerometer);
6413 pw.print(" mDeskDockEnablesAccelerometer=");
6414 pw.println(mDeskDockEnablesAccelerometer);
6415 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6416 pw.print(mLidKeyboardAccessibility);
6417 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006418 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006419 pw.print(prefix);
6420 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6421 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006422 pw.print(prefix);
6423 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6424 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006425 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006426 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6427 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6428 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6429 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6430 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6431 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6432 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006433 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6434 pw.print(","); pw.print(mOverscanScreenTop);
6435 pw.print(") "); pw.print(mOverscanScreenWidth);
6436 pw.print("x"); pw.println(mOverscanScreenHeight);
6437 if (mOverscanLeft != 0 || mOverscanTop != 0
6438 || mOverscanRight != 0 || mOverscanBottom != 0) {
6439 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6440 pw.print(" top="); pw.print(mOverscanTop);
6441 pw.print(" right="); pw.print(mOverscanRight);
6442 pw.print(" bottom="); pw.println(mOverscanBottom);
6443 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006444 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6445 pw.print(mRestrictedOverscanScreenLeft);
6446 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6447 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6448 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006449 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6450 pw.print(","); pw.print(mUnrestrictedScreenTop);
6451 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6452 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6453 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6454 pw.print(","); pw.print(mRestrictedScreenTop);
6455 pw.print(") "); pw.print(mRestrictedScreenWidth);
6456 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006457 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6458 pw.print(","); pw.print(mStableFullscreenTop);
6459 pw.print(")-("); pw.print(mStableFullscreenRight);
6460 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006461 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6462 pw.print(","); pw.print(mStableTop);
6463 pw.print(")-("); pw.print(mStableRight);
6464 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006465 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6466 pw.print(","); pw.print(mSystemTop);
6467 pw.print(")-("); pw.print(mSystemRight);
6468 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006469 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6470 pw.print(","); pw.print(mCurTop);
6471 pw.print(")-("); pw.print(mCurRight);
6472 pw.print(","); pw.print(mCurBottom); pw.println(")");
6473 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6474 pw.print(","); pw.print(mContentTop);
6475 pw.print(")-("); pw.print(mContentRight);
6476 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006477 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6478 pw.print(","); pw.print(mVoiceContentTop);
6479 pw.print(")-("); pw.print(mVoiceContentRight);
6480 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006481 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6482 pw.print(","); pw.print(mDockTop);
6483 pw.print(")-("); pw.print(mDockRight);
6484 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006485 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6486 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006487 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6488 pw.print(" mShowingDream="); pw.print(mShowingDream);
6489 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006490 if (mLastInputMethodWindow != null) {
6491 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6492 pw.println(mLastInputMethodWindow);
6493 }
6494 if (mLastInputMethodTargetWindow != null) {
6495 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6496 pw.println(mLastInputMethodTargetWindow);
6497 }
6498 if (mStatusBar != null) {
6499 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006500 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6501 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006502 }
6503 if (mNavigationBar != null) {
6504 pw.print(prefix); pw.print("mNavigationBar=");
6505 pw.println(mNavigationBar);
6506 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006507 if (mFocusedWindow != null) {
6508 pw.print(prefix); pw.print("mFocusedWindow=");
6509 pw.println(mFocusedWindow);
6510 }
6511 if (mFocusedApp != null) {
6512 pw.print(prefix); pw.print("mFocusedApp=");
6513 pw.println(mFocusedApp);
6514 }
6515 if (mWinDismissingKeyguard != null) {
6516 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6517 pw.println(mWinDismissingKeyguard);
6518 }
6519 if (mTopFullscreenOpaqueWindowState != null) {
6520 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6521 pw.println(mTopFullscreenOpaqueWindowState);
6522 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006523 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6524 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6525 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6526 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006527 if (mForcingShowNavBar) {
6528 pw.print(prefix); pw.print("mForcingShowNavBar=");
6529 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6530 pw.println(mForcingShowNavBarLayer);
6531 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006532 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006533 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006534 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6535 pw.print(" mForceStatusBarFromKeyguard=");
6536 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006537 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006538 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006539 pw.print(" mHomePressed="); pw.println(mHomePressed);
6540 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6541 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6542 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6543 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6544 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6545 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6546 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6547 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6548 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6549 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006550 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6551 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6552 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006553
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006554 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006555 mStatusBarController.dump(pw, prefix);
6556 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006557 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006558
Jeff Browna20dda42014-05-27 20:57:24 -07006559 if (mWakeGestureListener != null) {
6560 mWakeGestureListener.dump(pw, prefix);
6561 }
Jeff Brown600f0032014-05-22 17:06:00 -07006562 if (mOrientationListener != null) {
6563 mOrientationListener.dump(pw, prefix);
6564 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006565 if (mBurnInProtectionHelper != null) {
6566 mBurnInProtectionHelper.dump(prefix, pw);
6567 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006568 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006569}