blob: f94c77b08d8b8e47338ded472461b0f86c5f787b [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;
Jeff Brown061ea992015-04-17 19:55:47 -070020import android.app.ActivityManagerInternal;
21import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080022import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080023import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040024import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070025import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070026import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040027import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080028import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070029import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080030import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040031import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080032import android.content.ContentResolver;
33import android.content.Context;
34import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070035import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070036import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080037import android.content.pm.ActivityInfo;
38import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040039import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070040import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.content.res.Configuration;
42import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070043import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080044import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080045import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080046import android.graphics.Rect;
John Spurlock7b414672014-07-18 13:02:39 -040047import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080048import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050049import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080050import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070051import android.media.Ringtone;
52import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070053import android.media.session.MediaSessionLegacyHelper;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070054import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080055import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070056import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080057import android.os.Handler;
58import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080059import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070060import android.os.Message;
61import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080062import android.os.PowerManager;
63import android.os.RemoteException;
64import android.os.ServiceManager;
65import android.os.SystemClock;
66import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080067import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070068import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080069import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070070import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080071import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070072import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040073import android.service.dreams.DreamService;
74import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070075import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070076import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070077import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080078import android.util.EventLog;
79import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070080import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080081import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070082import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080083import android.view.Gravity;
84import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080085import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080086import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070087import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070088import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080089import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080090import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080091import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080092import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080093import android.view.KeyEvent;
94import android.view.MotionEvent;
Adam Powell6711f3b2015-05-06 15:57:09 -070095import com.android.internal.policy.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080096import android.view.Surface;
97import android.view.View;
98import android.view.ViewConfiguration;
99import 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
Adrian Roosddc8b272015-05-21 16:28:27 -0700210 // The panic gesture may become active only after the keyguard is dismissed and the immersive
211 // app shows again. If that doesn't happen for 30s we drop the gesture.
212 private static final long PANIC_GESTURE_EXPIRATION = 30000;
213
Jim Miller5ecd8112013-01-09 18:50:26 -0800214 /**
215 * Keyguard stuff
216 */
217 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100218 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700219 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800220
Jeff Brown6651a632011-11-28 12:59:11 -0800221 /* Table of Application Launch keys. Maps from key codes to intent categories.
222 *
223 * These are special keys that are used to launch particular kinds of applications,
224 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
225 * usage page. We don't support quite that many yet...
226 */
227 static SparseArray<String> sApplicationLaunchKeyCategories;
228 static {
229 sApplicationLaunchKeyCategories = new SparseArray<String>();
230 sApplicationLaunchKeyCategories.append(
231 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
232 sApplicationLaunchKeyCategories.append(
233 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
234 sApplicationLaunchKeyCategories.append(
235 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
236 sApplicationLaunchKeyCategories.append(
237 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
238 sApplicationLaunchKeyCategories.append(
239 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
240 sApplicationLaunchKeyCategories.append(
241 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
242 }
243
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700244 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
245 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
246
Dianne Hackborndf89e652011-10-06 22:35:11 -0700247 /**
248 * Lock protecting internal state. Must not call out into window
249 * manager with lock held. (This lock will be acquired in places
250 * where the window manager is calling in with its own lock held.)
251 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800252 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700253
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800254 Context mContext;
255 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700256 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700257 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700258 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700259 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700260 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400261 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700262 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700263 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800264 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700265 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800266 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000267 BurnInProtectionHelper mBurnInProtectionHelper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800268
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700269 // Vibrator pattern for haptic feedback of a long press.
270 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700271
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700272 // Vibrator pattern for haptic feedback of virtual key press.
273 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700274
Amith Yamasanic33cb712010-02-10 15:21:49 -0800275 // Vibrator pattern for a short vibration.
276 long[] mKeyboardTapVibePattern;
277
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700278 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
279 long[] mClockTickVibePattern;
280
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700281 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
282 long[] mCalendarDateVibePattern;
283
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700284 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
285 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700286
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700287 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
288 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700289
Mady Mellore82067b2015-04-30 09:58:35 -0700290 // Vibrator pattern for haptic feedback of a stylus button press.
291 long[] mStylusButtonPressVibePattern;
292
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800293 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
294 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400295
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800296 boolean mSafeMode;
297 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700298 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400299 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400300 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700301 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400302 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
303 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
304 int[] mNavigationBarHeightForRotation = new int[4];
305 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400306
Craig Mautnera631d492014-08-05 15:16:01 -0700307 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800308 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700309 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700310 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700311 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700312 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
313 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
314 }
315 };
316 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
317 @Override
318 public void onShown(IBinder windowToken) {
319 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
320 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
321 }
322 };
323
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800324 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800325 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900326 WindowState mLastInputMethodWindow = null;
327 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800328
Jeff Brown13f00f02014-10-31 14:45:50 -0700329 // FIXME This state is shared between the input reader and handler thread.
330 // Technically it's broken and buggy but it has been like this for many years
331 // and we have not yet seen any problems. Someday we'll rewrite this logic
332 // so that only one thread is involved in handling input policy. Unfortunately
333 // it's on a critical path for power management so we can't just post the work to the
334 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
335 // to hold wakelocks during dispatch and eliminating the critical path.
336 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800337 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700338 volatile int mPowerKeyPressCounter;
339 volatile boolean mEndCallKeyHandled;
340
Winson Chungd42a6cf2014-06-03 16:24:04 -0700341 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700342 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700343 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800344
Jeff Brown2e7760e2012-04-11 15:14:55 -0700345 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700346 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700347 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800348
Dianne Hackbornc777e072010-02-12 13:07:59 -0800349 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700350 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800351 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700352 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400353 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700354 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700355 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400356 int mCarDockRotation;
357 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700358 int mUndockedHdmiRotation;
359 int mDemoHdmiRotation;
360 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800361 int mDemoRotation;
362 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400363
Jeff Browna20dda42014-05-27 20:57:24 -0700364 boolean mWakeGestureEnabledSetting;
365 MyWakeGestureListener mWakeGestureListener;
366
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700367 // Default display does not rotate, apps that require non-default orientation will have to
368 // have the orientation emulated.
369 private boolean mForceDefaultOrientation = false;
370
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400371 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
372 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700373 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400374
Jeff Brownbcdfc622014-03-06 19:13:04 -0800375 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700376 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400377 boolean mCarDockEnablesAccelerometer;
378 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700379 int mLidKeyboardAccessibility;
380 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700381 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700382 int mShortPressOnPowerBehavior;
383 int mLongPressOnPowerBehavior;
384 int mDoublePressOnPowerBehavior;
385 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000386 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700387 boolean mAwake;
388 boolean mScreenOnEarly;
389 boolean mScreenOnFully;
390 ScreenOnListener mScreenOnListener;
391 boolean mKeyguardDrawComplete;
392 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800393 boolean mOrientationSensorEnabled = false;
394 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800395 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400396 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800397 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700398
Jeff Brown70825162012-03-28 17:27:48 -0700399 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800400
401 // The last window we were told about in focusChanged.
402 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800403 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800404
Jeff Brown70825162012-03-28 17:27:48 -0700405 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800406
Dianne Hackbornc652de82013-02-15 16:32:56 -0800407 // The current size of the screen; really; extends into the overscan area of
408 // the screen and doesn't account for any system elements like the status bar.
409 int mOverscanScreenLeft, mOverscanScreenTop;
410 int mOverscanScreenWidth, mOverscanScreenHeight;
411 // The current visible size of the screen; really; (ir)regardless of whether the status
412 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800413 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
414 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800415 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
416 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
417 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700418 // The current size of the screen; these may be different than (0,0)-(dw,dh)
419 // if the status bar can't be hidden; in that case it effectively carves out
420 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800421 int mRestrictedScreenLeft, mRestrictedScreenTop;
422 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700423 // During layout, the current screen borders accounting for any currently
424 // visible system UI elements.
425 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700426 // For applications requesting stable content insets, these are them.
427 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700428 // For applications requesting stable content insets but have also set the
429 // fullscreen window flag, these are the stable dimensions without the status bar.
430 int mStableFullscreenLeft, mStableFullscreenTop;
431 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800432 // During layout, the current screen borders with all outer decoration
433 // (status bar, input method dock) accounted for.
434 int mCurLeft, mCurTop, mCurRight, mCurBottom;
435 // During layout, the frame in which content should be displayed
436 // to the user, accounting for all screen decoration except for any
437 // space they deem as available for other content. This is usually
438 // the same as mCur*, but may be larger if the screen decor has supplied
439 // content insets.
440 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700441 // During layout, the frame in which voice content should be displayed
442 // to the user, accounting for all screen decoration except for any
443 // space they deem as available for other content.
444 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800445 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800446 // windows are placed.
447 int mDockLeft, mDockTop, mDockRight, mDockBottom;
448 // During layout, the layer at which the doc window is placed.
449 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700450 // During layout, this is the layer of the status bar.
451 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700452 int mLastSystemUiFlags;
453 // Bits that we are in the process of clearing, so we want to prevent
454 // them from being set by applications until everything has been updated
455 // to have them clear.
456 int mResettingSystemUiFlags = 0;
457 // Bits that we are currently always keeping cleared.
458 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800459 // What we last reported to system UI about whether the compatibility
460 // menu needs to be displayed.
461 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700462 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
463 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700464
Selim Cinekf83e8242015-05-19 18:08:14 -0700465 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700466
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800467 static final Rect mTmpParentFrame = new Rect();
468 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800469 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800470 static final Rect mTmpContentFrame = new Rect();
471 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400472 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700473 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700474 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700475
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800476 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100477 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700478 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200479 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400480 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800481 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700482 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700483 private boolean mForceStatusBarTransparent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700484 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800485 boolean mForcingShowNavBar;
486 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700487
488 // States of keyguard dismiss.
489 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
490 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
491 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
492 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
493
494 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
495 * be done once per window. */
496 private WindowState mWinDismissingKeyguard;
497
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700498 /** The window that is currently showing "over" the keyguard. If there is an app window
499 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
500 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
501 * the wallpaper. */
502 private WindowState mWinShowWhenLocked;
503
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700504 boolean mShowingLockscreen;
505 boolean mShowingDream;
506 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700507 boolean mDreamingSleepTokenNeeded;
508 SleepToken mDreamingSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700509 boolean mKeyguardSecure;
510 boolean mKeyguardSecureIncludingHidden;
511 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800512 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700513 boolean mHomeConsumed;
514 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800515 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700516 Intent mCarDockIntent;
517 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700518 boolean mSearchKeyShortcutPending;
519 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700520 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700521 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800522
Mike Lockwood28569302010-01-28 11:54:40 -0500523 // support for activating the lock screen while the screen is on
524 boolean mAllowLockscreenWhenOn;
525 int mLockScreenTimeout;
526 boolean mLockScreenTimerActive;
527
David Brownbaf8d092010-03-08 21:52:59 -0800528 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800529 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800530
531 // Behavior of POWER button while in-call and screen on.
532 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
533 int mIncallPowerBehavior;
534
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700535 Display mDisplay;
536
Dianne Hackborn9d132642011-04-21 17:26:39 -0700537 int mLandscapeRotation = 0; // default landscape rotation
538 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
539 int mPortraitRotation = 0; // default portrait rotation
540 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700541
Dianne Hackbornc652de82013-02-15 16:32:56 -0800542 int mOverscanLeft = 0;
543 int mOverscanTop = 0;
544 int mOverscanRight = 0;
545 int mOverscanBottom = 0;
546
Joe Onorato46b0d682010-11-22 17:37:27 -0800547 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700548 private int mLongPressOnHomeBehavior;
549
550 // What we do when the user double-taps on home
551 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800552
Bryce Lee584a4452014-10-21 15:55:55 -0700553 // Allowed theater mode wake actions
554 private boolean mAllowTheaterModeWakeFromKey;
555 private boolean mAllowTheaterModeWakeFromPowerKey;
556 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800557 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700558 private boolean mAllowTheaterModeWakeFromCameraLens;
559 private boolean mAllowTheaterModeWakeFromLidSwitch;
560 private boolean mAllowTheaterModeWakeFromWakeGesture;
561
Bryce Leed3b28402015-03-09 15:49:13 +0000562 // Whether to support long press from power button in non-interactive mode
563 private boolean mSupportLongPressPowerWhenNonInteractive;
564
Bryce Lee55e846d2014-11-04 12:43:44 -0800565 // Whether to go to sleep entering theater mode from power button
566 private boolean mGoToSleepOnButtonPressTheaterMode;
567
Winson Chung9112ec32011-06-27 13:15:32 -0700568 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700569 // Time to volume and power must be pressed within this interval of each other.
570 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700571 // Increase the chord delay when taking a screenshot from the keyguard
572 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800573 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700574 private boolean mScreenshotChordVolumeDownKeyTriggered;
575 private long mScreenshotChordVolumeDownKeyTime;
576 private boolean mScreenshotChordVolumeDownKeyConsumed;
577 private boolean mScreenshotChordVolumeUpKeyTriggered;
578 private boolean mScreenshotChordPowerKeyTriggered;
579 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700580
Michael Wrightb854e242013-02-05 17:54:02 -0800581 /* The number of steps between min and max brightness */
582 private static final int BRIGHTNESS_STEPS = 10;
583
Christopher Tate5e08af02012-09-21 17:17:22 -0700584 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800585 ShortcutManager mShortcutManager;
586 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700587 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700588 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800589
Craig Mautnerd625ab22013-09-06 13:40:31 -0700590 private int mCurrentUserId;
591
Justin Kohd378ad72013-04-01 12:18:26 -0700592 // Maps global key codes to the components that will handle them.
593 private GlobalKeyManager mGlobalKeyManager;
594
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700595 // Fallback actions by key code.
596 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
597 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800598
Jorim Jaggi76a16232014-08-08 17:00:47 +0200599 private final LogDecelerateInterpolator mLogDecelerateInterpolator
600 = new LogDecelerateInterpolator(100, 0);
601
Jeff Brown70825162012-03-28 17:27:48 -0700602 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
603 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700604 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
605 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700606 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
607 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
608 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700609 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700610 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700611 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700612 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700613 private static final int MSG_POWER_DELAYED_PRESS = 13;
614 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700615 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jeff Brown70825162012-03-28 17:27:48 -0700616
617 private class PolicyHandler extends Handler {
618 @Override
619 public void handleMessage(Message msg) {
620 switch (msg.what) {
621 case MSG_ENABLE_POINTER_LOCATION:
622 enablePointerLocation();
623 break;
624 case MSG_DISABLE_POINTER_LOCATION:
625 disablePointerLocation();
626 break;
Jeff Brown40013652012-05-16 21:22:36 -0700627 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
628 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
629 break;
630 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
631 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
632 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700633 case MSG_DISPATCH_SHOW_RECENTS:
634 showRecentApps(false);
635 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700636 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
637 showGlobalActionsInternal();
638 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700639 case MSG_KEYGUARD_DRAWN_COMPLETE:
640 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700641 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700642 break;
643 case MSG_KEYGUARD_DRAWN_TIMEOUT:
644 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700645 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700646 break;
647 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
648 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700649 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700650 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700651 case MSG_HIDE_BOOT_MESSAGE:
652 handleHideBootMessage();
653 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700654 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
655 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
656 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700657 case MSG_POWER_DELAYED_PRESS:
658 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
659 finishPowerKeyPress();
660 break;
661 case MSG_POWER_LONG_PRESS:
662 powerLongPress();
663 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700664 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
665 updateDreamingSleepToken(msg.arg1 != 0);
666 break;
Jeff Brown70825162012-03-28 17:27:48 -0700667 }
668 }
669 }
670
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800671 private UEventObserver mHDMIObserver = new UEventObserver() {
672 @Override
673 public void onUEvent(UEventObserver.UEvent event) {
674 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
675 }
676 };
677
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800678 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800679 SettingsObserver(Handler handler) {
680 super(handler);
681 }
David Brownbaf8d092010-03-08 21:52:59 -0800682
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800683 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700684 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800685 ContentResolver resolver = mContext.getContentResolver();
686 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700687 Settings.System.END_BUTTON_BEHAVIOR), false, this,
688 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800689 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700690 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
691 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700692 resolver.registerContentObserver(Settings.Secure.getUriFor(
693 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
694 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800695 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700696 Settings.System.ACCELEROMETER_ROTATION), false, this,
697 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500698 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700699 Settings.System.USER_ROTATION), false, this,
700 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400701 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700702 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
703 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800704 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700705 Settings.System.POINTER_LOCATION), false, this,
706 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800707 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700708 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
709 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500710 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400711 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700712 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500713 resolver.registerContentObserver(Settings.Global.getUriFor(
714 Settings.Global.POLICY_CONTROL), false, this,
715 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800716 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800717 }
718
719 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800720 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700721 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800722 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800723 }
Craig Mautner967212c2013-04-13 21:10:58 -0700724
Jeff Browna20dda42014-05-27 20:57:24 -0700725 class MyWakeGestureListener extends WakeGestureListener {
726 MyWakeGestureListener(Context context, Handler handler) {
727 super(context, handler);
728 }
729
730 @Override
731 public void onWakeUp() {
732 synchronized (mLock) {
733 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700734 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700735 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700736 }
737 }
738 }
739 }
740
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800741 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800742 MyOrientationListener(Context context, Handler handler) {
743 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800744 }
Craig Mautner967212c2013-04-13 21:10:58 -0700745
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800746 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700747 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700748 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700749 updateRotation(false);
750 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800751 }
752 MyOrientationListener mOrientationListener;
753
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100754 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400755
John Spurlock27735a42013-08-14 17:57:38 -0400756 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400757 View.NAVIGATION_BAR_TRANSIENT,
758 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400759 View.NAVIGATION_BAR_TRANSLUCENT,
760 StatusBarManager.WINDOW_NAVIGATION_BAR,
761 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400762
John Spurlockf1a36642013-10-12 17:50:42 -0400763 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400764
Craig Mautner037aa8d2013-06-07 10:35:44 -0700765 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400766
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700767 IStatusBarService getStatusBarService() {
768 synchronized (mServiceAquireLock) {
769 if (mStatusBarService == null) {
770 mStatusBarService = IStatusBarService.Stub.asInterface(
771 ServiceManager.getService("statusbar"));
772 }
773 return mStatusBarService;
774 }
775 }
776
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700777 /*
778 * We always let the sensor be switched on by default except when
779 * the user has explicitly disabled sensor based rotation or when the
780 * screen is switched off.
781 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700782 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800783 if (mSupportAutoRotation) {
784 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
785 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
786 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
787 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
788 // If the application has explicitly requested to follow the
789 // orientation, then we need to turn the sensor on.
790 return true;
791 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800792 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700793 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800794 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
795 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
796 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400797 // enable accelerometer if we are docked in a dock that enables accelerometer
798 // orientation management,
799 return true;
800 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700801 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800802 // If the setting for using the sensor by default is enabled, then
803 // we will always leave it on. Note that the user could go to
804 // a window that forces an orientation that does not use the
805 // sensor and in theory we could turn it off... however, when next
806 // turning it on we won't have a good value for the current
807 // orientation for a little bit, which can cause orientation
808 // changes to lag, so we'd like to keep it always on. (It will
809 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700810 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800811 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800812 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800813 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700814
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800815 /*
816 * Various use cases for invoking this function
817 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700818 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800819 * if not already enabled
820 * screen turned on and current app does not have sensor orientation, disable listeners if
821 * already enabled
822 * screen turning on and current app has sensor based orientation, enable listeners if needed
823 * screen turning on and current app has nosensor based orientation, do nothing
824 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700825 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800826 if (!mOrientationListener.canDetectOrientation()) {
827 // If sensor is turned off or nonexistent for some reason
828 return;
829 }
830 //Could have been invoked due to screen turning on or off or
831 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700832 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
833 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
834 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800835 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700836 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700837 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800838 disable = false;
839 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700840 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800841 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700842 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800843 mOrientationSensorEnabled = true;
844 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700845 }
846 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800847 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700848 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800849 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700850 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800851 mOrientationSensorEnabled = false;
852 }
853 }
854
Jeff Brown13f00f02014-10-31 14:45:50 -0700855 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
856 // Hold a wake lock until the power key is released.
857 if (!mPowerKeyWakeLock.isHeld()) {
858 mPowerKeyWakeLock.acquire();
859 }
860
861 // Cancel multi-press detection timeout.
862 if (mPowerKeyPressCounter != 0) {
863 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
864 }
865
866 // Detect user pressing the power button in panic when an application has
867 // taken over the whole screen.
868 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800869 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700870 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700871 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700872 }
873
874 // Latch power key state to detect screenshot chord.
875 if (interactive && !mScreenshotChordPowerKeyTriggered
876 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
877 mScreenshotChordPowerKeyTriggered = true;
878 mScreenshotChordPowerKeyTime = event.getDownTime();
879 interceptScreenshotChord();
880 }
881
882 // Stop ringing or end call if configured to do so when power is pressed.
883 TelecomManager telecomManager = getTelecommService();
884 boolean hungUp = false;
885 if (telecomManager != null) {
886 if (telecomManager.isRinging()) {
887 // Pressing Power while there's a ringing incoming
888 // call should silence the ringer.
889 telecomManager.silenceRinger();
890 } else if ((mIncallPowerBehavior
891 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
892 && telecomManager.isInCall() && interactive) {
893 // Otherwise, if "Power button ends call" is enabled,
894 // the Power button will hang up any current active call.
895 hungUp = telecomManager.endCall();
896 }
897 }
898
899 // If the power key has still not yet been handled, then detect short
900 // press, long press, or multi press and decide what to do.
901 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
902 || mScreenshotChordVolumeUpKeyTriggered;
903 if (!mPowerKeyHandled) {
904 if (interactive) {
905 // When interactive, we're already awake.
906 // Wait for a long press or for the button to be released to decide what to do.
907 if (hasLongPressOnPowerBehavior()) {
908 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
909 msg.setAsynchronous(true);
910 mHandler.sendMessageDelayed(msg,
911 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
912 }
913 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800914 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800915
Bryce Leed3b28402015-03-09 15:49:13 +0000916 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
917 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
918 msg.setAsynchronous(true);
919 mHandler.sendMessageDelayed(msg,
920 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800921 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000922 } else {
923 final int maxCount = getMaxMultiPressPowerCount();
924
925 if (maxCount <= 1) {
926 mPowerKeyHandled = true;
927 } else {
928 mBeganFromNonInteractive = true;
929 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700930 }
931 }
Jeff Brown4d396052010-10-29 21:50:21 -0700932 }
933 }
934
Jeff Brown13f00f02014-10-31 14:45:50 -0700935 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
936 final boolean handled = canceled || mPowerKeyHandled;
937 mScreenshotChordPowerKeyTriggered = false;
938 cancelPendingScreenshotChordAction();
939 cancelPendingPowerKeyAction();
940
941 if (!handled) {
942 // Figure out how to handle the key now that it has been released.
943 mPowerKeyPressCounter += 1;
944
945 final int maxCount = getMaxMultiPressPowerCount();
946 final long eventTime = event.getDownTime();
947 if (mPowerKeyPressCounter < maxCount) {
948 // This could be a multi-press. Wait a little bit longer to confirm.
949 // Continue holding the wake lock.
950 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
951 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
952 msg.setAsynchronous(true);
953 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
954 return;
955 }
956
957 // No other actions. Handle it immediately.
958 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700959 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700960
961 // Done. Reset our state.
962 finishPowerKeyPress();
963 }
964
965 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800966 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700967 mPowerKeyPressCounter = 0;
968 if (mPowerKeyWakeLock.isHeld()) {
969 mPowerKeyWakeLock.release();
970 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700971 }
972
973 private void cancelPendingPowerKeyAction() {
974 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700975 mPowerKeyHandled = true;
976 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700977 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700978 }
979
980 private void powerPress(long eventTime, boolean interactive, int count) {
981 if (mScreenOnEarly && !mScreenOnFully) {
982 Slog.i(TAG, "Suppressed redundant power key press while "
983 + "already in the process of turning the screen on.");
984 return;
Jeff Brownff204712011-10-25 21:27:54 -0700985 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700986
987 if (count == 2) {
988 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
989 } else if (count == 3) {
990 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -0800991 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700992 switch (mShortPressOnPowerBehavior) {
993 case SHORT_PRESS_POWER_NOTHING:
994 break;
995 case SHORT_PRESS_POWER_GO_TO_SLEEP:
996 mPowerManager.goToSleep(eventTime,
997 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
998 break;
999 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1000 mPowerManager.goToSleep(eventTime,
1001 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1002 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1003 break;
1004 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1005 mPowerManager.goToSleep(eventTime,
1006 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1007 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1008 launchHomeFromHotKey();
1009 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001010 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001011 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001012 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001013 }
1014 }
1015 }
1016
1017 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1018 switch (behavior) {
1019 case MULTI_PRESS_POWER_NOTHING:
1020 break;
1021 case MULTI_PRESS_POWER_THEATER_MODE:
1022 if (isTheaterModeEnabled()) {
1023 Slog.i(TAG, "Toggling theater mode off.");
1024 Settings.Global.putInt(mContext.getContentResolver(),
1025 Settings.Global.THEATER_MODE_ON, 0);
1026 if (!interactive) {
1027 wakeUpFromPowerKey(eventTime);
1028 }
1029 } else {
1030 Slog.i(TAG, "Toggling theater mode on.");
1031 Settings.Global.putInt(mContext.getContentResolver(),
1032 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001033
1034 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001035 mPowerManager.goToSleep(eventTime,
1036 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1037 }
1038 }
1039 break;
1040 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001041 Slog.i(TAG, "Starting brightness boost.");
1042 if (!interactive) {
1043 wakeUpFromPowerKey(eventTime);
1044 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001045 mPowerManager.boostScreenBrightness(eventTime);
1046 break;
1047 }
1048 }
1049
1050 private int getMaxMultiPressPowerCount() {
1051 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1052 return 3;
1053 }
1054 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1055 return 2;
1056 }
1057 return 1;
1058 }
1059
1060 private void powerLongPress() {
1061 final int behavior = getResolvedLongPressOnPowerBehavior();
1062 switch (behavior) {
1063 case LONG_PRESS_POWER_NOTHING:
1064 break;
1065 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1066 mPowerKeyHandled = true;
1067 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1068 performAuditoryFeedbackForAccessibilityIfNeed();
1069 }
1070 showGlobalActionsInternal();
1071 break;
1072 case LONG_PRESS_POWER_SHUT_OFF:
1073 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1074 mPowerKeyHandled = true;
1075 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1076 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1077 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1078 break;
1079 }
1080 }
1081
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001082 private void sleepPress(KeyEvent event) {
1083 switch (mShortPressOnSleepBehavior) {
1084 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
1085 mPowerManager.goToSleep(event.getEventTime(),
1086 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1087 break;
1088 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001089 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001090 mPowerManager.goToSleep(event.getEventTime(),
1091 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1092 break;
1093 }
1094 }
1095
Jeff Brown13f00f02014-10-31 14:45:50 -07001096 private int getResolvedLongPressOnPowerBehavior() {
1097 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1098 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1099 }
1100 return mLongPressOnPowerBehavior;
1101 }
1102
1103 private boolean hasLongPressOnPowerBehavior() {
1104 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001105 }
1106
1107 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001108 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001109 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1110 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001111 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001112 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1113 && now <= mScreenshotChordPowerKeyTime
1114 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1115 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001116 cancelPendingPowerKeyAction();
1117
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001118 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001119 }
1120 }
1121 }
1122
Winson Chung1cea2f32012-10-08 20:42:01 -07001123 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001124 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001125 // Double the time it takes to take a screenshot from the keyguard
1126 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001127 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001128 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001129 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001130 }
1131
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001132 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001133 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001134 }
1135
Jeff Brown13f00f02014-10-31 14:45:50 -07001136 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001137 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001138 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001139 mEndCallKeyHandled = true;
1140 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1141 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001142 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001143 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001144 }
1145 };
1146
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001147 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001148 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001149 public void run() {
1150 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001151 }
1152 };
1153
Alan Viverettee34560b22014-07-10 14:50:06 -07001154 @Override
1155 public void showGlobalActions() {
1156 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1157 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1158 }
1159
1160 void showGlobalActionsInternal() {
1161 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001162 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001163 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001164 }
Jim Millerab954542014-10-10 18:21:49 -07001165 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001166 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1167 if (keyguardShowing) {
1168 // since it took two seconds of long press to bring this up,
1169 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001170 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001171 }
1172 }
1173
1174 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001175 return Settings.Global.getInt(
1176 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001177 }
1178
Maurice Lam99c6e072014-04-28 18:24:28 -07001179 boolean isUserSetupComplete() {
1180 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1181 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1182 }
1183
Jeff Brown13f00f02014-10-31 14:45:50 -07001184 private void handleShortPressOnHome() {
1185 // If there's a dream running then use home to escape the dream
1186 // but don't actually go home.
1187 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1188 mDreamManagerInternal.stopDream(false /*immediate*/);
1189 return;
1190 }
1191
1192 // Go home!
1193 launchHomeFromHotKey();
1194 }
1195
Patrick Dubroyece94522011-02-23 18:35:01 -08001196 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -08001197 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001198 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001199 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001200
Jeff Browncaca8812013-05-09 13:34:33 -07001201 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1202 toggleRecentApps();
1203 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1204 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -07001205 }
1206 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001207 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001208
Jeff Browncaca8812013-05-09 13:34:33 -07001209 private void handleDoubleTapOnHome() {
1210 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1211 mHomeConsumed = true;
1212 toggleRecentApps();
1213 }
1214 }
1215
1216 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1217 @Override
1218 public void run() {
1219 if (mHomeDoubleTapPending) {
1220 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001221 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001222 }
1223 }
1224 };
1225
Mark Renoufc1256912015-03-11 14:38:23 -04001226 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001227 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001228 }
1229
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001230 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001231 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001232 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001233 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001234 mContext = context;
1235 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001236 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001237 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001238 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001239 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Mark Renoufc1256912015-03-11 14:38:23 -04001240
1241 // Init display burn-in protection
1242 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1243 com.android.internal.R.bool.config_enableBurnInProtection);
1244 // Allow a system property to override this. Used by developer settings.
1245 boolean burnInProtectionDevMode =
1246 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1247 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1248 final int minHorizontal;
1249 final int maxHorizontal;
1250 final int minVertical;
1251 final int maxVertical;
1252 final int maxRadius;
1253 if (burnInProtectionDevMode) {
1254 minHorizontal = -8;
1255 maxHorizontal = 8;
1256 minVertical = -8;
1257 maxVertical = -4;
1258 maxRadius = (isRoundWindow()) ? 6 : -1;
1259 } else {
1260 Resources resources = context.getResources();
1261 minHorizontal = resources.getInteger(
1262 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1263 maxHorizontal = resources.getInteger(
1264 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1265 minVertical = resources.getInteger(
1266 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1267 maxVertical = resources.getInteger(
1268 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1269 maxRadius = resources.getInteger(
1270 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1271 }
1272 mBurnInProtectionHelper = new BurnInProtectionHelper(
1273 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001274 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001275
Jeff Brown70825162012-03-28 17:27:48 -07001276 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001277 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001278 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001279 try {
1280 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1281 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001282 mSettingsObserver = new SettingsObserver(mHandler);
1283 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001284 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001285 mUiMode = context.getResources().getInteger(
1286 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001287 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1288 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1289 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1290 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001291 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1292 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1293 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1294 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1295 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1296 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1297 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1298 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001299
Jeff Brown96307042012-07-27 15:51:34 -07001300 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1301 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001302 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001303 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1304 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001305 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001306 mSupportAutoRotation = mContext.getResources().getBoolean(
1307 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001308 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001309 com.android.internal.R.integer.config_lidOpenRotation);
1310 mCarDockRotation = readRotation(
1311 com.android.internal.R.integer.config_carDockRotation);
1312 mDeskDockRotation = readRotation(
1313 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001314 mUndockedHdmiRotation = readRotation(
1315 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001316 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1317 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1318 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1319 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001320 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1321 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1322 mLidNavigationAccessibility = mContext.getResources().getInteger(
1323 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001324 mLidControlsSleep = mContext.getResources().getBoolean(
1325 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001326 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1327 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001328
1329 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1330 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1331 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1332 || mContext.getResources().getBoolean(
1333 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1334 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1335 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001336 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1337 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001338 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1339 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1340 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1341 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1342 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1343 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1344
Bryce Lee55e846d2014-11-04 12:43:44 -08001345 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1346 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1347
Bryce Leed3b28402015-03-09 15:49:13 +00001348 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1349 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1350
Jeff Brown13f00f02014-10-31 14:45:50 -07001351 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1352 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1353 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1354 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1355 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1356 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1357 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1358 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001359 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1360 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001361
John Spurlock61560172015-02-06 19:46:04 -05001362 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001363
Jeff Brownf71343d2013-05-31 17:59:11 -07001364 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001365
Svetoslav8e3feb12014-02-24 13:46:47 -08001366 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1367 Context.ACCESSIBILITY_SERVICE);
1368
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001369 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001370 IntentFilter filter = new IntentFilter();
1371 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1372 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1373 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1374 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001375 filter.addAction(Intent.ACTION_DOCK_EVENT);
1376 Intent intent = context.registerReceiver(mDockReceiver, filter);
1377 if (intent != null) {
1378 // Retrieve current sticky dock event broadcast.
1379 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1380 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1381 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001382
Jeff Brown6aaf2952012-10-05 16:01:08 -07001383 // register for dream-related broadcasts
1384 filter = new IntentFilter();
1385 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1386 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1387 context.registerReceiver(mDreamReceiver, filter);
1388
Christopher Tate5e08af02012-09-21 17:17:22 -07001389 // register for multiuser-relevant broadcasts
1390 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1391 context.registerReceiver(mMultiuserReceiver, filter);
1392
John Spurlock57306e62013-04-22 09:48:49 -04001393 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001394 mSystemGestures = new SystemGesturesPointerEventListener(context,
1395 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001396 @Override
1397 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001398 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001399 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001400 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001401 }
1402 @Override
1403 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001404 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001405 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001406 }
1407 }
1408 @Override
1409 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001410 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001411 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001412 }
1413 }
1414 @Override
1415 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001416 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001417 }
Adrian Roos3595be42015-03-05 16:31:15 +01001418 @Override
1419 public void onDown() {
1420 mOrientationListener.onTouchStart();
1421 }
1422 @Override
1423 public void onUpOrCancel() {
1424 mOrientationListener.onTouchEnd();
1425 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001426 });
John Spurlockf1a36642013-10-12 17:50:42 -04001427 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001428 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001429
Jeff Brownc2346132012-04-13 01:55:38 -07001430 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001431 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1432 com.android.internal.R.array.config_longPressVibePattern);
1433 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1434 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001435 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1436 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001437 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1438 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001439 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1440 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001441 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1442 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1443 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1444 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore82067b2015-04-30 09:58:35 -07001445 mStylusButtonPressVibePattern = getLongIntArray(mContext.getResources(),
1446 com.android.internal.R.array.config_stylusButtonPressVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001447
Christopher Tatee90585f2012-03-05 18:56:25 -08001448 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1449 com.android.internal.R.bool.config_enableScreenshotChord);
1450
Justin Kohd378ad72013-04-01 12:18:26 -07001451 mGlobalKeyManager = new GlobalKeyManager(mContext);
1452
Joe Onoratoea495d42011-04-06 11:41:11 -07001453 // Controls rotation and the like.
1454 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001455
1456 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001457 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001458 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001459 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001460
1461 mWindowManagerInternal.registerAppTransitionListener(
1462 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001463 }
1464
Jeff Brownf71343d2013-05-31 17:59:11 -07001465 /**
1466 * Read values from config.xml that may be overridden depending on
1467 * the configuration of the device.
1468 * eg. Disable long press on home goes to recents on sw600dp.
1469 */
1470 private void readConfigurationDependentBehaviors() {
1471 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1472 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1473 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1474 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1475 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1476 }
1477
1478 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1479 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1480 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1481 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1482 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1483 }
1484 }
1485
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001486 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001487 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001488 // This method might be called before the policy has been fully initialized
1489 // or for other displays we don't care about.
1490 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1491 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001492 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001493 mDisplay = display;
1494
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001495 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001496 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001497 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001498 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001499 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001500 mLandscapeRotation = Surface.ROTATION_0;
1501 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001502 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001503 mPortraitRotation = Surface.ROTATION_90;
1504 mUpsideDownRotation = Surface.ROTATION_270;
1505 } else {
1506 mPortraitRotation = Surface.ROTATION_270;
1507 mUpsideDownRotation = Surface.ROTATION_90;
1508 }
1509 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001510 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001511 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001512 mPortraitRotation = Surface.ROTATION_0;
1513 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001514 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001515 mLandscapeRotation = Surface.ROTATION_270;
1516 mSeascapeRotation = Surface.ROTATION_90;
1517 } else {
1518 mLandscapeRotation = Surface.ROTATION_90;
1519 mSeascapeRotation = Surface.ROTATION_270;
1520 }
1521 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001522
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001523 mStatusBarHeight =
1524 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001525
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001526 // Height of the navigation bar when presented horizontally at bottom
1527 mNavigationBarHeightForRotation[mPortraitRotation] =
1528 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001529 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001530 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001531 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1532 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001533
1534 // Width of the navigation bar when presented vertically along one side
1535 mNavigationBarWidthForRotation[mPortraitRotation] =
1536 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1537 mNavigationBarWidthForRotation[mLandscapeRotation] =
1538 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001539 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001540
1541 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001542 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001543 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001544
Devin Kimd7b12b42014-05-05 14:34:58 -07001545 // Allow the navigation bar to move on non-square small devices (phones).
1546 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001547
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001548 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001549 // Allow a system property to override this. Used by the emulator.
1550 // See also hasNavigationBar().
1551 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1552 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001553 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001554 } else if ("0".equals(navBarOverride)) {
1555 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001556 }
1557
Jeff Brown27f1d672012-10-17 18:32:34 -07001558 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1559 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001560 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001561 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001562 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001563 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001564 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001565 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001566
Chong Zhangae6119ff2014-11-11 18:54:39 -08001567 // For demo purposes, allow the rotation of the remote display to be controlled.
1568 // By default, remote display locks rotation to landscape.
1569 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1570 mDemoRotation = mPortraitRotation;
1571 } else {
1572 mDemoRotation = mLandscapeRotation;
1573 }
1574 mDemoRotationLock = SystemProperties.getBoolean(
1575 "persist.demo.rotationlock", false);
1576
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001577 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1578 // http://developer.android.com/guide/practices/screens_support.html#range
1579 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1580 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1581 // For debug purposes the next line turns this feature off with:
1582 // $ adb shell setprop config.override_forced_orient true
1583 // $ adb shell wm size reset
1584 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1585 }
1586
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001587 /**
1588 * @return whether the navigation bar can be hidden, e.g. the device has a
1589 * navigation bar and touch exploration is not enabled
1590 */
1591 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001592 return mHasNavigationBar
1593 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001594 }
1595
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001596 @Override
1597 public boolean isDefaultOrientationForced() {
1598 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001599 }
1600
Dianne Hackbornc652de82013-02-15 16:32:56 -08001601 @Override
1602 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1603 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1604 mOverscanLeft = left;
1605 mOverscanTop = top;
1606 mOverscanRight = right;
1607 mOverscanBottom = bottom;
1608 }
1609 }
1610
Dianne Hackbornc777e072010-02-12 13:07:59 -08001611 public void updateSettings() {
1612 ContentResolver resolver = mContext.getContentResolver();
1613 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001614 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001615 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001616 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001617 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1618 UserHandle.USER_CURRENT);
1619 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001620 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001621 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1622 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001623
Jeff Browna20dda42014-05-27 20:57:24 -07001624 // Configure wake gesture.
1625 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1626 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1627 UserHandle.USER_CURRENT) != 0;
1628 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1629 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1630 updateWakeGestureListenerLp();
1631 }
1632
Jeff Brown207673cd2012-06-05 17:47:11 -07001633 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001634 int userRotation = Settings.System.getIntForUser(resolver,
1635 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1636 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001637 if (mUserRotation != userRotation) {
1638 mUserRotation = userRotation;
1639 updateRotation = true;
1640 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001641 int userRotationMode = Settings.System.getIntForUser(resolver,
1642 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001643 WindowManagerPolicy.USER_ROTATION_FREE :
1644 WindowManagerPolicy.USER_ROTATION_LOCKED;
1645 if (mUserRotationMode != userRotationMode) {
1646 mUserRotationMode = userRotationMode;
1647 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001648 updateOrientationListenerLp();
1649 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001650
Dianne Hackbornc777e072010-02-12 13:07:59 -08001651 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001652 int pointerLocation = Settings.System.getIntForUser(resolver,
1653 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001654 if (mPointerLocationMode != pointerLocation) {
1655 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001656 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1657 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001658 }
1659 }
1660 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001661 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1662 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1663 String imId = Settings.Secure.getStringForUser(resolver,
1664 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001665 boolean hasSoftInput = imId != null && imId.length() > 0;
1666 if (mHasSoftInput != hasSoftInput) {
1667 mHasSoftInput = hasSoftInput;
1668 updateRotation = true;
1669 }
John Spurlockf1a36642013-10-12 17:50:42 -04001670 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001671 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001672 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001673 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001674 }
1675 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001676 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001677 }
Jeff Brown70825162012-03-28 17:27:48 -07001678 }
1679
Jeff Browna20dda42014-05-27 20:57:24 -07001680 private void updateWakeGestureListenerLp() {
1681 if (shouldEnableWakeGestureLp()) {
1682 mWakeGestureListener.requestWakeUpTrigger();
1683 } else {
1684 mWakeGestureListener.cancelWakeUpTrigger();
1685 }
1686 }
1687
1688 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001689 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001690 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1691 && mWakeGestureListener.isSupported();
1692 }
1693
Jeff Brown70825162012-03-28 17:27:48 -07001694 private void enablePointerLocation() {
1695 if (mPointerLocationView == null) {
1696 mPointerLocationView = new PointerLocationView(mContext);
1697 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001698 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1699 WindowManager.LayoutParams.MATCH_PARENT,
1700 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001701 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001702 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1703 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1704 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1705 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001706 if (ActivityManager.isHighEndGfx()) {
1707 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1708 lp.privateFlags |=
1709 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1710 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001711 lp.format = PixelFormat.TRANSLUCENT;
1712 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001713 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001714 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001715 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001716 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001717 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001718 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001719 }
Jeff Brown70825162012-03-28 17:27:48 -07001720
1721 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001722 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001723 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1724 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001725 wm.removeView(mPointerLocationView);
1726 mPointerLocationView = null;
1727 }
1728 }
1729
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001730 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001731 try {
1732 int rotation = mContext.getResources().getInteger(resID);
1733 switch (rotation) {
1734 case 0:
1735 return Surface.ROTATION_0;
1736 case 90:
1737 return Surface.ROTATION_90;
1738 case 180:
1739 return Surface.ROTATION_180;
1740 case 270:
1741 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001742 }
1743 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001744 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001745 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001746 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001747 }
1748
1749 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001750 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001751 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001752 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001753
1754 outAppOp[0] = AppOpsManager.OP_NONE;
1755
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001756 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1757 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1758 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1759 return WindowManagerGlobal.ADD_INVALID_TYPE;
1760 }
1761
1762 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1763 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001764 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001765 }
1766 String permission = null;
1767 switch (type) {
1768 case TYPE_TOAST:
1769 // XXX right now the app process has complete control over
1770 // this... should introduce a token to let the system
1771 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001772 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001773 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001774 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001775 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001776 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001777 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001778 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001779 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001780 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001781 break;
1782 case TYPE_PHONE:
1783 case TYPE_PRIORITY_PHONE:
1784 case TYPE_SYSTEM_ALERT:
1785 case TYPE_SYSTEM_ERROR:
1786 case TYPE_SYSTEM_OVERLAY:
1787 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001788 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001789 break;
1790 default:
1791 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1792 }
1793 if (permission != null) {
1794 if (mContext.checkCallingOrSelfPermission(permission)
1795 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001796 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001797 }
1798 }
Jeff Brown98365d72012-08-19 20:30:52 -07001799 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001800 }
Craig Mautner88400d32012-09-30 12:35:45 -07001801
1802 @Override
1803 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1804
1805 // If this switch statement is modified, modify the comment in the declarations of
1806 // the type in {@link WindowManager.LayoutParams} as well.
1807 switch (attrs.type) {
1808 default:
1809 // These are the windows that by default are shown only to the user that created
1810 // them. If this needs to be overridden, set
1811 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1812 // {@link WindowManager.LayoutParams}. Note that permission
1813 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1814 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1815 return true;
1816 }
1817 break;
1818
1819 // These are the windows that by default are shown to all users. However, to
1820 // protect against spoofing, check permissions below.
1821 case TYPE_APPLICATION_STARTING:
1822 case TYPE_BOOT_PROGRESS:
1823 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07001824 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001825 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001826 case TYPE_KEYGUARD_DIALOG:
1827 case TYPE_MAGNIFICATION_OVERLAY:
1828 case TYPE_NAVIGATION_BAR:
1829 case TYPE_NAVIGATION_BAR_PANEL:
1830 case TYPE_PHONE:
1831 case TYPE_POINTER:
1832 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001833 case TYPE_SEARCH_BAR:
1834 case TYPE_STATUS_BAR:
1835 case TYPE_STATUS_BAR_PANEL:
1836 case TYPE_STATUS_BAR_SUB_PANEL:
1837 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001838 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001839 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001840 break;
1841 }
1842
1843 // Check if third party app has set window to system window type.
1844 return mContext.checkCallingOrSelfPermission(
1845 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1846 != PackageManager.PERMISSION_GRANTED;
1847 }
1848
Craig Mautner967212c2013-04-13 21:10:58 -07001849 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001850 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1851 switch (attrs.type) {
1852 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001853 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001854 // These types of windows can't receive input events.
1855 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1856 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001857 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001858 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001859 case TYPE_STATUS_BAR:
1860
1861 // If the Keyguard is in a hidden state (occluded by another window), we force to
1862 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1863 // the keyguard as occluded wouldn't set these flags again.
1864 // See {@link #processKeyguardSetHiddenResultLw}.
1865 if (mKeyguardHidden) {
1866 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1867 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1868 }
1869 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001870 }
Adrian Roos38502112014-04-09 21:04:11 +02001871
1872 if (attrs.type != TYPE_STATUS_BAR) {
1873 // The status bar is the only window allowed to exhibit keyguard behavior.
1874 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1875 }
Adrian Roosea562512014-05-05 13:33:03 +02001876
1877 if (ActivityManager.isHighEndGfx()
1878 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001879 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001880 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1881 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001882 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001883
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001884 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001885 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001886 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001887
Michael Wright3818c922014-09-02 13:59:07 -07001888 private void readCameraLensCoverState() {
1889 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1890 }
1891
Jeff Browndaa37532012-05-01 15:54:03 -07001892 private boolean isHidden(int accessibilityMode) {
1893 switch (accessibilityMode) {
1894 case 1:
1895 return mLidState == LID_CLOSED;
1896 case 2:
1897 return mLidState == LID_OPEN;
1898 default:
1899 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001900 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001901 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001902
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001903 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001904 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001905 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1906 int navigationPresence) {
1907 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1908
Jeff Brownf71343d2013-05-31 17:59:11 -07001909 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001910 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001911 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001912
Jeff Browndaa37532012-05-01 15:54:03 -07001913 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1914 || (keyboardPresence == PRESENCE_INTERNAL
1915 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001916 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001917 if (!mHasSoftInput) {
1918 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1919 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001920 }
1921
Jeff Browndaa37532012-05-01 15:54:03 -07001922 if (config.navigation == Configuration.NAVIGATION_NONAV
1923 || (navigationPresence == PRESENCE_INTERNAL
1924 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001925 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001926 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001927 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001928
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001929 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001930 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001931 public int windowTypeToLayerLw(int type) {
1932 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001933 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001934 }
1935 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001936 case TYPE_PRIVATE_PRESENTATION:
1937 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001938 case TYPE_WALLPAPER:
1939 // wallpaper is at the bottom, though the window manager may move it.
1940 return 2;
1941 case TYPE_PHONE:
1942 return 3;
1943 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07001944 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001945 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001946 case TYPE_VOICE_INTERACTION:
1947 // voice interaction layer is almost immediately above apps.
1948 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07001949 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001950 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07001951 case TYPE_SYSTEM_DIALOG:
1952 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001953 case TYPE_TOAST:
1954 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07001955 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001956 case TYPE_PRIORITY_PHONE:
1957 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07001958 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001959 case TYPE_DREAM:
1960 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07001961 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001962 case TYPE_SYSTEM_ALERT:
1963 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07001964 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001965 case TYPE_INPUT_METHOD:
1966 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07001967 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001968 case TYPE_INPUT_METHOD_DIALOG:
1969 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07001970 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08001971 case TYPE_KEYGUARD_SCRIM:
1972 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001973 return 14;
Selim Cinekf83e8242015-05-19 18:08:14 -07001974 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001975 return 15;
Selim Cinekf83e8242015-05-19 18:08:14 -07001976 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001977 return 16;
Selim Cinekf83e8242015-05-19 18:08:14 -07001978 case TYPE_STATUS_BAR_PANEL:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001979 return 17;
Selim Cinekf83e8242015-05-19 18:08:14 -07001980 case TYPE_KEYGUARD_DIALOG:
1981 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001982 case TYPE_VOLUME_OVERLAY:
1983 // the on-screen volume indicator and controller shown when the user
1984 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07001985 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001986 case TYPE_SYSTEM_OVERLAY:
1987 // the on-screen volume indicator and controller shown when the user
1988 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07001989 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001990 case TYPE_NAVIGATION_BAR:
1991 // the navigation bar, if available, shows atop most things
Selim Cinekf83e8242015-05-19 18:08:14 -07001992 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001993 case TYPE_NAVIGATION_BAR_PANEL:
1994 // some panels (e.g. search) need to show on top of the navigation bar
Selim Cinekf83e8242015-05-19 18:08:14 -07001995 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001996 case TYPE_SYSTEM_ERROR:
1997 // system-level error dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07001998 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001999 case TYPE_MAGNIFICATION_OVERLAY:
2000 // used to highlight the magnified portion of a display
Selim Cinekf83e8242015-05-19 18:08:14 -07002001 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002002 case TYPE_DISPLAY_OVERLAY:
2003 // used to simulate secondary display devices
Selim Cinekf83e8242015-05-19 18:08:14 -07002004 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002005 case TYPE_DRAG:
2006 // the drag layer: input for drag-and-drop is associated with this window,
2007 // which sits above all other focusable windows
Selim Cinekf83e8242015-05-19 18:08:14 -07002008 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002009 case TYPE_ACCESSIBILITY_OVERLAY:
2010 // overlay put by accessibility services to intercept user interaction
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002011 return 27;
Selim Cinekf83e8242015-05-19 18:08:14 -07002012 case TYPE_SECURE_SYSTEM_OVERLAY:
Svetoslav3a5c7212014-10-14 09:54:26 -07002013 return 28;
Selim Cinekf83e8242015-05-19 18:08:14 -07002014 case TYPE_BOOT_PROGRESS:
2015 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002016 case TYPE_POINTER:
2017 // the (mouse) pointer layer
Svetoslav3a5c7212014-10-14 09:54:26 -07002018 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002019 }
2020 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002021 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002022 }
2023
2024 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002025 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002026 public int subWindowTypeToLayerLw(int type) {
2027 switch (type) {
2028 case TYPE_APPLICATION_PANEL:
2029 case TYPE_APPLICATION_ATTACHED_DIALOG:
2030 return APPLICATION_PANEL_SUBLAYER;
2031 case TYPE_APPLICATION_MEDIA:
2032 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002033 case TYPE_APPLICATION_MEDIA_OVERLAY:
2034 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002035 case TYPE_APPLICATION_SUB_PANEL:
2036 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002037 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2038 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002039 }
2040 Log.e(TAG, "Unknown sub-window type: " + type);
2041 return 0;
2042 }
2043
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002044 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002045 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002046 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002047 }
2048
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002049 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002050 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002051 if (mHasNavigationBar) {
2052 // For a basic navigation bar, when we are in landscape mode we place
2053 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002054 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2055 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002056 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002057 }
2058 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002059 }
2060
Jose Lima9546b202014-07-02 17:21:51 -07002061 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002062 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002063 if (mHasNavigationBar) {
2064 // For a basic navigation bar, when we are in portrait mode we place
2065 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002066 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2067 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002068 }
2069 }
2070 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002071 }
2072
Jose Lima9546b202014-07-02 17:21:51 -07002073 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002074 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2075 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002076 }
2077
Jose Lima9546b202014-07-02 17:21:51 -07002078 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002079 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002080 // There is a separate status bar at the top of the display. We don't count that as part
2081 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002082 // we do want to exclude it since applications can't generally use that part
2083 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002084 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002085 }
2086
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002087 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002088 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2089 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002090 (isKeyguardHostWindow(attrs) &&
2091 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002092 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002093 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002094
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002095 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002096 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2097 return attrs.type == TYPE_STATUS_BAR;
2098 }
2099
2100 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002101 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002102 switch (attrs.type) {
2103 case TYPE_STATUS_BAR:
2104 case TYPE_NAVIGATION_BAR:
2105 case TYPE_WALLPAPER:
2106 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002107 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002108 return false;
2109 default:
2110 return true;
2111 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002112 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002113
Craig Mautner7d7808f2014-09-11 18:02:38 -07002114 @Override
2115 public WindowState getWinShowWhenLockedLw() {
2116 return mWinShowWhenLocked;
2117 }
2118
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002119 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002120 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002121 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2122 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002123 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002124 if (!SHOW_STARTING_ANIMATIONS) {
2125 return null;
2126 }
2127 if (packageName == null) {
2128 return null;
2129 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002130
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002131 WindowManager wm = null;
2132 View view = null;
2133
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002134 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002135 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002136 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2137 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2138 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002139 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002140 try {
2141 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002142 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002143 } catch (PackageManager.NameNotFoundException e) {
2144 // Ignore
2145 }
2146 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002147
Jorim Jaggib10e33f2015-02-04 21:57:40 +01002148 Window win = new PhoneWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002149 final TypedArray ta = win.getWindowStyle();
2150 if (ta.getBoolean(
2151 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2152 || ta.getBoolean(
2153 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002154 return null;
2155 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002156
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002157 Resources r = context.getResources();
2158 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002159
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002160 win.setType(
2161 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002162
2163 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2164 // Assumes it's safe to show starting windows of launched apps while
2165 // the keyguard is being hidden. This is okay because starting windows never show
2166 // secret information.
2167 if (mKeyguardHidden) {
2168 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2169 }
2170 }
2171
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002172 // Force the window flags: this is a fake window, so it is not really
2173 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2174 // flag because we do know that the next window will take input
2175 // focus, so we want to get the IME window up on top of us right away.
2176 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002177 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002178 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2179 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2180 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002181 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002182 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2183 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2184 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002185
Adam Powell04fe6eb2013-05-31 14:39:48 -07002186 win.setDefaultIcon(icon);
2187 win.setDefaultLogo(logo);
2188
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002189 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002190 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002191
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002192 final WindowManager.LayoutParams params = win.getAttributes();
2193 params.token = appToken;
2194 params.packageName = packageName;
2195 params.windowAnimations = win.getWindowStyle().getResourceId(
2196 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002197 params.privateFlags |=
2198 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002199 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002200
2201 if (!compatInfo.supportsScreen()) {
2202 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2203 }
2204
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002205 params.setTitle("Starting " + packageName);
2206
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002207 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2208 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002209
2210 if (win.isFloating()) {
2211 // Whoops, there is no way to display an animation/preview
2212 // of such a thing! After all that work... let's skip it.
2213 // (Note that we must do this here because it is in
2214 // getDecorView() where the theme is evaluated... maybe
2215 // we should peek the floating attribute from the theme
2216 // earlier.)
2217 return null;
2218 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002219
Craig Mautner6fbda632012-07-03 09:26:39 -07002220 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002221 TAG, "Adding starting window for " + packageName
2222 + " / " + appToken + ": "
2223 + (view.getParent() != null ? view : null));
2224
2225 wm.addView(view, params);
2226
2227 // Only return the view if it was successfully added to the
2228 // window manager... which we can tell by it having a parent.
2229 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002230 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002231 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002232 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2233 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002234 } catch (RuntimeException e) {
2235 // don't crash if something else bad happens, for example a
2236 // failure loading resources because we are loading from an app
2237 // on external storage that has been unmounted.
2238 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002239 } finally {
2240 if (view != null && view.getParent() == null) {
2241 Log.w(TAG, "view not successfully added to wm, removing view");
2242 wm.removeViewImmediate(view);
2243 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002244 }
2245
2246 return null;
2247 }
2248
2249 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002250 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002251 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002252 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2253 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002254
2255 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002256 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002257 wm.removeView(window);
2258 }
2259 }
2260
2261 /**
2262 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002263 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002264 * Currently enforces that three window types are singletons:
2265 * <ul>
2266 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002267 * <li>KEYGUARD_TYPE</li>
2268 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002269 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002270 * @param win The window to be added
2271 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002272 *
Jeff Brown98365d72012-08-19 20:30:52 -07002273 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2274 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002275 */
Jose Lima9546b202014-07-02 17:21:51 -07002276 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002277 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2278 switch (attrs.type) {
2279 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002280 mContext.enforceCallingOrSelfPermission(
2281 android.Manifest.permission.STATUS_BAR_SERVICE,
2282 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002283 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002284 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002285 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002286 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002287 }
2288 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002289 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002290 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002291 case TYPE_NAVIGATION_BAR:
2292 mContext.enforceCallingOrSelfPermission(
2293 android.Manifest.permission.STATUS_BAR_SERVICE,
2294 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002295 if (mNavigationBar != null) {
2296 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002297 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002298 }
2299 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002300 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002301 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002302 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002303 break;
Jim Millere898ac52012-04-06 17:10:57 -07002304 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002305 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002306 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002307 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002308 mContext.enforceCallingOrSelfPermission(
2309 android.Manifest.permission.STATUS_BAR_SERVICE,
2310 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002311 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002312 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002313 if (mKeyguardScrim != null) {
2314 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2315 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002316 mKeyguardScrim = win;
2317 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002318 }
Jeff Brown98365d72012-08-19 20:30:52 -07002319 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002320 }
2321
2322 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002323 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002324 public void removeWindowLw(WindowState win) {
2325 if (mStatusBar == win) {
2326 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002327 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002328 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002329 } else if (mKeyguardScrim == win) {
2330 Log.v(TAG, "Removing keyguard scrim");
2331 mKeyguardScrim = null;
2332 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002333 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002334 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002335 }
2336 }
2337
2338 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002339
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002340 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002341 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002342 public int selectAnimationLw(WindowState win, int transit) {
2343 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2344 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002345 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002346 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002347 if (transit == TRANSIT_EXIT
2348 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002349 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002350 } else if (transit == TRANSIT_ENTER
2351 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002352 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002353 }
2354 } else if (win == mNavigationBar) {
2355 // This can be on either the bottom or the right.
2356 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002357 if (transit == TRANSIT_EXIT
2358 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002359 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002360 } else if (transit == TRANSIT_ENTER
2361 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002362 return R.anim.dock_bottom_enter;
2363 }
2364 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002365 if (transit == TRANSIT_EXIT
2366 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002367 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002368 } else if (transit == TRANSIT_ENTER
2369 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002370 return R.anim.dock_right_enter;
2371 }
2372 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002373 }
2374
2375 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002376 if (win.hasAppShownWindows()) {
2377 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2378 return com.android.internal.R.anim.app_starting_exit;
2379 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002380 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002381 && transit == TRANSIT_ENTER) {
2382 // Special case: we are animating in a dream, while the keyguard
2383 // is shown. We don't want an animation on the dream, because
2384 // we need it shown immediately with the keyguard animating away
2385 // to reveal it.
2386 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002387 }
2388
2389 return 0;
2390 }
2391
Craig Mautner3c174372013-02-21 17:54:37 -08002392 @Override
2393 public void selectRotationAnimationLw(int anim[]) {
2394 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2395 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2396 + (mTopFullscreenOpaqueWindowState == null ?
2397 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2398 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2399 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2400 case ROTATION_ANIMATION_CROSSFADE:
2401 anim[0] = R.anim.rotation_animation_xfade_exit;
2402 anim[1] = R.anim.rotation_animation_enter;
2403 break;
2404 case ROTATION_ANIMATION_JUMPCUT:
2405 anim[0] = R.anim.rotation_animation_jump_exit;
2406 anim[1] = R.anim.rotation_animation_enter;
2407 break;
2408 case ROTATION_ANIMATION_ROTATE:
2409 default:
2410 anim[0] = anim[1] = 0;
2411 break;
2412 }
2413 } else {
2414 anim[0] = anim[1] = 0;
2415 }
2416 }
2417
2418 @Override
2419 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2420 boolean forceDefault) {
2421 switch (exitAnimId) {
2422 case R.anim.rotation_animation_xfade_exit:
2423 case R.anim.rotation_animation_jump_exit:
2424 // These are the only cases that matter.
2425 if (forceDefault) {
2426 return false;
2427 }
2428 int anim[] = new int[2];
2429 selectRotationAnimationLw(anim);
2430 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2431 default:
2432 return true;
2433 }
2434 }
2435
2436 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002437 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2438 boolean goingToNotificationShade) {
2439 if (goingToNotificationShade) {
2440 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002441 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002442
2443 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2444 R.anim.lock_screen_behind_enter_wallpaper :
2445 R.anim.lock_screen_behind_enter);
2446
2447 // TODO: Use XML interpolators when we have log interpolators available in XML.
2448 final List<Animation> animations = set.getAnimations();
2449 for (int i = animations.size() - 1; i >= 0; --i) {
2450 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2451 }
2452
2453 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002454 }
2455
2456
2457 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002458 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2459 if (goingToNotificationShade) {
2460 return null;
2461 } else {
2462 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2463 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002464 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002465
2466 private static void awakenDreams() {
2467 IDreamManager dreamManager = getDreamManager();
2468 if (dreamManager != null) {
2469 try {
2470 dreamManager.awaken();
2471 } catch (RemoteException e) {
2472 // fine, stay asleep then
2473 }
2474 }
2475 }
2476
2477 static IDreamManager getDreamManager() {
2478 return IDreamManager.Stub.asInterface(
2479 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2480 }
2481
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002482 TelecomManager getTelecommService() {
2483 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002484 }
2485
Jeff Brown4d396052010-10-29 21:50:21 -07002486 static IAudioService getAudioService() {
2487 IAudioService audioService = IAudioService.Stub.asInterface(
2488 ServiceManager.checkService(Context.AUDIO_SERVICE));
2489 if (audioService == null) {
2490 Log.w(TAG, "Unable to find IAudioService interface.");
2491 }
2492 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002493 }
2494
2495 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002496 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002497 }
2498
2499 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2500 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2501 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2502 };
2503
2504 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002505 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002506 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002507 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002508 final int keyCode = event.getKeyCode();
2509 final int repeatCount = event.getRepeatCount();
2510 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002511 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002512 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2513 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002514
Jeff Brown40013652012-05-16 21:22:36 -07002515 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002516 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002517 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2518 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002519 }
2520
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002521 // If we think we might have a volume down & power key chord on the way
2522 // but we're not sure, then tell the dispatcher to wait a little while and
2523 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002524 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002525 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002526 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002527 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2528 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002529 if (now < timeoutTime) {
2530 return timeoutTime - now;
2531 }
2532 }
2533 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002534 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002535 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002536 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002537 }
2538 return -1;
2539 }
2540 }
2541
Michael Wright6a62e552014-06-03 19:19:48 -07002542 // Cancel any pending meta actions if we see any other keys being pressed between the down
2543 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002544 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002545 mPendingMetaAction = false;
2546 }
2547
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002548 // First we always handle the home key here, so applications
2549 // can never break it, although if keyguard is on, we do let
2550 // it handle it, because that gives us the correct 5 second
2551 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002552 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002553
Jeff Brown49ed71d2010-12-06 17:13:33 -08002554 // If we have released the home key, and didn't do anything else
2555 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002556 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002557 cancelPreloadRecentApps();
2558
Jeff Brown49ed71d2010-12-06 17:13:33 -08002559 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002560 if (mHomeConsumed) {
2561 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002562 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002563 }
Jeff Browncaca8812013-05-09 13:34:33 -07002564
2565 if (canceled) {
2566 Log.i(TAG, "Ignoring HOME; event canceled.");
2567 return -1;
2568 }
2569
Yorke Lee4f803242014-12-15 23:22:06 +00002570 // If an incoming call is ringing, HOME is totally disabled.
2571 // (The user is already on the InCallUI at this point,
2572 // and his ONLY options are to answer or reject the call.)
2573 TelecomManager telecomManager = getTelecommService();
2574 if (telecomManager != null && telecomManager.isRinging()) {
2575 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2576 return -1;
2577 }
2578
Jeff Browncaca8812013-05-09 13:34:33 -07002579 // Delay handling home if a double-tap is possible.
2580 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2581 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2582 mHomeDoubleTapPending = true;
2583 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2584 ViewConfiguration.getDoubleTapTimeout());
2585 return -1;
2586 }
2587
Jeff Brown13f00f02014-10-31 14:45:50 -07002588 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002589 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002590 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002591
2592 // If a system window has focus, then it doesn't make sense
2593 // right now to interact with applications.
2594 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2595 if (attrs != null) {
2596 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002597 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2598 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2599 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002600 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002601 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002602 }
2603 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2604 for (int i=0; i<typeCount; i++) {
2605 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2606 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002607 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002608 }
2609 }
2610 }
Jeff Browncaca8812013-05-09 13:34:33 -07002611
2612 // Remember that home is pressed and handle special actions.
2613 if (repeatCount == 0) {
2614 mHomePressed = true;
2615 if (mHomeDoubleTapPending) {
2616 mHomeDoubleTapPending = false;
2617 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2618 handleDoubleTapOnHome();
2619 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2620 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2621 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002622 }
Jeff Browncaca8812013-05-09 13:34:33 -07002623 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2624 if (!keyguardOn) {
2625 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002626 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002627 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002628 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002629 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002630 // Hijack modified menu keys for debugging features
2631 final int chordBug = KeyEvent.META_SHIFT_ON;
2632
2633 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002634 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002635 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002636 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2637 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002638 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002639 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002640 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002641 Intent service = new Intent();
2642 service.setClassName(mContext, "com.android.server.LoadAverageService");
2643 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002644 boolean shown = Settings.Global.getInt(
2645 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002646 if (!shown) {
2647 mContext.startService(service);
2648 } else {
2649 mContext.stopService(service);
2650 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002651 Settings.Global.putInt(
2652 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002653 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002654 }
2655 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002656 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002657 if (down) {
2658 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002659 mSearchKeyShortcutPending = true;
2660 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002661 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002662 } else {
2663 mSearchKeyShortcutPending = false;
2664 if (mConsumeSearchKeyUp) {
2665 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002666 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002667 }
2668 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002669 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002670 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002671 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002672 if (down && repeatCount == 0) {
2673 preloadRecentApps();
2674 } else if (!down) {
2675 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002676 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002677 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002678 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002679 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2680 if (down) {
2681 IStatusBarService service = getStatusBarService();
2682 if (service != null) {
2683 try {
2684 service.expandNotificationsPanel();
2685 } catch (RemoteException e) {
2686 // do nothing.
2687 }
2688 }
2689 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002690 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2691 if (down) {
2692 if (repeatCount == 0) {
2693 mAssistKeyLongPressed = false;
2694 } else if (repeatCount == 1) {
2695 mAssistKeyLongPressed = true;
2696 if (!keyguardOn) {
2697 launchAssistLongPressAction();
2698 }
2699 }
2700 } else {
2701 if (mAssistKeyLongPressed) {
2702 mAssistKeyLongPressed = false;
2703 } else {
2704 if (!keyguardOn) {
2705 launchAssistAction();
2706 }
2707 }
2708 }
2709 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002710 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2711 if (!down) {
2712 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002713 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002714 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2715 } else {
2716 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002717 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002718 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002719 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002720 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002721 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2722 if (down && repeatCount == 0) {
2723 mHandler.post(mScreenshotRunnable);
2724 }
2725 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002726 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2727 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2728 if (down) {
2729 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2730
2731 // Disable autobrightness if it's on
2732 int auto = Settings.System.getIntForUser(
2733 mContext.getContentResolver(),
2734 Settings.System.SCREEN_BRIGHTNESS_MODE,
2735 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2736 UserHandle.USER_CURRENT_OR_SELF);
2737 if (auto != 0) {
2738 Settings.System.putIntForUser(mContext.getContentResolver(),
2739 Settings.System.SCREEN_BRIGHTNESS_MODE,
2740 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2741 UserHandle.USER_CURRENT_OR_SELF);
2742 }
2743
2744 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2745 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2746 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2747 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2748 Settings.System.SCREEN_BRIGHTNESS,
2749 mPowerManager.getDefaultScreenBrightnessSetting(),
2750 UserHandle.USER_CURRENT_OR_SELF);
2751 brightness += step;
2752 // Make sure we don't go beyond the limits.
2753 brightness = Math.min(max, brightness);
2754 brightness = Math.max(min, brightness);
2755
2756 Settings.System.putIntForUser(mContext.getContentResolver(),
2757 Settings.System.SCREEN_BRIGHTNESS, brightness,
2758 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002759 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002760 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002761 }
2762 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002763 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002764 if (down) {
2765 mPendingMetaAction = true;
2766 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002767 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002768 }
2769 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002770 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002771
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002772 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002773 // Any printing key that is chorded with Search should be consumed
2774 // even if no shortcut was invoked. This prevents text from being
2775 // inadvertently inserted when using a keyboard that has built-in macro
2776 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002777 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002778 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2779 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002780 mConsumeSearchKeyUp = true;
2781 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002782 if (down && repeatCount == 0 && !keyguardOn) {
2783 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2784 if (shortcutIntent != null) {
2785 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002786 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002787 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002788 } catch (ActivityNotFoundException ex) {
2789 Slog.w(TAG, "Dropping shortcut key combination because "
2790 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002791 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002792 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002793 } else {
2794 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002795 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002796 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002797 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002798 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002799 }
2800 }
2801
Jeff Brown68b909d2011-12-07 16:36:01 -08002802 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002803 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002804 && (metaState & KeyEvent.META_META_ON) != 0) {
2805 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002806 if (kcm.isPrintingKey(keyCode)) {
2807 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2808 metaState & ~(KeyEvent.META_META_ON
2809 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2810 if (shortcutIntent != null) {
2811 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2812 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002813 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002814 } catch (ActivityNotFoundException ex) {
2815 Slog.w(TAG, "Dropping shortcut key combination because "
2816 + "the activity to which it is registered was not found: "
2817 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2818 }
2819 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002820 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002821 }
2822 }
2823
Jeff Brown6651a632011-11-28 12:59:11 -08002824 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002825 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002826 String category = sApplicationLaunchKeyCategories.get(keyCode);
2827 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002828 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002829 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2830 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002831 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002832 } catch (ActivityNotFoundException ex) {
2833 Slog.w(TAG, "Dropping application launch key because "
2834 + "the activity to which it is registered was not found: "
2835 + "keyCode=" + keyCode + ", category=" + category, ex);
2836 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002837 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002838 }
2839 }
2840
Michael Wright61c46752014-08-21 16:57:33 -07002841 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002842 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002843 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002844 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002845 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002846 mRecentAppsHeldModifiers = shiftlessModifiers;
2847 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002848 return -1;
2849 }
2850 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002851 } else if (!down && mRecentAppsHeldModifiers != 0
2852 && (metaState & mRecentAppsHeldModifiers) == 0) {
2853 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002854 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002855 }
2856
Jeff Browncf39bdf2012-05-18 14:41:19 -07002857 // Handle keyboard language switching.
2858 if (down && repeatCount == 0
2859 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2860 || (keyCode == KeyEvent.KEYCODE_SPACE
2861 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2862 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2863 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2864 return -1;
2865 }
2866 if (mLanguageSwitchKeyPressed && !down
2867 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2868 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2869 mLanguageSwitchKeyPressed = false;
2870 return -1;
2871 }
2872
Jeff Brown13f00f02014-10-31 14:45:50 -07002873 if (isValidGlobalKey(keyCode)
2874 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002875 return -1;
2876 }
2877
Michael Wright6a62e552014-06-03 19:19:48 -07002878 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002879 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002880 return -1;
2881 }
2882
Jeff Brown68b909d2011-12-07 16:36:01 -08002883 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002884 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002885 }
2886
Jeff Brown3915bb82010-11-05 15:02:16 -07002887 /** {@inheritDoc} */
2888 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002889 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002890 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002891 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002892 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2893 + ", flags=" + event.getFlags()
2894 + ", keyCode=" + event.getKeyCode()
2895 + ", scanCode=" + event.getScanCode()
2896 + ", metaState=" + event.getMetaState()
2897 + ", repeatCount=" + event.getRepeatCount()
2898 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002899 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002900
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002901 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002902 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2903 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002904 final int keyCode = event.getKeyCode();
2905 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002906 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2907 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002908
Jeff Brown54875002011-04-06 15:33:01 -07002909 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002910 final FallbackAction fallbackAction;
2911 if (initialDown) {
2912 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2913 } else {
2914 fallbackAction = mFallbackActions.get(keyCode);
2915 }
2916
2917 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002918 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002919 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2920 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002921 }
2922
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002923 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2924 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002925 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002926 event.getAction(), fallbackAction.keyCode,
2927 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002928 event.getDeviceId(), event.getScanCode(),
2929 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002930
2931 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2932 fallbackEvent.recycle();
2933 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002934 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002935
2936 if (initialDown) {
2937 mFallbackActions.put(keyCode, fallbackAction);
2938 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2939 mFallbackActions.remove(keyCode);
2940 fallbackAction.recycle();
2941 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002942 }
2943 }
2944
Jeff Brown40013652012-05-16 21:22:36 -07002945 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002946 if (fallbackEvent == null) {
2947 Slog.d(TAG, "No fallback.");
2948 } else {
2949 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2950 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002951 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002952 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002953 }
2954
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002955 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002956 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002957 if ((actions & ACTION_PASS_TO_USER) != 0) {
2958 long delayMillis = interceptKeyBeforeDispatching(
2959 win, fallbackEvent, policyFlags);
2960 if (delayMillis == 0) {
2961 return true;
2962 }
2963 }
2964 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002965 }
2966
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002967 private void launchAssistLongPressAction() {
2968 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2969 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2970
2971 // launch the search activity
2972 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2973 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2974 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002975 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002976 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002977 SearchManager searchManager = getSearchManager();
2978 if (searchManager != null) {
2979 searchManager.stopSearch();
2980 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002981 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002982 } catch (ActivityNotFoundException e) {
2983 Slog.w(TAG, "No activity to handle assist long press action.", e);
2984 }
2985 }
2986
2987 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002988 launchAssistAction(null);
2989 }
2990
2991 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002992 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002993 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002994 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002995 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002996 if (hint != null) {
2997 intent.putExtra(hint, true);
2998 }
Jim Miller45308b12012-06-18 19:23:39 -07002999 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
3000 | Intent.FLAG_ACTIVITY_SINGLE_TOP
3001 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
3002 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003003 startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07003004 } catch (ActivityNotFoundException e) {
3005 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003006 }
3007 }
3008 }
3009
Bart Sears8b1c27c2015-03-18 23:51:02 +00003010 private void startActivityAsUser(Intent intent, UserHandle handle) {
3011 if (isUserSetupComplete()) {
3012 mContext.startActivityAsUser(intent, handle);
3013 } else {
3014 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3015 }
3016 }
3017
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003018 private SearchManager getSearchManager() {
3019 if (mSearchManager == null) {
3020 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3021 }
3022 return mSearchManager;
3023 }
3024
Jeff Browncaca8812013-05-09 13:34:33 -07003025 private void preloadRecentApps() {
3026 mPreloadedRecentApps = true;
3027 try {
3028 IStatusBarService statusbar = getStatusBarService();
3029 if (statusbar != null) {
3030 statusbar.preloadRecentApps();
3031 }
3032 } catch (RemoteException e) {
3033 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3034 // re-acquire status bar service next time it is needed.
3035 mStatusBarService = null;
3036 }
3037 }
3038
3039 private void cancelPreloadRecentApps() {
3040 if (mPreloadedRecentApps) {
3041 mPreloadedRecentApps = false;
3042 try {
3043 IStatusBarService statusbar = getStatusBarService();
3044 if (statusbar != null) {
3045 statusbar.cancelPreloadRecentApps();
3046 }
3047 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003048 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003049 // re-acquire status bar service next time it is needed.
3050 mStatusBarService = null;
3051 }
3052 }
3053 }
3054
3055 private void toggleRecentApps() {
3056 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003057 try {
3058 IStatusBarService statusbar = getStatusBarService();
3059 if (statusbar != null) {
3060 statusbar.toggleRecentApps();
3061 }
3062 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003063 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3064 // re-acquire status bar service next time it is needed.
3065 mStatusBarService = null;
3066 }
3067 }
3068
Craig Mautner84984fa2014-06-19 11:19:20 -07003069 @Override
3070 public void showRecentApps() {
3071 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3072 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3073 }
3074
Winson Chung1e8d71b2014-05-16 17:05:22 -07003075 private void showRecentApps(boolean triggeredFromAltTab) {
3076 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3077 try {
3078 IStatusBarService statusbar = getStatusBarService();
3079 if (statusbar != null) {
3080 statusbar.showRecentApps(triggeredFromAltTab);
3081 }
3082 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003083 Slog.e(TAG, "RemoteException when showing recent apps", e);
3084 // re-acquire status bar service next time it is needed.
3085 mStatusBarService = null;
3086 }
3087 }
3088
Winson Chungcdcd4872014-08-05 18:00:13 -07003089 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003090 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3091 try {
3092 IStatusBarService statusbar = getStatusBarService();
3093 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003094 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003095 }
3096 } catch (RemoteException e) {
3097 Slog.e(TAG, "RemoteException when closing recent apps", e);
3098 // re-acquire status bar service next time it is needed.
3099 mStatusBarService = null;
3100 }
3101 }
3102
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003103 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003104 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003105 }
3106
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003107 /**
3108 * A home key -> launch home action was detected. Take the appropriate action
3109 * given the situation with the keyguard.
3110 */
Bryce Lee662ed802015-04-10 20:11:39 +00003111 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3112 if (respectKeyguard) {
3113 if (isKeyguardShowingAndNotOccluded()) {
3114 // don't launch home if keyguard showing
3115 return;
3116 }
3117
3118 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3119 // when in keyguard restricted mode, must first verify unlock
3120 // before launching home
3121 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3122 @Override
3123 public void onKeyguardExitResult(boolean success) {
3124 if (success) {
3125 try {
3126 ActivityManagerNative.getDefault().stopAppSwitches();
3127 } catch (RemoteException e) {
3128 }
3129 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3130 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003131 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003132 }
Bryce Lee662ed802015-04-10 20:11:39 +00003133 });
3134 return;
3135 }
3136 }
3137
3138 // no keyguard stuff to worry about, just launch home!
3139 try {
3140 ActivityManagerNative.getDefault().stopAppSwitches();
3141 } catch (RemoteException e) {
3142 }
3143 if (mRecentsVisible) {
3144 // Hide Recents and notify it to launch Home
3145 if (awakenFromDreams) {
3146 awakenDreams();
3147 }
3148 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3149 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003150 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003151 // Otherwise, just launch Home
3152 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3153 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003154 }
3155 }
3156
John Spurlock04db1762013-05-13 12:46:41 -04003157 private final Runnable mClearHideNavigationFlag = new Runnable() {
3158 @Override
3159 public void run() {
3160 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3161 // Clear flags.
3162 mForceClearedSystemUiFlags &=
3163 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3164 }
3165 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003166 }
3167 };
3168
3169 /**
3170 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3171 * to determine when the nav bar should be shown and prevent applications from
3172 * receiving those touches.
3173 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003174 final class HideNavInputEventReceiver extends InputEventReceiver {
3175 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3176 super(inputChannel, looper);
3177 }
3178
Dianne Hackborndf89e652011-10-06 22:35:11 -07003179 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003180 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003181 boolean handled = false;
3182 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003183 if (event instanceof MotionEvent
3184 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3185 final MotionEvent motionEvent = (MotionEvent)event;
3186 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003187 // When the user taps down, we re-show the nav bar.
3188 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003189 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003190 // Any user activity always causes us to show the
3191 // navigation controls, if they had been hidden.
3192 // We also clear the low profile and only content
3193 // flags so that tapping on the screen will atomically
3194 // restore all currently hidden screen decorations.
3195 int newVal = mResettingSystemUiFlags |
3196 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3197 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3198 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003199 if (mResettingSystemUiFlags != newVal) {
3200 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003201 changed = true;
3202 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003203 // We don't allow the system's nav bar to be hidden
3204 // again for 1 second, to prevent applications from
3205 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003206 newVal = mForceClearedSystemUiFlags |
3207 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003208 if (mForceClearedSystemUiFlags != newVal) {
3209 mForceClearedSystemUiFlags = newVal;
3210 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003211 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003212 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003213 }
3214 if (changed) {
3215 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3216 }
3217 }
3218 }
3219 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003220 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003221 }
3222 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003223 }
3224 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3225 new InputEventReceiver.Factory() {
3226 @Override
3227 public InputEventReceiver createInputEventReceiver(
3228 InputChannel inputChannel, Looper looper) {
3229 return new HideNavInputEventReceiver(inputChannel, looper);
3230 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003231 };
3232
3233 @Override
3234 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003235 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3236 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003237 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003238
Dianne Hackborndf89e652011-10-06 22:35:11 -07003239 // Reset any bits in mForceClearingStatusBarVisibility that
3240 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003241 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003242 // Clear any bits in the new visibility that are currently being
3243 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003244 return visibility & ~mResettingSystemUiFlags
3245 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003246 }
3247
Craig Mautner69b08182012-09-05 13:07:13 -07003248 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003249 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3250 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003251 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003252 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3253 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003254
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003255 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003256 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003257 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003258 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003259 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003260 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3261 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3262 } else {
3263 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3264 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3265 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003266 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3267 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003268 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003269 availRight - mStableFullscreenRight,
3270 availBottom - mStableFullscreenBottom);
3271 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003272 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003273 availRight - mStableRight, availBottom - mStableBottom);
3274 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003275 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003276 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003277 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003278 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003279 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003280 availRight - mCurRight, availBottom - mCurBottom);
3281 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003282 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003283 availRight - mCurRight, availBottom - mCurBottom);
3284 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003285
3286 outStableInsets.set(mStableLeft, mStableTop,
3287 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003288 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003289 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003290 outContentInsets.setEmpty();
3291 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003292 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003293
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003294 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003295 @Override
3296 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3297 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003298 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3299 if (isDefaultDisplay) {
3300 switch (displayRotation) {
3301 case Surface.ROTATION_90:
3302 overscanLeft = mOverscanTop;
3303 overscanTop = mOverscanRight;
3304 overscanRight = mOverscanBottom;
3305 overscanBottom = mOverscanLeft;
3306 break;
3307 case Surface.ROTATION_180:
3308 overscanLeft = mOverscanRight;
3309 overscanTop = mOverscanBottom;
3310 overscanRight = mOverscanLeft;
3311 overscanBottom = mOverscanTop;
3312 break;
3313 case Surface.ROTATION_270:
3314 overscanLeft = mOverscanBottom;
3315 overscanTop = mOverscanLeft;
3316 overscanRight = mOverscanTop;
3317 overscanBottom = mOverscanRight;
3318 break;
3319 default:
3320 overscanLeft = mOverscanLeft;
3321 overscanTop = mOverscanTop;
3322 overscanRight = mOverscanRight;
3323 overscanBottom = mOverscanBottom;
3324 break;
3325 }
3326 } else {
3327 overscanLeft = 0;
3328 overscanTop = 0;
3329 overscanRight = 0;
3330 overscanBottom = 0;
3331 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003332 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3333 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3334 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3335 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003336 mSystemLeft = 0;
3337 mSystemTop = 0;
3338 mSystemRight = displayWidth;
3339 mSystemBottom = displayHeight;
3340 mUnrestrictedScreenLeft = overscanLeft;
3341 mUnrestrictedScreenTop = overscanTop;
3342 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3343 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3344 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3345 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003346 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3347 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003348 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003349 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003350 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003351 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003352 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003353 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003354 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003355 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003356 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003357 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003358
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003359 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3360 final Rect pf = mTmpParentFrame;
3361 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003362 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003363 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003364 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003365 pf.left = df.left = of.left = vf.left = mDockLeft;
3366 pf.top = df.top = of.top = vf.top = mDockTop;
3367 pf.right = df.right = of.right = vf.right = mDockRight;
3368 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003369 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003370
Craig Mautner69b08182012-09-05 13:07:13 -07003371 if (isDefaultDisplay) {
3372 // For purposes of putting out fake window up to steal focus, we will
3373 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003374 final int sysui = mLastSystemUiFlags;
3375 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003376 boolean navTranslucent = (sysui
3377 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003378 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3379 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3380 boolean navAllowedHidden = immersive || immersiveSticky;
3381 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003382 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3383 if (!isKeyguardShowing) {
3384 navTranslucent &= areTranslucentBarsAllowed();
3385 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003386
Craig Mautner69b08182012-09-05 13:07:13 -07003387 // When the navigation bar isn't visible, we put up a fake
3388 // input window to catch all touch events. This way we can
3389 // detect when the user presses anywhere to bring back the nav
3390 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003391 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003392 if (mInputConsumer != null) {
3393 mInputConsumer.dismiss();
3394 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003395 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003396 } else if (mInputConsumer == null) {
3397 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3398 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003399 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003400
Craig Mautner69b08182012-09-05 13:07:13 -07003401 // For purposes of positioning and showing the nav bar, if we have
3402 // decided that it can't be hidden (because of the screen aspect ratio),
3403 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003404 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003405
John Spurlockad3e6cb2013-04-30 08:47:43 -04003406 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003407 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003408 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003409 // Force the navigation bar to its appropriate place and
3410 // size. We need to do this directly, instead of relying on
3411 // it to bubble up from the nav bar, because this needs to
3412 // change atomically with screen rotations.
3413 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3414 if (mNavigationBarOnBottom) {
3415 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003416 int top = displayHeight - overscanBottom
3417 - mNavigationBarHeightForRotation[displayRotation];
3418 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003419 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003420 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003421 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003422 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003423 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003424 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003425 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3426 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003427 } else {
3428 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003429 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003430 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003431 if (navVisible && !navTranslucent && !navAllowedHidden
3432 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003433 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003434 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003435 // and not in the process of animating on or off, then
3436 // we can tell the app that it is covered by it.
3437 mSystemBottom = mTmpNavigationFrame.top;
3438 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003439 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003440 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003441 int left = displayWidth - overscanRight
3442 - mNavigationBarWidthForRotation[displayRotation];
3443 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003444 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003445 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003446 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003447 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003448 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003449 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003450 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3451 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003452 } else {
3453 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003454 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003455 }
John Spurlockbd957402013-10-03 11:38:39 -04003456 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3457 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003458 // If the nav bar is currently requested to be visible,
3459 // and not in the process of animating on or off, then
3460 // we can tell the app that it is covered by it.
3461 mSystemRight = mTmpNavigationFrame.left;
3462 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003463 }
Craig Mautner69b08182012-09-05 13:07:13 -07003464 // Make sure the content and current rectangles are updated to
3465 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003466 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3467 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3468 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3469 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003470 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3471 // And compute the final frame.
3472 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003473 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
Dianne Hackborn4bb6b752015-05-22 16:34:44 -07003474 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003475 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003476 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003477 updateSysUiVisibility = true;
3478 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003479 }
Craig Mautnereda67292013-04-28 13:50:14 -07003480 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003481 mDockLeft, mDockTop, mDockRight, mDockBottom));
3482
3483 // decide where the status bar goes ahead of time
3484 if (mStatusBar != null) {
3485 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003486 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3487 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3488 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3489 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3490 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003491 vf.left = mStableLeft;
3492 vf.top = mStableTop;
3493 vf.right = mStableRight;
3494 vf.bottom = mStableBottom;
3495
3496 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3497
3498 // Let the status bar determine its size.
Dianne Hackborn4bb6b752015-05-22 16:34:44 -07003499 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003500
3501 // For layout, the status bar is always at the top with our fixed height.
3502 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3503
John Spurlocke1f366f2013-08-05 12:22:40 -04003504 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003505 boolean statusBarTranslucent = (sysui
3506 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003507 if (!isKeyguardShowing) {
3508 statusBarTranslucent &= areTranslucentBarsAllowed();
3509 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003510
Craig Mautner69b08182012-09-05 13:07:13 -07003511 // If the status bar is hidden, we don't want to cause
3512 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003513 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003514 // Status bar may go away, so the screen area it occupies
3515 // is available to apps but just covering them when the
3516 // status bar is visible.
3517 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3518
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003519 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3520 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3521 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3522 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003523
Craig Mautnereda67292013-04-28 13:50:14 -07003524 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003525 String.format(
3526 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3527 mDockLeft, mDockTop, mDockRight, mDockBottom,
3528 mContentLeft, mContentTop, mContentRight, mContentBottom,
3529 mCurLeft, mCurTop, mCurRight, mCurBottom));
3530 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003531 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003532 && !statusBarTransient && !statusBarTranslucent
3533 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003534 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003535 // and not in the process of animating on or off, then
3536 // we can tell the app that it is covered by it.
3537 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3538 }
John Spurlock27735a42013-08-14 17:57:38 -04003539 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003540 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003541 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003542 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003543 if (updateSysUiVisibility) {
3544 updateSystemUiVisibilityLw();
3545 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003546 }
3547 }
3548
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003549 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003550 @Override
John Spurlock46646232013-09-30 22:32:42 -04003551 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003552 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3553 return mStatusBar.getSurfaceLayer();
3554 }
3555
3556 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3557 return mNavigationBar.getSurfaceLayer();
3558 }
3559
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003560 return 0;
3561 }
3562
Craig Mautner967212c2013-04-13 21:10:58 -07003563 @Override
3564 public void getContentRectLw(Rect r) {
3565 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3566 }
3567
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003568 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3569 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003570 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3571 // Here's a special case: if this attached window is a panel that is
3572 // above the dock window, and the window it is attached to is below
3573 // the dock window, then the frames we computed for the window it is
3574 // attached to can not be used because the dock is effectively part
3575 // of the underlying window and the attached window is floating on top
3576 // of the whole thing. So, we ignore the attached window and explicitly
3577 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003578 df.left = of.left = cf.left = vf.left = mDockLeft;
3579 df.top = of.top = cf.top = vf.top = mDockTop;
3580 df.right = of.right = cf.right = vf.right = mDockRight;
3581 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003582 } else {
3583 // The effective display frame of the attached window depends on
3584 // whether it is taking care of insetting its content. If not,
3585 // we need to use the parent's content frame so that the entire
3586 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003587 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003588 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003589 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003590 // Set the content frame of the attached window to the parent's decor frame
3591 // (same as content frame when IME isn't present) if specifically requested by
3592 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3593 // Otherwise, use the overscan frame.
3594 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3595 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003596 } else {
3597 // If the window is resizing, then we want to base the content
3598 // frame on our attached content frame to resize... however,
3599 // things can be tricky if the attached window is NOT in resize
3600 // mode, in which case its content frame will be larger.
3601 // Ungh. So to deal with that, make sure the content frame
3602 // we end up using is not covering the IM dock.
3603 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003604 if (attached.isVoiceInteraction()) {
3605 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3606 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3607 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3608 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3609 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003610 if (cf.left < mContentLeft) cf.left = mContentLeft;
3611 if (cf.top < mContentTop) cf.top = mContentTop;
3612 if (cf.right > mContentRight) cf.right = mContentRight;
3613 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3614 }
3615 }
3616 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003617 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003618 vf.set(attached.getVisibleFrameLw());
3619 }
3620 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3621 // window should be positioned relative to its parent or the entire
3622 // screen.
3623 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3624 ? attached.getFrameLw() : df);
3625 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003626
3627 private void applyStableConstraints(int sysui, int fl, Rect r) {
3628 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3629 // If app is requesting a stable layout, don't let the
3630 // content insets go below the stable values.
3631 if ((fl & FLAG_FULLSCREEN) != 0) {
3632 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3633 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3634 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3635 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3636 } else {
3637 if (r.left < mStableLeft) r.left = mStableLeft;
3638 if (r.top < mStableTop) r.top = mStableTop;
3639 if (r.right > mStableRight) r.right = mStableRight;
3640 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3641 }
3642 }
3643 }
3644
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003645 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003646 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003647 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003648 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003649 final WindowManager.LayoutParams attrs = win.getAttrs();
3650 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3651 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003652 return;
3653 }
Craig Mautner69b08182012-09-05 13:07:13 -07003654 final boolean isDefaultDisplay = win.isDefaultDisplay();
3655 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003656 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3657 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003658 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003659 offsetInputMethodWindowLw(mLastInputMethodWindow);
3660 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003661
John Spurlockc6d1c602014-01-17 15:22:06 -05003662 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003663 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003664 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003665
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003666 final Rect pf = mTmpParentFrame;
3667 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003668 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003669 final Rect cf = mTmpContentFrame;
3670 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003671 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003672 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003673 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003674
3675 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003676 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003677
Craig Mautnerf683b562012-10-02 11:10:57 -07003678 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3679
Adrian Roosfa104232014-06-20 16:10:14 -07003680 if (isDefaultDisplay) {
3681 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3682 } else {
3683 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3684 }
3685
Craig Mautner69b08182012-09-05 13:07:13 -07003686 if (!isDefaultDisplay) {
3687 if (attached != null) {
3688 // If this window is attached to another, our display
3689 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003690 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003691 } else {
3692 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003693 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3694 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3695 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003696 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003697 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003698 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003699 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003700 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003701 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3702 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3703 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003704 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003705 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003706 // ...with content insets above the nav bar
3707 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003708 // IM dock windows always go to the bottom of the screen.
3709 attrs.gravity = Gravity.BOTTOM;
3710 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003711 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
3712 pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft;
3713 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3714 pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft
3715 + mUnrestrictedScreenWidth;
3716 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3717 + mUnrestrictedScreenHeight;
3718 cf.bottom = vf.bottom = mStableBottom;
3719 cf.top = vf.top = mStableTop;
Jorim Jaggie0700182014-08-21 01:12:37 +02003720 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3721 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3722 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3723 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3724 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3725 cf.left = vf.left = mStableLeft;
3726 cf.top = vf.top = mStableTop;
3727 cf.right = vf.right = mStableRight;
3728 vf.bottom = mStableBottom;
3729 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003730 } else {
John Spurlock46646232013-09-30 22:32:42 -04003731
3732 // Default policy decor for the default display
3733 dcf.left = mSystemLeft;
3734 dcf.top = mSystemTop;
3735 dcf.right = mSystemRight;
3736 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003737 final boolean inheritTranslucentDecor = (attrs.privateFlags
3738 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003739 final boolean isAppWindow =
3740 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3741 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3742 final boolean topAtRest =
3743 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3744 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003745 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3746 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003747 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3748 && (fl & WindowManager.LayoutParams.
3749 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003750 // Ensure policy decor includes status bar
3751 dcf.top = mStableTop;
3752 }
John Spurlockbd957402013-10-03 11:38:39 -04003753 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003754 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3755 && (fl & WindowManager.LayoutParams.
3756 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003757 // Ensure policy decor includes navigation bar
3758 dcf.bottom = mStableBottom;
3759 dcf.right = mStableRight;
3760 }
3761 }
3762
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003763 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3764 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003765 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003766 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003767 // This is the case for a normal activity window: we want it
3768 // to cover all of the screen space, and it can take care of
3769 // moving its contents to account for screen decorations that
3770 // intrude into that space.
3771 if (attached != null) {
3772 // If this window is attached to another, our display
3773 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003774 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003775 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003776 if (attrs.type == TYPE_STATUS_BAR_PANEL
3777 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003778 // Status bar panels are the only windows who can go on top of
3779 // the status bar. They are protected by the STATUS_BAR_SERVICE
3780 // permission, so they have the same privileges as the status
3781 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003782 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003783 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003784
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003785 pf.left = df.left = of.left = hasNavBar
3786 ? mDockLeft : mUnrestrictedScreenLeft;
3787 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3788 pf.right = df.right = of.right = hasNavBar
3789 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3790 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3791 pf.bottom = df.bottom = of.bottom = hasNavBar
3792 ? mRestrictedScreenTop+mRestrictedScreenHeight
3793 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003794
Craig Mautnereda67292013-04-28 13:50:14 -07003795 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003796 "Laying out status bar window: (%d,%d - %d,%d)",
3797 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003798 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003799 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3800 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3801 // Asking to layout into the overscan region, so give it that pure
3802 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003803 pf.left = df.left = of.left = mOverscanScreenLeft;
3804 pf.top = df.top = of.top = mOverscanScreenTop;
3805 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3806 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3807 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003808 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003809 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003810 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3811 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003812 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003813 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003814 // only do this for application windows to ensure no window that
3815 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003816 pf.left = df.left = mOverscanScreenLeft;
3817 pf.top = df.top = mOverscanScreenTop;
3818 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3819 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003820 // We need to tell the app about where the frame inside the overscan
3821 // is, so it can inset its content by that amount -- it didn't ask
3822 // to actually extend itself into the overscan region.
3823 of.left = mUnrestrictedScreenLeft;
3824 of.top = mUnrestrictedScreenTop;
3825 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3826 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003827 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003828 pf.left = df.left = mRestrictedOverscanScreenLeft;
3829 pf.top = df.top = mRestrictedOverscanScreenTop;
3830 pf.right = df.right = mRestrictedOverscanScreenLeft
3831 + mRestrictedOverscanScreenWidth;
3832 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3833 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003834 // We need to tell the app about where the frame inside the overscan
3835 // is, so it can inset its content by that amount -- it didn't ask
3836 // to actually extend itself into the overscan region.
3837 of.left = mUnrestrictedScreenLeft;
3838 of.top = mUnrestrictedScreenTop;
3839 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3840 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003841 }
Craig Mautner69b08182012-09-05 13:07:13 -07003842
John Spurlock46646232013-09-30 22:32:42 -04003843 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003844 if (win.isVoiceInteraction()) {
3845 cf.left = mVoiceContentLeft;
3846 cf.top = mVoiceContentTop;
3847 cf.right = mVoiceContentRight;
3848 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003849 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003850 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3851 cf.left = mDockLeft;
3852 cf.top = mDockTop;
3853 cf.right = mDockRight;
3854 cf.bottom = mDockBottom;
3855 } else {
3856 cf.left = mContentLeft;
3857 cf.top = mContentTop;
3858 cf.right = mContentRight;
3859 cf.bottom = mContentBottom;
3860 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003861 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003862 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003863 // Full screen windows are always given a layout that is as if the
3864 // status bar and other transient decors are gone. This is to avoid
3865 // bad states when moving from a window that is not hding the
3866 // status bar to one that is.
3867 cf.left = mRestrictedScreenLeft;
3868 cf.top = mRestrictedScreenTop;
3869 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3870 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003871 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003872 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003873 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3874 vf.left = mCurLeft;
3875 vf.top = mCurTop;
3876 vf.right = mCurRight;
3877 vf.bottom = mCurBottom;
3878 } else {
3879 vf.set(cf);
3880 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003881 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003882 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3883 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3884 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003885 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3886 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003887 // A window that has requested to fill the entire screen just
3888 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003889 if (attrs.type == TYPE_STATUS_BAR_PANEL
3890 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003891 pf.left = df.left = of.left = cf.left = hasNavBar
3892 ? mDockLeft : mUnrestrictedScreenLeft;
3893 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3894 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003895 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003896 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003897 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003898 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003899 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003900 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003901 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3902 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003903 } else if (attrs.type == TYPE_NAVIGATION_BAR
3904 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003905 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003906 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3907 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3908 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3909 + mUnrestrictedScreenWidth;
3910 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3911 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003912 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003913 "Laying out navigation bar window: (%d,%d - %d,%d)",
3914 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003915 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3916 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003917 && ((fl & FLAG_FULLSCREEN) != 0)) {
3918 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003919 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3920 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3921 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3922 + mOverscanScreenWidth;
3923 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3924 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003925 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003926 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003927 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3928 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3929 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3930 + mOverscanScreenWidth;
3931 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3932 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003933 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003934 // The wallpaper also has Real Ultimate Power, but we want to tell
3935 // it about the overscan area.
3936 pf.left = df.left = mOverscanScreenLeft;
3937 pf.top = df.top = mOverscanScreenTop;
3938 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3939 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3940 of.left = cf.left = mUnrestrictedScreenLeft;
3941 of.top = cf.top = mUnrestrictedScreenTop;
3942 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3943 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003944 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003945 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3946 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3947 // Asking to layout into the overscan region, so give it that pure
3948 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003949 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3950 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3951 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003952 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003953 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003954 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003955 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003956 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003957 && (attrs.type == TYPE_STATUS_BAR
3958 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07003959 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04003960 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3961 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003962 // Asking for layout as if the nav bar is hidden, lets the
3963 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003964 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003965 // can be above the nav bar can do this.
3966 // XXX This assumes that an app asking for this will also
3967 // ask for layout in only content. We can't currently figure out
3968 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003969 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3970 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3971 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3972 + mUnrestrictedScreenWidth;
3973 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3974 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003975 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003976 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3977 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3978 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3979 + mRestrictedScreenWidth;
3980 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3981 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003982 }
Craig Mautner69b08182012-09-05 13:07:13 -07003983
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003984 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003985
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003986 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3987 vf.left = mCurLeft;
3988 vf.top = mCurTop;
3989 vf.right = mCurRight;
3990 vf.bottom = mCurBottom;
3991 } else {
3992 vf.set(cf);
3993 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003994 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003995 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3996 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003997 // A child window should be placed inside of the same visible
3998 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003999 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004000 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004001 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4002 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004003 // Otherwise, a normal window must be placed inside the content
4004 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07004005 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
4006 // Status bar panels are the only windows who can go on top of
4007 // the status bar. They are protected by the STATUS_BAR_SERVICE
4008 // permission, so they have the same privileges as the status
4009 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004010 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4011 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4012 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4013 + mRestrictedScreenWidth;
4014 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4015 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05004016 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
4017 || attrs.type == TYPE_VOLUME_OVERLAY) {
4018 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004019 pf.left = df.left = of.left = cf.left = mStableLeft;
4020 pf.top = df.top = of.top = cf.top = mStableTop;
4021 pf.right = df.right = of.right = cf.right = mStableRight;
4022 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004023 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004024 pf.left = mContentLeft;
4025 pf.top = mContentTop;
4026 pf.right = mContentRight;
4027 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004028 if (win.isVoiceInteraction()) {
4029 df.left = of.left = cf.left = mVoiceContentLeft;
4030 df.top = of.top = cf.top = mVoiceContentTop;
4031 df.right = of.right = cf.right = mVoiceContentRight;
4032 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4033 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004034 df.left = of.left = cf.left = mDockLeft;
4035 df.top = of.top = cf.top = mDockTop;
4036 df.right = of.right = cf.right = mDockRight;
4037 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004038 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004039 df.left = of.left = cf.left = mContentLeft;
4040 df.top = of.top = cf.top = mContentTop;
4041 df.right = of.right = cf.right = mContentRight;
4042 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004043 }
4044 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4045 vf.left = mCurLeft;
4046 vf.top = mCurTop;
4047 vf.right = mCurRight;
4048 vf.bottom = mCurBottom;
4049 } else {
4050 vf.set(cf);
4051 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004052 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004053 }
4054 }
Craig Mautner69b08182012-09-05 13:07:13 -07004055
Craig Mautnerb816bed2013-07-23 10:26:17 -07004056 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4057 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004058 df.left = df.top = -10000;
4059 df.right = df.bottom = 10000;
4060 if (attrs.type != TYPE_WALLPAPER) {
4061 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4062 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4063 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004064 }
4065
Craig Mautnereda67292013-04-28 13:50:14 -07004066 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004067 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004068 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004069 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004070 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004071 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004072 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004073 + " dcf=" + dcf.toShortString()
Dianne Hackborn4bb6b752015-05-22 16:34:44 -07004074 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07004075
Dianne Hackborn4bb6b752015-05-22 16:34:44 -07004076 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07004077
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004078 // Dock windows carve out the bottom of the screen, so normal windows
4079 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004080 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4081 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004082 setLastInputMethodWindowLw(null, null);
4083 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004084 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004085 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4086 && !win.getGivenInsetsPendingLw()) {
4087 offsetVoiceInputWindowLw(win);
4088 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004089 }
4090
satok1bc0a492012-04-25 22:47:12 +09004091 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004092 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004093 top += win.getGivenContentInsetsLw().top;
4094 if (mContentBottom > top) {
4095 mContentBottom = top;
4096 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004097 if (mVoiceContentBottom > top) {
4098 mVoiceContentBottom = top;
4099 }
satok1bc0a492012-04-25 22:47:12 +09004100 top = win.getVisibleFrameLw().top;
4101 top += win.getGivenVisibleInsetsLw().top;
4102 if (mCurBottom > top) {
4103 mCurBottom = top;
4104 }
Craig Mautnereda67292013-04-28 13:50:14 -07004105 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004106 + mDockBottom + " mContentBottom="
4107 + mContentBottom + " mCurBottom=" + mCurBottom);
4108 }
4109
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004110 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004111 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004112 top += win.getGivenContentInsetsLw().top;
4113 if (mVoiceContentBottom > top) {
4114 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004115 }
4116 }
4117
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004118 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004119 @Override
4120 public void finishLayoutLw() {
4121 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004122 }
4123
4124 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004125 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004126 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004127 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004128 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004129 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004130 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004131 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004132 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004133 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004134 mForcingShowNavBar = false;
4135 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004136
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004137 mHideLockScreen = false;
4138 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004139 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004140 mShowingLockscreen = false;
4141 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004142 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004143 mKeyguardSecure = isKeyguardSecure();
4144 mKeyguardSecureIncludingHidden = mKeyguardSecure
4145 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004146 }
4147
4148 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004149 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004150 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004151 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4152 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004153 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004154 if (mTopFullscreenOpaqueWindowState == null
4155 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4156 mForcingShowNavBar = true;
4157 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004158 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004159 if (attrs.type == TYPE_STATUS_BAR) {
4160 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4161 mForceStatusBarFromKeyguard = true;
4162 }
4163 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4164 mForceStatusBarTransparent = true;
4165 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004166 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004167
4168 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4169 && attrs.type < FIRST_SYSTEM_WINDOW;
4170 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4171 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4172
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004173 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004174 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004175 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004176 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004177 mForceStatusBarFromKeyguard = true;
4178 } else {
4179 mForceStatusBar = true;
4180 }
4181 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004182 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004183 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004184 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004185 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004186 // If the lockscreen was showing when the dream started then wait
4187 // for the dream to draw before hiding the lockscreen.
4188 if (!mDreamingLockscreen
4189 || (win.isVisibleLw() && win.hasDrawnLw())) {
4190 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004191 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004192 }
4193 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004194
Craig Mautnerab55e522014-03-03 13:26:03 -08004195 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004196 final IApplicationToken appToken = win.getAppToken();
4197 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004198 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004199 mAppsToBeHidden.remove(appToken);
4200 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004201 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004202 if (dismissKeyguard && !mKeyguardSecure) {
4203 mAppsThatDismissKeyguard.add(appToken);
4204 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004205 mWinShowWhenLocked = win;
4206 mHideLockScreen = true;
4207 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004208 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004209 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004210 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004211 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004212 mAppsToBeHidden.add(appToken);
4213 } else {
4214 mAppsToBeHidden.remove(appToken);
4215 }
4216 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004217 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004218 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004219 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004220 if (attrs.x == 0 && attrs.y == 0
4221 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4222 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4223 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4224 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004225 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4226 mTopFullscreenOpaqueOrDimmingWindowState = win;
4227 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004228 if (!mAppsThatDismissKeyguard.isEmpty() &&
4229 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4230 if (DEBUG_LAYOUT) Slog.v(TAG,
4231 "Setting mDismissKeyguard true by win " + win);
4232 mDismissKeyguard = mWinDismissingKeyguard == win ?
4233 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
4234 mWinDismissingKeyguard = win;
Jim Millerab954542014-10-10 18:21:49 -07004235 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004236 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4237 if (DEBUG_LAYOUT) Slog.v(TAG,
4238 "Setting mHideLockScreen to true by win " + win);
4239 mHideLockScreen = true;
4240 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004241 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004242 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004243 mAllowLockscreenWhenOn = true;
4244 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004245 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004246
4247 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004248 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4249 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004250 win.hideLw(false);
4251 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004252 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004253 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4254 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4255 // that is being hidden in an animation - keep the
4256 // keyguard hidden until the new window shows up and
4257 // we know whether to show the keyguard or not.
4258 if (win.isAnimatingLw() && appWindow && showWhenLocked) {
4259 mHideLockScreen = true;
4260 mWinShowWhenLocked = win;
4261 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004262 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004263 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4264 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4265 && win.isDimming()) {
4266 mTopFullscreenOpaqueOrDimmingWindowState = win;
4267 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004268 }
4269
4270 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004271 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004272 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004273 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4274 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4275 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004276 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4277 // fullscreen window.
4278 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4279 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4280 mTopFullscreenOpaqueWindowState.hideLw(false);
4281 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4282 }
4283
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004284 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004285 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004286
4287 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4288 ? mTopFullscreenOpaqueWindowState.getAttrs()
4289 : null;
4290
Jeff Brownc8018eb2012-10-29 21:33:27 -07004291 // If we are not currently showing a dream then remember the current
4292 // lockscreen state. We will use this to determine whether the dream
4293 // started while the lockscreen was showing and remember this state
4294 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004295 if (!mShowingDream) {
4296 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004297 if (mDreamingSleepTokenNeeded) {
4298 mDreamingSleepTokenNeeded = false;
4299 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4300 }
4301 } else {
4302 if (!mDreamingSleepTokenNeeded) {
4303 mDreamingSleepTokenNeeded = true;
4304 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4305 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004306 }
4307
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004308 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004309 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004310 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004311 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004312 boolean shouldBeTransparent = mForceStatusBarTransparent
4313 && !mForceStatusBar
4314 && !mForceStatusBarFromKeyguard;
4315 if (!shouldBeTransparent) {
4316 mStatusBarController.setShowTransparent(false /* transparent */);
4317 } else if (!mStatusBar.isVisibleLw()) {
4318 mStatusBarController.setShowTransparent(true /* transparent */);
4319 }
4320 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004321 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004322 if (mStatusBarController.setBarShowingLw(true)) {
4323 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4324 }
Craig Mautner81defc72013-10-29 11:10:42 -07004325 // Maintain fullscreen layout until incoming animation is complete.
4326 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004327 // Transient status bar on the lockscreen is not allowed
4328 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4329 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4330 mLastSystemUiFlags, mLastSystemUiFlags);
4331 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004332 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004333 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004334 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004335 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004336 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004337 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004338 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004339 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004340 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004341 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004342 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004343 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004344 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4345 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004346 if (mStatusBarController.isTransientShowing()) {
4347 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004348 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4349 }
4350 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004351 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004352 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004353 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004354 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004355 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004356 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004357 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004358 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004359 if (mStatusBarController.setBarShowingLw(true)) {
4360 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4361 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004362 }
4363 }
4364 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004365
Craig Mautner81defc72013-10-29 11:10:42 -07004366 if (mTopIsFullscreen != topIsFullscreen) {
4367 if (!topIsFullscreen) {
4368 // Force another layout when status bar becomes fully shown.
4369 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4370 }
4371 mTopIsFullscreen = topIsFullscreen;
4372 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004373
Craig Mautner39834192012-09-02 07:47:24 -07004374 // Hide the key guard if a visible window explicitly specifies that it wants to be
4375 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004376 if (mKeyguardDelegate != null && mStatusBar != null) {
4377 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4378 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004379 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004380 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004381 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004382 changes |= FINISH_LAYOUT_REDO_LAYOUT
4383 | FINISH_LAYOUT_REDO_CONFIG
4384 | FINISH_LAYOUT_REDO_WALLPAPER;
4385 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004386 if (mKeyguardDelegate.isShowing()) {
4387 mHandler.post(new Runnable() {
4388 @Override
4389 public void run() {
4390 mKeyguardDelegate.keyguardDone(false, false);
4391 }
4392 });
4393 }
4394 } else if (mHideLockScreen) {
4395 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004396 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004397 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004398 changes |= FINISH_LAYOUT_REDO_LAYOUT
4399 | FINISH_LAYOUT_REDO_CONFIG
4400 | FINISH_LAYOUT_REDO_WALLPAPER;
4401 }
4402 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004403 mKeyguardHidden = false;
4404 if (setKeyguardOccludedLw(false)) {
4405 changes |= FINISH_LAYOUT_REDO_LAYOUT
4406 | FINISH_LAYOUT_REDO_CONFIG
4407 | FINISH_LAYOUT_REDO_WALLPAPER;
4408 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004409 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4410 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004411 mHandler.post(new Runnable() {
4412 @Override
4413 public void run() {
4414 mKeyguardDelegate.dismiss();
4415 }
4416 });
4417 }
4418 } else {
4419 mWinDismissingKeyguard = null;
4420 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004421 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004422 changes |= FINISH_LAYOUT_REDO_LAYOUT
4423 | FINISH_LAYOUT_REDO_CONFIG
4424 | FINISH_LAYOUT_REDO_WALLPAPER;
4425 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004426 }
4427 }
Joe Onorato664644d2011-01-23 17:53:23 -08004428
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004429 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004430 // If the navigation bar has been hidden or shown, we need to do another
4431 // layout pass to update that window.
4432 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4433 }
Joe Onorato664644d2011-01-23 17:53:23 -08004434
Mike Lockwood28569302010-01-28 11:54:40 -05004435 // update since mAllowLockscreenWhenOn might have changed
4436 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004437 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004438 }
4439
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004440 /**
Jim Millerab954542014-10-10 18:21:49 -07004441 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004442 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004443 * @return Whether the flags have changed and we have to redo the layout.
4444 */
Jim Millerab954542014-10-10 18:21:49 -07004445 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4446 boolean wasOccluded = mKeyguardOccluded;
4447 boolean showing = mKeyguardDelegate.isShowing();
4448 if (wasOccluded && !isOccluded && showing) {
4449 mKeyguardOccluded = false;
4450 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004451 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4452 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4453 return true;
Jim Millerab954542014-10-10 18:21:49 -07004454 } else if (!wasOccluded && isOccluded && showing) {
4455 mKeyguardOccluded = true;
4456 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004457 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4458 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4459 return true;
4460 } else {
4461 return false;
4462 }
4463 }
4464
4465 private boolean isStatusBarKeyguard() {
4466 return mStatusBar != null
4467 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4468 }
4469
Jose Lima9546b202014-07-02 17:21:51 -07004470 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004471 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004472 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004473 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004474 return false;
4475 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004476 return true;
4477 }
4478
Jose Lima9546b202014-07-02 17:21:51 -07004479 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004480 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004481 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004482 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004483 // If the navigation bar has been hidden or shown, we need to do another
4484 // layout pass to update that window.
4485 return FINISH_LAYOUT_REDO_LAYOUT;
4486 }
4487 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004488 }
4489
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004490 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004491 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004492 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4493 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004494 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4495 if (newLidState == mLidState) {
4496 return;
4497 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004498
Jeff Brownc458ce92012-04-30 14:58:40 -07004499 mLidState = newLidState;
4500 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004501 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004502
4503 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004504 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004505 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004506 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004507 }
4508 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004509
Michael Wright3818c922014-09-02 13:59:07 -07004510 @Override
4511 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4512 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4513 if (mCameraLensCoverState == lensCoverState) {
4514 return;
4515 }
4516 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4517 lensCoverState == CAMERA_LENS_UNCOVERED) {
4518 Intent intent;
4519 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4520 mKeyguardDelegate.isShowing();
4521 if (keyguardActive) {
4522 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4523 } else {
4524 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4525 }
Bryce Lee584a4452014-10-21 15:55:55 -07004526 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004527 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004528 }
4529 mCameraLensCoverState = lensCoverState;
4530 }
4531
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004532 void setHdmiPlugged(boolean plugged) {
4533 if (mHdmiPlugged != plugged) {
4534 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004535 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004536 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004537 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004538 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004539 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004540 }
4541 }
4542
Joe Onoratoea495d42011-04-06 11:41:11 -07004543 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004544 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004545 // watch for HDMI plug messages if the hdmi switch exists
4546 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4547 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4548
Joe Onoratoea495d42011-04-06 11:41:11 -07004549 final String filename = "/sys/class/switch/hdmi/state";
4550 FileReader reader = null;
4551 try {
4552 reader = new FileReader(filename);
4553 char[] buf = new char[15];
4554 int n = reader.read(buf);
4555 if (n > 1) {
4556 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4557 }
4558 } catch (IOException ex) {
4559 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4560 } catch (NumberFormatException ex) {
4561 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4562 } finally {
4563 if (reader != null) {
4564 try {
4565 reader.close();
4566 } catch (IOException ex) {
4567 }
Joe Onoratodc100302011-01-11 17:07:41 -08004568 }
4569 }
4570 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004571 // This dance forces the code in setHdmiPlugged to run.
4572 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4573 mHdmiPlugged = !plugged;
4574 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004575 }
4576
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004577 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004578 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004579
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004580 final Runnable mScreenshotTimeout = new Runnable() {
4581 @Override public void run() {
4582 synchronized (mScreenshotLock) {
4583 if (mScreenshotConnection != null) {
4584 mContext.unbindService(mScreenshotConnection);
4585 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004586 }
Winson Chung9112ec32011-06-27 13:15:32 -07004587 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004588 }
4589 };
4590
4591 // Assume this is called from the Handler thread.
4592 private void takeScreenshot() {
4593 synchronized (mScreenshotLock) {
4594 if (mScreenshotConnection != null) {
4595 return;
4596 }
4597 ComponentName cn = new ComponentName("com.android.systemui",
4598 "com.android.systemui.screenshot.TakeScreenshotService");
4599 Intent intent = new Intent();
4600 intent.setComponent(cn);
4601 ServiceConnection conn = new ServiceConnection() {
4602 @Override
4603 public void onServiceConnected(ComponentName name, IBinder service) {
4604 synchronized (mScreenshotLock) {
4605 if (mScreenshotConnection != this) {
4606 return;
4607 }
4608 Messenger messenger = new Messenger(service);
4609 Message msg = Message.obtain(null, 1);
4610 final ServiceConnection myConn = this;
4611 Handler h = new Handler(mHandler.getLooper()) {
4612 @Override
4613 public void handleMessage(Message msg) {
4614 synchronized (mScreenshotLock) {
4615 if (mScreenshotConnection == myConn) {
4616 mContext.unbindService(mScreenshotConnection);
4617 mScreenshotConnection = null;
4618 mHandler.removeCallbacks(mScreenshotTimeout);
4619 }
4620 }
4621 }
4622 };
4623 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004624 msg.arg1 = msg.arg2 = 0;
4625 if (mStatusBar != null && mStatusBar.isVisibleLw())
4626 msg.arg1 = 1;
4627 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4628 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004629 try {
4630 messenger.send(msg);
4631 } catch (RemoteException e) {
4632 }
4633 }
4634 }
4635 @Override
4636 public void onServiceDisconnected(ComponentName name) {}
4637 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004638 if (mContext.bindServiceAsUser(
4639 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004640 mScreenshotConnection = conn;
4641 mHandler.postDelayed(mScreenshotTimeout, 10000);
4642 }
4643 }
Winson Chung9112ec32011-06-27 13:15:32 -07004644 }
4645
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004646 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004647 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004648 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004649 if (!mSystemBooted) {
4650 // If we have not yet booted, don't let key events do anything.
4651 return 0;
4652 }
4653
Jeff Brown037c33e2014-04-09 00:31:55 -07004654 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004655 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4656 final boolean canceled = event.isCanceled();
4657 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004658
Jeff Brown3122e442010-10-11 23:32:49 -07004659 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004660
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004661 // If screen is off then we treat the case where the keyguard is open but hidden
4662 // the same as if it were open and in front.
4663 // This will prevent any keys other than the power button from waking the screen
4664 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004665 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004666 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004667 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004668 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004669
Jeff Brown40013652012-05-16 21:22:36 -07004670 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004671 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004672 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004673 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004674 }
4675
Jeff Brown037c33e2014-04-09 00:31:55 -07004676 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004677 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004678 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4679 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004680 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004681 // When the device is interactive or the key is injected pass the
4682 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004683 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004684 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004685 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4686 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4687 // to the application but preserve its wake key status to make sure we still move
4688 // from dozing to fully interactive if we would normally go from off to fully
4689 // interactive.
4690 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004691 } else {
4692 // When the screen is off and the key is not injected, determine whether
4693 // to wake the device but don't pass the key to the application.
4694 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004695 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4696 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004697 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004698 }
4699
Justin Kohd378ad72013-04-01 12:18:26 -07004700 // If the key would be handled globally, just return the result, don't worry about special
4701 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004702 if (isValidGlobalKey(keyCode)
4703 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004704 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004705 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004706 }
Justin Kohd378ad72013-04-01 12:18:26 -07004707 return result;
4708 }
4709
Jeff Brownbae8e772014-06-12 19:59:45 -07004710 boolean useHapticFeedback = down
4711 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4712 && event.getRepeatCount() == 0;
4713
Jeff Brown4d396052010-10-29 21:50:21 -07004714 // Handle special keys.
4715 switch (keyCode) {
4716 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004717 case KeyEvent.KEYCODE_VOLUME_UP:
4718 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004719 if (mUseTvRouting) {
4720 // On TVs volume keys never go to the foreground app
4721 result &= ~ACTION_PASS_TO_USER;
4722 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004723 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4724 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004725 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004726 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004727 mScreenshotChordVolumeDownKeyTriggered = true;
4728 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4729 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004730 cancelPendingPowerKeyAction();
4731 interceptScreenshotChord();
4732 }
4733 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004734 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004735 cancelPendingScreenshotChordAction();
4736 }
4737 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4738 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004739 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004740 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004741 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004742 cancelPendingPowerKeyAction();
4743 cancelPendingScreenshotChordAction();
4744 }
4745 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004746 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004747 cancelPendingScreenshotChordAction();
4748 }
4749 }
Jeff Brown4d396052010-10-29 21:50:21 -07004750 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004751 TelecomManager telecomManager = getTelecommService();
4752 if (telecomManager != null) {
4753 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004754 // If an incoming call is ringing, either VOLUME key means
4755 // "silence ringer". We handle these keys here, rather than
4756 // in the InCallScreen, to make sure we'll respond to them
4757 // even if the InCallScreen hasn't come to the foreground yet.
4758 // Look for the DOWN event here, to agree with the "fallback"
4759 // behavior in the InCallScreen.
4760 Log.i(TAG, "interceptKeyBeforeQueueing:"
4761 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004762
Santos Cordon6848f722014-05-21 15:22:12 -07004763 // Silence the ringer. (It's safe to call this
4764 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004765 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004766
Santos Cordon6848f722014-05-21 15:22:12 -07004767 // And *don't* pass this key thru to the current activity
4768 // (which is probably the InCallScreen.)
4769 result &= ~ACTION_PASS_TO_USER;
4770 break;
4771 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004772 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004773 && (result & ACTION_PASS_TO_USER) == 0) {
4774 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004775 // the application, just pass it to the session service.
4776
4777 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004778 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004779 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004780 }
4781 }
4782
RoboErik430fc482014-06-12 15:49:20 -07004783 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004784 if (mUseTvRouting) {
4785 dispatchDirectAudioEvent(event);
4786 } else {
4787 // If we aren't passing to the user and no one else
4788 // handled it send it to the session manager to
4789 // figure out.
4790 MediaSessionLegacyHelper.getHelper(mContext)
4791 .sendVolumeKeyEvent(event, true);
4792 }
Jeff Brown4d396052010-10-29 21:50:21 -07004793 break;
4794 }
4795 }
4796 break;
4797 }
4798
4799 case KeyEvent.KEYCODE_ENDCALL: {
4800 result &= ~ACTION_PASS_TO_USER;
4801 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004802 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004803 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004804 if (telecomManager != null) {
4805 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004806 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004807 if (interactive && !hungUp) {
4808 mEndCallKeyHandled = false;
4809 mHandler.postDelayed(mEndCallLongPress,
4810 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4811 } else {
4812 mEndCallKeyHandled = true;
4813 }
Jeff Brown4d396052010-10-29 21:50:21 -07004814 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004815 if (!mEndCallKeyHandled) {
4816 mHandler.removeCallbacks(mEndCallLongPress);
4817 if (!canceled) {
4818 if ((mEndcallBehavior
4819 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4820 if (goHome()) {
4821 break;
4822 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004823 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004824 if ((mEndcallBehavior
4825 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4826 mPowerManager.goToSleep(event.getEventTime(),
4827 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4828 isWakeKey = false;
4829 }
Jeff Brown4d396052010-10-29 21:50:21 -07004830 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004831 }
Jeff Brown4d396052010-10-29 21:50:21 -07004832 }
4833 break;
4834 }
4835
4836 case KeyEvent.KEYCODE_POWER: {
4837 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004838 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004839 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004840 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004841 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004842 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004843 }
4844 break;
4845 }
4846
Jeff Brown6212a492014-03-07 13:58:47 -08004847 case KeyEvent.KEYCODE_SLEEP: {
4848 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004849 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004850 if (!mPowerManager.isInteractive()) {
4851 useHapticFeedback = false; // suppress feedback if already non-interactive
4852 }
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004853 sleepPress(event);
Jeff Brown6212a492014-03-07 13:58:47 -08004854 break;
4855 }
4856
4857 case KeyEvent.KEYCODE_WAKEUP: {
4858 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004859 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004860 break;
4861 }
4862
Jeff Brown4d396052010-10-29 21:50:21 -07004863 case KeyEvent.KEYCODE_MEDIA_PLAY:
4864 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4865 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004866 case KeyEvent.KEYCODE_HEADSETHOOK:
4867 case KeyEvent.KEYCODE_MUTE:
4868 case KeyEvent.KEYCODE_MEDIA_STOP:
4869 case KeyEvent.KEYCODE_MEDIA_NEXT:
4870 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4871 case KeyEvent.KEYCODE_MEDIA_REWIND:
4872 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004873 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4874 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004875 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4876 // If the global session is active pass all media keys to it
4877 // instead of the active window.
4878 result &= ~ACTION_PASS_TO_USER;
4879 }
Jeff Brown4d396052010-10-29 21:50:21 -07004880 if ((result & ACTION_PASS_TO_USER) == 0) {
4881 // Only do this if we would otherwise not pass it to the user. In that
4882 // case, the PhoneWindow class will do the same thing, except it will
4883 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004884 // Note that we need to make a copy of the key event here because the
4885 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004886 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004887 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4888 new KeyEvent(event));
4889 msg.setAsynchronous(true);
4890 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004891 }
4892 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004893 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004894
Jeff Brown4d396052010-10-29 21:50:21 -07004895 case KeyEvent.KEYCODE_CALL: {
4896 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004897 TelecomManager telecomManager = getTelecommService();
4898 if (telecomManager != null) {
4899 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004900 Log.i(TAG, "interceptKeyBeforeQueueing:"
4901 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004902 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004903
Santos Cordon6848f722014-05-21 15:22:12 -07004904 // And *don't* pass this key thru to the current activity
4905 // (which is presumably the InCallScreen.)
4906 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004907 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004908 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004909 }
Jeff Brown4d396052010-10-29 21:50:21 -07004910 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004911 }
Michael Wright869a67c2014-08-26 19:33:06 -07004912 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4913 // Only do this if we would otherwise not pass it to the user. In that case,
4914 // interceptKeyBeforeDispatching would apply a similar but different policy in
4915 // order to invoke voice assist actions. Note that we need to make a copy of the
4916 // key event here because the original key event will be recycled when we return.
4917 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4918 mBroadcastWakeLock.acquire();
4919 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4920 keyguardActive ? 1 : 0, 0);
4921 msg.setAsynchronous(true);
4922 msg.sendToTarget();
4923 }
4924 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004925 }
Jeff Brown26875502014-01-30 21:47:47 -08004926
Jeff Brownbae8e772014-06-12 19:59:45 -07004927 if (useHapticFeedback) {
4928 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4929 }
4930
Jeff Brown26875502014-01-30 21:47:47 -08004931 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004932 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004933 }
Bryce Lee584a4452014-10-21 15:55:55 -07004934
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004935 return result;
4936 }
4937
Jeff Brown1c2e4942012-11-06 16:32:01 -08004938 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004939 * Returns true if the key can have global actions attached to it.
4940 * We reserve all power management keys for the system since they require
4941 * very careful handling.
4942 */
4943 private static boolean isValidGlobalKey(int keyCode) {
4944 switch (keyCode) {
4945 case KeyEvent.KEYCODE_POWER:
4946 case KeyEvent.KEYCODE_WAKEUP:
4947 case KeyEvent.KEYCODE_SLEEP:
4948 return false;
4949 default:
4950 return true;
4951 }
4952 }
4953
4954 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08004955 * When the screen is off we ignore some keys that might otherwise typically
4956 * be considered wake keys. We filter them out here.
4957 *
4958 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4959 * is always considered a wake key.
4960 */
4961 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4962 switch (keyCode) {
4963 // ignore volume keys unless docked
4964 case KeyEvent.KEYCODE_VOLUME_UP:
4965 case KeyEvent.KEYCODE_VOLUME_DOWN:
4966 case KeyEvent.KEYCODE_VOLUME_MUTE:
4967 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4968
4969 // ignore media and camera keys
4970 case KeyEvent.KEYCODE_MUTE:
4971 case KeyEvent.KEYCODE_HEADSETHOOK:
4972 case KeyEvent.KEYCODE_MEDIA_PLAY:
4973 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4974 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4975 case KeyEvent.KEYCODE_MEDIA_STOP:
4976 case KeyEvent.KEYCODE_MEDIA_NEXT:
4977 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4978 case KeyEvent.KEYCODE_MEDIA_REWIND:
4979 case KeyEvent.KEYCODE_MEDIA_RECORD:
4980 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004981 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004982 case KeyEvent.KEYCODE_CAMERA:
4983 return false;
4984 }
4985 return true;
4986 }
4987
4988
Jeff Brown56194eb2011-03-02 19:23:13 -08004989 /** {@inheritDoc} */
4990 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004991 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4992 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08004993 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
4994 return 0;
4995 }
Michael Wright70af00a2014-09-03 19:30:20 -07004996 }
Bryce Lee5c138322014-11-03 08:26:09 -08004997
Michael Wright70af00a2014-09-03 19:30:20 -07004998 if (shouldDispatchInputWhenNonInteractive()) {
4999 return ACTION_PASS_TO_USER;
5000 }
Bryce Lee5c138322014-11-03 08:26:09 -08005001
Bryce Lee812d7022014-11-10 13:33:28 -08005002 // If we have not passed the action up and we are in theater mode without dreaming,
5003 // there will be no dream to intercept the touch and wake into ambient. The device should
5004 // wake up in this case.
5005 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
5006 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
5007 }
5008
Jeff Brown037c33e2014-04-09 00:31:55 -07005009 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005010 }
5011
Michael Wright70af00a2014-09-03 19:30:20 -07005012 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08005013 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07005014 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5015 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005016 return true;
5017 }
5018
5019 // Send events to a dozing dream even if the screen is off since the dream
5020 // is in control of the state of the screen.
5021 IDreamManager dreamManager = getDreamManager();
5022
5023 try {
5024 if (dreamManager != null && dreamManager.isDreaming()) {
5025 return true;
5026 }
5027 } catch (RemoteException e) {
5028 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5029 }
5030
5031 // Otherwise, consume events since the user can't see what is being
5032 // interacted with.
5033 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005034 }
5035
RoboErik001c59c2015-01-26 15:53:51 -08005036 private void dispatchDirectAudioEvent(KeyEvent event) {
5037 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5038 return;
5039 }
5040 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005041 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5042 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005043 String pkgName = mContext.getOpPackageName();
5044 switch (keyCode) {
5045 case KeyEvent.KEYCODE_VOLUME_UP:
5046 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005047 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005048 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005049 } catch (RemoteException e) {
5050 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5051 }
5052 break;
5053 case KeyEvent.KEYCODE_VOLUME_DOWN:
5054 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005055 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005056 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005057 } catch (RemoteException e) {
5058 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5059 }
5060 break;
5061 case KeyEvent.KEYCODE_VOLUME_MUTE:
5062 try {
5063 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005064 getAudioService().adjustSuggestedStreamVolume(
5065 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005066 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005067 }
5068 } catch (RemoteException e) {
5069 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5070 }
5071 break;
5072 }
5073 }
5074
Jeff Brown40013652012-05-16 21:22:36 -07005075 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5076 if (DEBUG_INPUT) {
5077 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005078 }
5079
Jeff Brown40013652012-05-16 21:22:36 -07005080 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5081 if (DEBUG_INPUT) {
5082 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5083 }
5084
5085 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5086 mHavePendingMediaKeyRepeatWithWakeLock = false;
5087 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5088 }
5089
5090 dispatchMediaKeyWithWakeLockToAudioService(event);
5091
5092 if (event.getAction() == KeyEvent.ACTION_DOWN
5093 && event.getRepeatCount() == 0) {
5094 mHavePendingMediaKeyRepeatWithWakeLock = true;
5095
5096 Message msg = mHandler.obtainMessage(
5097 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5098 msg.setAsynchronous(true);
5099 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5100 } else {
5101 mBroadcastWakeLock.release();
5102 }
5103 }
5104
5105 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5106 mHavePendingMediaKeyRepeatWithWakeLock = false;
5107
5108 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5109 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5110 if (DEBUG_INPUT) {
5111 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5112 }
5113
5114 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5115 mBroadcastWakeLock.release();
5116 }
5117
5118 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5119 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005120 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005121 }
5122 }
5123
Michael Wright869a67c2014-08-26 19:33:06 -07005124 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
5125 Intent voiceIntent =
5126 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5127 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005128 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005129 mBroadcastWakeLock.release();
5130 }
5131
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005132 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005133 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005134 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005135 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5136 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5137 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005138 } else {
5139 try {
5140 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5141 ServiceManager.getService(Context.UI_MODE_SERVICE));
5142 mUiMode = uiModeService.getCurrentModeType();
5143 } catch (RemoteException e) {
5144 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005145 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005146 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005147 synchronized (mLock) {
5148 updateOrientationListenerLp();
5149 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005150 }
5151 };
5152
Jeff Brown6aaf2952012-10-05 16:01:08 -07005153 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5154 @Override
5155 public void onReceive(Context context, Intent intent) {
5156 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005157 if (mKeyguardDelegate != null) {
5158 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005159 }
5160 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005161 if (mKeyguardDelegate != null) {
5162 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005163 }
5164 }
5165 }
5166 };
5167
Christopher Tate5e08af02012-09-21 17:17:22 -07005168 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5169 @Override
5170 public void onReceive(Context context, Intent intent) {
5171 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5172 // tickle the settings observer: this first ensures that we're
5173 // observing the relevant settings for the newly-active user,
5174 // and then updates our own bookkeeping based on the now-
5175 // current user.
5176 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005177
5178 // force a re-application of focused window sysui visibility.
5179 // the window may never have been shown for this user
5180 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005181 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005182 mLastSystemUiFlags = 0;
5183 updateSystemUiVisibilityLw();
5184 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005185 }
5186 }
5187 };
5188
Adrian Roosddc8b272015-05-21 16:28:27 -07005189 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005190 @Override
5191 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005192 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5193 if (!isUserSetupComplete()) {
5194 // Swipe-up for navigation bar is disabled during setup
5195 return;
5196 }
5197 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5198 mNavigationBarController.showTransient();
5199 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005200 }
5201 };
5202
John Spurlocke1f366f2013-08-05 12:22:40 -04005203 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005204 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005205 if (!isUserSetupComplete()) {
5206 // Swipe-up for navigation bar is disabled during setup
5207 return;
5208 }
John Spurlock27735a42013-08-14 17:57:38 -04005209 boolean sb = mStatusBarController.checkShowTransientBarLw();
5210 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005211 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005212 // Don't show status bar when swiping on already visible navigation bar
5213 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005214 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005215 return;
5216 }
John Spurlock27735a42013-08-14 17:57:38 -04005217 if (sb) mStatusBarController.showTransient();
5218 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005219 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005220 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005221 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005222 }
5223 }
5224
Jeff Brown3ee549c2014-09-22 20:14:39 -07005225 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005226 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07005227 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005228 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07005229 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005230
5231 // We must get this work done here because the power manager will drop
5232 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005233 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005234 mAwake = false;
5235 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005236 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005237 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005238 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005239 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005240
5241 if (mKeyguardDelegate != null) {
5242 mKeyguardDelegate.onScreenTurnedOff(why);
5243 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005244 }
5245
Jeff Brown13f00f02014-10-31 14:45:50 -07005246 private void wakeUpFromPowerKey(long eventTime) {
5247 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5248 }
5249
Bryce Lee5c138322014-11-03 08:26:09 -08005250 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Lee584a4452014-10-21 15:55:55 -07005251 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005252 return false;
Bryce Lee584a4452014-10-21 15:55:55 -07005253 }
5254
5255 mPowerManager.wakeUp(wakeTime);
Bryce Lee5c138322014-11-03 08:26:09 -08005256 return true;
Bryce Lee584a4452014-10-21 15:55:55 -07005257 }
5258
Jeff Brown3ee549c2014-09-22 20:14:39 -07005259 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005260 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07005261 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005262 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07005263 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005264
Jeff Brown3ee549c2014-09-22 20:14:39 -07005265 // Since goToSleep performs these functions synchronously, we must
5266 // do the same here. We cannot post this work to a handler because
5267 // that might cause it to become reordered with respect to what
5268 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005269 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005270 mAwake = true;
5271 mKeyguardDrawComplete = false;
5272 if (mKeyguardDelegate != null) {
5273 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5274 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5275 }
5276
Jeff Browna20dda42014-05-27 20:57:24 -07005277 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005278 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005279 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005280 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005281
Jim Miller5ecd8112013-01-09 18:50:26 -08005282 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07005283 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005284 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005285 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005286 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005287 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005288 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005289 }
5290
Jeff Brown36c4db82014-09-19 12:05:31 -07005291 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005292 synchronized (mLock) {
5293 if (!mAwake || mKeyguardDrawComplete) {
5294 return; // spurious
5295 }
5296
Jeff Brown36c4db82014-09-19 12:05:31 -07005297 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005298 if (mKeyguardDelegate != null) {
5299 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5300 }
5301 }
5302
5303 finishScreenTurningOn();
5304 }
5305
5306 // Called on the DisplayManager's DisplayPowerController thread.
5307 @Override
5308 public void screenTurnedOff() {
5309 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5310
5311 synchronized (mLock) {
5312 mScreenOnEarly = false;
5313 mScreenOnFully = false;
5314 mWindowManagerDrawComplete = false;
5315 mScreenOnListener = null;
5316 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005317 }
5318 }
5319
Jeff Brown3ee549c2014-09-22 20:14:39 -07005320 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005321 @Override
5322 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005323 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005324
Jeff Brown3ee549c2014-09-22 20:14:39 -07005325 synchronized (mLock) {
5326 mScreenOnEarly = true;
5327 mScreenOnFully = false;
5328 mWindowManagerDrawComplete = false;
5329 mScreenOnListener = screenOnListener;
5330 updateOrientationListenerLp();
5331 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005332
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005333 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5334 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005335 // ... eventually calls finishWindowsDrawn
5336 }
5337
Jeff Brown36c4db82014-09-19 12:05:31 -07005338 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005339 synchronized (mLock) {
5340 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5341 return; // spurious
5342 }
5343
Jeff Brown36c4db82014-09-19 12:05:31 -07005344 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005345 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005346
5347 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005348 }
5349
Craig Mautner8a0da012014-05-31 15:13:37 -07005350 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005351 final ScreenOnListener listener;
5352 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005353 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005354 if (DEBUG_WAKEUP) Slog.d(TAG,
5355 "finishScreenTurningOn: mAwake=" + mAwake
5356 + ", mScreenOnEarly=" + mScreenOnEarly
5357 + ", mScreenOnFully=" + mScreenOnFully
5358 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5359 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5360
5361 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5362 || (mAwake && !mKeyguardDrawComplete)) {
5363 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005364 }
5365
Jeff Brown3ee549c2014-09-22 20:14:39 -07005366 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5367 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005368 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005369 mScreenOnFully = true;
5370
5371 // Remember the first time we draw the keyguard so we know when we're done with
5372 // the main part of booting and can enable the screen and hide boot messages.
5373 if (!mKeyguardDrawnOnce && mAwake) {
5374 mKeyguardDrawnOnce = true;
5375 enableScreen = true;
5376 if (mBootMessageNeedsHiding) {
5377 mBootMessageNeedsHiding = false;
5378 hideBootMessages();
5379 }
5380 } else {
5381 enableScreen = false;
5382 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005383 }
5384
Jeff Brown3ee549c2014-09-22 20:14:39 -07005385 if (listener != null) {
5386 listener.onScreenOn();
5387 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005388
Jeff Brown3ee549c2014-09-22 20:14:39 -07005389 if (enableScreen) {
5390 try {
5391 mWindowManager.enableScreenIfNeeded();
5392 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005393 }
Craig Mautnera631d492014-08-05 15:16:01 -07005394 }
5395 }
5396
5397 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005398 synchronized (mLock) {
5399 if (!mKeyguardDrawnOnce) {
5400 mBootMessageNeedsHiding = true;
5401 return; // keyguard hasn't drawn the first time yet, not done booting
5402 }
Craig Mautnera631d492014-08-05 15:16:01 -07005403 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005404
5405 if (mBootMsgDialog != null) {
5406 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5407 mBootMsgDialog.dismiss();
5408 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005409 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005410 }
5411
5412 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005413 public boolean isScreenOn() {
5414 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005415 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005416
Dianne Hackborn08743722009-12-21 12:16:51 -08005417 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005418 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005419 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005420 if (mKeyguardDelegate != null) {
5421 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005422 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005423 }
5424
5425 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005426 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005427 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005428 if (mKeyguardDelegate != null) {
5429 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005430 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005431 }
5432
Jim Millerab954542014-10-10 18:21:49 -07005433 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005434 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005435 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005436 }
5437
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005438 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005439 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005440 public boolean isKeyguardLocked() {
5441 return keyguardOn();
5442 }
5443
5444 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005445 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005446 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005447 if (mKeyguardDelegate == null) return false;
5448 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005449 }
5450
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005451 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005452 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005453 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005454 if (mKeyguardDelegate == null) return false;
5455 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005456 }
5457
Jose Lima9546b202014-07-02 17:21:51 -07005458 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005459 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005460 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005461 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005462 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005463 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005464 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005465 // ask the keyguard to prompt the user to authenticate if necessary
5466 mKeyguardDelegate.dismiss();
5467 }
5468 });
5469 }
5470 }
5471
5472 public void notifyActivityDrawnForKeyguardLw() {
5473 if (mKeyguardDelegate != null) {
5474 mHandler.post(new Runnable() {
5475 @Override
5476 public void run() {
5477 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005478 }
5479 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005480 }
5481 }
5482
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005483 @Override
5484 public boolean isKeyguardDrawnLw() {
5485 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005486 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005487 }
5488 }
5489
Jorim Jaggi0d674622014-05-21 01:34:15 +02005490 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005491 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005492 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005493 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005494 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005495 }
5496 }
5497
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005498 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005499 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005500 }
5501
5502 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005503 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005504 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005505
Jeff Brown01a98dd2011-09-20 15:08:29 -07005506 @Override
5507 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005508 if (false) {
5509 Slog.v(TAG, "rotationForOrientationLw(orient="
5510 + orientation + ", last=" + lastRotation
5511 + "); user=" + mUserRotation + " "
5512 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5513 ? "USER_ROTATION_LOCKED" : "")
5514 );
5515 }
5516
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005517 if (mForceDefaultOrientation) {
5518 return Surface.ROTATION_0;
5519 }
5520
The Android Open Source Project0727d222009-03-11 12:11:58 -07005521 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005522 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5523 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005524 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005525 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005526
Jeff Browndec6cf42011-11-15 14:08:20 -08005527 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005528 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005529 // Ignore sensor when lid switch is open and rotation is forced.
5530 preferredRotation = mLidOpenRotation;
5531 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005532 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005533 // Ignore sensor when in car dock unless explicitly enabled.
5534 // This case can override the behavior of NOSENSOR, and can also
5535 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005536 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005537 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005538 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5539 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5540 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005541 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005542 // Ignore sensor when in desk dock unless explicitly enabled.
5543 // This case can override the behavior of NOSENSOR, and can also
5544 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005545 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005546 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005547 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5548 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005549 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005550 preferredRotation = mDemoHdmiRotation;
5551 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5552 && mUndockedHdmiRotation >= 0) {
5553 // Ignore sensor when plugged into HDMI and an undocked orientation has
5554 // been specified in the configuration (only for legacy devices without
5555 // full multi-display support).
5556 // Note that the dock orientation overrides the HDMI orientation.
5557 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005558 } else if (mDemoRotationLock) {
5559 // Ignore sensor when demo rotation lock is enabled.
5560 // Note that the dock orientation and HDMI rotation lock override this.
5561 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005562 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5563 // Application just wants to remain locked in the last rotation.
5564 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005565 } else if (!mSupportAutoRotation) {
5566 // If we don't support auto-rotation then bail out here and ignore
5567 // the sensor and any rotation lock settings.
5568 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005569 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005570 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005571 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5572 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5573 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5574 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005575 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5576 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5577 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5578 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5579 // Otherwise, use sensor only if requested by the application or enabled
5580 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005581 if (mAllowAllRotations < 0) {
5582 // Can't read this during init() because the context doesn't
5583 // have display metrics at that time so we cannot determine
5584 // tablet vs. phone then.
5585 mAllowAllRotations = mContext.getResources().getBoolean(
5586 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5587 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005588 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005589 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005590 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5591 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005592 preferredRotation = sensorRotation;
5593 } else {
5594 preferredRotation = lastRotation;
5595 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005596 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5597 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5598 // Apply rotation lock. Does not apply to NOSENSOR.
5599 // The idea is that the user rotation expresses a weak preference for the direction
5600 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5601 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005602 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005603 } else {
5604 // No overriding preference.
5605 // We will do exactly what the application asked us to do.
5606 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005607 }
5608
Dianne Hackborne5439f22010-10-02 16:53:50 -07005609 switch (orientation) {
5610 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005611 // Return portrait unless overridden.
5612 if (isAnyPortrait(preferredRotation)) {
5613 return preferredRotation;
5614 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005615 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005616
Jeff Brown01a98dd2011-09-20 15:08:29 -07005617 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005618 // Return landscape unless overridden.
5619 if (isLandscapeOrSeascape(preferredRotation)) {
5620 return preferredRotation;
5621 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005622 return mLandscapeRotation;
5623
5624 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005625 // Return reverse portrait unless overridden.
5626 if (isAnyPortrait(preferredRotation)) {
5627 return preferredRotation;
5628 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005629 return mUpsideDownRotation;
5630
5631 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005632 // Return seascape unless overridden.
5633 if (isLandscapeOrSeascape(preferredRotation)) {
5634 return preferredRotation;
5635 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005636 return mSeascapeRotation;
5637
5638 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005639 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005640 // Return either landscape rotation.
5641 if (isLandscapeOrSeascape(preferredRotation)) {
5642 return preferredRotation;
5643 }
5644 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005645 return lastRotation;
5646 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005647 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005648
Jeff Brown01a98dd2011-09-20 15:08:29 -07005649 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005650 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005651 // Return either portrait rotation.
5652 if (isAnyPortrait(preferredRotation)) {
5653 return preferredRotation;
5654 }
5655 if (isAnyPortrait(lastRotation)) {
5656 return lastRotation;
5657 }
5658 return mPortraitRotation;
5659
5660 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005661 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5662 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005663 if (preferredRotation >= 0) {
5664 return preferredRotation;
5665 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005666 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005667 }
5668 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005669 }
5670
Jeff Brown01a98dd2011-09-20 15:08:29 -07005671 @Override
5672 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5673 switch (orientation) {
5674 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5675 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5676 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5677 return isAnyPortrait(rotation);
5678
5679 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5680 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5681 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5682 return isLandscapeOrSeascape(rotation);
5683
5684 default:
5685 return true;
5686 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005687 }
5688
Jeff Brownc0347aa2011-09-23 17:26:09 -07005689 @Override
5690 public void setRotationLw(int rotation) {
5691 mOrientationListener.setCurrentRotation(rotation);
5692 }
5693
Jeff Brown01a98dd2011-09-20 15:08:29 -07005694 private boolean isLandscapeOrSeascape(int rotation) {
5695 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005696 }
5697
Jeff Brown01a98dd2011-09-20 15:08:29 -07005698 private boolean isAnyPortrait(int rotation) {
5699 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005700 }
5701
Jose Lima9546b202014-07-02 17:21:51 -07005702 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005703 public int getUserRotationMode() {
5704 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005705 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5706 WindowManagerPolicy.USER_ROTATION_FREE :
5707 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005708 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005709
5710 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005711 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005712 public void setUserRotationMode(int mode, int rot) {
5713 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005714
5715 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005716 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005717 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005718 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005719 rot,
5720 UserHandle.USER_CURRENT);
5721 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005722 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005723 0,
5724 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005725 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005726 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005727 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005728 1,
5729 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005730 }
5731 }
5732
Jose Lima9546b202014-07-02 17:21:51 -07005733 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005734 public void setSafeMode(boolean safeMode) {
5735 mSafeMode = safeMode;
5736 performHapticFeedbackLw(null, safeMode
5737 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5738 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005739 }
Craig Mautnereda67292013-04-28 13:50:14 -07005740
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005741 static long[] getLongIntArray(Resources r, int resid) {
5742 int[] ar = r.getIntArray(resid);
5743 if (ar == null) {
5744 return null;
5745 }
5746 long[] out = new long[ar.length];
5747 for (int i=0; i<ar.length; i++) {
5748 out[i] = ar[i];
5749 }
5750 return out;
5751 }
Craig Mautnereda67292013-04-28 13:50:14 -07005752
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005753 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005754 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005755 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005756 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005757 mKeyguardDelegate.onSystemReady();
5758
Michael Wright3818c922014-09-02 13:59:07 -07005759 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005760 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005761 synchronized (mLock) {
5762 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005763 mSystemReady = true;
5764 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005765 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005766 public void run() {
5767 updateSettings();
5768 }
5769 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005770 }
5771 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005772
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005773 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005774 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005775 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005776 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005777 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005778 mKeyguardDelegate.onBootCompleted();
5779 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005780 synchronized (mLock) {
5781 mSystemBooted = true;
5782 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005783 wakingUp();
5784 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005785 }
5786
Dianne Hackborn661cd522011-08-22 00:26:20 -07005787 ProgressDialog mBootMsgDialog = null;
5788
5789 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005790 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005791 public void showBootMessage(final CharSequence msg, final boolean always) {
5792 mHandler.post(new Runnable() {
5793 @Override public void run() {
5794 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005795 int theme;
5796 if (mContext.getPackageManager().hasSystemFeature(
5797 PackageManager.FEATURE_WATCH)) {
5798 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5799 } else if (mContext.getPackageManager().hasSystemFeature(
5800 PackageManager.FEATURE_TELEVISION)) {
5801 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5802 } else {
5803 theme = 0;
5804 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005805
5806 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005807 // This dialog will consume all events coming in to
5808 // it, to avoid it trying to do things too early in boot.
5809 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5810 return true;
5811 }
5812 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5813 return true;
5814 }
5815 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5816 return true;
5817 }
5818 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5819 return true;
5820 }
5821 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5822 return true;
5823 }
5824 @Override public boolean dispatchPopulateAccessibilityEvent(
5825 AccessibilityEvent event) {
5826 return true;
5827 }
5828 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005829 if (mContext.getPackageManager().isUpgrade()) {
5830 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5831 } else {
5832 mBootMsgDialog.setTitle(R.string.android_start_title);
5833 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005834 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5835 mBootMsgDialog.setIndeterminate(true);
5836 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005837 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005838 mBootMsgDialog.getWindow().addFlags(
5839 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5840 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5841 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005842 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5843 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5844 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005845 mBootMsgDialog.setCancelable(false);
5846 mBootMsgDialog.show();
5847 }
5848 mBootMsgDialog.setMessage(msg);
5849 }
5850 });
5851 }
5852
5853 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005854 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005855 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005856 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005857 }
5858
Mike Lockwood28569302010-01-28 11:54:40 -05005859 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005860 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005861 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005862 // ***************************************
5863 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5864 // ***************************************
5865 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5866 // WITH ITS LOCKS HELD.
5867 //
5868 // This code must be VERY careful about the locks
5869 // it acquires.
5870 // In fact, the current code acquires way too many,
5871 // and probably has lurking deadlocks.
5872
Mike Lockwood28569302010-01-28 11:54:40 -05005873 synchronized (mScreenLockTimeout) {
5874 if (mLockScreenTimerActive) {
5875 // reset the timer
5876 mHandler.removeCallbacks(mScreenLockTimeout);
5877 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5878 }
5879 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005880 }
5881
Adam Cohenf7522022012-10-03 20:03:18 -07005882 class ScreenLockTimeout implements Runnable {
5883 Bundle options;
5884
5885 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005886 public void run() {
5887 synchronized (this) {
5888 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005889 if (mKeyguardDelegate != null) {
5890 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005891 }
Mike Lockwood28569302010-01-28 11:54:40 -05005892 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005893 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005894 }
5895 }
Mike Lockwood28569302010-01-28 11:54:40 -05005896
Adam Cohenf7522022012-10-03 20:03:18 -07005897 public void setLockOptions(Bundle options) {
5898 this.options = options;
5899 }
5900 }
5901
5902 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5903
Jose Lima9546b202014-07-02 17:21:51 -07005904 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005905 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005906 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5907 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005908 if (options != null) {
5909 // In case multiple calls are made to lockNow, we don't wipe out the options
5910 // until the runnable actually executes.
5911 mScreenLockTimeout.setLockOptions(options);
5912 }
Jim Miller93c518e2012-01-17 15:55:31 -08005913 mHandler.post(mScreenLockTimeout);
5914 }
5915
Mike Lockwood28569302010-01-28 11:54:40 -05005916 private void updateLockScreenTimeout() {
5917 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005918 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005919 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005920 if (mLockScreenTimerActive != enable) {
5921 if (enable) {
5922 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5923 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5924 } else {
5925 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5926 mHandler.removeCallbacks(mScreenLockTimeout);
5927 }
5928 mLockScreenTimerActive = enable;
5929 }
5930 }
5931 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005932
Jeff Brown061ea992015-04-17 19:55:47 -07005933 private void updateDreamingSleepToken(boolean acquire) {
5934 if (acquire) {
5935 if (mDreamingSleepToken == null) {
5936 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
5937 }
5938 } else {
5939 if (mDreamingSleepToken != null) {
5940 mDreamingSleepToken.release();
5941 }
5942 }
5943 }
5944
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005945 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005946 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005947 public void enableScreenAfterBoot() {
5948 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005949 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005950 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005951 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005952
Jeff Brownc458ce92012-04-30 14:58:40 -07005953 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005954 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005955 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005956 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005957 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005958 }
Jeff Browna20dda42014-05-27 20:57:24 -07005959
5960 synchronized (mLock) {
5961 updateWakeGestureListenerLp();
5962 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005963 }
5964
Jeff Brown4f5fa282014-06-12 19:19:15 -07005965 void updateUiMode() {
5966 if (mUiModeManager == null) {
5967 mUiModeManager = IUiModeManager.Stub.asInterface(
5968 ServiceManager.getService(Context.UI_MODE_SERVICE));
5969 }
5970 try {
5971 mUiMode = mUiModeManager.getCurrentModeType();
5972 } catch (RemoteException e) {
5973 }
5974 }
5975
Jeff Brown01a98dd2011-09-20 15:08:29 -07005976 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005977 try {
5978 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005979 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5980 } catch (RemoteException e) {
5981 // Ignore
5982 }
5983 }
5984
5985 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5986 try {
5987 //set orientation on WindowManager
5988 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005989 } catch (RemoteException e) {
5990 // Ignore
5991 }
5992 }
5993
Daniel Sandler6396c722013-04-16 20:19:09 -04005994 /**
5995 * Return an Intent to launch the currently active dock app as home. Returns
5996 * null if the standard home should be launched, which is the case if any of the following is
5997 * true:
5998 * <ul>
5999 * <li>The device is not in either car mode or desk mode
6000 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
6001 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6002 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6003 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6004 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006005 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006006 */
6007 Intent createHomeDockIntent() {
6008 Intent intent = null;
6009
6010 // What home does is based on the mode, not the dock state. That
6011 // is, when in car mode you should be taken to car home regardless
6012 // of whether we are actually in a car dock.
6013 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6014 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
6015 intent = mCarDockIntent;
6016 }
6017 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6018 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6019 intent = mDeskDockIntent;
6020 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006021 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6022 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6023 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6024 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6025 // Always launch dock home from home when watch is docked, if it exists.
6026 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006027 }
6028
6029 if (intent == null) {
6030 return null;
6031 }
6032
6033 ActivityInfo ai = null;
6034 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6035 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006036 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006037 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006038 if (info != null) {
6039 ai = info.activityInfo;
6040 }
6041 if (ai != null
6042 && ai.metaData != null
6043 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6044 intent = new Intent(intent);
6045 intent.setClassName(ai.packageName, ai.name);
6046 return intent;
6047 }
6048
6049 return null;
6050 }
6051
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006052 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6053 if (awakenFromDreams) {
6054 awakenDreams();
6055 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006056
6057 Intent dock = createHomeDockIntent();
6058 if (dock != null) {
6059 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006060 if (fromHomeKey) {
6061 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6062 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006063 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006064 return;
6065 } catch (ActivityNotFoundException e) {
6066 }
6067 }
6068
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006069 Intent intent;
6070
6071 if (fromHomeKey) {
6072 intent = new Intent(mHomeIntent);
6073 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6074 } else {
6075 intent = mHomeIntent;
6076 }
6077
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006078 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006079 }
Craig Mautnereda67292013-04-28 13:50:14 -07006080
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006081 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006082 * goes to the home screen
6083 * @return whether it did anything
6084 */
6085 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006086 if (!isUserSetupComplete()) {
6087 Slog.i(TAG, "Not going home because user setup is in progress.");
6088 return false;
6089 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006090 if (false) {
6091 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006092 try {
6093 ActivityManagerNative.getDefault().stopAppSwitches();
6094 } catch (RemoteException e) {
6095 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006096 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006097 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006098 } else {
6099 // This code brings home to the front or, if it is already
6100 // at the front, puts the device to sleep.
6101 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006102 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6103 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6104 Log.d(TAG, "UTS-TEST-MODE");
6105 } else {
6106 ActivityManagerNative.getDefault().stopAppSwitches();
6107 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006108 Intent dock = createHomeDockIntent();
6109 if (dock != null) {
6110 int result = ActivityManagerNative.getDefault()
6111 .startActivityAsUser(null, null, dock,
6112 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6113 null, null, 0,
6114 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006115 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006116 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6117 return false;
6118 }
6119 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006120 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006121 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006122 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006123 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006124 null, null, 0,
6125 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006126 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006127 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006128 return false;
6129 }
6130 } catch (RemoteException ex) {
6131 // bummer, the activity manager, which is in this process, is dead
6132 }
6133 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006134 return true;
6135 }
Craig Mautnereda67292013-04-28 13:50:14 -07006136
6137 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006138 public void setCurrentOrientationLw(int newOrientation) {
6139 synchronized (mLock) {
6140 if (newOrientation != mCurrentAppOrientation) {
6141 mCurrentAppOrientation = newOrientation;
6142 updateOrientationListenerLp();
6143 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006144 }
6145 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006146
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006147 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6148 if (!isGlobalAccessibilityGestureEnabled()) {
6149 return;
6150 }
6151 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6152 Context.AUDIO_SERVICE);
6153 if (audioManager.isSilentMode()) {
6154 return;
6155 }
6156 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6157 Settings.System.DEFAULT_NOTIFICATION_URI);
6158 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6159 ringTone.play();
6160 }
Craig Mautnereda67292013-04-28 13:50:14 -07006161
Bryce Lee584a4452014-10-21 15:55:55 -07006162 private boolean isTheaterModeEnabled() {
6163 return Settings.Global.getInt(mContext.getContentResolver(),
6164 Settings.Global.THEATER_MODE_ON, 0) == 1;
6165 }
6166
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006167 private boolean isGlobalAccessibilityGestureEnabled() {
6168 return Settings.Global.getInt(mContext.getContentResolver(),
6169 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6170 }
6171
Craig Mautnereda67292013-04-28 13:50:14 -07006172 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006173 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006174 if (!mVibrator.hasVibrator()) {
6175 return false;
6176 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006177 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6178 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006179 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006180 return false;
6181 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006182 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006183 switch (effectId) {
6184 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006185 pattern = mLongPressVibePattern;
6186 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006187 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006188 pattern = mVirtualKeyVibePattern;
6189 break;
6190 case HapticFeedbackConstants.KEYBOARD_TAP:
6191 pattern = mKeyboardTapVibePattern;
6192 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006193 case HapticFeedbackConstants.CLOCK_TICK:
6194 pattern = mClockTickVibePattern;
6195 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006196 case HapticFeedbackConstants.CALENDAR_DATE:
6197 pattern = mCalendarDateVibePattern;
6198 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006199 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006200 pattern = mSafeModeDisabledVibePattern;
6201 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006202 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006203 pattern = mSafeModeEnabledVibePattern;
6204 break;
Mady Mellore82067b2015-04-30 09:58:35 -07006205 case HapticFeedbackConstants.STYLUS_BUTTON_PRESS:
6206 pattern = mStylusButtonPressVibePattern;
6207 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006208 default:
6209 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006210 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006211 int owningUid;
6212 String owningPackage;
6213 if (win != null) {
6214 owningUid = win.getOwningUid();
6215 owningPackage = win.getOwningPackage();
6216 } else {
6217 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006218 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006219 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006220 if (pattern.length == 1) {
6221 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006222 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006223 } else {
6224 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006225 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006226 }
6227 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006228 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006229
6230 @Override
6231 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006232 }
6233
Jeff Brownc38c9be2012-10-04 13:16:19 -07006234 @Override
6235 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006236 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006237 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006238 }
6239 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006240
Dianne Hackborndf89e652011-10-06 22:35:11 -07006241 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006242 // If there is no window focused, there will be nobody to handle the events
6243 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006244 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6245 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006246 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006247 return 0;
6248 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006249 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006250 // We are updating at a point where the keyguard has gotten
6251 // focus, but we were last in a state where the top window is
6252 // hiding it. This is probably because the keyguard as been
6253 // shown while the top window was displayed, so we want to ignore
6254 // it here because this is just a very transient change and it
6255 // will quickly lose focus once it correctly gets hidden.
6256 return 0;
6257 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006258
John Spurlock1db8b682014-02-18 11:18:59 -05006259 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006260 & ~mResettingSystemUiFlags
6261 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006262 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006263 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006264 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006265 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006266 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006267 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006268 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006269 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006270 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006271 return 0;
6272 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006273 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006274 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006275 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006276 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006277 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006278 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006279 try {
6280 IStatusBarService statusbar = getStatusBarService();
6281 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006282 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006283 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006284 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006285 } catch (RemoteException e) {
6286 // re-acquire status bar service next time it is needed.
6287 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006288 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006289 }
6290 });
6291 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006292 }
6293
Adrian Rooscd3884d2015-02-18 17:25:23 +01006294 private int updateLightStatusBarLw(int vis) {
6295 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6296 ? mStatusBar
6297 : mTopFullscreenOpaqueOrDimmingWindowState;
6298
6299 if (statusColorWin != null) {
6300 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6301 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6302 // its light flag.
6303 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6304 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6305 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6306 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6307 // Otherwise if it's dimming, clear the light flag.
6308 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6309 }
6310 }
6311 return vis;
6312 }
6313
John Spurlock79da8332013-09-20 12:04:47 -04006314 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006315 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006316 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6317 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006318 : mTopFullscreenOpaqueWindowState;
6319 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6320 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6321
John Spurlock27735a42013-08-14 17:57:38 -04006322 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006323 int type = win.getAttrs().type;
6324 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006325 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006326 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6327 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006328 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006329 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6330 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006331 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006332 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6333 }
John Spurlockbd957402013-10-03 11:38:39 -04006334 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006335 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006336
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006337 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006338 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6339 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006340 }
6341
John Spurlock27735a42013-08-14 17:57:38 -04006342 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006343 boolean immersiveSticky =
6344 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006345 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006346 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006347 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006348 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6349 boolean hideStatusBarSysui =
6350 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006351 boolean hideNavBarSysui =
6352 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006353
John Spurlock27735a42013-08-14 17:57:38 -04006354 boolean transientStatusBarAllowed =
6355 mStatusBar != null && (
6356 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006357 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006358 || statusBarHasFocus);
6359
John Spurlockf1a36642013-10-12 17:50:42 -04006360 boolean transientNavBarAllowed =
6361 mNavigationBar != null &&
6362 hideNavBarSysui && immersiveSticky;
6363
Adrian Roosddc8b272015-05-21 16:28:27 -07006364 final long now = SystemClock.uptimeMillis();
6365 final boolean pendingPanic = mPendingPanicGestureUptime != 0
6366 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
6367 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
6368 // The user performed the panic gesture recently, we're about to hide the bars,
6369 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
6370 mPendingPanicGestureUptime = 0;
6371 mStatusBarController.showTransient();
6372 mNavigationBarController.showTransient();
6373 }
6374
John Spurlockf25706f2013-11-07 18:02:43 -05006375 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006376 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006377 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006378 && !transientNavBarAllowed;
6379 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006380 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006381 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006382 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006383 }
John Spurlock27735a42013-08-14 17:57:38 -04006384
Selim Cinekf98702e2015-05-20 22:48:40 -07006385 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
6386 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
6387 final boolean navAllowedHidden = immersive || immersiveSticky;
6388
Selim Cinekd6623612015-05-22 18:56:22 -07006389 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
6390 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07006391 // We can't hide the navbar from this window otherwise the input consumer would not get
6392 // the input events.
6393 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
6394 }
6395
John Spurlock27735a42013-08-14 17:57:38 -04006396 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6397
6398 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006399 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6400 boolean newImmersiveMode = isImmersiveMode(vis);
6401 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006402 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006403 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6404 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006405 }
John Spurlock27735a42013-08-14 17:57:38 -04006406
John Spurlockf1a36642013-10-12 17:50:42 -04006407 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6408
John Spurlocke1f366f2013-08-05 12:22:40 -04006409 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006410 }
6411
John Spurlockf1a36642013-10-12 17:50:42 -04006412 private void clearClearableFlagsLw() {
6413 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6414 if (newVal != mResettingSystemUiFlags) {
6415 mResettingSystemUiFlags = newVal;
6416 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6417 }
6418 }
6419
6420 private boolean isImmersiveMode(int vis) {
6421 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006422 return mNavigationBar != null
6423 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006424 && (vis & flags) != 0
6425 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006426 }
6427
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006428 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006429 * @return whether the navigation or status bar can be made translucent
6430 *
6431 * This should return true unless touch exploration is not enabled or
6432 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006433 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006434 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006435 return mTranslucentDecorEnabled
6436 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006437 }
6438
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006439 // Use this instead of checking config_showNavigationBar so that it can be consistently
6440 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006441 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006442 public boolean hasNavigationBar() {
6443 return mHasNavigationBar;
6444 }
6445
satok1bc0a492012-04-25 22:47:12 +09006446 @Override
6447 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6448 mLastInputMethodWindow = ime;
6449 mLastInputMethodTargetWindow = target;
6450 }
6451
Craig Mautnerf1b67412012-09-19 13:18:29 -07006452 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006453 public int getInputMethodWindowVisibleHeightLw() {
6454 return mDockBottom - mCurBottom;
6455 }
6456
6457 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006458 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006459 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006460 if (mKeyguardDelegate != null) {
6461 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006462 }
John Spurlock13451a22012-09-28 14:40:41 -04006463 if (mStatusBarService != null) {
6464 try {
6465 mStatusBarService.setCurrentUser(newUserId);
6466 } catch (RemoteException e) {
6467 // oh well
6468 }
6469 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006470 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006471 }
6472
6473 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006474 public boolean canMagnifyWindow(int windowType) {
6475 switch (windowType) {
6476 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6477 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6478 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6479 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6480 return false;
6481 }
6482 }
6483 return true;
6484 }
6485
6486 @Override
6487 public boolean isTopLevelWindow(int windowType) {
6488 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6489 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6490 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6491 }
6492 return true;
6493 }
6494
Jim Miller4eeb4f62012-11-08 00:04:29 -08006495 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006496 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006497 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006498 pw.print(" mSystemReady="); pw.print(mSystemReady);
6499 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006500 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006501 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006502 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006503 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006504 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6505 || mForceClearedSystemUiFlags != 0) {
6506 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6507 pw.print(Integer.toHexString(mLastSystemUiFlags));
6508 pw.print(" mResettingSystemUiFlags=0x");
6509 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6510 pw.print(" mForceClearedSystemUiFlags=0x");
6511 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006512 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006513 if (mLastFocusNeedsMenu) {
6514 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6515 pw.println(mLastFocusNeedsMenu);
6516 }
Jeff Browna20dda42014-05-27 20:57:24 -07006517 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6518 pw.println(mWakeGestureEnabledSetting);
6519
Jeff Brownbcdfc622014-03-06 19:13:04 -08006520 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006521 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6522 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006523 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6524 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6525 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6526 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006527 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006528 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006529 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6530 pw.print(mCarDockEnablesAccelerometer);
6531 pw.print(" mDeskDockEnablesAccelerometer=");
6532 pw.println(mDeskDockEnablesAccelerometer);
6533 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6534 pw.print(mLidKeyboardAccessibility);
6535 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006536 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006537 pw.print(prefix);
6538 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6539 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006540 pw.print(prefix);
6541 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6542 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006543 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006544 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6545 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6546 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6547 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6548 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6549 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6550 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006551 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6552 pw.print(","); pw.print(mOverscanScreenTop);
6553 pw.print(") "); pw.print(mOverscanScreenWidth);
6554 pw.print("x"); pw.println(mOverscanScreenHeight);
6555 if (mOverscanLeft != 0 || mOverscanTop != 0
6556 || mOverscanRight != 0 || mOverscanBottom != 0) {
6557 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6558 pw.print(" top="); pw.print(mOverscanTop);
6559 pw.print(" right="); pw.print(mOverscanRight);
6560 pw.print(" bottom="); pw.println(mOverscanBottom);
6561 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006562 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6563 pw.print(mRestrictedOverscanScreenLeft);
6564 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6565 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6566 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006567 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6568 pw.print(","); pw.print(mUnrestrictedScreenTop);
6569 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6570 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6571 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6572 pw.print(","); pw.print(mRestrictedScreenTop);
6573 pw.print(") "); pw.print(mRestrictedScreenWidth);
6574 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006575 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6576 pw.print(","); pw.print(mStableFullscreenTop);
6577 pw.print(")-("); pw.print(mStableFullscreenRight);
6578 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006579 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6580 pw.print(","); pw.print(mStableTop);
6581 pw.print(")-("); pw.print(mStableRight);
6582 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006583 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6584 pw.print(","); pw.print(mSystemTop);
6585 pw.print(")-("); pw.print(mSystemRight);
6586 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006587 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6588 pw.print(","); pw.print(mCurTop);
6589 pw.print(")-("); pw.print(mCurRight);
6590 pw.print(","); pw.print(mCurBottom); pw.println(")");
6591 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6592 pw.print(","); pw.print(mContentTop);
6593 pw.print(")-("); pw.print(mContentRight);
6594 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006595 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6596 pw.print(","); pw.print(mVoiceContentTop);
6597 pw.print(")-("); pw.print(mVoiceContentRight);
6598 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006599 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6600 pw.print(","); pw.print(mDockTop);
6601 pw.print(")-("); pw.print(mDockRight);
6602 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006603 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6604 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006605 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6606 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006607 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6608 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006609 if (mLastInputMethodWindow != null) {
6610 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6611 pw.println(mLastInputMethodWindow);
6612 }
6613 if (mLastInputMethodTargetWindow != null) {
6614 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6615 pw.println(mLastInputMethodTargetWindow);
6616 }
6617 if (mStatusBar != null) {
6618 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006619 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6620 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006621 }
6622 if (mNavigationBar != null) {
6623 pw.print(prefix); pw.print("mNavigationBar=");
6624 pw.println(mNavigationBar);
6625 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006626 if (mFocusedWindow != null) {
6627 pw.print(prefix); pw.print("mFocusedWindow=");
6628 pw.println(mFocusedWindow);
6629 }
6630 if (mFocusedApp != null) {
6631 pw.print(prefix); pw.print("mFocusedApp=");
6632 pw.println(mFocusedApp);
6633 }
6634 if (mWinDismissingKeyguard != null) {
6635 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6636 pw.println(mWinDismissingKeyguard);
6637 }
6638 if (mTopFullscreenOpaqueWindowState != null) {
6639 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6640 pw.println(mTopFullscreenOpaqueWindowState);
6641 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006642 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6643 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6644 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6645 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006646 if (mForcingShowNavBar) {
6647 pw.print(prefix); pw.print("mForcingShowNavBar=");
6648 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6649 pw.println(mForcingShowNavBarLayer);
6650 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006651 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006652 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006653 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6654 pw.print(" mForceStatusBarFromKeyguard=");
6655 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006656 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006657 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006658 pw.print(" mHomePressed="); pw.println(mHomePressed);
6659 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6660 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6661 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6662 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6663 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6664 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6665 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6666 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6667 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6668 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006669 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6670 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6671 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006672
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006673 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006674 mStatusBarController.dump(pw, prefix);
6675 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006676 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006677
Jeff Browna20dda42014-05-27 20:57:24 -07006678 if (mWakeGestureListener != null) {
6679 mWakeGestureListener.dump(pw, prefix);
6680 }
Jeff Brown600f0032014-05-22 17:06:00 -07006681 if (mOrientationListener != null) {
6682 mOrientationListener.dump(pw, prefix);
6683 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006684 if (mBurnInProtectionHelper != null) {
6685 mBurnInProtectionHelper.dump(prefix, pw);
6686 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006687 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006688}