blob: d6c72a694773ee8dc58adf8813e67b3791b59fb2 [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
tingna_sunge785ffa2015-05-12 13:23:15 +0800498 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
499 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
500 * lock SIM card. This variable is used to record the previous keyguard secure state for
501 * monitoring secure state change on window dismissing keyguard. */
502 private boolean mSecureDismissingKeyguard;
503
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700504 /** The window that is currently showing "over" the keyguard. If there is an app window
505 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
506 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
507 * the wallpaper. */
508 private WindowState mWinShowWhenLocked;
509
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700510 boolean mShowingLockscreen;
511 boolean mShowingDream;
512 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700513 boolean mDreamingSleepTokenNeeded;
514 SleepToken mDreamingSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700515 boolean mKeyguardSecure;
516 boolean mKeyguardSecureIncludingHidden;
517 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800518 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700519 boolean mHomeConsumed;
520 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800521 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700522 Intent mCarDockIntent;
523 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700524 boolean mSearchKeyShortcutPending;
525 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700526 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700527 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800528
Mike Lockwood28569302010-01-28 11:54:40 -0500529 // support for activating the lock screen while the screen is on
530 boolean mAllowLockscreenWhenOn;
531 int mLockScreenTimeout;
532 boolean mLockScreenTimerActive;
533
David Brownbaf8d092010-03-08 21:52:59 -0800534 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800535 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800536
537 // Behavior of POWER button while in-call and screen on.
538 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
539 int mIncallPowerBehavior;
540
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700541 Display mDisplay;
542
Dianne Hackborn9d132642011-04-21 17:26:39 -0700543 int mLandscapeRotation = 0; // default landscape rotation
544 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
545 int mPortraitRotation = 0; // default portrait rotation
546 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700547
Dianne Hackbornc652de82013-02-15 16:32:56 -0800548 int mOverscanLeft = 0;
549 int mOverscanTop = 0;
550 int mOverscanRight = 0;
551 int mOverscanBottom = 0;
552
Joe Onorato46b0d682010-11-22 17:37:27 -0800553 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700554 private int mLongPressOnHomeBehavior;
555
556 // What we do when the user double-taps on home
557 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800558
Bryce Lee584a4452014-10-21 15:55:55 -0700559 // Allowed theater mode wake actions
560 private boolean mAllowTheaterModeWakeFromKey;
561 private boolean mAllowTheaterModeWakeFromPowerKey;
562 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800563 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700564 private boolean mAllowTheaterModeWakeFromCameraLens;
565 private boolean mAllowTheaterModeWakeFromLidSwitch;
566 private boolean mAllowTheaterModeWakeFromWakeGesture;
567
Bryce Leed3b28402015-03-09 15:49:13 +0000568 // Whether to support long press from power button in non-interactive mode
569 private boolean mSupportLongPressPowerWhenNonInteractive;
570
Bryce Lee55e846d2014-11-04 12:43:44 -0800571 // Whether to go to sleep entering theater mode from power button
572 private boolean mGoToSleepOnButtonPressTheaterMode;
573
Winson Chung9112ec32011-06-27 13:15:32 -0700574 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700575 // Time to volume and power must be pressed within this interval of each other.
576 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700577 // Increase the chord delay when taking a screenshot from the keyguard
578 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800579 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700580 private boolean mScreenshotChordVolumeDownKeyTriggered;
581 private long mScreenshotChordVolumeDownKeyTime;
582 private boolean mScreenshotChordVolumeDownKeyConsumed;
583 private boolean mScreenshotChordVolumeUpKeyTriggered;
584 private boolean mScreenshotChordPowerKeyTriggered;
585 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700586
Michael Wrightb854e242013-02-05 17:54:02 -0800587 /* The number of steps between min and max brightness */
588 private static final int BRIGHTNESS_STEPS = 10;
589
Christopher Tate5e08af02012-09-21 17:17:22 -0700590 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800591 ShortcutManager mShortcutManager;
592 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700593 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700594 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800595
Craig Mautnerd625ab22013-09-06 13:40:31 -0700596 private int mCurrentUserId;
597
Justin Kohd378ad72013-04-01 12:18:26 -0700598 // Maps global key codes to the components that will handle them.
599 private GlobalKeyManager mGlobalKeyManager;
600
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700601 // Fallback actions by key code.
602 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
603 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800604
Jorim Jaggi76a16232014-08-08 17:00:47 +0200605 private final LogDecelerateInterpolator mLogDecelerateInterpolator
606 = new LogDecelerateInterpolator(100, 0);
607
Jeff Brown70825162012-03-28 17:27:48 -0700608 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
609 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700610 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
611 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700612 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
613 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
614 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700615 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700616 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700617 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700618 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700619 private static final int MSG_POWER_DELAYED_PRESS = 13;
620 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700621 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jeff Brown70825162012-03-28 17:27:48 -0700622
623 private class PolicyHandler extends Handler {
624 @Override
625 public void handleMessage(Message msg) {
626 switch (msg.what) {
627 case MSG_ENABLE_POINTER_LOCATION:
628 enablePointerLocation();
629 break;
630 case MSG_DISABLE_POINTER_LOCATION:
631 disablePointerLocation();
632 break;
Jeff Brown40013652012-05-16 21:22:36 -0700633 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
634 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
635 break;
636 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
637 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
638 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700639 case MSG_DISPATCH_SHOW_RECENTS:
640 showRecentApps(false);
641 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700642 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
643 showGlobalActionsInternal();
644 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700645 case MSG_KEYGUARD_DRAWN_COMPLETE:
646 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700647 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700648 break;
649 case MSG_KEYGUARD_DRAWN_TIMEOUT:
650 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700651 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700652 break;
653 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
654 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700655 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700656 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700657 case MSG_HIDE_BOOT_MESSAGE:
658 handleHideBootMessage();
659 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700660 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
661 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
662 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700663 case MSG_POWER_DELAYED_PRESS:
664 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
665 finishPowerKeyPress();
666 break;
667 case MSG_POWER_LONG_PRESS:
668 powerLongPress();
669 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700670 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
671 updateDreamingSleepToken(msg.arg1 != 0);
672 break;
Jeff Brown70825162012-03-28 17:27:48 -0700673 }
674 }
675 }
676
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800677 private UEventObserver mHDMIObserver = new UEventObserver() {
678 @Override
679 public void onUEvent(UEventObserver.UEvent event) {
680 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
681 }
682 };
683
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800684 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800685 SettingsObserver(Handler handler) {
686 super(handler);
687 }
David Brownbaf8d092010-03-08 21:52:59 -0800688
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800689 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700690 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800691 ContentResolver resolver = mContext.getContentResolver();
692 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700693 Settings.System.END_BUTTON_BEHAVIOR), false, this,
694 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800695 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700696 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
697 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700698 resolver.registerContentObserver(Settings.Secure.getUriFor(
699 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
700 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800701 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700702 Settings.System.ACCELEROMETER_ROTATION), false, this,
703 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500704 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700705 Settings.System.USER_ROTATION), false, this,
706 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400707 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700708 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
709 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800710 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700711 Settings.System.POINTER_LOCATION), false, this,
712 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800713 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700714 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
715 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500716 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400717 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700718 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500719 resolver.registerContentObserver(Settings.Global.getUriFor(
720 Settings.Global.POLICY_CONTROL), false, this,
721 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800722 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800723 }
724
725 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800726 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700727 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800728 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800729 }
Craig Mautner967212c2013-04-13 21:10:58 -0700730
Jeff Browna20dda42014-05-27 20:57:24 -0700731 class MyWakeGestureListener extends WakeGestureListener {
732 MyWakeGestureListener(Context context, Handler handler) {
733 super(context, handler);
734 }
735
736 @Override
737 public void onWakeUp() {
738 synchronized (mLock) {
739 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700740 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700741 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700742 }
743 }
744 }
745 }
746
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800747 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800748 MyOrientationListener(Context context, Handler handler) {
749 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800750 }
Craig Mautner967212c2013-04-13 21:10:58 -0700751
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800752 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700753 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700754 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700755 updateRotation(false);
756 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800757 }
758 MyOrientationListener mOrientationListener;
759
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100760 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400761
John Spurlock27735a42013-08-14 17:57:38 -0400762 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400763 View.NAVIGATION_BAR_TRANSIENT,
764 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400765 View.NAVIGATION_BAR_TRANSLUCENT,
766 StatusBarManager.WINDOW_NAVIGATION_BAR,
767 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400768
John Spurlockf1a36642013-10-12 17:50:42 -0400769 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400770
Craig Mautner037aa8d2013-06-07 10:35:44 -0700771 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400772
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700773 IStatusBarService getStatusBarService() {
774 synchronized (mServiceAquireLock) {
775 if (mStatusBarService == null) {
776 mStatusBarService = IStatusBarService.Stub.asInterface(
777 ServiceManager.getService("statusbar"));
778 }
779 return mStatusBarService;
780 }
781 }
782
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700783 /*
784 * We always let the sensor be switched on by default except when
785 * the user has explicitly disabled sensor based rotation or when the
786 * screen is switched off.
787 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700788 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800789 if (mSupportAutoRotation) {
790 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
791 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
792 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
793 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
794 // If the application has explicitly requested to follow the
795 // orientation, then we need to turn the sensor on.
796 return true;
797 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800798 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700799 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800800 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
801 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
802 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400803 // enable accelerometer if we are docked in a dock that enables accelerometer
804 // orientation management,
805 return true;
806 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700807 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800808 // If the setting for using the sensor by default is enabled, then
809 // we will always leave it on. Note that the user could go to
810 // a window that forces an orientation that does not use the
811 // sensor and in theory we could turn it off... however, when next
812 // turning it on we won't have a good value for the current
813 // orientation for a little bit, which can cause orientation
814 // changes to lag, so we'd like to keep it always on. (It will
815 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700816 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800817 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800818 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800819 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700820
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800821 /*
822 * Various use cases for invoking this function
823 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700824 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800825 * if not already enabled
826 * screen turned on and current app does not have sensor orientation, disable listeners if
827 * already enabled
828 * screen turning on and current app has sensor based orientation, enable listeners if needed
829 * screen turning on and current app has nosensor based orientation, do nothing
830 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700831 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800832 if (!mOrientationListener.canDetectOrientation()) {
833 // If sensor is turned off or nonexistent for some reason
834 return;
835 }
836 //Could have been invoked due to screen turning on or off or
837 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700838 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
839 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
840 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800841 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700842 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700843 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800844 disable = false;
845 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700846 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800847 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700848 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800849 mOrientationSensorEnabled = true;
850 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700851 }
852 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800853 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700854 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800855 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700856 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800857 mOrientationSensorEnabled = false;
858 }
859 }
860
Jeff Brown13f00f02014-10-31 14:45:50 -0700861 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
862 // Hold a wake lock until the power key is released.
863 if (!mPowerKeyWakeLock.isHeld()) {
864 mPowerKeyWakeLock.acquire();
865 }
866
867 // Cancel multi-press detection timeout.
868 if (mPowerKeyPressCounter != 0) {
869 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
870 }
871
872 // Detect user pressing the power button in panic when an application has
873 // taken over the whole screen.
874 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800875 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700876 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700877 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700878 }
879
880 // Latch power key state to detect screenshot chord.
881 if (interactive && !mScreenshotChordPowerKeyTriggered
882 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
883 mScreenshotChordPowerKeyTriggered = true;
884 mScreenshotChordPowerKeyTime = event.getDownTime();
885 interceptScreenshotChord();
886 }
887
888 // Stop ringing or end call if configured to do so when power is pressed.
889 TelecomManager telecomManager = getTelecommService();
890 boolean hungUp = false;
891 if (telecomManager != null) {
892 if (telecomManager.isRinging()) {
893 // Pressing Power while there's a ringing incoming
894 // call should silence the ringer.
895 telecomManager.silenceRinger();
896 } else if ((mIncallPowerBehavior
897 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
898 && telecomManager.isInCall() && interactive) {
899 // Otherwise, if "Power button ends call" is enabled,
900 // the Power button will hang up any current active call.
901 hungUp = telecomManager.endCall();
902 }
903 }
904
905 // If the power key has still not yet been handled, then detect short
906 // press, long press, or multi press and decide what to do.
907 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
908 || mScreenshotChordVolumeUpKeyTriggered;
909 if (!mPowerKeyHandled) {
910 if (interactive) {
911 // When interactive, we're already awake.
912 // Wait for a long press or for the button to be released to decide what to do.
913 if (hasLongPressOnPowerBehavior()) {
914 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
915 msg.setAsynchronous(true);
916 mHandler.sendMessageDelayed(msg,
917 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
918 }
919 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800920 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800921
Bryce Leed3b28402015-03-09 15:49:13 +0000922 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
923 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
924 msg.setAsynchronous(true);
925 mHandler.sendMessageDelayed(msg,
926 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800927 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000928 } else {
929 final int maxCount = getMaxMultiPressPowerCount();
930
931 if (maxCount <= 1) {
932 mPowerKeyHandled = true;
933 } else {
934 mBeganFromNonInteractive = true;
935 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700936 }
937 }
Jeff Brown4d396052010-10-29 21:50:21 -0700938 }
939 }
940
Jeff Brown13f00f02014-10-31 14:45:50 -0700941 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
942 final boolean handled = canceled || mPowerKeyHandled;
943 mScreenshotChordPowerKeyTriggered = false;
944 cancelPendingScreenshotChordAction();
945 cancelPendingPowerKeyAction();
946
947 if (!handled) {
948 // Figure out how to handle the key now that it has been released.
949 mPowerKeyPressCounter += 1;
950
951 final int maxCount = getMaxMultiPressPowerCount();
952 final long eventTime = event.getDownTime();
953 if (mPowerKeyPressCounter < maxCount) {
954 // This could be a multi-press. Wait a little bit longer to confirm.
955 // Continue holding the wake lock.
956 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
957 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
958 msg.setAsynchronous(true);
959 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
960 return;
961 }
962
963 // No other actions. Handle it immediately.
964 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700965 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700966
967 // Done. Reset our state.
968 finishPowerKeyPress();
969 }
970
971 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800972 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700973 mPowerKeyPressCounter = 0;
974 if (mPowerKeyWakeLock.isHeld()) {
975 mPowerKeyWakeLock.release();
976 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700977 }
978
979 private void cancelPendingPowerKeyAction() {
980 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700981 mPowerKeyHandled = true;
982 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700983 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700984 }
985
986 private void powerPress(long eventTime, boolean interactive, int count) {
987 if (mScreenOnEarly && !mScreenOnFully) {
988 Slog.i(TAG, "Suppressed redundant power key press while "
989 + "already in the process of turning the screen on.");
990 return;
Jeff Brownff204712011-10-25 21:27:54 -0700991 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700992
993 if (count == 2) {
994 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
995 } else if (count == 3) {
996 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -0800997 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700998 switch (mShortPressOnPowerBehavior) {
999 case SHORT_PRESS_POWER_NOTHING:
1000 break;
1001 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1002 mPowerManager.goToSleep(eventTime,
1003 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1004 break;
1005 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1006 mPowerManager.goToSleep(eventTime,
1007 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1008 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1009 break;
1010 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1011 mPowerManager.goToSleep(eventTime,
1012 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1013 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1014 launchHomeFromHotKey();
1015 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001016 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001017 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001018 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001019 }
1020 }
1021 }
1022
1023 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1024 switch (behavior) {
1025 case MULTI_PRESS_POWER_NOTHING:
1026 break;
1027 case MULTI_PRESS_POWER_THEATER_MODE:
1028 if (isTheaterModeEnabled()) {
1029 Slog.i(TAG, "Toggling theater mode off.");
1030 Settings.Global.putInt(mContext.getContentResolver(),
1031 Settings.Global.THEATER_MODE_ON, 0);
1032 if (!interactive) {
1033 wakeUpFromPowerKey(eventTime);
1034 }
1035 } else {
1036 Slog.i(TAG, "Toggling theater mode on.");
1037 Settings.Global.putInt(mContext.getContentResolver(),
1038 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001039
1040 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001041 mPowerManager.goToSleep(eventTime,
1042 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1043 }
1044 }
1045 break;
1046 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001047 Slog.i(TAG, "Starting brightness boost.");
1048 if (!interactive) {
1049 wakeUpFromPowerKey(eventTime);
1050 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001051 mPowerManager.boostScreenBrightness(eventTime);
1052 break;
1053 }
1054 }
1055
1056 private int getMaxMultiPressPowerCount() {
1057 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1058 return 3;
1059 }
1060 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1061 return 2;
1062 }
1063 return 1;
1064 }
1065
1066 private void powerLongPress() {
1067 final int behavior = getResolvedLongPressOnPowerBehavior();
1068 switch (behavior) {
1069 case LONG_PRESS_POWER_NOTHING:
1070 break;
1071 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1072 mPowerKeyHandled = true;
1073 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1074 performAuditoryFeedbackForAccessibilityIfNeed();
1075 }
1076 showGlobalActionsInternal();
1077 break;
1078 case LONG_PRESS_POWER_SHUT_OFF:
1079 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1080 mPowerKeyHandled = true;
1081 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1082 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1083 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1084 break;
1085 }
1086 }
1087
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001088 private void sleepPress(KeyEvent event) {
1089 switch (mShortPressOnSleepBehavior) {
1090 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
1091 mPowerManager.goToSleep(event.getEventTime(),
1092 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1093 break;
1094 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001095 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001096 mPowerManager.goToSleep(event.getEventTime(),
1097 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1098 break;
1099 }
1100 }
1101
Jeff Brown13f00f02014-10-31 14:45:50 -07001102 private int getResolvedLongPressOnPowerBehavior() {
1103 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1104 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1105 }
1106 return mLongPressOnPowerBehavior;
1107 }
1108
1109 private boolean hasLongPressOnPowerBehavior() {
1110 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001111 }
1112
1113 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001114 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001115 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1116 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001117 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001118 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1119 && now <= mScreenshotChordPowerKeyTime
1120 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1121 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001122 cancelPendingPowerKeyAction();
1123
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001124 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001125 }
1126 }
1127 }
1128
Winson Chung1cea2f32012-10-08 20:42:01 -07001129 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001130 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001131 // Double the time it takes to take a screenshot from the keyguard
1132 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001133 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001134 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001135 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001136 }
1137
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001138 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001139 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001140 }
1141
Jeff Brown13f00f02014-10-31 14:45:50 -07001142 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001143 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001144 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001145 mEndCallKeyHandled = true;
1146 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1147 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001148 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001149 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001150 }
1151 };
1152
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001153 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001154 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001155 public void run() {
1156 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001157 }
1158 };
1159
Alan Viverettee34560b22014-07-10 14:50:06 -07001160 @Override
1161 public void showGlobalActions() {
1162 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1163 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1164 }
1165
1166 void showGlobalActionsInternal() {
1167 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001168 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001169 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001170 }
Jim Millerab954542014-10-10 18:21:49 -07001171 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001172 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1173 if (keyguardShowing) {
1174 // since it took two seconds of long press to bring this up,
1175 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001176 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001177 }
1178 }
1179
1180 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001181 return Settings.Global.getInt(
1182 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001183 }
1184
Maurice Lam99c6e072014-04-28 18:24:28 -07001185 boolean isUserSetupComplete() {
1186 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1187 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1188 }
1189
Jeff Brown13f00f02014-10-31 14:45:50 -07001190 private void handleShortPressOnHome() {
1191 // If there's a dream running then use home to escape the dream
1192 // but don't actually go home.
1193 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1194 mDreamManagerInternal.stopDream(false /*immediate*/);
1195 return;
1196 }
1197
1198 // Go home!
1199 launchHomeFromHotKey();
1200 }
1201
Patrick Dubroyece94522011-02-23 18:35:01 -08001202 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -08001203 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001204 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001205 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001206
Jeff Browncaca8812013-05-09 13:34:33 -07001207 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1208 toggleRecentApps();
1209 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1210 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -07001211 }
1212 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001213 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001214
Jeff Browncaca8812013-05-09 13:34:33 -07001215 private void handleDoubleTapOnHome() {
1216 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1217 mHomeConsumed = true;
1218 toggleRecentApps();
1219 }
1220 }
1221
1222 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1223 @Override
1224 public void run() {
1225 if (mHomeDoubleTapPending) {
1226 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001227 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001228 }
1229 }
1230 };
1231
Mark Renoufc1256912015-03-11 14:38:23 -04001232 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001233 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001234 }
1235
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001236 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001237 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001238 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001239 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001240 mContext = context;
1241 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001242 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001243 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001244 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001245 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Mark Renoufc1256912015-03-11 14:38:23 -04001246
1247 // Init display burn-in protection
1248 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1249 com.android.internal.R.bool.config_enableBurnInProtection);
1250 // Allow a system property to override this. Used by developer settings.
1251 boolean burnInProtectionDevMode =
1252 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1253 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1254 final int minHorizontal;
1255 final int maxHorizontal;
1256 final int minVertical;
1257 final int maxVertical;
1258 final int maxRadius;
1259 if (burnInProtectionDevMode) {
1260 minHorizontal = -8;
1261 maxHorizontal = 8;
1262 minVertical = -8;
1263 maxVertical = -4;
1264 maxRadius = (isRoundWindow()) ? 6 : -1;
1265 } else {
1266 Resources resources = context.getResources();
1267 minHorizontal = resources.getInteger(
1268 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1269 maxHorizontal = resources.getInteger(
1270 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1271 minVertical = resources.getInteger(
1272 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1273 maxVertical = resources.getInteger(
1274 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1275 maxRadius = resources.getInteger(
1276 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1277 }
1278 mBurnInProtectionHelper = new BurnInProtectionHelper(
1279 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001280 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001281
Jeff Brown70825162012-03-28 17:27:48 -07001282 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001283 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001284 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001285 try {
1286 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1287 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001288 mSettingsObserver = new SettingsObserver(mHandler);
1289 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001290 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001291 mUiMode = context.getResources().getInteger(
1292 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001293 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1294 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1295 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1296 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001297 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1298 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1299 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1300 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1301 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1302 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1303 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1304 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001305
Jeff Brown96307042012-07-27 15:51:34 -07001306 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1307 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001308 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001309 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1310 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001311 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001312 mSupportAutoRotation = mContext.getResources().getBoolean(
1313 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001314 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001315 com.android.internal.R.integer.config_lidOpenRotation);
1316 mCarDockRotation = readRotation(
1317 com.android.internal.R.integer.config_carDockRotation);
1318 mDeskDockRotation = readRotation(
1319 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001320 mUndockedHdmiRotation = readRotation(
1321 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001322 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1323 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1324 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1325 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001326 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1327 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1328 mLidNavigationAccessibility = mContext.getResources().getInteger(
1329 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001330 mLidControlsSleep = mContext.getResources().getBoolean(
1331 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001332 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1333 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001334
1335 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1336 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1337 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1338 || mContext.getResources().getBoolean(
1339 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1340 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1341 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001342 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1343 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001344 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1345 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1346 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1347 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1348 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1349 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1350
Bryce Lee55e846d2014-11-04 12:43:44 -08001351 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1352 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1353
Bryce Leed3b28402015-03-09 15:49:13 +00001354 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1355 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1356
Jeff Brown13f00f02014-10-31 14:45:50 -07001357 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1358 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1359 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1360 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1361 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1362 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1363 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1364 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001365 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1366 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001367
John Spurlock61560172015-02-06 19:46:04 -05001368 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001369
Jeff Brownf71343d2013-05-31 17:59:11 -07001370 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001371
Svetoslav8e3feb12014-02-24 13:46:47 -08001372 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1373 Context.ACCESSIBILITY_SERVICE);
1374
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001375 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001376 IntentFilter filter = new IntentFilter();
1377 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1378 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1379 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1380 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001381 filter.addAction(Intent.ACTION_DOCK_EVENT);
1382 Intent intent = context.registerReceiver(mDockReceiver, filter);
1383 if (intent != null) {
1384 // Retrieve current sticky dock event broadcast.
1385 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1386 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1387 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001388
Jeff Brown6aaf2952012-10-05 16:01:08 -07001389 // register for dream-related broadcasts
1390 filter = new IntentFilter();
1391 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1392 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1393 context.registerReceiver(mDreamReceiver, filter);
1394
Christopher Tate5e08af02012-09-21 17:17:22 -07001395 // register for multiuser-relevant broadcasts
1396 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1397 context.registerReceiver(mMultiuserReceiver, filter);
1398
John Spurlock57306e62013-04-22 09:48:49 -04001399 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001400 mSystemGestures = new SystemGesturesPointerEventListener(context,
1401 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001402 @Override
1403 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001404 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001405 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001406 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001407 }
1408 @Override
1409 public void onSwipeFromBottom() {
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 onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001416 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001417 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001418 }
1419 }
1420 @Override
1421 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001422 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001423 }
Adrian Roos3595be42015-03-05 16:31:15 +01001424 @Override
1425 public void onDown() {
1426 mOrientationListener.onTouchStart();
1427 }
1428 @Override
1429 public void onUpOrCancel() {
1430 mOrientationListener.onTouchEnd();
1431 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001432 });
John Spurlockf1a36642013-10-12 17:50:42 -04001433 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001434 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001435
Jeff Brownc2346132012-04-13 01:55:38 -07001436 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001437 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1438 com.android.internal.R.array.config_longPressVibePattern);
1439 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1440 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001441 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1442 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001443 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1444 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001445 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1446 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001447 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1448 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1449 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1450 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore82067b2015-04-30 09:58:35 -07001451 mStylusButtonPressVibePattern = getLongIntArray(mContext.getResources(),
1452 com.android.internal.R.array.config_stylusButtonPressVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001453
Christopher Tatee90585f2012-03-05 18:56:25 -08001454 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1455 com.android.internal.R.bool.config_enableScreenshotChord);
1456
Justin Kohd378ad72013-04-01 12:18:26 -07001457 mGlobalKeyManager = new GlobalKeyManager(mContext);
1458
Joe Onoratoea495d42011-04-06 11:41:11 -07001459 // Controls rotation and the like.
1460 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001461
1462 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001463 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001464 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001465 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001466
1467 mWindowManagerInternal.registerAppTransitionListener(
1468 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001469 }
1470
Jeff Brownf71343d2013-05-31 17:59:11 -07001471 /**
1472 * Read values from config.xml that may be overridden depending on
1473 * the configuration of the device.
1474 * eg. Disable long press on home goes to recents on sw600dp.
1475 */
1476 private void readConfigurationDependentBehaviors() {
1477 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1478 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1479 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1480 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1481 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1482 }
1483
1484 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1485 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1486 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1487 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1488 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1489 }
1490 }
1491
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001492 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001493 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001494 // This method might be called before the policy has been fully initialized
1495 // or for other displays we don't care about.
1496 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1497 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001498 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001499 mDisplay = display;
1500
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001501 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001502 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001503 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001504 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001505 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001506 mLandscapeRotation = Surface.ROTATION_0;
1507 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001508 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001509 mPortraitRotation = Surface.ROTATION_90;
1510 mUpsideDownRotation = Surface.ROTATION_270;
1511 } else {
1512 mPortraitRotation = Surface.ROTATION_270;
1513 mUpsideDownRotation = Surface.ROTATION_90;
1514 }
1515 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001516 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001517 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001518 mPortraitRotation = Surface.ROTATION_0;
1519 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001520 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001521 mLandscapeRotation = Surface.ROTATION_270;
1522 mSeascapeRotation = Surface.ROTATION_90;
1523 } else {
1524 mLandscapeRotation = Surface.ROTATION_90;
1525 mSeascapeRotation = Surface.ROTATION_270;
1526 }
1527 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001528
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001529 mStatusBarHeight =
1530 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001531
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001532 // Height of the navigation bar when presented horizontally at bottom
1533 mNavigationBarHeightForRotation[mPortraitRotation] =
1534 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001535 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001536 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001537 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1538 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001539
1540 // Width of the navigation bar when presented vertically along one side
1541 mNavigationBarWidthForRotation[mPortraitRotation] =
1542 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1543 mNavigationBarWidthForRotation[mLandscapeRotation] =
1544 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001545 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001546
1547 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001548 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001549 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001550
Devin Kimd7b12b42014-05-05 14:34:58 -07001551 // Allow the navigation bar to move on non-square small devices (phones).
1552 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001553
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001554 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001555 // Allow a system property to override this. Used by the emulator.
1556 // See also hasNavigationBar().
1557 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1558 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001559 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001560 } else if ("0".equals(navBarOverride)) {
1561 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001562 }
1563
Jeff Brown27f1d672012-10-17 18:32:34 -07001564 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1565 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001566 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001567 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001568 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001569 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001570 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001571 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001572
Chong Zhangae6119ff2014-11-11 18:54:39 -08001573 // For demo purposes, allow the rotation of the remote display to be controlled.
1574 // By default, remote display locks rotation to landscape.
1575 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1576 mDemoRotation = mPortraitRotation;
1577 } else {
1578 mDemoRotation = mLandscapeRotation;
1579 }
1580 mDemoRotationLock = SystemProperties.getBoolean(
1581 "persist.demo.rotationlock", false);
1582
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001583 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1584 // http://developer.android.com/guide/practices/screens_support.html#range
1585 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1586 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1587 // For debug purposes the next line turns this feature off with:
1588 // $ adb shell setprop config.override_forced_orient true
1589 // $ adb shell wm size reset
1590 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1591 }
1592
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001593 /**
1594 * @return whether the navigation bar can be hidden, e.g. the device has a
1595 * navigation bar and touch exploration is not enabled
1596 */
1597 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001598 return mHasNavigationBar
1599 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001600 }
1601
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001602 @Override
1603 public boolean isDefaultOrientationForced() {
1604 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001605 }
1606
Dianne Hackbornc652de82013-02-15 16:32:56 -08001607 @Override
1608 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1609 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1610 mOverscanLeft = left;
1611 mOverscanTop = top;
1612 mOverscanRight = right;
1613 mOverscanBottom = bottom;
1614 }
1615 }
1616
Dianne Hackbornc777e072010-02-12 13:07:59 -08001617 public void updateSettings() {
1618 ContentResolver resolver = mContext.getContentResolver();
1619 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001620 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001621 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001622 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001623 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1624 UserHandle.USER_CURRENT);
1625 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001626 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001627 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1628 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001629
Jeff Browna20dda42014-05-27 20:57:24 -07001630 // Configure wake gesture.
1631 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1632 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1633 UserHandle.USER_CURRENT) != 0;
1634 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1635 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1636 updateWakeGestureListenerLp();
1637 }
1638
Jeff Brown207673cd2012-06-05 17:47:11 -07001639 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001640 int userRotation = Settings.System.getIntForUser(resolver,
1641 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1642 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001643 if (mUserRotation != userRotation) {
1644 mUserRotation = userRotation;
1645 updateRotation = true;
1646 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001647 int userRotationMode = Settings.System.getIntForUser(resolver,
1648 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001649 WindowManagerPolicy.USER_ROTATION_FREE :
1650 WindowManagerPolicy.USER_ROTATION_LOCKED;
1651 if (mUserRotationMode != userRotationMode) {
1652 mUserRotationMode = userRotationMode;
1653 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001654 updateOrientationListenerLp();
1655 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001656
Dianne Hackbornc777e072010-02-12 13:07:59 -08001657 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001658 int pointerLocation = Settings.System.getIntForUser(resolver,
1659 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001660 if (mPointerLocationMode != pointerLocation) {
1661 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001662 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1663 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001664 }
1665 }
1666 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001667 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1668 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1669 String imId = Settings.Secure.getStringForUser(resolver,
1670 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001671 boolean hasSoftInput = imId != null && imId.length() > 0;
1672 if (mHasSoftInput != hasSoftInput) {
1673 mHasSoftInput = hasSoftInput;
1674 updateRotation = true;
1675 }
John Spurlockf1a36642013-10-12 17:50:42 -04001676 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001677 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001678 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001679 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001680 }
1681 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001682 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001683 }
Jeff Brown70825162012-03-28 17:27:48 -07001684 }
1685
Jeff Browna20dda42014-05-27 20:57:24 -07001686 private void updateWakeGestureListenerLp() {
1687 if (shouldEnableWakeGestureLp()) {
1688 mWakeGestureListener.requestWakeUpTrigger();
1689 } else {
1690 mWakeGestureListener.cancelWakeUpTrigger();
1691 }
1692 }
1693
1694 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001695 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001696 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1697 && mWakeGestureListener.isSupported();
1698 }
1699
Jeff Brown70825162012-03-28 17:27:48 -07001700 private void enablePointerLocation() {
1701 if (mPointerLocationView == null) {
1702 mPointerLocationView = new PointerLocationView(mContext);
1703 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001704 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1705 WindowManager.LayoutParams.MATCH_PARENT,
1706 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001707 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001708 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1709 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1710 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1711 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001712 if (ActivityManager.isHighEndGfx()) {
1713 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1714 lp.privateFlags |=
1715 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1716 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001717 lp.format = PixelFormat.TRANSLUCENT;
1718 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001719 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001720 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001721 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001722 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001723 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001724 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001725 }
Jeff Brown70825162012-03-28 17:27:48 -07001726
1727 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001728 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001729 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1730 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001731 wm.removeView(mPointerLocationView);
1732 mPointerLocationView = null;
1733 }
1734 }
1735
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001736 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001737 try {
1738 int rotation = mContext.getResources().getInteger(resID);
1739 switch (rotation) {
1740 case 0:
1741 return Surface.ROTATION_0;
1742 case 90:
1743 return Surface.ROTATION_90;
1744 case 180:
1745 return Surface.ROTATION_180;
1746 case 270:
1747 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001748 }
1749 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001750 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001751 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001752 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001753 }
1754
1755 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001756 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001757 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001758 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001759
1760 outAppOp[0] = AppOpsManager.OP_NONE;
1761
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001762 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1763 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1764 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1765 return WindowManagerGlobal.ADD_INVALID_TYPE;
1766 }
1767
1768 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1769 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001770 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001771 }
1772 String permission = null;
1773 switch (type) {
1774 case TYPE_TOAST:
1775 // XXX right now the app process has complete control over
1776 // this... should introduce a token to let the system
1777 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001778 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001779 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001780 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001781 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001782 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001783 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001784 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001785 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001786 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001787 break;
1788 case TYPE_PHONE:
1789 case TYPE_PRIORITY_PHONE:
1790 case TYPE_SYSTEM_ALERT:
1791 case TYPE_SYSTEM_ERROR:
1792 case TYPE_SYSTEM_OVERLAY:
1793 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001794 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001795 break;
1796 default:
1797 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1798 }
1799 if (permission != null) {
1800 if (mContext.checkCallingOrSelfPermission(permission)
1801 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001802 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001803 }
1804 }
Jeff Brown98365d72012-08-19 20:30:52 -07001805 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001806 }
Craig Mautner88400d32012-09-30 12:35:45 -07001807
1808 @Override
1809 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1810
1811 // If this switch statement is modified, modify the comment in the declarations of
1812 // the type in {@link WindowManager.LayoutParams} as well.
1813 switch (attrs.type) {
1814 default:
1815 // These are the windows that by default are shown only to the user that created
1816 // them. If this needs to be overridden, set
1817 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1818 // {@link WindowManager.LayoutParams}. Note that permission
1819 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1820 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1821 return true;
1822 }
1823 break;
1824
1825 // These are the windows that by default are shown to all users. However, to
1826 // protect against spoofing, check permissions below.
1827 case TYPE_APPLICATION_STARTING:
1828 case TYPE_BOOT_PROGRESS:
1829 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07001830 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001831 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001832 case TYPE_KEYGUARD_DIALOG:
1833 case TYPE_MAGNIFICATION_OVERLAY:
1834 case TYPE_NAVIGATION_BAR:
1835 case TYPE_NAVIGATION_BAR_PANEL:
1836 case TYPE_PHONE:
1837 case TYPE_POINTER:
1838 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001839 case TYPE_SEARCH_BAR:
1840 case TYPE_STATUS_BAR:
1841 case TYPE_STATUS_BAR_PANEL:
1842 case TYPE_STATUS_BAR_SUB_PANEL:
1843 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001844 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001845 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001846 break;
1847 }
1848
1849 // Check if third party app has set window to system window type.
1850 return mContext.checkCallingOrSelfPermission(
1851 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1852 != PackageManager.PERMISSION_GRANTED;
1853 }
1854
Craig Mautner967212c2013-04-13 21:10:58 -07001855 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001856 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1857 switch (attrs.type) {
1858 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001859 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001860 // These types of windows can't receive input events.
1861 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1862 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001863 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001864 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001865 case TYPE_STATUS_BAR:
1866
1867 // If the Keyguard is in a hidden state (occluded by another window), we force to
1868 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1869 // the keyguard as occluded wouldn't set these flags again.
1870 // See {@link #processKeyguardSetHiddenResultLw}.
1871 if (mKeyguardHidden) {
1872 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1873 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1874 }
1875 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001876 }
Adrian Roos38502112014-04-09 21:04:11 +02001877
1878 if (attrs.type != TYPE_STATUS_BAR) {
1879 // The status bar is the only window allowed to exhibit keyguard behavior.
1880 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1881 }
Adrian Roosea562512014-05-05 13:33:03 +02001882
1883 if (ActivityManager.isHighEndGfx()
1884 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001885 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001886 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1887 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001888 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001889
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001890 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001891 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001892 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001893
Michael Wright3818c922014-09-02 13:59:07 -07001894 private void readCameraLensCoverState() {
1895 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1896 }
1897
Jeff Browndaa37532012-05-01 15:54:03 -07001898 private boolean isHidden(int accessibilityMode) {
1899 switch (accessibilityMode) {
1900 case 1:
1901 return mLidState == LID_CLOSED;
1902 case 2:
1903 return mLidState == LID_OPEN;
1904 default:
1905 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001906 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001907 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001908
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001909 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001910 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001911 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1912 int navigationPresence) {
1913 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1914
Jeff Brownf71343d2013-05-31 17:59:11 -07001915 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001916 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001917 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001918
Jeff Browndaa37532012-05-01 15:54:03 -07001919 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1920 || (keyboardPresence == PRESENCE_INTERNAL
1921 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001922 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001923 if (!mHasSoftInput) {
1924 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1925 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001926 }
1927
Jeff Browndaa37532012-05-01 15:54:03 -07001928 if (config.navigation == Configuration.NAVIGATION_NONAV
1929 || (navigationPresence == PRESENCE_INTERNAL
1930 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001931 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001932 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001933 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001934
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001935 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001936 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001937 public int windowTypeToLayerLw(int type) {
1938 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001939 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001940 }
1941 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001942 case TYPE_PRIVATE_PRESENTATION:
1943 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001944 case TYPE_WALLPAPER:
1945 // wallpaper is at the bottom, though the window manager may move it.
1946 return 2;
1947 case TYPE_PHONE:
1948 return 3;
1949 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07001950 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001951 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001952 case TYPE_VOICE_INTERACTION:
1953 // voice interaction layer is almost immediately above apps.
1954 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07001955 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001956 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07001957 case TYPE_SYSTEM_DIALOG:
1958 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001959 case TYPE_TOAST:
1960 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07001961 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001962 case TYPE_PRIORITY_PHONE:
1963 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07001964 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001965 case TYPE_DREAM:
1966 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07001967 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001968 case TYPE_SYSTEM_ALERT:
1969 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07001970 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001971 case TYPE_INPUT_METHOD:
1972 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07001973 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001974 case TYPE_INPUT_METHOD_DIALOG:
1975 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07001976 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08001977 case TYPE_KEYGUARD_SCRIM:
1978 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001979 return 14;
Selim Cinekf83e8242015-05-19 18:08:14 -07001980 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001981 return 15;
Selim Cinekf83e8242015-05-19 18:08:14 -07001982 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001983 return 16;
Selim Cinekf83e8242015-05-19 18:08:14 -07001984 case TYPE_STATUS_BAR_PANEL:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001985 return 17;
Selim Cinekf83e8242015-05-19 18:08:14 -07001986 case TYPE_KEYGUARD_DIALOG:
1987 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001988 case TYPE_VOLUME_OVERLAY:
1989 // the on-screen volume indicator and controller shown when the user
1990 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07001991 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001992 case TYPE_SYSTEM_OVERLAY:
1993 // the on-screen volume indicator and controller shown when the user
1994 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07001995 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001996 case TYPE_NAVIGATION_BAR:
1997 // the navigation bar, if available, shows atop most things
Selim Cinekf83e8242015-05-19 18:08:14 -07001998 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001999 case TYPE_NAVIGATION_BAR_PANEL:
2000 // some panels (e.g. search) need to show on top of the navigation bar
Selim Cinekf83e8242015-05-19 18:08:14 -07002001 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002002 case TYPE_SYSTEM_ERROR:
2003 // system-level error dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002004 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002005 case TYPE_MAGNIFICATION_OVERLAY:
2006 // used to highlight the magnified portion of a display
Selim Cinekf83e8242015-05-19 18:08:14 -07002007 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002008 case TYPE_DISPLAY_OVERLAY:
2009 // used to simulate secondary display devices
Selim Cinekf83e8242015-05-19 18:08:14 -07002010 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002011 case TYPE_DRAG:
2012 // the drag layer: input for drag-and-drop is associated with this window,
2013 // which sits above all other focusable windows
Selim Cinekf83e8242015-05-19 18:08:14 -07002014 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002015 case TYPE_ACCESSIBILITY_OVERLAY:
2016 // overlay put by accessibility services to intercept user interaction
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002017 return 27;
Selim Cinekf83e8242015-05-19 18:08:14 -07002018 case TYPE_SECURE_SYSTEM_OVERLAY:
Svetoslav3a5c7212014-10-14 09:54:26 -07002019 return 28;
Selim Cinekf83e8242015-05-19 18:08:14 -07002020 case TYPE_BOOT_PROGRESS:
2021 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002022 case TYPE_POINTER:
2023 // the (mouse) pointer layer
Svetoslav3a5c7212014-10-14 09:54:26 -07002024 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002025 }
2026 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002027 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002028 }
2029
2030 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002031 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002032 public int subWindowTypeToLayerLw(int type) {
2033 switch (type) {
2034 case TYPE_APPLICATION_PANEL:
2035 case TYPE_APPLICATION_ATTACHED_DIALOG:
2036 return APPLICATION_PANEL_SUBLAYER;
2037 case TYPE_APPLICATION_MEDIA:
2038 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002039 case TYPE_APPLICATION_MEDIA_OVERLAY:
2040 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002041 case TYPE_APPLICATION_SUB_PANEL:
2042 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002043 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2044 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002045 }
2046 Log.e(TAG, "Unknown sub-window type: " + type);
2047 return 0;
2048 }
2049
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002050 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002051 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002052 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002053 }
2054
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002055 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002056 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002057 if (mHasNavigationBar) {
2058 // For a basic navigation bar, when we are in landscape mode we place
2059 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002060 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2061 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002062 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002063 }
2064 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002065 }
2066
Jose Lima9546b202014-07-02 17:21:51 -07002067 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002068 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002069 if (mHasNavigationBar) {
2070 // For a basic navigation bar, when we are in portrait mode we place
2071 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002072 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2073 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002074 }
2075 }
2076 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002077 }
2078
Jose Lima9546b202014-07-02 17:21:51 -07002079 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002080 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2081 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002082 }
2083
Jose Lima9546b202014-07-02 17:21:51 -07002084 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002085 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002086 // There is a separate status bar at the top of the display. We don't count that as part
2087 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002088 // we do want to exclude it since applications can't generally use that part
2089 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002090 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002091 }
2092
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002093 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002094 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2095 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002096 (isKeyguardHostWindow(attrs) &&
2097 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002098 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002099 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002100
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002101 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002102 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2103 return attrs.type == TYPE_STATUS_BAR;
2104 }
2105
2106 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002107 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002108 switch (attrs.type) {
2109 case TYPE_STATUS_BAR:
2110 case TYPE_NAVIGATION_BAR:
2111 case TYPE_WALLPAPER:
2112 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002113 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002114 return false;
2115 default:
2116 return true;
2117 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002118 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002119
Craig Mautner7d7808f2014-09-11 18:02:38 -07002120 @Override
2121 public WindowState getWinShowWhenLockedLw() {
2122 return mWinShowWhenLocked;
2123 }
2124
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002125 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002126 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002127 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2128 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002129 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002130 if (!SHOW_STARTING_ANIMATIONS) {
2131 return null;
2132 }
2133 if (packageName == null) {
2134 return null;
2135 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002136
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002137 WindowManager wm = null;
2138 View view = null;
2139
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002140 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002141 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002142 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2143 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2144 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002145 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002146 try {
2147 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002148 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002149 } catch (PackageManager.NameNotFoundException e) {
2150 // Ignore
2151 }
2152 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002153
Jorim Jaggib10e33f2015-02-04 21:57:40 +01002154 Window win = new PhoneWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002155 final TypedArray ta = win.getWindowStyle();
2156 if (ta.getBoolean(
2157 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2158 || ta.getBoolean(
2159 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002160 return null;
2161 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002162
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002163 Resources r = context.getResources();
2164 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002165
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002166 win.setType(
2167 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002168
2169 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2170 // Assumes it's safe to show starting windows of launched apps while
2171 // the keyguard is being hidden. This is okay because starting windows never show
2172 // secret information.
2173 if (mKeyguardHidden) {
2174 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2175 }
2176 }
2177
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002178 // Force the window flags: this is a fake window, so it is not really
2179 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2180 // flag because we do know that the next window will take input
2181 // focus, so we want to get the IME window up on top of us right away.
2182 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002183 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002184 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2185 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2186 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002187 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002188 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2189 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2190 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002191
Adam Powell04fe6eb2013-05-31 14:39:48 -07002192 win.setDefaultIcon(icon);
2193 win.setDefaultLogo(logo);
2194
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002195 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002196 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002197
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002198 final WindowManager.LayoutParams params = win.getAttributes();
2199 params.token = appToken;
2200 params.packageName = packageName;
2201 params.windowAnimations = win.getWindowStyle().getResourceId(
2202 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002203 params.privateFlags |=
2204 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002205 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002206
2207 if (!compatInfo.supportsScreen()) {
2208 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2209 }
2210
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002211 params.setTitle("Starting " + packageName);
2212
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002213 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2214 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002215
2216 if (win.isFloating()) {
2217 // Whoops, there is no way to display an animation/preview
2218 // of such a thing! After all that work... let's skip it.
2219 // (Note that we must do this here because it is in
2220 // getDecorView() where the theme is evaluated... maybe
2221 // we should peek the floating attribute from the theme
2222 // earlier.)
2223 return null;
2224 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002225
Craig Mautner6fbda632012-07-03 09:26:39 -07002226 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002227 TAG, "Adding starting window for " + packageName
2228 + " / " + appToken + ": "
2229 + (view.getParent() != null ? view : null));
2230
2231 wm.addView(view, params);
2232
2233 // Only return the view if it was successfully added to the
2234 // window manager... which we can tell by it having a parent.
2235 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002236 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002237 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002238 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2239 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002240 } catch (RuntimeException e) {
2241 // don't crash if something else bad happens, for example a
2242 // failure loading resources because we are loading from an app
2243 // on external storage that has been unmounted.
2244 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002245 } finally {
2246 if (view != null && view.getParent() == null) {
2247 Log.w(TAG, "view not successfully added to wm, removing view");
2248 wm.removeViewImmediate(view);
2249 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002250 }
2251
2252 return null;
2253 }
2254
2255 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002256 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002257 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002258 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2259 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002260
2261 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002262 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002263 wm.removeView(window);
2264 }
2265 }
2266
2267 /**
2268 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002269 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002270 * Currently enforces that three window types are singletons:
2271 * <ul>
2272 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002273 * <li>KEYGUARD_TYPE</li>
2274 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002275 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002276 * @param win The window to be added
2277 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002278 *
Jeff Brown98365d72012-08-19 20:30:52 -07002279 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2280 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002281 */
Jose Lima9546b202014-07-02 17:21:51 -07002282 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002283 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2284 switch (attrs.type) {
2285 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002286 mContext.enforceCallingOrSelfPermission(
2287 android.Manifest.permission.STATUS_BAR_SERVICE,
2288 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002289 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002290 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002291 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002292 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002293 }
2294 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002295 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002296 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002297 case TYPE_NAVIGATION_BAR:
2298 mContext.enforceCallingOrSelfPermission(
2299 android.Manifest.permission.STATUS_BAR_SERVICE,
2300 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002301 if (mNavigationBar != null) {
2302 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002303 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002304 }
2305 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002306 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002307 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002308 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002309 break;
Jim Millere898ac52012-04-06 17:10:57 -07002310 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002311 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002312 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002313 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002314 mContext.enforceCallingOrSelfPermission(
2315 android.Manifest.permission.STATUS_BAR_SERVICE,
2316 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002317 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002318 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002319 if (mKeyguardScrim != null) {
2320 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2321 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002322 mKeyguardScrim = win;
2323 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002324 }
Jeff Brown98365d72012-08-19 20:30:52 -07002325 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002326 }
2327
2328 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002329 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002330 public void removeWindowLw(WindowState win) {
2331 if (mStatusBar == win) {
2332 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002333 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002334 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002335 } else if (mKeyguardScrim == win) {
2336 Log.v(TAG, "Removing keyguard scrim");
2337 mKeyguardScrim = null;
2338 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002339 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002340 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002341 }
2342 }
2343
2344 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002345
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002346 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002347 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002348 public int selectAnimationLw(WindowState win, int transit) {
2349 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2350 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002351 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002352 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002353 if (transit == TRANSIT_EXIT
2354 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002355 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002356 } else if (transit == TRANSIT_ENTER
2357 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002358 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002359 }
2360 } else if (win == mNavigationBar) {
2361 // This can be on either the bottom or the right.
2362 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002363 if (transit == TRANSIT_EXIT
2364 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002365 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002366 } else if (transit == TRANSIT_ENTER
2367 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002368 return R.anim.dock_bottom_enter;
2369 }
2370 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002371 if (transit == TRANSIT_EXIT
2372 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002373 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002374 } else if (transit == TRANSIT_ENTER
2375 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002376 return R.anim.dock_right_enter;
2377 }
2378 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002379 }
2380
2381 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002382 if (win.hasAppShownWindows()) {
2383 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2384 return com.android.internal.R.anim.app_starting_exit;
2385 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002386 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002387 && transit == TRANSIT_ENTER) {
2388 // Special case: we are animating in a dream, while the keyguard
2389 // is shown. We don't want an animation on the dream, because
2390 // we need it shown immediately with the keyguard animating away
2391 // to reveal it.
2392 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002393 }
2394
2395 return 0;
2396 }
2397
Craig Mautner3c174372013-02-21 17:54:37 -08002398 @Override
2399 public void selectRotationAnimationLw(int anim[]) {
2400 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2401 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2402 + (mTopFullscreenOpaqueWindowState == null ?
2403 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2404 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2405 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2406 case ROTATION_ANIMATION_CROSSFADE:
2407 anim[0] = R.anim.rotation_animation_xfade_exit;
2408 anim[1] = R.anim.rotation_animation_enter;
2409 break;
2410 case ROTATION_ANIMATION_JUMPCUT:
2411 anim[0] = R.anim.rotation_animation_jump_exit;
2412 anim[1] = R.anim.rotation_animation_enter;
2413 break;
2414 case ROTATION_ANIMATION_ROTATE:
2415 default:
2416 anim[0] = anim[1] = 0;
2417 break;
2418 }
2419 } else {
2420 anim[0] = anim[1] = 0;
2421 }
2422 }
2423
2424 @Override
2425 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2426 boolean forceDefault) {
2427 switch (exitAnimId) {
2428 case R.anim.rotation_animation_xfade_exit:
2429 case R.anim.rotation_animation_jump_exit:
2430 // These are the only cases that matter.
2431 if (forceDefault) {
2432 return false;
2433 }
2434 int anim[] = new int[2];
2435 selectRotationAnimationLw(anim);
2436 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2437 default:
2438 return true;
2439 }
2440 }
2441
2442 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002443 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2444 boolean goingToNotificationShade) {
2445 if (goingToNotificationShade) {
2446 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002447 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002448
2449 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2450 R.anim.lock_screen_behind_enter_wallpaper :
2451 R.anim.lock_screen_behind_enter);
2452
2453 // TODO: Use XML interpolators when we have log interpolators available in XML.
2454 final List<Animation> animations = set.getAnimations();
2455 for (int i = animations.size() - 1; i >= 0; --i) {
2456 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2457 }
2458
2459 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002460 }
2461
2462
2463 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002464 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2465 if (goingToNotificationShade) {
2466 return null;
2467 } else {
2468 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2469 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002470 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002471
2472 private static void awakenDreams() {
2473 IDreamManager dreamManager = getDreamManager();
2474 if (dreamManager != null) {
2475 try {
2476 dreamManager.awaken();
2477 } catch (RemoteException e) {
2478 // fine, stay asleep then
2479 }
2480 }
2481 }
2482
2483 static IDreamManager getDreamManager() {
2484 return IDreamManager.Stub.asInterface(
2485 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2486 }
2487
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002488 TelecomManager getTelecommService() {
2489 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002490 }
2491
Jeff Brown4d396052010-10-29 21:50:21 -07002492 static IAudioService getAudioService() {
2493 IAudioService audioService = IAudioService.Stub.asInterface(
2494 ServiceManager.checkService(Context.AUDIO_SERVICE));
2495 if (audioService == null) {
2496 Log.w(TAG, "Unable to find IAudioService interface.");
2497 }
2498 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002499 }
2500
2501 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002502 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002503 }
2504
2505 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2506 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2507 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2508 };
2509
2510 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002511 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002512 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002513 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002514 final int keyCode = event.getKeyCode();
2515 final int repeatCount = event.getRepeatCount();
2516 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002517 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002518 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2519 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002520
Jeff Brown40013652012-05-16 21:22:36 -07002521 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002522 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002523 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2524 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002525 }
2526
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002527 // If we think we might have a volume down & power key chord on the way
2528 // but we're not sure, then tell the dispatcher to wait a little while and
2529 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002530 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002531 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002532 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002533 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2534 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002535 if (now < timeoutTime) {
2536 return timeoutTime - now;
2537 }
2538 }
2539 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002540 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002541 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002542 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002543 }
2544 return -1;
2545 }
2546 }
2547
Michael Wright6a62e552014-06-03 19:19:48 -07002548 // Cancel any pending meta actions if we see any other keys being pressed between the down
2549 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002550 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002551 mPendingMetaAction = false;
2552 }
2553
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002554 // First we always handle the home key here, so applications
2555 // can never break it, although if keyguard is on, we do let
2556 // it handle it, because that gives us the correct 5 second
2557 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002558 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002559
Jeff Brown49ed71d2010-12-06 17:13:33 -08002560 // If we have released the home key, and didn't do anything else
2561 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002562 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002563 cancelPreloadRecentApps();
2564
Jeff Brown49ed71d2010-12-06 17:13:33 -08002565 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002566 if (mHomeConsumed) {
2567 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002568 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002569 }
Jeff Browncaca8812013-05-09 13:34:33 -07002570
2571 if (canceled) {
2572 Log.i(TAG, "Ignoring HOME; event canceled.");
2573 return -1;
2574 }
2575
Yorke Lee4f803242014-12-15 23:22:06 +00002576 // If an incoming call is ringing, HOME is totally disabled.
2577 // (The user is already on the InCallUI at this point,
2578 // and his ONLY options are to answer or reject the call.)
2579 TelecomManager telecomManager = getTelecommService();
2580 if (telecomManager != null && telecomManager.isRinging()) {
2581 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2582 return -1;
2583 }
2584
Jeff Browncaca8812013-05-09 13:34:33 -07002585 // Delay handling home if a double-tap is possible.
2586 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2587 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2588 mHomeDoubleTapPending = true;
2589 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2590 ViewConfiguration.getDoubleTapTimeout());
2591 return -1;
2592 }
2593
Jeff Brown13f00f02014-10-31 14:45:50 -07002594 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002595 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002596 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002597
2598 // If a system window has focus, then it doesn't make sense
2599 // right now to interact with applications.
2600 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2601 if (attrs != null) {
2602 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002603 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2604 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2605 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002606 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002607 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002608 }
2609 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2610 for (int i=0; i<typeCount; i++) {
2611 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2612 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002613 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002614 }
2615 }
2616 }
Jeff Browncaca8812013-05-09 13:34:33 -07002617
2618 // Remember that home is pressed and handle special actions.
2619 if (repeatCount == 0) {
2620 mHomePressed = true;
2621 if (mHomeDoubleTapPending) {
2622 mHomeDoubleTapPending = false;
2623 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2624 handleDoubleTapOnHome();
2625 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2626 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2627 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002628 }
Jeff Browncaca8812013-05-09 13:34:33 -07002629 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2630 if (!keyguardOn) {
2631 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002632 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002633 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002634 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002635 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002636 // Hijack modified menu keys for debugging features
2637 final int chordBug = KeyEvent.META_SHIFT_ON;
2638
2639 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002640 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002641 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002642 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2643 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002644 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002645 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002646 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002647 Intent service = new Intent();
2648 service.setClassName(mContext, "com.android.server.LoadAverageService");
2649 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002650 boolean shown = Settings.Global.getInt(
2651 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002652 if (!shown) {
2653 mContext.startService(service);
2654 } else {
2655 mContext.stopService(service);
2656 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002657 Settings.Global.putInt(
2658 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002659 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002660 }
2661 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002662 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002663 if (down) {
2664 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002665 mSearchKeyShortcutPending = true;
2666 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002667 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002668 } else {
2669 mSearchKeyShortcutPending = false;
2670 if (mConsumeSearchKeyUp) {
2671 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002672 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002673 }
2674 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002675 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002676 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002677 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002678 if (down && repeatCount == 0) {
2679 preloadRecentApps();
2680 } else if (!down) {
2681 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002682 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002683 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002684 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002685 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2686 if (down) {
2687 IStatusBarService service = getStatusBarService();
2688 if (service != null) {
2689 try {
2690 service.expandNotificationsPanel();
2691 } catch (RemoteException e) {
2692 // do nothing.
2693 }
2694 }
2695 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002696 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2697 if (down) {
2698 if (repeatCount == 0) {
2699 mAssistKeyLongPressed = false;
2700 } else if (repeatCount == 1) {
2701 mAssistKeyLongPressed = true;
2702 if (!keyguardOn) {
2703 launchAssistLongPressAction();
2704 }
2705 }
2706 } else {
2707 if (mAssistKeyLongPressed) {
2708 mAssistKeyLongPressed = false;
2709 } else {
2710 if (!keyguardOn) {
2711 launchAssistAction();
2712 }
2713 }
2714 }
2715 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002716 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2717 if (!down) {
2718 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002719 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002720 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2721 } else {
2722 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002723 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002724 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002725 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002726 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002727 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2728 if (down && repeatCount == 0) {
2729 mHandler.post(mScreenshotRunnable);
2730 }
2731 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002732 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2733 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2734 if (down) {
2735 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2736
2737 // Disable autobrightness if it's on
2738 int auto = Settings.System.getIntForUser(
2739 mContext.getContentResolver(),
2740 Settings.System.SCREEN_BRIGHTNESS_MODE,
2741 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2742 UserHandle.USER_CURRENT_OR_SELF);
2743 if (auto != 0) {
2744 Settings.System.putIntForUser(mContext.getContentResolver(),
2745 Settings.System.SCREEN_BRIGHTNESS_MODE,
2746 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2747 UserHandle.USER_CURRENT_OR_SELF);
2748 }
2749
2750 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2751 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2752 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2753 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2754 Settings.System.SCREEN_BRIGHTNESS,
2755 mPowerManager.getDefaultScreenBrightnessSetting(),
2756 UserHandle.USER_CURRENT_OR_SELF);
2757 brightness += step;
2758 // Make sure we don't go beyond the limits.
2759 brightness = Math.min(max, brightness);
2760 brightness = Math.max(min, brightness);
2761
2762 Settings.System.putIntForUser(mContext.getContentResolver(),
2763 Settings.System.SCREEN_BRIGHTNESS, brightness,
2764 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002765 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002766 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002767 }
2768 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002769 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002770 if (down) {
2771 mPendingMetaAction = true;
2772 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002773 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002774 }
2775 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002776 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002777
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002778 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002779 // Any printing key that is chorded with Search should be consumed
2780 // even if no shortcut was invoked. This prevents text from being
2781 // inadvertently inserted when using a keyboard that has built-in macro
2782 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002783 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002784 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2785 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002786 mConsumeSearchKeyUp = true;
2787 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002788 if (down && repeatCount == 0 && !keyguardOn) {
2789 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2790 if (shortcutIntent != null) {
2791 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002792 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002793 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002794 } catch (ActivityNotFoundException ex) {
2795 Slog.w(TAG, "Dropping shortcut key combination because "
2796 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002797 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002798 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002799 } else {
2800 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002801 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002802 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002803 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002804 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002805 }
2806 }
2807
Jeff Brown68b909d2011-12-07 16:36:01 -08002808 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002809 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002810 && (metaState & KeyEvent.META_META_ON) != 0) {
2811 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002812 if (kcm.isPrintingKey(keyCode)) {
2813 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2814 metaState & ~(KeyEvent.META_META_ON
2815 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2816 if (shortcutIntent != null) {
2817 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2818 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002819 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002820 } catch (ActivityNotFoundException ex) {
2821 Slog.w(TAG, "Dropping shortcut key combination because "
2822 + "the activity to which it is registered was not found: "
2823 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2824 }
2825 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002826 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002827 }
2828 }
2829
Jeff Brown6651a632011-11-28 12:59:11 -08002830 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002831 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002832 String category = sApplicationLaunchKeyCategories.get(keyCode);
2833 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002834 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002835 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2836 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002837 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002838 } catch (ActivityNotFoundException ex) {
2839 Slog.w(TAG, "Dropping application launch key because "
2840 + "the activity to which it is registered was not found: "
2841 + "keyCode=" + keyCode + ", category=" + category, ex);
2842 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002843 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002844 }
2845 }
2846
Michael Wright61c46752014-08-21 16:57:33 -07002847 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002848 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002849 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002850 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002851 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002852 mRecentAppsHeldModifiers = shiftlessModifiers;
2853 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002854 return -1;
2855 }
2856 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002857 } else if (!down && mRecentAppsHeldModifiers != 0
2858 && (metaState & mRecentAppsHeldModifiers) == 0) {
2859 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002860 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002861 }
2862
Jeff Browncf39bdf2012-05-18 14:41:19 -07002863 // Handle keyboard language switching.
2864 if (down && repeatCount == 0
2865 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2866 || (keyCode == KeyEvent.KEYCODE_SPACE
2867 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2868 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2869 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2870 return -1;
2871 }
2872 if (mLanguageSwitchKeyPressed && !down
2873 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2874 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2875 mLanguageSwitchKeyPressed = false;
2876 return -1;
2877 }
2878
Jeff Brown13f00f02014-10-31 14:45:50 -07002879 if (isValidGlobalKey(keyCode)
2880 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002881 return -1;
2882 }
2883
Michael Wright6a62e552014-06-03 19:19:48 -07002884 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002885 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002886 return -1;
2887 }
2888
Jeff Brown68b909d2011-12-07 16:36:01 -08002889 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002890 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002891 }
2892
Jeff Brown3915bb82010-11-05 15:02:16 -07002893 /** {@inheritDoc} */
2894 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002895 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002896 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002897 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002898 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2899 + ", flags=" + event.getFlags()
2900 + ", keyCode=" + event.getKeyCode()
2901 + ", scanCode=" + event.getScanCode()
2902 + ", metaState=" + event.getMetaState()
2903 + ", repeatCount=" + event.getRepeatCount()
2904 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002905 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002906
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002907 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002908 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2909 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002910 final int keyCode = event.getKeyCode();
2911 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002912 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2913 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002914
Jeff Brown54875002011-04-06 15:33:01 -07002915 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002916 final FallbackAction fallbackAction;
2917 if (initialDown) {
2918 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2919 } else {
2920 fallbackAction = mFallbackActions.get(keyCode);
2921 }
2922
2923 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002924 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002925 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2926 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002927 }
2928
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002929 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2930 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002931 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002932 event.getAction(), fallbackAction.keyCode,
2933 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002934 event.getDeviceId(), event.getScanCode(),
2935 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002936
2937 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2938 fallbackEvent.recycle();
2939 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002940 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002941
2942 if (initialDown) {
2943 mFallbackActions.put(keyCode, fallbackAction);
2944 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2945 mFallbackActions.remove(keyCode);
2946 fallbackAction.recycle();
2947 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002948 }
2949 }
2950
Jeff Brown40013652012-05-16 21:22:36 -07002951 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002952 if (fallbackEvent == null) {
2953 Slog.d(TAG, "No fallback.");
2954 } else {
2955 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2956 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002957 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002958 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002959 }
2960
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002961 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002962 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002963 if ((actions & ACTION_PASS_TO_USER) != 0) {
2964 long delayMillis = interceptKeyBeforeDispatching(
2965 win, fallbackEvent, policyFlags);
2966 if (delayMillis == 0) {
2967 return true;
2968 }
2969 }
2970 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002971 }
2972
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002973 private void launchAssistLongPressAction() {
2974 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2975 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2976
2977 // launch the search activity
2978 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2979 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2980 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002981 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002982 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002983 SearchManager searchManager = getSearchManager();
2984 if (searchManager != null) {
2985 searchManager.stopSearch();
2986 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002987 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002988 } catch (ActivityNotFoundException e) {
2989 Slog.w(TAG, "No activity to handle assist long press action.", e);
2990 }
2991 }
2992
2993 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002994 launchAssistAction(null);
2995 }
2996
2997 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002998 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002999 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08003000 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07003001 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07003002 if (hint != null) {
3003 intent.putExtra(hint, true);
3004 }
Jim Miller45308b12012-06-18 19:23:39 -07003005 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
3006 | Intent.FLAG_ACTIVITY_SINGLE_TOP
3007 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
3008 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003009 startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07003010 } catch (ActivityNotFoundException e) {
3011 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003012 }
3013 }
3014 }
3015
Bart Sears8b1c27c2015-03-18 23:51:02 +00003016 private void startActivityAsUser(Intent intent, UserHandle handle) {
3017 if (isUserSetupComplete()) {
3018 mContext.startActivityAsUser(intent, handle);
3019 } else {
3020 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3021 }
3022 }
3023
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003024 private SearchManager getSearchManager() {
3025 if (mSearchManager == null) {
3026 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3027 }
3028 return mSearchManager;
3029 }
3030
Jeff Browncaca8812013-05-09 13:34:33 -07003031 private void preloadRecentApps() {
3032 mPreloadedRecentApps = true;
3033 try {
3034 IStatusBarService statusbar = getStatusBarService();
3035 if (statusbar != null) {
3036 statusbar.preloadRecentApps();
3037 }
3038 } catch (RemoteException e) {
3039 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3040 // re-acquire status bar service next time it is needed.
3041 mStatusBarService = null;
3042 }
3043 }
3044
3045 private void cancelPreloadRecentApps() {
3046 if (mPreloadedRecentApps) {
3047 mPreloadedRecentApps = false;
3048 try {
3049 IStatusBarService statusbar = getStatusBarService();
3050 if (statusbar != null) {
3051 statusbar.cancelPreloadRecentApps();
3052 }
3053 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003054 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003055 // re-acquire status bar service next time it is needed.
3056 mStatusBarService = null;
3057 }
3058 }
3059 }
3060
3061 private void toggleRecentApps() {
3062 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003063 try {
3064 IStatusBarService statusbar = getStatusBarService();
3065 if (statusbar != null) {
3066 statusbar.toggleRecentApps();
3067 }
3068 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003069 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3070 // re-acquire status bar service next time it is needed.
3071 mStatusBarService = null;
3072 }
3073 }
3074
Craig Mautner84984fa2014-06-19 11:19:20 -07003075 @Override
3076 public void showRecentApps() {
3077 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3078 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3079 }
3080
Winson Chung1e8d71b2014-05-16 17:05:22 -07003081 private void showRecentApps(boolean triggeredFromAltTab) {
3082 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3083 try {
3084 IStatusBarService statusbar = getStatusBarService();
3085 if (statusbar != null) {
3086 statusbar.showRecentApps(triggeredFromAltTab);
3087 }
3088 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003089 Slog.e(TAG, "RemoteException when showing recent apps", e);
3090 // re-acquire status bar service next time it is needed.
3091 mStatusBarService = null;
3092 }
3093 }
3094
Winson Chungcdcd4872014-08-05 18:00:13 -07003095 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003096 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3097 try {
3098 IStatusBarService statusbar = getStatusBarService();
3099 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003100 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003101 }
3102 } catch (RemoteException e) {
3103 Slog.e(TAG, "RemoteException when closing recent apps", e);
3104 // re-acquire status bar service next time it is needed.
3105 mStatusBarService = null;
3106 }
3107 }
3108
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003109 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003110 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003111 }
3112
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003113 /**
3114 * A home key -> launch home action was detected. Take the appropriate action
3115 * given the situation with the keyguard.
3116 */
Bryce Lee662ed802015-04-10 20:11:39 +00003117 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3118 if (respectKeyguard) {
3119 if (isKeyguardShowingAndNotOccluded()) {
3120 // don't launch home if keyguard showing
3121 return;
3122 }
3123
3124 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3125 // when in keyguard restricted mode, must first verify unlock
3126 // before launching home
3127 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3128 @Override
3129 public void onKeyguardExitResult(boolean success) {
3130 if (success) {
3131 try {
3132 ActivityManagerNative.getDefault().stopAppSwitches();
3133 } catch (RemoteException e) {
3134 }
3135 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3136 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003137 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003138 }
Bryce Lee662ed802015-04-10 20:11:39 +00003139 });
3140 return;
3141 }
3142 }
3143
3144 // no keyguard stuff to worry about, just launch home!
3145 try {
3146 ActivityManagerNative.getDefault().stopAppSwitches();
3147 } catch (RemoteException e) {
3148 }
3149 if (mRecentsVisible) {
3150 // Hide Recents and notify it to launch Home
3151 if (awakenFromDreams) {
3152 awakenDreams();
3153 }
3154 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3155 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003156 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003157 // Otherwise, just launch Home
3158 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3159 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003160 }
3161 }
3162
John Spurlock04db1762013-05-13 12:46:41 -04003163 private final Runnable mClearHideNavigationFlag = new Runnable() {
3164 @Override
3165 public void run() {
3166 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3167 // Clear flags.
3168 mForceClearedSystemUiFlags &=
3169 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3170 }
3171 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003172 }
3173 };
3174
3175 /**
3176 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3177 * to determine when the nav bar should be shown and prevent applications from
3178 * receiving those touches.
3179 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003180 final class HideNavInputEventReceiver extends InputEventReceiver {
3181 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3182 super(inputChannel, looper);
3183 }
3184
Dianne Hackborndf89e652011-10-06 22:35:11 -07003185 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003186 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003187 boolean handled = false;
3188 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003189 if (event instanceof MotionEvent
3190 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3191 final MotionEvent motionEvent = (MotionEvent)event;
3192 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003193 // When the user taps down, we re-show the nav bar.
3194 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003195 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003196 // Any user activity always causes us to show the
3197 // navigation controls, if they had been hidden.
3198 // We also clear the low profile and only content
3199 // flags so that tapping on the screen will atomically
3200 // restore all currently hidden screen decorations.
3201 int newVal = mResettingSystemUiFlags |
3202 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3203 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3204 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003205 if (mResettingSystemUiFlags != newVal) {
3206 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003207 changed = true;
3208 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003209 // We don't allow the system's nav bar to be hidden
3210 // again for 1 second, to prevent applications from
3211 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003212 newVal = mForceClearedSystemUiFlags |
3213 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003214 if (mForceClearedSystemUiFlags != newVal) {
3215 mForceClearedSystemUiFlags = newVal;
3216 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003217 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003218 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003219 }
3220 if (changed) {
3221 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3222 }
3223 }
3224 }
3225 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003226 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003227 }
3228 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003229 }
3230 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3231 new InputEventReceiver.Factory() {
3232 @Override
3233 public InputEventReceiver createInputEventReceiver(
3234 InputChannel inputChannel, Looper looper) {
3235 return new HideNavInputEventReceiver(inputChannel, looper);
3236 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003237 };
3238
3239 @Override
3240 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003241 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3242 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003243 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003244
Dianne Hackborndf89e652011-10-06 22:35:11 -07003245 // Reset any bits in mForceClearingStatusBarVisibility that
3246 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003247 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003248 // Clear any bits in the new visibility that are currently being
3249 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003250 return visibility & ~mResettingSystemUiFlags
3251 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003252 }
3253
Craig Mautner69b08182012-09-05 13:07:13 -07003254 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003255 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3256 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003257 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003258 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3259 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003260
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003261 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003262 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003263 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003264 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003265 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003266 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3267 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3268 } else {
3269 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3270 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3271 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003272 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3273 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003274 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003275 availRight - mStableFullscreenRight,
3276 availBottom - mStableFullscreenBottom);
3277 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003278 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003279 availRight - mStableRight, availBottom - mStableBottom);
3280 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003281 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003282 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003283 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003284 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003285 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003286 availRight - mCurRight, availBottom - mCurBottom);
3287 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003288 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003289 availRight - mCurRight, availBottom - mCurBottom);
3290 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003291
3292 outStableInsets.set(mStableLeft, mStableTop,
3293 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003294 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003295 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003296 outContentInsets.setEmpty();
3297 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003298 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003299
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003300 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003301 @Override
3302 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3303 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003304 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3305 if (isDefaultDisplay) {
3306 switch (displayRotation) {
3307 case Surface.ROTATION_90:
3308 overscanLeft = mOverscanTop;
3309 overscanTop = mOverscanRight;
3310 overscanRight = mOverscanBottom;
3311 overscanBottom = mOverscanLeft;
3312 break;
3313 case Surface.ROTATION_180:
3314 overscanLeft = mOverscanRight;
3315 overscanTop = mOverscanBottom;
3316 overscanRight = mOverscanLeft;
3317 overscanBottom = mOverscanTop;
3318 break;
3319 case Surface.ROTATION_270:
3320 overscanLeft = mOverscanBottom;
3321 overscanTop = mOverscanLeft;
3322 overscanRight = mOverscanTop;
3323 overscanBottom = mOverscanRight;
3324 break;
3325 default:
3326 overscanLeft = mOverscanLeft;
3327 overscanTop = mOverscanTop;
3328 overscanRight = mOverscanRight;
3329 overscanBottom = mOverscanBottom;
3330 break;
3331 }
3332 } else {
3333 overscanLeft = 0;
3334 overscanTop = 0;
3335 overscanRight = 0;
3336 overscanBottom = 0;
3337 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003338 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3339 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3340 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3341 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003342 mSystemLeft = 0;
3343 mSystemTop = 0;
3344 mSystemRight = displayWidth;
3345 mSystemBottom = displayHeight;
3346 mUnrestrictedScreenLeft = overscanLeft;
3347 mUnrestrictedScreenTop = overscanTop;
3348 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3349 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3350 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3351 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003352 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3353 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003354 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003355 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003356 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003357 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003358 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003359 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003360 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003361 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003362 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003363 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003364
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003365 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3366 final Rect pf = mTmpParentFrame;
3367 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003368 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003369 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003370 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003371 pf.left = df.left = of.left = vf.left = mDockLeft;
3372 pf.top = df.top = of.top = vf.top = mDockTop;
3373 pf.right = df.right = of.right = vf.right = mDockRight;
3374 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003375 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003376
Craig Mautner69b08182012-09-05 13:07:13 -07003377 if (isDefaultDisplay) {
3378 // For purposes of putting out fake window up to steal focus, we will
3379 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003380 final int sysui = mLastSystemUiFlags;
3381 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003382 boolean navTranslucent = (sysui
3383 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003384 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3385 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3386 boolean navAllowedHidden = immersive || immersiveSticky;
3387 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003388 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3389 if (!isKeyguardShowing) {
3390 navTranslucent &= areTranslucentBarsAllowed();
3391 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003392
Craig Mautner69b08182012-09-05 13:07:13 -07003393 // When the navigation bar isn't visible, we put up a fake
3394 // input window to catch all touch events. This way we can
3395 // detect when the user presses anywhere to bring back the nav
3396 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003397 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003398 if (mInputConsumer != null) {
3399 mInputConsumer.dismiss();
3400 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003401 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003402 } else if (mInputConsumer == null) {
3403 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3404 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003405 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003406
Craig Mautner69b08182012-09-05 13:07:13 -07003407 // For purposes of positioning and showing the nav bar, if we have
3408 // decided that it can't be hidden (because of the screen aspect ratio),
3409 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003410 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003411
John Spurlockad3e6cb2013-04-30 08:47:43 -04003412 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003413 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003414 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003415 // Force the navigation bar to its appropriate place and
3416 // size. We need to do this directly, instead of relying on
3417 // it to bubble up from the nav bar, because this needs to
3418 // change atomically with screen rotations.
3419 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3420 if (mNavigationBarOnBottom) {
3421 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003422 int top = displayHeight - overscanBottom
3423 - mNavigationBarHeightForRotation[displayRotation];
3424 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003425 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003426 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003427 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003428 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003429 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003430 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003431 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3432 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003433 } else {
3434 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003435 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003436 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003437 if (navVisible && !navTranslucent && !navAllowedHidden
3438 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003439 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003440 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003441 // and not in the process of animating on or off, then
3442 // we can tell the app that it is covered by it.
3443 mSystemBottom = mTmpNavigationFrame.top;
3444 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003445 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003446 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003447 int left = displayWidth - overscanRight
3448 - mNavigationBarWidthForRotation[displayRotation];
3449 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003450 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003451 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003452 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003453 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003454 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003455 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003456 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3457 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003458 } else {
3459 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003460 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003461 }
John Spurlockbd957402013-10-03 11:38:39 -04003462 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3463 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003464 // If the nav bar is currently requested to be visible,
3465 // and not in the process of animating on or off, then
3466 // we can tell the app that it is covered by it.
3467 mSystemRight = mTmpNavigationFrame.left;
3468 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003469 }
Craig Mautner69b08182012-09-05 13:07:13 -07003470 // Make sure the content and current rectangles are updated to
3471 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003472 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3473 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3474 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3475 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003476 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3477 // And compute the final frame.
3478 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003479 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
Dianne Hackborn4bb6b752015-05-22 16:34:44 -07003480 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003481 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003482 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003483 updateSysUiVisibility = true;
3484 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003485 }
Craig Mautnereda67292013-04-28 13:50:14 -07003486 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003487 mDockLeft, mDockTop, mDockRight, mDockBottom));
3488
3489 // decide where the status bar goes ahead of time
3490 if (mStatusBar != null) {
3491 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003492 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3493 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3494 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3495 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3496 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003497 vf.left = mStableLeft;
3498 vf.top = mStableTop;
3499 vf.right = mStableRight;
3500 vf.bottom = mStableBottom;
3501
3502 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3503
3504 // Let the status bar determine its size.
Dianne Hackborn4bb6b752015-05-22 16:34:44 -07003505 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003506
3507 // For layout, the status bar is always at the top with our fixed height.
3508 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3509
John Spurlocke1f366f2013-08-05 12:22:40 -04003510 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003511 boolean statusBarTranslucent = (sysui
3512 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003513 if (!isKeyguardShowing) {
3514 statusBarTranslucent &= areTranslucentBarsAllowed();
3515 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003516
Craig Mautner69b08182012-09-05 13:07:13 -07003517 // If the status bar is hidden, we don't want to cause
3518 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003519 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003520 // Status bar may go away, so the screen area it occupies
3521 // is available to apps but just covering them when the
3522 // status bar is visible.
3523 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3524
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003525 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3526 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3527 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3528 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003529
Craig Mautnereda67292013-04-28 13:50:14 -07003530 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003531 String.format(
3532 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3533 mDockLeft, mDockTop, mDockRight, mDockBottom,
3534 mContentLeft, mContentTop, mContentRight, mContentBottom,
3535 mCurLeft, mCurTop, mCurRight, mCurBottom));
3536 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003537 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003538 && !statusBarTransient && !statusBarTranslucent
3539 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003540 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003541 // and not in the process of animating on or off, then
3542 // we can tell the app that it is covered by it.
3543 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3544 }
John Spurlock27735a42013-08-14 17:57:38 -04003545 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003546 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003547 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003548 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003549 if (updateSysUiVisibility) {
3550 updateSystemUiVisibilityLw();
3551 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003552 }
3553 }
3554
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003555 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003556 @Override
John Spurlock46646232013-09-30 22:32:42 -04003557 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003558 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3559 return mStatusBar.getSurfaceLayer();
3560 }
3561
3562 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3563 return mNavigationBar.getSurfaceLayer();
3564 }
3565
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003566 return 0;
3567 }
3568
Craig Mautner967212c2013-04-13 21:10:58 -07003569 @Override
3570 public void getContentRectLw(Rect r) {
3571 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3572 }
3573
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003574 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3575 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003576 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3577 // Here's a special case: if this attached window is a panel that is
3578 // above the dock window, and the window it is attached to is below
3579 // the dock window, then the frames we computed for the window it is
3580 // attached to can not be used because the dock is effectively part
3581 // of the underlying window and the attached window is floating on top
3582 // of the whole thing. So, we ignore the attached window and explicitly
3583 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003584 df.left = of.left = cf.left = vf.left = mDockLeft;
3585 df.top = of.top = cf.top = vf.top = mDockTop;
3586 df.right = of.right = cf.right = vf.right = mDockRight;
3587 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003588 } else {
3589 // The effective display frame of the attached window depends on
3590 // whether it is taking care of insetting its content. If not,
3591 // we need to use the parent's content frame so that the entire
3592 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003593 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003594 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003595 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003596 // Set the content frame of the attached window to the parent's decor frame
3597 // (same as content frame when IME isn't present) if specifically requested by
3598 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3599 // Otherwise, use the overscan frame.
3600 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3601 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003602 } else {
3603 // If the window is resizing, then we want to base the content
3604 // frame on our attached content frame to resize... however,
3605 // things can be tricky if the attached window is NOT in resize
3606 // mode, in which case its content frame will be larger.
3607 // Ungh. So to deal with that, make sure the content frame
3608 // we end up using is not covering the IM dock.
3609 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003610 if (attached.isVoiceInteraction()) {
3611 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3612 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3613 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3614 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3615 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003616 if (cf.left < mContentLeft) cf.left = mContentLeft;
3617 if (cf.top < mContentTop) cf.top = mContentTop;
3618 if (cf.right > mContentRight) cf.right = mContentRight;
3619 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3620 }
3621 }
3622 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003623 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003624 vf.set(attached.getVisibleFrameLw());
3625 }
3626 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3627 // window should be positioned relative to its parent or the entire
3628 // screen.
3629 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3630 ? attached.getFrameLw() : df);
3631 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003632
3633 private void applyStableConstraints(int sysui, int fl, Rect r) {
3634 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3635 // If app is requesting a stable layout, don't let the
3636 // content insets go below the stable values.
3637 if ((fl & FLAG_FULLSCREEN) != 0) {
3638 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3639 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3640 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3641 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3642 } else {
3643 if (r.left < mStableLeft) r.left = mStableLeft;
3644 if (r.top < mStableTop) r.top = mStableTop;
3645 if (r.right > mStableRight) r.right = mStableRight;
3646 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3647 }
3648 }
3649 }
3650
Jorim Jaggiaa806142015-05-20 18:04:16 -07003651 private boolean canReceiveInput(WindowState win) {
3652 boolean notFocusable =
3653 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
3654 boolean altFocusableIm =
3655 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
3656 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
3657 return !notFocusableForIm;
3658 }
3659
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003660 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003661 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003662 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07003663 // We've already done the navigation bar and status bar. If the status bar can receive
3664 // input, we need to layout it again to accomodate for the IME window.
3665 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003666 return;
3667 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07003668 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07003669 final boolean isDefaultDisplay = win.isDefaultDisplay();
3670 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003671 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3672 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003673 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003674 offsetInputMethodWindowLw(mLastInputMethodWindow);
3675 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003676
John Spurlockc6d1c602014-01-17 15:22:06 -05003677 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003678 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003679 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003680
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003681 final Rect pf = mTmpParentFrame;
3682 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003683 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003684 final Rect cf = mTmpContentFrame;
3685 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003686 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003687 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003688 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003689
3690 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003691 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003692
Craig Mautnerf683b562012-10-02 11:10:57 -07003693 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3694
Adrian Roosfa104232014-06-20 16:10:14 -07003695 if (isDefaultDisplay) {
3696 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3697 } else {
3698 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3699 }
3700
Craig Mautner69b08182012-09-05 13:07:13 -07003701 if (!isDefaultDisplay) {
3702 if (attached != null) {
3703 // If this window is attached to another, our display
3704 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003705 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003706 } else {
3707 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003708 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3709 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3710 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003711 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003712 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003713 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003714 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003715 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003716 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3717 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3718 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003719 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003720 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003721 // ...with content insets above the nav bar
3722 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003723 // IM dock windows always go to the bottom of the screen.
3724 attrs.gravity = Gravity.BOTTOM;
3725 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003726 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
3727 pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft;
3728 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3729 pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft
3730 + mUnrestrictedScreenWidth;
3731 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3732 + mUnrestrictedScreenHeight;
3733 cf.bottom = vf.bottom = mStableBottom;
3734 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07003735 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02003736 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3737 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3738 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3739 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3740 cf.left = vf.left = mStableLeft;
3741 cf.top = vf.top = mStableTop;
3742 cf.right = vf.right = mStableRight;
3743 vf.bottom = mStableBottom;
3744 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003745 } else {
John Spurlock46646232013-09-30 22:32:42 -04003746
3747 // Default policy decor for the default display
3748 dcf.left = mSystemLeft;
3749 dcf.top = mSystemTop;
3750 dcf.right = mSystemRight;
3751 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003752 final boolean inheritTranslucentDecor = (attrs.privateFlags
3753 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003754 final boolean isAppWindow =
3755 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3756 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3757 final boolean topAtRest =
3758 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3759 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003760 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3761 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003762 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3763 && (fl & WindowManager.LayoutParams.
3764 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003765 // Ensure policy decor includes status bar
3766 dcf.top = mStableTop;
3767 }
John Spurlockbd957402013-10-03 11:38:39 -04003768 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003769 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3770 && (fl & WindowManager.LayoutParams.
3771 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003772 // Ensure policy decor includes navigation bar
3773 dcf.bottom = mStableBottom;
3774 dcf.right = mStableRight;
3775 }
3776 }
3777
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003778 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3779 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003780 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003781 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003782 // This is the case for a normal activity window: we want it
3783 // to cover all of the screen space, and it can take care of
3784 // moving its contents to account for screen decorations that
3785 // intrude into that space.
3786 if (attached != null) {
3787 // If this window is attached to another, our display
3788 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003789 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003790 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003791 if (attrs.type == TYPE_STATUS_BAR_PANEL
3792 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003793 // Status bar panels are the only windows who can go on top of
3794 // the status bar. They are protected by the STATUS_BAR_SERVICE
3795 // permission, so they have the same privileges as the status
3796 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003797 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003798 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003799
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003800 pf.left = df.left = of.left = hasNavBar
3801 ? mDockLeft : mUnrestrictedScreenLeft;
3802 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3803 pf.right = df.right = of.right = hasNavBar
3804 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3805 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3806 pf.bottom = df.bottom = of.bottom = hasNavBar
3807 ? mRestrictedScreenTop+mRestrictedScreenHeight
3808 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003809
Craig Mautnereda67292013-04-28 13:50:14 -07003810 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003811 "Laying out status bar window: (%d,%d - %d,%d)",
3812 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003813 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003814 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3815 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3816 // Asking to layout into the overscan region, so give it that pure
3817 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003818 pf.left = df.left = of.left = mOverscanScreenLeft;
3819 pf.top = df.top = of.top = mOverscanScreenTop;
3820 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3821 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3822 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003823 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003824 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003825 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3826 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003827 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003828 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003829 // only do this for application windows to ensure no window that
3830 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003831 pf.left = df.left = mOverscanScreenLeft;
3832 pf.top = df.top = mOverscanScreenTop;
3833 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3834 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003835 // We need to tell the app about where the frame inside the overscan
3836 // is, so it can inset its content by that amount -- it didn't ask
3837 // to actually extend itself into the overscan region.
3838 of.left = mUnrestrictedScreenLeft;
3839 of.top = mUnrestrictedScreenTop;
3840 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3841 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003842 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003843 pf.left = df.left = mRestrictedOverscanScreenLeft;
3844 pf.top = df.top = mRestrictedOverscanScreenTop;
3845 pf.right = df.right = mRestrictedOverscanScreenLeft
3846 + mRestrictedOverscanScreenWidth;
3847 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3848 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003849 // We need to tell the app about where the frame inside the overscan
3850 // is, so it can inset its content by that amount -- it didn't ask
3851 // to actually extend itself into the overscan region.
3852 of.left = mUnrestrictedScreenLeft;
3853 of.top = mUnrestrictedScreenTop;
3854 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3855 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003856 }
Craig Mautner69b08182012-09-05 13:07:13 -07003857
John Spurlock46646232013-09-30 22:32:42 -04003858 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003859 if (win.isVoiceInteraction()) {
3860 cf.left = mVoiceContentLeft;
3861 cf.top = mVoiceContentTop;
3862 cf.right = mVoiceContentRight;
3863 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003864 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003865 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3866 cf.left = mDockLeft;
3867 cf.top = mDockTop;
3868 cf.right = mDockRight;
3869 cf.bottom = mDockBottom;
3870 } else {
3871 cf.left = mContentLeft;
3872 cf.top = mContentTop;
3873 cf.right = mContentRight;
3874 cf.bottom = mContentBottom;
3875 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003876 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003877 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003878 // Full screen windows are always given a layout that is as if the
3879 // status bar and other transient decors are gone. This is to avoid
3880 // bad states when moving from a window that is not hding the
3881 // status bar to one that is.
3882 cf.left = mRestrictedScreenLeft;
3883 cf.top = mRestrictedScreenTop;
3884 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3885 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003886 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003887 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003888 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3889 vf.left = mCurLeft;
3890 vf.top = mCurTop;
3891 vf.right = mCurRight;
3892 vf.bottom = mCurBottom;
3893 } else {
3894 vf.set(cf);
3895 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003896 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003897 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3898 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3899 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003900 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3901 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003902 // A window that has requested to fill the entire screen just
3903 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003904 if (attrs.type == TYPE_STATUS_BAR_PANEL
3905 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003906 pf.left = df.left = of.left = cf.left = hasNavBar
3907 ? mDockLeft : mUnrestrictedScreenLeft;
3908 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3909 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003910 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003911 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003912 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003913 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003914 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003915 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003916 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3917 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003918 } else if (attrs.type == TYPE_NAVIGATION_BAR
3919 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003920 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003921 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3922 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3923 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3924 + mUnrestrictedScreenWidth;
3925 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3926 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003927 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003928 "Laying out navigation bar window: (%d,%d - %d,%d)",
3929 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003930 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3931 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003932 && ((fl & FLAG_FULLSCREEN) != 0)) {
3933 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003934 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3935 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3936 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3937 + mOverscanScreenWidth;
3938 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3939 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003940 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003941 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003942 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3943 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3944 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3945 + mOverscanScreenWidth;
3946 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3947 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003948 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003949 // The wallpaper also has Real Ultimate Power, but we want to tell
3950 // it about the overscan area.
3951 pf.left = df.left = mOverscanScreenLeft;
3952 pf.top = df.top = mOverscanScreenTop;
3953 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3954 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3955 of.left = cf.left = mUnrestrictedScreenLeft;
3956 of.top = cf.top = mUnrestrictedScreenTop;
3957 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3958 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003959 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003960 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3961 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3962 // Asking to layout into the overscan region, so give it that pure
3963 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003964 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3965 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3966 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003967 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003968 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003969 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003970 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003971 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003972 && (attrs.type == TYPE_STATUS_BAR
3973 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07003974 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04003975 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3976 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003977 // Asking for layout as if the nav bar is hidden, lets the
3978 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003979 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003980 // can be above the nav bar can do this.
3981 // XXX This assumes that an app asking for this will also
3982 // ask for layout in only content. We can't currently figure out
3983 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003984 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3985 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3986 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3987 + mUnrestrictedScreenWidth;
3988 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3989 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003990 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003991 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3992 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3993 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3994 + mRestrictedScreenWidth;
3995 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3996 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003997 }
Craig Mautner69b08182012-09-05 13:07:13 -07003998
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003999 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004000
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004001 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4002 vf.left = mCurLeft;
4003 vf.top = mCurTop;
4004 vf.right = mCurRight;
4005 vf.bottom = mCurBottom;
4006 } else {
4007 vf.set(cf);
4008 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004009 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004010 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4011 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004012 // A child window should be placed inside of the same visible
4013 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004014 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004015 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004016 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4017 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004018 // Otherwise, a normal window must be placed inside the content
4019 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07004020 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
4021 // Status bar panels are the only windows who can go on top of
4022 // the status bar. They are protected by the STATUS_BAR_SERVICE
4023 // permission, so they have the same privileges as the status
4024 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004025 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4026 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4027 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4028 + mRestrictedScreenWidth;
4029 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4030 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05004031 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
4032 || attrs.type == TYPE_VOLUME_OVERLAY) {
4033 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004034 pf.left = df.left = of.left = cf.left = mStableLeft;
4035 pf.top = df.top = of.top = cf.top = mStableTop;
4036 pf.right = df.right = of.right = cf.right = mStableRight;
4037 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004038 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004039 pf.left = mContentLeft;
4040 pf.top = mContentTop;
4041 pf.right = mContentRight;
4042 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004043 if (win.isVoiceInteraction()) {
4044 df.left = of.left = cf.left = mVoiceContentLeft;
4045 df.top = of.top = cf.top = mVoiceContentTop;
4046 df.right = of.right = cf.right = mVoiceContentRight;
4047 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4048 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004049 df.left = of.left = cf.left = mDockLeft;
4050 df.top = of.top = cf.top = mDockTop;
4051 df.right = of.right = cf.right = mDockRight;
4052 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004053 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004054 df.left = of.left = cf.left = mContentLeft;
4055 df.top = of.top = cf.top = mContentTop;
4056 df.right = of.right = cf.right = mContentRight;
4057 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004058 }
4059 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4060 vf.left = mCurLeft;
4061 vf.top = mCurTop;
4062 vf.right = mCurRight;
4063 vf.bottom = mCurBottom;
4064 } else {
4065 vf.set(cf);
4066 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004067 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004068 }
4069 }
Craig Mautner69b08182012-09-05 13:07:13 -07004070
Craig Mautnerb816bed2013-07-23 10:26:17 -07004071 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4072 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004073 df.left = df.top = -10000;
4074 df.right = df.bottom = 10000;
4075 if (attrs.type != TYPE_WALLPAPER) {
4076 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4077 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4078 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004079 }
4080
Craig Mautnereda67292013-04-28 13:50:14 -07004081 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004082 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004083 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004084 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004085 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004086 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004087 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004088 + " dcf=" + dcf.toShortString()
Dianne Hackborn4bb6b752015-05-22 16:34:44 -07004089 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07004090
Dianne Hackborn4bb6b752015-05-22 16:34:44 -07004091 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07004092
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004093 // Dock windows carve out the bottom of the screen, so normal windows
4094 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004095 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4096 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004097 setLastInputMethodWindowLw(null, null);
4098 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004099 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004100 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4101 && !win.getGivenInsetsPendingLw()) {
4102 offsetVoiceInputWindowLw(win);
4103 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004104 }
4105
satok1bc0a492012-04-25 22:47:12 +09004106 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004107 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004108 top += win.getGivenContentInsetsLw().top;
4109 if (mContentBottom > top) {
4110 mContentBottom = top;
4111 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004112 if (mVoiceContentBottom > top) {
4113 mVoiceContentBottom = top;
4114 }
satok1bc0a492012-04-25 22:47:12 +09004115 top = win.getVisibleFrameLw().top;
4116 top += win.getGivenVisibleInsetsLw().top;
4117 if (mCurBottom > top) {
4118 mCurBottom = top;
4119 }
Craig Mautnereda67292013-04-28 13:50:14 -07004120 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004121 + mDockBottom + " mContentBottom="
4122 + mContentBottom + " mCurBottom=" + mCurBottom);
4123 }
4124
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004125 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004126 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004127 top += win.getGivenContentInsetsLw().top;
4128 if (mVoiceContentBottom > top) {
4129 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004130 }
4131 }
4132
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004133 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004134 @Override
4135 public void finishLayoutLw() {
4136 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004137 }
4138
4139 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004140 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004141 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004142 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004143 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004144 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004145 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004146 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004147 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004148 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004149 mForcingShowNavBar = false;
4150 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004151
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004152 mHideLockScreen = false;
4153 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004154 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004155 mShowingLockscreen = false;
4156 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004157 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004158 mKeyguardSecure = isKeyguardSecure();
4159 mKeyguardSecureIncludingHidden = mKeyguardSecure
4160 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004161 }
4162
4163 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004164 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004165 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004166 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4167 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004168 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004169 if (mTopFullscreenOpaqueWindowState == null
4170 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4171 mForcingShowNavBar = true;
4172 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004173 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004174 if (attrs.type == TYPE_STATUS_BAR) {
4175 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4176 mForceStatusBarFromKeyguard = true;
4177 }
4178 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4179 mForceStatusBarTransparent = true;
4180 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004181 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004182
4183 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4184 && attrs.type < FIRST_SYSTEM_WINDOW;
4185 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4186 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4187
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004188 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004189 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004190 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004191 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004192 mForceStatusBarFromKeyguard = true;
4193 } else {
4194 mForceStatusBar = true;
4195 }
4196 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004197 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004198 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004199 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004200 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004201 // If the lockscreen was showing when the dream started then wait
4202 // for the dream to draw before hiding the lockscreen.
4203 if (!mDreamingLockscreen
4204 || (win.isVisibleLw() && win.hasDrawnLw())) {
4205 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004206 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004207 }
4208 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004209
Craig Mautnerab55e522014-03-03 13:26:03 -08004210 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004211 final IApplicationToken appToken = win.getAppToken();
4212 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004213 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004214 mAppsToBeHidden.remove(appToken);
4215 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004216 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004217 if (dismissKeyguard && !mKeyguardSecure) {
4218 mAppsThatDismissKeyguard.add(appToken);
4219 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004220 mWinShowWhenLocked = win;
4221 mHideLockScreen = true;
4222 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004223 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004224 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004225 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004226 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004227 mAppsToBeHidden.add(appToken);
4228 } else {
4229 mAppsToBeHidden.remove(appToken);
4230 }
4231 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004232 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004233 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004234 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004235 if (attrs.x == 0 && attrs.y == 0
4236 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4237 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4238 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4239 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004240 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4241 mTopFullscreenOpaqueOrDimmingWindowState = win;
4242 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004243 if (!mAppsThatDismissKeyguard.isEmpty() &&
4244 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4245 if (DEBUG_LAYOUT) Slog.v(TAG,
4246 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004247 mDismissKeyguard = (mWinDismissingKeyguard == win
4248 && mSecureDismissingKeyguard == mKeyguardSecure)
4249 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004250 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004251 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004252 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004253 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4254 if (DEBUG_LAYOUT) Slog.v(TAG,
4255 "Setting mHideLockScreen to true by win " + win);
4256 mHideLockScreen = true;
4257 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004258 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004259 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004260 mAllowLockscreenWhenOn = true;
4261 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004262 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004263
4264 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004265 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4266 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004267 win.hideLw(false);
4268 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004269 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004270 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4271 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4272 // that is being hidden in an animation - keep the
4273 // keyguard hidden until the new window shows up and
4274 // we know whether to show the keyguard or not.
4275 if (win.isAnimatingLw() && appWindow && showWhenLocked) {
4276 mHideLockScreen = true;
4277 mWinShowWhenLocked = win;
4278 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004279 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004280 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4281 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4282 && win.isDimming()) {
4283 mTopFullscreenOpaqueOrDimmingWindowState = win;
4284 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004285 }
4286
4287 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004288 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004289 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004290 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4291 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4292 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004293 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4294 // fullscreen window.
4295 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4296 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4297 mTopFullscreenOpaqueWindowState.hideLw(false);
4298 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4299 }
4300
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004301 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004302 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004303
4304 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4305 ? mTopFullscreenOpaqueWindowState.getAttrs()
4306 : null;
4307
Jeff Brownc8018eb2012-10-29 21:33:27 -07004308 // If we are not currently showing a dream then remember the current
4309 // lockscreen state. We will use this to determine whether the dream
4310 // started while the lockscreen was showing and remember this state
4311 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004312 if (!mShowingDream) {
4313 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004314 if (mDreamingSleepTokenNeeded) {
4315 mDreamingSleepTokenNeeded = false;
4316 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4317 }
4318 } else {
4319 if (!mDreamingSleepTokenNeeded) {
4320 mDreamingSleepTokenNeeded = true;
4321 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4322 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004323 }
4324
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004325 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004326 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004327 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004328 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004329 boolean shouldBeTransparent = mForceStatusBarTransparent
4330 && !mForceStatusBar
4331 && !mForceStatusBarFromKeyguard;
4332 if (!shouldBeTransparent) {
4333 mStatusBarController.setShowTransparent(false /* transparent */);
4334 } else if (!mStatusBar.isVisibleLw()) {
4335 mStatusBarController.setShowTransparent(true /* transparent */);
4336 }
4337 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004338 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004339 if (mStatusBarController.setBarShowingLw(true)) {
4340 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4341 }
Craig Mautner81defc72013-10-29 11:10:42 -07004342 // Maintain fullscreen layout until incoming animation is complete.
4343 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004344 // Transient status bar on the lockscreen is not allowed
4345 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4346 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4347 mLastSystemUiFlags, mLastSystemUiFlags);
4348 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004349 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004350 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004351 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004352 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004353 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004354 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004355 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004356 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004357 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004358 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004359 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004360 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004361 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4362 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004363 if (mStatusBarController.isTransientShowing()) {
4364 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004365 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4366 }
4367 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004368 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004369 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004370 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004371 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004372 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004373 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004374 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004375 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004376 if (mStatusBarController.setBarShowingLw(true)) {
4377 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4378 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004379 }
4380 }
4381 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004382
Craig Mautner81defc72013-10-29 11:10:42 -07004383 if (mTopIsFullscreen != topIsFullscreen) {
4384 if (!topIsFullscreen) {
4385 // Force another layout when status bar becomes fully shown.
4386 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4387 }
4388 mTopIsFullscreen = topIsFullscreen;
4389 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004390
Craig Mautner39834192012-09-02 07:47:24 -07004391 // Hide the key guard if a visible window explicitly specifies that it wants to be
4392 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004393 if (mKeyguardDelegate != null && mStatusBar != null) {
4394 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4395 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004396 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004397 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004398 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004399 changes |= FINISH_LAYOUT_REDO_LAYOUT
4400 | FINISH_LAYOUT_REDO_CONFIG
4401 | FINISH_LAYOUT_REDO_WALLPAPER;
4402 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004403 if (mKeyguardDelegate.isShowing()) {
4404 mHandler.post(new Runnable() {
4405 @Override
4406 public void run() {
4407 mKeyguardDelegate.keyguardDone(false, false);
4408 }
4409 });
4410 }
4411 } else if (mHideLockScreen) {
4412 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004413 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004414 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004415 changes |= FINISH_LAYOUT_REDO_LAYOUT
4416 | FINISH_LAYOUT_REDO_CONFIG
4417 | FINISH_LAYOUT_REDO_WALLPAPER;
4418 }
4419 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004420 mKeyguardHidden = false;
4421 if (setKeyguardOccludedLw(false)) {
4422 changes |= FINISH_LAYOUT_REDO_LAYOUT
4423 | FINISH_LAYOUT_REDO_CONFIG
4424 | FINISH_LAYOUT_REDO_WALLPAPER;
4425 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004426 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4427 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004428 mHandler.post(new Runnable() {
4429 @Override
4430 public void run() {
4431 mKeyguardDelegate.dismiss();
4432 }
4433 });
4434 }
4435 } else {
4436 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004437 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004438 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004439 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004440 changes |= FINISH_LAYOUT_REDO_LAYOUT
4441 | FINISH_LAYOUT_REDO_CONFIG
4442 | FINISH_LAYOUT_REDO_WALLPAPER;
4443 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004444 }
4445 }
Joe Onorato664644d2011-01-23 17:53:23 -08004446
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004447 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004448 // If the navigation bar has been hidden or shown, we need to do another
4449 // layout pass to update that window.
4450 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4451 }
Joe Onorato664644d2011-01-23 17:53:23 -08004452
Mike Lockwood28569302010-01-28 11:54:40 -05004453 // update since mAllowLockscreenWhenOn might have changed
4454 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004455 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004456 }
4457
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004458 /**
Jim Millerab954542014-10-10 18:21:49 -07004459 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004460 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004461 * @return Whether the flags have changed and we have to redo the layout.
4462 */
Jim Millerab954542014-10-10 18:21:49 -07004463 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4464 boolean wasOccluded = mKeyguardOccluded;
4465 boolean showing = mKeyguardDelegate.isShowing();
4466 if (wasOccluded && !isOccluded && showing) {
4467 mKeyguardOccluded = false;
4468 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004469 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4470 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4471 return true;
Jim Millerab954542014-10-10 18:21:49 -07004472 } else if (!wasOccluded && isOccluded && showing) {
4473 mKeyguardOccluded = true;
4474 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004475 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4476 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4477 return true;
4478 } else {
4479 return false;
4480 }
4481 }
4482
4483 private boolean isStatusBarKeyguard() {
4484 return mStatusBar != null
4485 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4486 }
4487
Jose Lima9546b202014-07-02 17:21:51 -07004488 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004489 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004490 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004491 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004492 return false;
4493 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004494 return true;
4495 }
4496
Jose Lima9546b202014-07-02 17:21:51 -07004497 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004498 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004499 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004500 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004501 // If the navigation bar has been hidden or shown, we need to do another
4502 // layout pass to update that window.
4503 return FINISH_LAYOUT_REDO_LAYOUT;
4504 }
4505 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004506 }
4507
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004508 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004509 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004510 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4511 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004512 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4513 if (newLidState == mLidState) {
4514 return;
4515 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004516
Jeff Brownc458ce92012-04-30 14:58:40 -07004517 mLidState = newLidState;
4518 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004519 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004520
4521 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004522 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004523 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004524 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004525 }
4526 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004527
Michael Wright3818c922014-09-02 13:59:07 -07004528 @Override
4529 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4530 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4531 if (mCameraLensCoverState == lensCoverState) {
4532 return;
4533 }
4534 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4535 lensCoverState == CAMERA_LENS_UNCOVERED) {
4536 Intent intent;
4537 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4538 mKeyguardDelegate.isShowing();
4539 if (keyguardActive) {
4540 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4541 } else {
4542 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4543 }
Bryce Lee584a4452014-10-21 15:55:55 -07004544 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004545 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004546 }
4547 mCameraLensCoverState = lensCoverState;
4548 }
4549
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004550 void setHdmiPlugged(boolean plugged) {
4551 if (mHdmiPlugged != plugged) {
4552 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004553 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004554 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004555 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004556 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004557 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004558 }
4559 }
4560
Joe Onoratoea495d42011-04-06 11:41:11 -07004561 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004562 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004563 // watch for HDMI plug messages if the hdmi switch exists
4564 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4565 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4566
Joe Onoratoea495d42011-04-06 11:41:11 -07004567 final String filename = "/sys/class/switch/hdmi/state";
4568 FileReader reader = null;
4569 try {
4570 reader = new FileReader(filename);
4571 char[] buf = new char[15];
4572 int n = reader.read(buf);
4573 if (n > 1) {
4574 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4575 }
4576 } catch (IOException ex) {
4577 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4578 } catch (NumberFormatException ex) {
4579 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4580 } finally {
4581 if (reader != null) {
4582 try {
4583 reader.close();
4584 } catch (IOException ex) {
4585 }
Joe Onoratodc100302011-01-11 17:07:41 -08004586 }
4587 }
4588 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004589 // This dance forces the code in setHdmiPlugged to run.
4590 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4591 mHdmiPlugged = !plugged;
4592 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004593 }
4594
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004595 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004596 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004597
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004598 final Runnable mScreenshotTimeout = new Runnable() {
4599 @Override public void run() {
4600 synchronized (mScreenshotLock) {
4601 if (mScreenshotConnection != null) {
4602 mContext.unbindService(mScreenshotConnection);
4603 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004604 }
Winson Chung9112ec32011-06-27 13:15:32 -07004605 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004606 }
4607 };
4608
4609 // Assume this is called from the Handler thread.
4610 private void takeScreenshot() {
4611 synchronized (mScreenshotLock) {
4612 if (mScreenshotConnection != null) {
4613 return;
4614 }
4615 ComponentName cn = new ComponentName("com.android.systemui",
4616 "com.android.systemui.screenshot.TakeScreenshotService");
4617 Intent intent = new Intent();
4618 intent.setComponent(cn);
4619 ServiceConnection conn = new ServiceConnection() {
4620 @Override
4621 public void onServiceConnected(ComponentName name, IBinder service) {
4622 synchronized (mScreenshotLock) {
4623 if (mScreenshotConnection != this) {
4624 return;
4625 }
4626 Messenger messenger = new Messenger(service);
4627 Message msg = Message.obtain(null, 1);
4628 final ServiceConnection myConn = this;
4629 Handler h = new Handler(mHandler.getLooper()) {
4630 @Override
4631 public void handleMessage(Message msg) {
4632 synchronized (mScreenshotLock) {
4633 if (mScreenshotConnection == myConn) {
4634 mContext.unbindService(mScreenshotConnection);
4635 mScreenshotConnection = null;
4636 mHandler.removeCallbacks(mScreenshotTimeout);
4637 }
4638 }
4639 }
4640 };
4641 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004642 msg.arg1 = msg.arg2 = 0;
4643 if (mStatusBar != null && mStatusBar.isVisibleLw())
4644 msg.arg1 = 1;
4645 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4646 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004647 try {
4648 messenger.send(msg);
4649 } catch (RemoteException e) {
4650 }
4651 }
4652 }
4653 @Override
4654 public void onServiceDisconnected(ComponentName name) {}
4655 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004656 if (mContext.bindServiceAsUser(
4657 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004658 mScreenshotConnection = conn;
4659 mHandler.postDelayed(mScreenshotTimeout, 10000);
4660 }
4661 }
Winson Chung9112ec32011-06-27 13:15:32 -07004662 }
4663
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004664 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004665 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004666 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004667 if (!mSystemBooted) {
4668 // If we have not yet booted, don't let key events do anything.
4669 return 0;
4670 }
4671
Jeff Brown037c33e2014-04-09 00:31:55 -07004672 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004673 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4674 final boolean canceled = event.isCanceled();
4675 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004676
Jeff Brown3122e442010-10-11 23:32:49 -07004677 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004678
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004679 // If screen is off then we treat the case where the keyguard is open but hidden
4680 // the same as if it were open and in front.
4681 // This will prevent any keys other than the power button from waking the screen
4682 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004683 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004684 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004685 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004686 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004687
Jeff Brown40013652012-05-16 21:22:36 -07004688 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004689 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004690 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004691 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004692 }
4693
Jeff Brown037c33e2014-04-09 00:31:55 -07004694 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004695 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004696 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4697 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004698 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004699 // When the device is interactive or the key is injected pass the
4700 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004701 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004702 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004703 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4704 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4705 // to the application but preserve its wake key status to make sure we still move
4706 // from dozing to fully interactive if we would normally go from off to fully
4707 // interactive.
4708 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004709 } else {
4710 // When the screen is off and the key is not injected, determine whether
4711 // to wake the device but don't pass the key to the application.
4712 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004713 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4714 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004715 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004716 }
4717
Justin Kohd378ad72013-04-01 12:18:26 -07004718 // If the key would be handled globally, just return the result, don't worry about special
4719 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004720 if (isValidGlobalKey(keyCode)
4721 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004722 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004723 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004724 }
Justin Kohd378ad72013-04-01 12:18:26 -07004725 return result;
4726 }
4727
Jeff Brownbae8e772014-06-12 19:59:45 -07004728 boolean useHapticFeedback = down
4729 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4730 && event.getRepeatCount() == 0;
4731
Jeff Brown4d396052010-10-29 21:50:21 -07004732 // Handle special keys.
4733 switch (keyCode) {
4734 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004735 case KeyEvent.KEYCODE_VOLUME_UP:
4736 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004737 if (mUseTvRouting) {
4738 // On TVs volume keys never go to the foreground app
4739 result &= ~ACTION_PASS_TO_USER;
4740 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004741 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4742 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004743 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004744 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004745 mScreenshotChordVolumeDownKeyTriggered = true;
4746 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4747 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004748 cancelPendingPowerKeyAction();
4749 interceptScreenshotChord();
4750 }
4751 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004752 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004753 cancelPendingScreenshotChordAction();
4754 }
4755 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4756 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004757 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004758 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004759 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004760 cancelPendingPowerKeyAction();
4761 cancelPendingScreenshotChordAction();
4762 }
4763 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004764 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004765 cancelPendingScreenshotChordAction();
4766 }
4767 }
Jeff Brown4d396052010-10-29 21:50:21 -07004768 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004769 TelecomManager telecomManager = getTelecommService();
4770 if (telecomManager != null) {
4771 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004772 // If an incoming call is ringing, either VOLUME key means
4773 // "silence ringer". We handle these keys here, rather than
4774 // in the InCallScreen, to make sure we'll respond to them
4775 // even if the InCallScreen hasn't come to the foreground yet.
4776 // Look for the DOWN event here, to agree with the "fallback"
4777 // behavior in the InCallScreen.
4778 Log.i(TAG, "interceptKeyBeforeQueueing:"
4779 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004780
Santos Cordon6848f722014-05-21 15:22:12 -07004781 // Silence the ringer. (It's safe to call this
4782 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004783 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004784
Santos Cordon6848f722014-05-21 15:22:12 -07004785 // And *don't* pass this key thru to the current activity
4786 // (which is probably the InCallScreen.)
4787 result &= ~ACTION_PASS_TO_USER;
4788 break;
4789 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004790 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004791 && (result & ACTION_PASS_TO_USER) == 0) {
4792 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004793 // the application, just pass it to the session service.
4794
4795 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004796 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004797 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004798 }
4799 }
4800
RoboErik430fc482014-06-12 15:49:20 -07004801 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004802 if (mUseTvRouting) {
4803 dispatchDirectAudioEvent(event);
4804 } else {
4805 // If we aren't passing to the user and no one else
4806 // handled it send it to the session manager to
4807 // figure out.
4808 MediaSessionLegacyHelper.getHelper(mContext)
4809 .sendVolumeKeyEvent(event, true);
4810 }
Jeff Brown4d396052010-10-29 21:50:21 -07004811 break;
4812 }
4813 }
4814 break;
4815 }
4816
4817 case KeyEvent.KEYCODE_ENDCALL: {
4818 result &= ~ACTION_PASS_TO_USER;
4819 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004820 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004821 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004822 if (telecomManager != null) {
4823 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004824 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004825 if (interactive && !hungUp) {
4826 mEndCallKeyHandled = false;
4827 mHandler.postDelayed(mEndCallLongPress,
4828 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4829 } else {
4830 mEndCallKeyHandled = true;
4831 }
Jeff Brown4d396052010-10-29 21:50:21 -07004832 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004833 if (!mEndCallKeyHandled) {
4834 mHandler.removeCallbacks(mEndCallLongPress);
4835 if (!canceled) {
4836 if ((mEndcallBehavior
4837 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4838 if (goHome()) {
4839 break;
4840 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004841 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004842 if ((mEndcallBehavior
4843 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4844 mPowerManager.goToSleep(event.getEventTime(),
4845 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4846 isWakeKey = false;
4847 }
Jeff Brown4d396052010-10-29 21:50:21 -07004848 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004849 }
Jeff Brown4d396052010-10-29 21:50:21 -07004850 }
4851 break;
4852 }
4853
4854 case KeyEvent.KEYCODE_POWER: {
4855 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004856 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004857 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004858 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004859 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004860 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004861 }
4862 break;
4863 }
4864
Jeff Brown6212a492014-03-07 13:58:47 -08004865 case KeyEvent.KEYCODE_SLEEP: {
4866 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004867 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004868 if (!mPowerManager.isInteractive()) {
4869 useHapticFeedback = false; // suppress feedback if already non-interactive
4870 }
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004871 sleepPress(event);
Jeff Brown6212a492014-03-07 13:58:47 -08004872 break;
4873 }
4874
4875 case KeyEvent.KEYCODE_WAKEUP: {
4876 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004877 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004878 break;
4879 }
4880
Jeff Brown4d396052010-10-29 21:50:21 -07004881 case KeyEvent.KEYCODE_MEDIA_PLAY:
4882 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4883 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004884 case KeyEvent.KEYCODE_HEADSETHOOK:
4885 case KeyEvent.KEYCODE_MUTE:
4886 case KeyEvent.KEYCODE_MEDIA_STOP:
4887 case KeyEvent.KEYCODE_MEDIA_NEXT:
4888 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4889 case KeyEvent.KEYCODE_MEDIA_REWIND:
4890 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004891 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4892 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004893 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4894 // If the global session is active pass all media keys to it
4895 // instead of the active window.
4896 result &= ~ACTION_PASS_TO_USER;
4897 }
Jeff Brown4d396052010-10-29 21:50:21 -07004898 if ((result & ACTION_PASS_TO_USER) == 0) {
4899 // Only do this if we would otherwise not pass it to the user. In that
4900 // case, the PhoneWindow class will do the same thing, except it will
4901 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004902 // Note that we need to make a copy of the key event here because the
4903 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004904 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004905 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4906 new KeyEvent(event));
4907 msg.setAsynchronous(true);
4908 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004909 }
4910 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004911 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004912
Jeff Brown4d396052010-10-29 21:50:21 -07004913 case KeyEvent.KEYCODE_CALL: {
4914 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004915 TelecomManager telecomManager = getTelecommService();
4916 if (telecomManager != null) {
4917 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004918 Log.i(TAG, "interceptKeyBeforeQueueing:"
4919 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004920 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004921
Santos Cordon6848f722014-05-21 15:22:12 -07004922 // And *don't* pass this key thru to the current activity
4923 // (which is presumably the InCallScreen.)
4924 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004925 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004926 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004927 }
Jeff Brown4d396052010-10-29 21:50:21 -07004928 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004929 }
Michael Wright869a67c2014-08-26 19:33:06 -07004930 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4931 // Only do this if we would otherwise not pass it to the user. In that case,
4932 // interceptKeyBeforeDispatching would apply a similar but different policy in
4933 // order to invoke voice assist actions. Note that we need to make a copy of the
4934 // key event here because the original key event will be recycled when we return.
4935 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4936 mBroadcastWakeLock.acquire();
4937 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4938 keyguardActive ? 1 : 0, 0);
4939 msg.setAsynchronous(true);
4940 msg.sendToTarget();
4941 }
4942 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004943 }
Jeff Brown26875502014-01-30 21:47:47 -08004944
Jeff Brownbae8e772014-06-12 19:59:45 -07004945 if (useHapticFeedback) {
4946 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4947 }
4948
Jeff Brown26875502014-01-30 21:47:47 -08004949 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004950 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004951 }
Bryce Lee584a4452014-10-21 15:55:55 -07004952
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004953 return result;
4954 }
4955
Jeff Brown1c2e4942012-11-06 16:32:01 -08004956 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004957 * Returns true if the key can have global actions attached to it.
4958 * We reserve all power management keys for the system since they require
4959 * very careful handling.
4960 */
4961 private static boolean isValidGlobalKey(int keyCode) {
4962 switch (keyCode) {
4963 case KeyEvent.KEYCODE_POWER:
4964 case KeyEvent.KEYCODE_WAKEUP:
4965 case KeyEvent.KEYCODE_SLEEP:
4966 return false;
4967 default:
4968 return true;
4969 }
4970 }
4971
4972 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08004973 * When the screen is off we ignore some keys that might otherwise typically
4974 * be considered wake keys. We filter them out here.
4975 *
4976 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4977 * is always considered a wake key.
4978 */
4979 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4980 switch (keyCode) {
4981 // ignore volume keys unless docked
4982 case KeyEvent.KEYCODE_VOLUME_UP:
4983 case KeyEvent.KEYCODE_VOLUME_DOWN:
4984 case KeyEvent.KEYCODE_VOLUME_MUTE:
4985 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4986
4987 // ignore media and camera keys
4988 case KeyEvent.KEYCODE_MUTE:
4989 case KeyEvent.KEYCODE_HEADSETHOOK:
4990 case KeyEvent.KEYCODE_MEDIA_PLAY:
4991 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4992 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4993 case KeyEvent.KEYCODE_MEDIA_STOP:
4994 case KeyEvent.KEYCODE_MEDIA_NEXT:
4995 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4996 case KeyEvent.KEYCODE_MEDIA_REWIND:
4997 case KeyEvent.KEYCODE_MEDIA_RECORD:
4998 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004999 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005000 case KeyEvent.KEYCODE_CAMERA:
5001 return false;
5002 }
5003 return true;
5004 }
5005
5006
Jeff Brown56194eb2011-03-02 19:23:13 -08005007 /** {@inheritDoc} */
5008 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005009 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5010 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08005011 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
5012 return 0;
5013 }
Michael Wright70af00a2014-09-03 19:30:20 -07005014 }
Bryce Lee5c138322014-11-03 08:26:09 -08005015
Michael Wright70af00a2014-09-03 19:30:20 -07005016 if (shouldDispatchInputWhenNonInteractive()) {
5017 return ACTION_PASS_TO_USER;
5018 }
Bryce Lee5c138322014-11-03 08:26:09 -08005019
Bryce Lee812d7022014-11-10 13:33:28 -08005020 // If we have not passed the action up and we are in theater mode without dreaming,
5021 // there will be no dream to intercept the touch and wake into ambient. The device should
5022 // wake up in this case.
5023 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
5024 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
5025 }
5026
Jeff Brown037c33e2014-04-09 00:31:55 -07005027 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005028 }
5029
Michael Wright70af00a2014-09-03 19:30:20 -07005030 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08005031 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07005032 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5033 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005034 return true;
5035 }
5036
5037 // Send events to a dozing dream even if the screen is off since the dream
5038 // is in control of the state of the screen.
5039 IDreamManager dreamManager = getDreamManager();
5040
5041 try {
5042 if (dreamManager != null && dreamManager.isDreaming()) {
5043 return true;
5044 }
5045 } catch (RemoteException e) {
5046 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5047 }
5048
5049 // Otherwise, consume events since the user can't see what is being
5050 // interacted with.
5051 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005052 }
5053
RoboErik001c59c2015-01-26 15:53:51 -08005054 private void dispatchDirectAudioEvent(KeyEvent event) {
5055 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5056 return;
5057 }
5058 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005059 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5060 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005061 String pkgName = mContext.getOpPackageName();
5062 switch (keyCode) {
5063 case KeyEvent.KEYCODE_VOLUME_UP:
5064 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005065 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005066 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005067 } catch (RemoteException e) {
5068 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5069 }
5070 break;
5071 case KeyEvent.KEYCODE_VOLUME_DOWN:
5072 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005073 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005074 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005075 } catch (RemoteException e) {
5076 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5077 }
5078 break;
5079 case KeyEvent.KEYCODE_VOLUME_MUTE:
5080 try {
5081 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005082 getAudioService().adjustSuggestedStreamVolume(
5083 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005084 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005085 }
5086 } catch (RemoteException e) {
5087 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5088 }
5089 break;
5090 }
5091 }
5092
Jeff Brown40013652012-05-16 21:22:36 -07005093 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5094 if (DEBUG_INPUT) {
5095 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005096 }
5097
Jeff Brown40013652012-05-16 21:22:36 -07005098 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5099 if (DEBUG_INPUT) {
5100 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5101 }
5102
5103 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5104 mHavePendingMediaKeyRepeatWithWakeLock = false;
5105 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5106 }
5107
5108 dispatchMediaKeyWithWakeLockToAudioService(event);
5109
5110 if (event.getAction() == KeyEvent.ACTION_DOWN
5111 && event.getRepeatCount() == 0) {
5112 mHavePendingMediaKeyRepeatWithWakeLock = true;
5113
5114 Message msg = mHandler.obtainMessage(
5115 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5116 msg.setAsynchronous(true);
5117 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5118 } else {
5119 mBroadcastWakeLock.release();
5120 }
5121 }
5122
5123 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5124 mHavePendingMediaKeyRepeatWithWakeLock = false;
5125
5126 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5127 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5128 if (DEBUG_INPUT) {
5129 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5130 }
5131
5132 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5133 mBroadcastWakeLock.release();
5134 }
5135
5136 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5137 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005138 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005139 }
5140 }
5141
Michael Wright869a67c2014-08-26 19:33:06 -07005142 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
5143 Intent voiceIntent =
5144 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5145 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005146 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005147 mBroadcastWakeLock.release();
5148 }
5149
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005150 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005151 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005152 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005153 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5154 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5155 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005156 } else {
5157 try {
5158 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5159 ServiceManager.getService(Context.UI_MODE_SERVICE));
5160 mUiMode = uiModeService.getCurrentModeType();
5161 } catch (RemoteException e) {
5162 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005163 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005164 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005165 synchronized (mLock) {
5166 updateOrientationListenerLp();
5167 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005168 }
5169 };
5170
Jeff Brown6aaf2952012-10-05 16:01:08 -07005171 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5172 @Override
5173 public void onReceive(Context context, Intent intent) {
5174 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005175 if (mKeyguardDelegate != null) {
5176 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005177 }
5178 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005179 if (mKeyguardDelegate != null) {
5180 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005181 }
5182 }
5183 }
5184 };
5185
Christopher Tate5e08af02012-09-21 17:17:22 -07005186 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5187 @Override
5188 public void onReceive(Context context, Intent intent) {
5189 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5190 // tickle the settings observer: this first ensures that we're
5191 // observing the relevant settings for the newly-active user,
5192 // and then updates our own bookkeeping based on the now-
5193 // current user.
5194 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005195
5196 // force a re-application of focused window sysui visibility.
5197 // the window may never have been shown for this user
5198 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005199 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005200 mLastSystemUiFlags = 0;
5201 updateSystemUiVisibilityLw();
5202 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005203 }
5204 }
5205 };
5206
Adrian Roosddc8b272015-05-21 16:28:27 -07005207 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005208 @Override
5209 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005210 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5211 if (!isUserSetupComplete()) {
5212 // Swipe-up for navigation bar is disabled during setup
5213 return;
5214 }
5215 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5216 mNavigationBarController.showTransient();
5217 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005218 }
5219 };
5220
John Spurlocke1f366f2013-08-05 12:22:40 -04005221 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005222 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005223 if (!isUserSetupComplete()) {
5224 // Swipe-up for navigation bar is disabled during setup
5225 return;
5226 }
John Spurlock27735a42013-08-14 17:57:38 -04005227 boolean sb = mStatusBarController.checkShowTransientBarLw();
5228 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005229 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005230 // Don't show status bar when swiping on already visible navigation bar
5231 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005232 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005233 return;
5234 }
John Spurlock27735a42013-08-14 17:57:38 -04005235 if (sb) mStatusBarController.showTransient();
5236 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005237 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005238 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005239 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005240 }
5241 }
5242
Jeff Brown3ee549c2014-09-22 20:14:39 -07005243 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005244 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07005245 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005246 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07005247 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005248
5249 // We must get this work done here because the power manager will drop
5250 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005251 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005252 mAwake = false;
5253 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005254 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005255 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005256 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005257 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005258
5259 if (mKeyguardDelegate != null) {
5260 mKeyguardDelegate.onScreenTurnedOff(why);
5261 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005262 }
5263
Jeff Brown13f00f02014-10-31 14:45:50 -07005264 private void wakeUpFromPowerKey(long eventTime) {
5265 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5266 }
5267
Bryce Lee5c138322014-11-03 08:26:09 -08005268 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Lee584a4452014-10-21 15:55:55 -07005269 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005270 return false;
Bryce Lee584a4452014-10-21 15:55:55 -07005271 }
5272
5273 mPowerManager.wakeUp(wakeTime);
Bryce Lee5c138322014-11-03 08:26:09 -08005274 return true;
Bryce Lee584a4452014-10-21 15:55:55 -07005275 }
5276
Jeff Brown3ee549c2014-09-22 20:14:39 -07005277 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005278 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07005279 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005280 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07005281 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005282
Jeff Brown3ee549c2014-09-22 20:14:39 -07005283 // Since goToSleep performs these functions synchronously, we must
5284 // do the same here. We cannot post this work to a handler because
5285 // that might cause it to become reordered with respect to what
5286 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005287 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005288 mAwake = true;
5289 mKeyguardDrawComplete = false;
5290 if (mKeyguardDelegate != null) {
5291 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5292 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5293 }
5294
Jeff Browna20dda42014-05-27 20:57:24 -07005295 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005296 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005297 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005298 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005299
Jim Miller5ecd8112013-01-09 18:50:26 -08005300 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07005301 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005302 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005303 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005304 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005305 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005306 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005307 }
5308
Jeff Brown36c4db82014-09-19 12:05:31 -07005309 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005310 synchronized (mLock) {
5311 if (!mAwake || mKeyguardDrawComplete) {
5312 return; // spurious
5313 }
5314
Jeff Brown36c4db82014-09-19 12:05:31 -07005315 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005316 if (mKeyguardDelegate != null) {
5317 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5318 }
5319 }
5320
5321 finishScreenTurningOn();
5322 }
5323
5324 // Called on the DisplayManager's DisplayPowerController thread.
5325 @Override
5326 public void screenTurnedOff() {
5327 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5328
5329 synchronized (mLock) {
5330 mScreenOnEarly = false;
5331 mScreenOnFully = false;
5332 mWindowManagerDrawComplete = false;
5333 mScreenOnListener = null;
5334 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005335 }
5336 }
5337
Jeff Brown3ee549c2014-09-22 20:14:39 -07005338 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005339 @Override
5340 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005341 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005342
Jeff Brown3ee549c2014-09-22 20:14:39 -07005343 synchronized (mLock) {
5344 mScreenOnEarly = true;
5345 mScreenOnFully = false;
5346 mWindowManagerDrawComplete = false;
5347 mScreenOnListener = screenOnListener;
5348 updateOrientationListenerLp();
5349 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005350
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005351 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5352 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005353 // ... eventually calls finishWindowsDrawn
5354 }
5355
Jeff Brown36c4db82014-09-19 12:05:31 -07005356 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005357 synchronized (mLock) {
5358 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5359 return; // spurious
5360 }
5361
Jeff Brown36c4db82014-09-19 12:05:31 -07005362 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005363 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005364
5365 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005366 }
5367
Craig Mautner8a0da012014-05-31 15:13:37 -07005368 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005369 final ScreenOnListener listener;
5370 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005371 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005372 if (DEBUG_WAKEUP) Slog.d(TAG,
5373 "finishScreenTurningOn: mAwake=" + mAwake
5374 + ", mScreenOnEarly=" + mScreenOnEarly
5375 + ", mScreenOnFully=" + mScreenOnFully
5376 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5377 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5378
5379 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5380 || (mAwake && !mKeyguardDrawComplete)) {
5381 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005382 }
5383
Jeff Brown3ee549c2014-09-22 20:14:39 -07005384 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5385 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005386 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005387 mScreenOnFully = true;
5388
5389 // Remember the first time we draw the keyguard so we know when we're done with
5390 // the main part of booting and can enable the screen and hide boot messages.
5391 if (!mKeyguardDrawnOnce && mAwake) {
5392 mKeyguardDrawnOnce = true;
5393 enableScreen = true;
5394 if (mBootMessageNeedsHiding) {
5395 mBootMessageNeedsHiding = false;
5396 hideBootMessages();
5397 }
5398 } else {
5399 enableScreen = false;
5400 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005401 }
5402
Jeff Brown3ee549c2014-09-22 20:14:39 -07005403 if (listener != null) {
5404 listener.onScreenOn();
5405 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005406
Jeff Brown3ee549c2014-09-22 20:14:39 -07005407 if (enableScreen) {
5408 try {
5409 mWindowManager.enableScreenIfNeeded();
5410 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005411 }
Craig Mautnera631d492014-08-05 15:16:01 -07005412 }
5413 }
5414
5415 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005416 synchronized (mLock) {
5417 if (!mKeyguardDrawnOnce) {
5418 mBootMessageNeedsHiding = true;
5419 return; // keyguard hasn't drawn the first time yet, not done booting
5420 }
Craig Mautnera631d492014-08-05 15:16:01 -07005421 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005422
5423 if (mBootMsgDialog != null) {
5424 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5425 mBootMsgDialog.dismiss();
5426 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005427 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005428 }
5429
5430 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005431 public boolean isScreenOn() {
5432 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005433 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005434
Dianne Hackborn08743722009-12-21 12:16:51 -08005435 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005436 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005437 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005438 if (mKeyguardDelegate != null) {
5439 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005440 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005441 }
5442
5443 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005444 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005445 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005446 if (mKeyguardDelegate != null) {
5447 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005448 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005449 }
5450
Jim Millerab954542014-10-10 18:21:49 -07005451 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005452 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005453 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005454 }
5455
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005456 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005457 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005458 public boolean isKeyguardLocked() {
5459 return keyguardOn();
5460 }
5461
5462 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005463 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005464 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005465 if (mKeyguardDelegate == null) return false;
5466 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005467 }
5468
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005469 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005470 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005471 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005472 if (mKeyguardDelegate == null) return false;
5473 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005474 }
5475
Jose Lima9546b202014-07-02 17:21:51 -07005476 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005477 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005478 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005479 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005480 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005481 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005482 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005483 // ask the keyguard to prompt the user to authenticate if necessary
5484 mKeyguardDelegate.dismiss();
5485 }
5486 });
5487 }
5488 }
5489
5490 public void notifyActivityDrawnForKeyguardLw() {
5491 if (mKeyguardDelegate != null) {
5492 mHandler.post(new Runnable() {
5493 @Override
5494 public void run() {
5495 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005496 }
5497 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005498 }
5499 }
5500
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005501 @Override
5502 public boolean isKeyguardDrawnLw() {
5503 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005504 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005505 }
5506 }
5507
Jorim Jaggi0d674622014-05-21 01:34:15 +02005508 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005509 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005510 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005511 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005512 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005513 }
5514 }
5515
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005516 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005517 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005518 }
5519
5520 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005521 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005522 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005523
Jeff Brown01a98dd2011-09-20 15:08:29 -07005524 @Override
5525 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005526 if (false) {
5527 Slog.v(TAG, "rotationForOrientationLw(orient="
5528 + orientation + ", last=" + lastRotation
5529 + "); user=" + mUserRotation + " "
5530 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5531 ? "USER_ROTATION_LOCKED" : "")
5532 );
5533 }
5534
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005535 if (mForceDefaultOrientation) {
5536 return Surface.ROTATION_0;
5537 }
5538
The Android Open Source Project0727d222009-03-11 12:11:58 -07005539 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005540 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5541 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005542 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005543 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005544
Jeff Browndec6cf42011-11-15 14:08:20 -08005545 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005546 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005547 // Ignore sensor when lid switch is open and rotation is forced.
5548 preferredRotation = mLidOpenRotation;
5549 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005550 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005551 // Ignore sensor when in car dock unless explicitly enabled.
5552 // This case can override the behavior of NOSENSOR, and can also
5553 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005554 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005555 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005556 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5557 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5558 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005559 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005560 // Ignore sensor when in desk dock unless explicitly enabled.
5561 // This case can override the behavior of NOSENSOR, and can also
5562 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005563 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005564 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005565 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5566 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005567 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005568 preferredRotation = mDemoHdmiRotation;
5569 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5570 && mUndockedHdmiRotation >= 0) {
5571 // Ignore sensor when plugged into HDMI and an undocked orientation has
5572 // been specified in the configuration (only for legacy devices without
5573 // full multi-display support).
5574 // Note that the dock orientation overrides the HDMI orientation.
5575 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005576 } else if (mDemoRotationLock) {
5577 // Ignore sensor when demo rotation lock is enabled.
5578 // Note that the dock orientation and HDMI rotation lock override this.
5579 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005580 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5581 // Application just wants to remain locked in the last rotation.
5582 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005583 } else if (!mSupportAutoRotation) {
5584 // If we don't support auto-rotation then bail out here and ignore
5585 // the sensor and any rotation lock settings.
5586 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005587 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005588 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005589 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5590 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5591 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5592 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005593 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5594 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5595 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5596 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5597 // Otherwise, use sensor only if requested by the application or enabled
5598 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005599 if (mAllowAllRotations < 0) {
5600 // Can't read this during init() because the context doesn't
5601 // have display metrics at that time so we cannot determine
5602 // tablet vs. phone then.
5603 mAllowAllRotations = mContext.getResources().getBoolean(
5604 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5605 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005606 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005607 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005608 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5609 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005610 preferredRotation = sensorRotation;
5611 } else {
5612 preferredRotation = lastRotation;
5613 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005614 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5615 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5616 // Apply rotation lock. Does not apply to NOSENSOR.
5617 // The idea is that the user rotation expresses a weak preference for the direction
5618 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5619 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005620 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005621 } else {
5622 // No overriding preference.
5623 // We will do exactly what the application asked us to do.
5624 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005625 }
5626
Dianne Hackborne5439f22010-10-02 16:53:50 -07005627 switch (orientation) {
5628 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005629 // Return portrait unless overridden.
5630 if (isAnyPortrait(preferredRotation)) {
5631 return preferredRotation;
5632 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005633 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005634
Jeff Brown01a98dd2011-09-20 15:08:29 -07005635 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005636 // Return landscape unless overridden.
5637 if (isLandscapeOrSeascape(preferredRotation)) {
5638 return preferredRotation;
5639 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005640 return mLandscapeRotation;
5641
5642 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005643 // Return reverse portrait unless overridden.
5644 if (isAnyPortrait(preferredRotation)) {
5645 return preferredRotation;
5646 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005647 return mUpsideDownRotation;
5648
5649 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005650 // Return seascape unless overridden.
5651 if (isLandscapeOrSeascape(preferredRotation)) {
5652 return preferredRotation;
5653 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005654 return mSeascapeRotation;
5655
5656 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005657 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005658 // Return either landscape rotation.
5659 if (isLandscapeOrSeascape(preferredRotation)) {
5660 return preferredRotation;
5661 }
5662 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005663 return lastRotation;
5664 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005665 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005666
Jeff Brown01a98dd2011-09-20 15:08:29 -07005667 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005668 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005669 // Return either portrait rotation.
5670 if (isAnyPortrait(preferredRotation)) {
5671 return preferredRotation;
5672 }
5673 if (isAnyPortrait(lastRotation)) {
5674 return lastRotation;
5675 }
5676 return mPortraitRotation;
5677
5678 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005679 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5680 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005681 if (preferredRotation >= 0) {
5682 return preferredRotation;
5683 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005684 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005685 }
5686 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005687 }
5688
Jeff Brown01a98dd2011-09-20 15:08:29 -07005689 @Override
5690 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5691 switch (orientation) {
5692 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5693 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5694 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5695 return isAnyPortrait(rotation);
5696
5697 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5698 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5699 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5700 return isLandscapeOrSeascape(rotation);
5701
5702 default:
5703 return true;
5704 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005705 }
5706
Jeff Brownc0347aa2011-09-23 17:26:09 -07005707 @Override
5708 public void setRotationLw(int rotation) {
5709 mOrientationListener.setCurrentRotation(rotation);
5710 }
5711
Jeff Brown01a98dd2011-09-20 15:08:29 -07005712 private boolean isLandscapeOrSeascape(int rotation) {
5713 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005714 }
5715
Jeff Brown01a98dd2011-09-20 15:08:29 -07005716 private boolean isAnyPortrait(int rotation) {
5717 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005718 }
5719
Jose Lima9546b202014-07-02 17:21:51 -07005720 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005721 public int getUserRotationMode() {
5722 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005723 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5724 WindowManagerPolicy.USER_ROTATION_FREE :
5725 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005726 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005727
5728 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005729 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005730 public void setUserRotationMode(int mode, int rot) {
5731 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005732
5733 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005734 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005735 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005736 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005737 rot,
5738 UserHandle.USER_CURRENT);
5739 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005740 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005741 0,
5742 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005743 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005744 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005745 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005746 1,
5747 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005748 }
5749 }
5750
Jose Lima9546b202014-07-02 17:21:51 -07005751 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005752 public void setSafeMode(boolean safeMode) {
5753 mSafeMode = safeMode;
5754 performHapticFeedbackLw(null, safeMode
5755 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5756 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005757 }
Craig Mautnereda67292013-04-28 13:50:14 -07005758
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005759 static long[] getLongIntArray(Resources r, int resid) {
5760 int[] ar = r.getIntArray(resid);
5761 if (ar == null) {
5762 return null;
5763 }
5764 long[] out = new long[ar.length];
5765 for (int i=0; i<ar.length; i++) {
5766 out[i] = ar[i];
5767 }
5768 return out;
5769 }
Craig Mautnereda67292013-04-28 13:50:14 -07005770
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005771 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005772 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005773 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005774 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005775 mKeyguardDelegate.onSystemReady();
5776
Michael Wright3818c922014-09-02 13:59:07 -07005777 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005778 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005779 synchronized (mLock) {
5780 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005781 mSystemReady = true;
5782 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005783 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005784 public void run() {
5785 updateSettings();
5786 }
5787 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005788 }
5789 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005790
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005791 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005792 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005793 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005794 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005795 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005796 mKeyguardDelegate.onBootCompleted();
5797 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005798 synchronized (mLock) {
5799 mSystemBooted = true;
5800 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005801 wakingUp();
5802 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005803 }
5804
Dianne Hackborn661cd522011-08-22 00:26:20 -07005805 ProgressDialog mBootMsgDialog = null;
5806
5807 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005808 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005809 public void showBootMessage(final CharSequence msg, final boolean always) {
5810 mHandler.post(new Runnable() {
5811 @Override public void run() {
5812 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005813 int theme;
5814 if (mContext.getPackageManager().hasSystemFeature(
5815 PackageManager.FEATURE_WATCH)) {
5816 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5817 } else if (mContext.getPackageManager().hasSystemFeature(
5818 PackageManager.FEATURE_TELEVISION)) {
5819 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5820 } else {
5821 theme = 0;
5822 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005823
5824 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005825 // This dialog will consume all events coming in to
5826 // it, to avoid it trying to do things too early in boot.
5827 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5828 return true;
5829 }
5830 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5831 return true;
5832 }
5833 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5834 return true;
5835 }
5836 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5837 return true;
5838 }
5839 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5840 return true;
5841 }
5842 @Override public boolean dispatchPopulateAccessibilityEvent(
5843 AccessibilityEvent event) {
5844 return true;
5845 }
5846 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005847 if (mContext.getPackageManager().isUpgrade()) {
5848 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5849 } else {
5850 mBootMsgDialog.setTitle(R.string.android_start_title);
5851 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005852 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5853 mBootMsgDialog.setIndeterminate(true);
5854 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005855 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005856 mBootMsgDialog.getWindow().addFlags(
5857 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5858 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5859 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005860 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5861 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5862 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005863 mBootMsgDialog.setCancelable(false);
5864 mBootMsgDialog.show();
5865 }
5866 mBootMsgDialog.setMessage(msg);
5867 }
5868 });
5869 }
5870
5871 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005872 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005873 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005874 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005875 }
5876
Mike Lockwood28569302010-01-28 11:54:40 -05005877 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005878 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005879 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005880 // ***************************************
5881 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5882 // ***************************************
5883 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5884 // WITH ITS LOCKS HELD.
5885 //
5886 // This code must be VERY careful about the locks
5887 // it acquires.
5888 // In fact, the current code acquires way too many,
5889 // and probably has lurking deadlocks.
5890
Mike Lockwood28569302010-01-28 11:54:40 -05005891 synchronized (mScreenLockTimeout) {
5892 if (mLockScreenTimerActive) {
5893 // reset the timer
5894 mHandler.removeCallbacks(mScreenLockTimeout);
5895 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5896 }
5897 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005898 }
5899
Adam Cohenf7522022012-10-03 20:03:18 -07005900 class ScreenLockTimeout implements Runnable {
5901 Bundle options;
5902
5903 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005904 public void run() {
5905 synchronized (this) {
5906 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005907 if (mKeyguardDelegate != null) {
5908 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005909 }
Mike Lockwood28569302010-01-28 11:54:40 -05005910 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005911 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005912 }
5913 }
Mike Lockwood28569302010-01-28 11:54:40 -05005914
Adam Cohenf7522022012-10-03 20:03:18 -07005915 public void setLockOptions(Bundle options) {
5916 this.options = options;
5917 }
5918 }
5919
5920 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5921
Jose Lima9546b202014-07-02 17:21:51 -07005922 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005923 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005924 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5925 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005926 if (options != null) {
5927 // In case multiple calls are made to lockNow, we don't wipe out the options
5928 // until the runnable actually executes.
5929 mScreenLockTimeout.setLockOptions(options);
5930 }
Jim Miller93c518e2012-01-17 15:55:31 -08005931 mHandler.post(mScreenLockTimeout);
5932 }
5933
Mike Lockwood28569302010-01-28 11:54:40 -05005934 private void updateLockScreenTimeout() {
5935 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005936 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005937 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005938 if (mLockScreenTimerActive != enable) {
5939 if (enable) {
5940 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5941 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5942 } else {
5943 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5944 mHandler.removeCallbacks(mScreenLockTimeout);
5945 }
5946 mLockScreenTimerActive = enable;
5947 }
5948 }
5949 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005950
Jeff Brown061ea992015-04-17 19:55:47 -07005951 private void updateDreamingSleepToken(boolean acquire) {
5952 if (acquire) {
5953 if (mDreamingSleepToken == null) {
5954 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
5955 }
5956 } else {
5957 if (mDreamingSleepToken != null) {
5958 mDreamingSleepToken.release();
5959 }
5960 }
5961 }
5962
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005963 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005964 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005965 public void enableScreenAfterBoot() {
5966 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005967 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005968 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005969 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005970
Jeff Brownc458ce92012-04-30 14:58:40 -07005971 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005972 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005973 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005974 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005975 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005976 }
Jeff Browna20dda42014-05-27 20:57:24 -07005977
5978 synchronized (mLock) {
5979 updateWakeGestureListenerLp();
5980 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005981 }
5982
Jeff Brown4f5fa282014-06-12 19:19:15 -07005983 void updateUiMode() {
5984 if (mUiModeManager == null) {
5985 mUiModeManager = IUiModeManager.Stub.asInterface(
5986 ServiceManager.getService(Context.UI_MODE_SERVICE));
5987 }
5988 try {
5989 mUiMode = mUiModeManager.getCurrentModeType();
5990 } catch (RemoteException e) {
5991 }
5992 }
5993
Jeff Brown01a98dd2011-09-20 15:08:29 -07005994 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005995 try {
5996 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005997 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5998 } catch (RemoteException e) {
5999 // Ignore
6000 }
6001 }
6002
6003 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6004 try {
6005 //set orientation on WindowManager
6006 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006007 } catch (RemoteException e) {
6008 // Ignore
6009 }
6010 }
6011
Daniel Sandler6396c722013-04-16 20:19:09 -04006012 /**
6013 * Return an Intent to launch the currently active dock app as home. Returns
6014 * null if the standard home should be launched, which is the case if any of the following is
6015 * true:
6016 * <ul>
6017 * <li>The device is not in either car mode or desk mode
6018 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
6019 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6020 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6021 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6022 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006023 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006024 */
6025 Intent createHomeDockIntent() {
6026 Intent intent = null;
6027
6028 // What home does is based on the mode, not the dock state. That
6029 // is, when in car mode you should be taken to car home regardless
6030 // of whether we are actually in a car dock.
6031 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6032 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
6033 intent = mCarDockIntent;
6034 }
6035 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6036 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6037 intent = mDeskDockIntent;
6038 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006039 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6040 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6041 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6042 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6043 // Always launch dock home from home when watch is docked, if it exists.
6044 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006045 }
6046
6047 if (intent == null) {
6048 return null;
6049 }
6050
6051 ActivityInfo ai = null;
6052 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6053 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006054 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006055 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006056 if (info != null) {
6057 ai = info.activityInfo;
6058 }
6059 if (ai != null
6060 && ai.metaData != null
6061 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6062 intent = new Intent(intent);
6063 intent.setClassName(ai.packageName, ai.name);
6064 return intent;
6065 }
6066
6067 return null;
6068 }
6069
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006070 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6071 if (awakenFromDreams) {
6072 awakenDreams();
6073 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006074
6075 Intent dock = createHomeDockIntent();
6076 if (dock != null) {
6077 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006078 if (fromHomeKey) {
6079 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6080 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006081 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006082 return;
6083 } catch (ActivityNotFoundException e) {
6084 }
6085 }
6086
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006087 Intent intent;
6088
6089 if (fromHomeKey) {
6090 intent = new Intent(mHomeIntent);
6091 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6092 } else {
6093 intent = mHomeIntent;
6094 }
6095
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006096 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006097 }
Craig Mautnereda67292013-04-28 13:50:14 -07006098
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006099 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006100 * goes to the home screen
6101 * @return whether it did anything
6102 */
6103 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006104 if (!isUserSetupComplete()) {
6105 Slog.i(TAG, "Not going home because user setup is in progress.");
6106 return false;
6107 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006108 if (false) {
6109 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006110 try {
6111 ActivityManagerNative.getDefault().stopAppSwitches();
6112 } catch (RemoteException e) {
6113 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006114 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006115 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006116 } else {
6117 // This code brings home to the front or, if it is already
6118 // at the front, puts the device to sleep.
6119 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006120 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6121 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6122 Log.d(TAG, "UTS-TEST-MODE");
6123 } else {
6124 ActivityManagerNative.getDefault().stopAppSwitches();
6125 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006126 Intent dock = createHomeDockIntent();
6127 if (dock != null) {
6128 int result = ActivityManagerNative.getDefault()
6129 .startActivityAsUser(null, null, dock,
6130 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6131 null, null, 0,
6132 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006133 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006134 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6135 return false;
6136 }
6137 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006138 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006139 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006140 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006141 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006142 null, null, 0,
6143 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006144 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006145 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006146 return false;
6147 }
6148 } catch (RemoteException ex) {
6149 // bummer, the activity manager, which is in this process, is dead
6150 }
6151 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006152 return true;
6153 }
Craig Mautnereda67292013-04-28 13:50:14 -07006154
6155 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006156 public void setCurrentOrientationLw(int newOrientation) {
6157 synchronized (mLock) {
6158 if (newOrientation != mCurrentAppOrientation) {
6159 mCurrentAppOrientation = newOrientation;
6160 updateOrientationListenerLp();
6161 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006162 }
6163 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006164
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006165 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6166 if (!isGlobalAccessibilityGestureEnabled()) {
6167 return;
6168 }
6169 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6170 Context.AUDIO_SERVICE);
6171 if (audioManager.isSilentMode()) {
6172 return;
6173 }
6174 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6175 Settings.System.DEFAULT_NOTIFICATION_URI);
6176 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6177 ringTone.play();
6178 }
Craig Mautnereda67292013-04-28 13:50:14 -07006179
Bryce Lee584a4452014-10-21 15:55:55 -07006180 private boolean isTheaterModeEnabled() {
6181 return Settings.Global.getInt(mContext.getContentResolver(),
6182 Settings.Global.THEATER_MODE_ON, 0) == 1;
6183 }
6184
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006185 private boolean isGlobalAccessibilityGestureEnabled() {
6186 return Settings.Global.getInt(mContext.getContentResolver(),
6187 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6188 }
6189
Craig Mautnereda67292013-04-28 13:50:14 -07006190 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006191 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006192 if (!mVibrator.hasVibrator()) {
6193 return false;
6194 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006195 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6196 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006197 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006198 return false;
6199 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006200 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006201 switch (effectId) {
6202 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006203 pattern = mLongPressVibePattern;
6204 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006205 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006206 pattern = mVirtualKeyVibePattern;
6207 break;
6208 case HapticFeedbackConstants.KEYBOARD_TAP:
6209 pattern = mKeyboardTapVibePattern;
6210 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006211 case HapticFeedbackConstants.CLOCK_TICK:
6212 pattern = mClockTickVibePattern;
6213 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006214 case HapticFeedbackConstants.CALENDAR_DATE:
6215 pattern = mCalendarDateVibePattern;
6216 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006217 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006218 pattern = mSafeModeDisabledVibePattern;
6219 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006220 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006221 pattern = mSafeModeEnabledVibePattern;
6222 break;
Mady Mellore82067b2015-04-30 09:58:35 -07006223 case HapticFeedbackConstants.STYLUS_BUTTON_PRESS:
6224 pattern = mStylusButtonPressVibePattern;
6225 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006226 default:
6227 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006228 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006229 int owningUid;
6230 String owningPackage;
6231 if (win != null) {
6232 owningUid = win.getOwningUid();
6233 owningPackage = win.getOwningPackage();
6234 } else {
6235 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006236 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006237 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006238 if (pattern.length == 1) {
6239 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006240 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006241 } else {
6242 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006243 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006244 }
6245 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006246 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006247
6248 @Override
6249 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006250 }
6251
Jeff Brownc38c9be2012-10-04 13:16:19 -07006252 @Override
6253 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006254 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006255 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006256 }
6257 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006258
Dianne Hackborndf89e652011-10-06 22:35:11 -07006259 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006260 // If there is no window focused, there will be nobody to handle the events
6261 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006262 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6263 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006264 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006265 return 0;
6266 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006267 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006268 // We are updating at a point where the keyguard has gotten
6269 // focus, but we were last in a state where the top window is
6270 // hiding it. This is probably because the keyguard as been
6271 // shown while the top window was displayed, so we want to ignore
6272 // it here because this is just a very transient change and it
6273 // will quickly lose focus once it correctly gets hidden.
6274 return 0;
6275 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006276
John Spurlock1db8b682014-02-18 11:18:59 -05006277 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006278 & ~mResettingSystemUiFlags
6279 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006280 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006281 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006282 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006283 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006284 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006285 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006286 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006287 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006288 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006289 return 0;
6290 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006291 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006292 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006293 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006294 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006295 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006296 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006297 try {
6298 IStatusBarService statusbar = getStatusBarService();
6299 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006300 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006301 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006302 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006303 } catch (RemoteException e) {
6304 // re-acquire status bar service next time it is needed.
6305 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006306 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006307 }
6308 });
6309 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006310 }
6311
Adrian Rooscd3884d2015-02-18 17:25:23 +01006312 private int updateLightStatusBarLw(int vis) {
6313 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6314 ? mStatusBar
6315 : mTopFullscreenOpaqueOrDimmingWindowState;
6316
6317 if (statusColorWin != null) {
6318 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6319 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6320 // its light flag.
6321 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6322 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6323 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6324 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6325 // Otherwise if it's dimming, clear the light flag.
6326 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6327 }
6328 }
6329 return vis;
6330 }
6331
John Spurlock79da8332013-09-20 12:04:47 -04006332 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006333 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006334 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6335 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006336 : mTopFullscreenOpaqueWindowState;
6337 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6338 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6339
John Spurlock27735a42013-08-14 17:57:38 -04006340 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006341 int type = win.getAttrs().type;
6342 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006343 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006344 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6345 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006346 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006347 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6348 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006349 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006350 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6351 }
John Spurlockbd957402013-10-03 11:38:39 -04006352 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006353 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006354
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006355 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006356 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6357 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006358 }
6359
John Spurlock27735a42013-08-14 17:57:38 -04006360 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006361 boolean immersiveSticky =
6362 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006363 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006364 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006365 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006366 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6367 boolean hideStatusBarSysui =
6368 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006369 boolean hideNavBarSysui =
6370 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006371
John Spurlock27735a42013-08-14 17:57:38 -04006372 boolean transientStatusBarAllowed =
6373 mStatusBar != null && (
6374 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006375 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006376 || statusBarHasFocus);
6377
John Spurlockf1a36642013-10-12 17:50:42 -04006378 boolean transientNavBarAllowed =
6379 mNavigationBar != null &&
6380 hideNavBarSysui && immersiveSticky;
6381
Adrian Roosddc8b272015-05-21 16:28:27 -07006382 final long now = SystemClock.uptimeMillis();
6383 final boolean pendingPanic = mPendingPanicGestureUptime != 0
6384 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
6385 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
6386 // The user performed the panic gesture recently, we're about to hide the bars,
6387 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
6388 mPendingPanicGestureUptime = 0;
6389 mStatusBarController.showTransient();
6390 mNavigationBarController.showTransient();
6391 }
6392
John Spurlockf25706f2013-11-07 18:02:43 -05006393 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006394 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006395 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006396 && !transientNavBarAllowed;
6397 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006398 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006399 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006400 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006401 }
John Spurlock27735a42013-08-14 17:57:38 -04006402
Selim Cinekf98702e2015-05-20 22:48:40 -07006403 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
6404 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
6405 final boolean navAllowedHidden = immersive || immersiveSticky;
6406
Selim Cinekd6623612015-05-22 18:56:22 -07006407 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
6408 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07006409 // We can't hide the navbar from this window otherwise the input consumer would not get
6410 // the input events.
6411 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
6412 }
6413
John Spurlock27735a42013-08-14 17:57:38 -04006414 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6415
6416 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006417 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6418 boolean newImmersiveMode = isImmersiveMode(vis);
6419 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006420 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006421 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6422 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006423 }
John Spurlock27735a42013-08-14 17:57:38 -04006424
John Spurlockf1a36642013-10-12 17:50:42 -04006425 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6426
John Spurlocke1f366f2013-08-05 12:22:40 -04006427 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006428 }
6429
John Spurlockf1a36642013-10-12 17:50:42 -04006430 private void clearClearableFlagsLw() {
6431 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6432 if (newVal != mResettingSystemUiFlags) {
6433 mResettingSystemUiFlags = newVal;
6434 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6435 }
6436 }
6437
6438 private boolean isImmersiveMode(int vis) {
6439 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006440 return mNavigationBar != null
6441 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006442 && (vis & flags) != 0
6443 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006444 }
6445
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006446 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006447 * @return whether the navigation or status bar can be made translucent
6448 *
6449 * This should return true unless touch exploration is not enabled or
6450 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006451 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006452 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006453 return mTranslucentDecorEnabled
6454 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006455 }
6456
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006457 // Use this instead of checking config_showNavigationBar so that it can be consistently
6458 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006459 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006460 public boolean hasNavigationBar() {
6461 return mHasNavigationBar;
6462 }
6463
satok1bc0a492012-04-25 22:47:12 +09006464 @Override
6465 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6466 mLastInputMethodWindow = ime;
6467 mLastInputMethodTargetWindow = target;
6468 }
6469
Craig Mautnerf1b67412012-09-19 13:18:29 -07006470 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006471 public int getInputMethodWindowVisibleHeightLw() {
6472 return mDockBottom - mCurBottom;
6473 }
6474
6475 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006476 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006477 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006478 if (mKeyguardDelegate != null) {
6479 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006480 }
John Spurlock13451a22012-09-28 14:40:41 -04006481 if (mStatusBarService != null) {
6482 try {
6483 mStatusBarService.setCurrentUser(newUserId);
6484 } catch (RemoteException e) {
6485 // oh well
6486 }
6487 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006488 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006489 }
6490
6491 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006492 public boolean canMagnifyWindow(int windowType) {
6493 switch (windowType) {
6494 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6495 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6496 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6497 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6498 return false;
6499 }
6500 }
6501 return true;
6502 }
6503
6504 @Override
6505 public boolean isTopLevelWindow(int windowType) {
6506 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6507 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6508 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6509 }
6510 return true;
6511 }
6512
Jim Miller4eeb4f62012-11-08 00:04:29 -08006513 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006514 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006515 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006516 pw.print(" mSystemReady="); pw.print(mSystemReady);
6517 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006518 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006519 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006520 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006521 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006522 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6523 || mForceClearedSystemUiFlags != 0) {
6524 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6525 pw.print(Integer.toHexString(mLastSystemUiFlags));
6526 pw.print(" mResettingSystemUiFlags=0x");
6527 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6528 pw.print(" mForceClearedSystemUiFlags=0x");
6529 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006530 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006531 if (mLastFocusNeedsMenu) {
6532 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6533 pw.println(mLastFocusNeedsMenu);
6534 }
Jeff Browna20dda42014-05-27 20:57:24 -07006535 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6536 pw.println(mWakeGestureEnabledSetting);
6537
Jeff Brownbcdfc622014-03-06 19:13:04 -08006538 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006539 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6540 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006541 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6542 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6543 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6544 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006545 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006546 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006547 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6548 pw.print(mCarDockEnablesAccelerometer);
6549 pw.print(" mDeskDockEnablesAccelerometer=");
6550 pw.println(mDeskDockEnablesAccelerometer);
6551 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6552 pw.print(mLidKeyboardAccessibility);
6553 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006554 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006555 pw.print(prefix);
6556 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6557 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006558 pw.print(prefix);
6559 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6560 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006561 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006562 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6563 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6564 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6565 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6566 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6567 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6568 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006569 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6570 pw.print(","); pw.print(mOverscanScreenTop);
6571 pw.print(") "); pw.print(mOverscanScreenWidth);
6572 pw.print("x"); pw.println(mOverscanScreenHeight);
6573 if (mOverscanLeft != 0 || mOverscanTop != 0
6574 || mOverscanRight != 0 || mOverscanBottom != 0) {
6575 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6576 pw.print(" top="); pw.print(mOverscanTop);
6577 pw.print(" right="); pw.print(mOverscanRight);
6578 pw.print(" bottom="); pw.println(mOverscanBottom);
6579 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006580 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6581 pw.print(mRestrictedOverscanScreenLeft);
6582 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6583 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6584 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006585 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6586 pw.print(","); pw.print(mUnrestrictedScreenTop);
6587 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6588 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6589 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6590 pw.print(","); pw.print(mRestrictedScreenTop);
6591 pw.print(") "); pw.print(mRestrictedScreenWidth);
6592 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006593 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6594 pw.print(","); pw.print(mStableFullscreenTop);
6595 pw.print(")-("); pw.print(mStableFullscreenRight);
6596 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006597 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6598 pw.print(","); pw.print(mStableTop);
6599 pw.print(")-("); pw.print(mStableRight);
6600 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006601 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6602 pw.print(","); pw.print(mSystemTop);
6603 pw.print(")-("); pw.print(mSystemRight);
6604 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006605 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6606 pw.print(","); pw.print(mCurTop);
6607 pw.print(")-("); pw.print(mCurRight);
6608 pw.print(","); pw.print(mCurBottom); pw.println(")");
6609 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6610 pw.print(","); pw.print(mContentTop);
6611 pw.print(")-("); pw.print(mContentRight);
6612 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006613 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6614 pw.print(","); pw.print(mVoiceContentTop);
6615 pw.print(")-("); pw.print(mVoiceContentRight);
6616 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006617 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6618 pw.print(","); pw.print(mDockTop);
6619 pw.print(")-("); pw.print(mDockRight);
6620 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006621 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6622 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006623 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6624 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006625 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6626 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006627 if (mLastInputMethodWindow != null) {
6628 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6629 pw.println(mLastInputMethodWindow);
6630 }
6631 if (mLastInputMethodTargetWindow != null) {
6632 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6633 pw.println(mLastInputMethodTargetWindow);
6634 }
6635 if (mStatusBar != null) {
6636 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006637 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6638 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006639 }
6640 if (mNavigationBar != null) {
6641 pw.print(prefix); pw.print("mNavigationBar=");
6642 pw.println(mNavigationBar);
6643 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006644 if (mFocusedWindow != null) {
6645 pw.print(prefix); pw.print("mFocusedWindow=");
6646 pw.println(mFocusedWindow);
6647 }
6648 if (mFocusedApp != null) {
6649 pw.print(prefix); pw.print("mFocusedApp=");
6650 pw.println(mFocusedApp);
6651 }
6652 if (mWinDismissingKeyguard != null) {
6653 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6654 pw.println(mWinDismissingKeyguard);
6655 }
6656 if (mTopFullscreenOpaqueWindowState != null) {
6657 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6658 pw.println(mTopFullscreenOpaqueWindowState);
6659 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006660 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6661 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6662 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6663 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006664 if (mForcingShowNavBar) {
6665 pw.print(prefix); pw.print("mForcingShowNavBar=");
6666 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6667 pw.println(mForcingShowNavBarLayer);
6668 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006669 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006670 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006671 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6672 pw.print(" mForceStatusBarFromKeyguard=");
6673 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006674 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006675 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006676 pw.print(" mHomePressed="); pw.println(mHomePressed);
6677 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6678 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6679 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6680 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6681 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6682 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6683 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6684 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6685 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6686 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006687 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6688 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6689 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006690
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006691 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006692 mStatusBarController.dump(pw, prefix);
6693 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006694 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006695
Jeff Browna20dda42014-05-27 20:57:24 -07006696 if (mWakeGestureListener != null) {
6697 mWakeGestureListener.dump(pw, prefix);
6698 }
Jeff Brown600f0032014-05-22 17:06:00 -07006699 if (mOrientationListener != null) {
6700 mOrientationListener.dump(pw, prefix);
6701 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006702 if (mBurnInProtectionHelper != null) {
6703 mBurnInProtectionHelper.dump(prefix, pw);
6704 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006705 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006706}