blob: 93e1f187b5434280180b5d9e216d69cf5488630e [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;
Dianne Hackbornb6683c42015-06-18 17:40:33 -070059import android.os.IDeviceIdleController;
Jeff Brown32cbc38552011-12-01 14:01:49 -080060import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070061import android.os.Message;
62import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080063import android.os.PowerManager;
64import android.os.RemoteException;
65import android.os.ServiceManager;
66import android.os.SystemClock;
67import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080068import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070069import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080070import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070071import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080072import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070073import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040074import android.service.dreams.DreamService;
75import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070076import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070077import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070078import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080079import android.util.EventLog;
80import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070081import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080082import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070083import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080084import android.view.Gravity;
85import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080086import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080087import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070088import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070089import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080090import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080091import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080092import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080093import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080094import android.view.KeyEvent;
95import android.view.MotionEvent;
Adam Powell6711f3b2015-05-06 15:57:09 -070096import com.android.internal.policy.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080097import android.view.Surface;
98import android.view.View;
99import android.view.ViewConfiguration;
100import android.view.Window;
101import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800102import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700103import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800104import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800105import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800106import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800107import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200108import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800109import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800110import com.android.internal.R;
Craig Mautnerae446592012-12-06 19:05:05 -0800111import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700112import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800113import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700114import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100115import com.android.server.policy.keyguard.KeyguardServiceDelegate;
116import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800117
118import java.io.File;
119import java.io.FileReader;
120import java.io.IOException;
121import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700122import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800123import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800124
Dianne Hackbornc652de82013-02-15 16:32:56 -0800125import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700126import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
127import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
128import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700129import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
130import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
131import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800132
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800133/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700134 * WindowManagerPolicy implementation for the Android phone UI. This
135 * introduces a new method suffix, Lp, for an internal lock of the
136 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400137 * 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 -0700138 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800139 */
140public class PhoneWindowManager implements WindowManagerPolicy {
141 static final String TAG = "WindowManager";
142 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700143 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700144 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700145 static final boolean DEBUG_KEYGUARD = false;
146 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700147 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700148 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800149 static final boolean SHOW_STARTING_ANIMATIONS = true;
150 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400151
Daniel Sandler6396c722013-04-16 20:19:09 -0400152 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
153 // No longer recommended for desk docks; still useful in car docks.
154 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
155 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
156
Jeff Brown6d8fd272014-05-20 21:24:38 -0700157 static final int SHORT_PRESS_POWER_NOTHING = 0;
158 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
159 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
160 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800161 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700162
Joe Onoratod208e702010-10-08 16:22:43 -0400163 static final int LONG_PRESS_POWER_NOTHING = 0;
164 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
165 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700166 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700167
Jeff Brown13f00f02014-10-31 14:45:50 -0700168 static final int MULTI_PRESS_POWER_NOTHING = 0;
169 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
170 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
171
Michael Jurka3b1fc472011-06-13 10:54:40 -0700172 // These need to match the documentation/constant in
173 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800174 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800175 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700176 static final int LONG_PRESS_HOME_ASSIST = 2;
177
178 static final int DOUBLE_TAP_HOME_NOTHING = 0;
179 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800180
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000181 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
182 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
183
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700184 static final int APPLICATION_MEDIA_SUBLAYER = -2;
185 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800186 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800187 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700188 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700189
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800190 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
191 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
192 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500193 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700194 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800195
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700196 /**
197 * These are the system UI flags that, when changing, can cause the layout
198 * of the screen to change.
199 */
200 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400201 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400202 | View.SYSTEM_UI_FLAG_FULLSCREEN
203 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200204 | View.NAVIGATION_BAR_TRANSLUCENT
205 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700206
John Spurlock7b414672014-07-18 13:02:39 -0400207 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
208 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
209 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
210 .build();
211
Adrian Roosddc8b272015-05-21 16:28:27 -0700212 // The panic gesture may become active only after the keyguard is dismissed and the immersive
213 // app shows again. If that doesn't happen for 30s we drop the gesture.
214 private static final long PANIC_GESTURE_EXPIRATION = 30000;
215
Jim Miller5ecd8112013-01-09 18:50:26 -0800216 /**
217 * Keyguard stuff
218 */
219 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100220 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700221 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800222
Jeff Brown6651a632011-11-28 12:59:11 -0800223 /* Table of Application Launch keys. Maps from key codes to intent categories.
224 *
225 * These are special keys that are used to launch particular kinds of applications,
226 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
227 * usage page. We don't support quite that many yet...
228 */
229 static SparseArray<String> sApplicationLaunchKeyCategories;
230 static {
231 sApplicationLaunchKeyCategories = new SparseArray<String>();
232 sApplicationLaunchKeyCategories.append(
233 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
234 sApplicationLaunchKeyCategories.append(
235 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
236 sApplicationLaunchKeyCategories.append(
237 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
238 sApplicationLaunchKeyCategories.append(
239 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
240 sApplicationLaunchKeyCategories.append(
241 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
242 sApplicationLaunchKeyCategories.append(
243 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
244 }
245
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700246 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000247 static final int WAITING_FOR_DRAWN_TIMEOUT = 500;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700248
Dianne Hackborndf89e652011-10-06 22:35:11 -0700249 /**
250 * Lock protecting internal state. Must not call out into window
251 * manager with lock held. (This lock will be acquired in places
252 * where the window manager is calling in with its own lock held.)
253 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800254 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700255
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800256 Context mContext;
257 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700258 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700259 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700260 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700261 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700262 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400263 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700264 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700265 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800266 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700267 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800268 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000269 BurnInProtectionHelper mBurnInProtectionHelper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800270
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700271 // Vibrator pattern for haptic feedback of a long press.
272 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700273
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700274 // Vibrator pattern for haptic feedback of virtual key press.
275 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700276
Amith Yamasanic33cb712010-02-10 15:21:49 -0800277 // Vibrator pattern for a short vibration.
278 long[] mKeyboardTapVibePattern;
279
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700280 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
281 long[] mClockTickVibePattern;
282
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700283 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
284 long[] mCalendarDateVibePattern;
285
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700286 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
287 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700288
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700289 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
290 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700291
Mady Mellore8608912015-06-05 09:02:55 -0700292 // Vibrator pattern for haptic feedback of a context click.
293 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700294
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800295 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
296 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400297
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800298 boolean mSafeMode;
299 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700300 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400301 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400302 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700303 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400304 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
305 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
306 int[] mNavigationBarHeightForRotation = new int[4];
307 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400308
Craig Mautnera631d492014-08-05 15:16:01 -0700309 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800310 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700311 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700312 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700313 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700314 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
315 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
316 }
317 };
318 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
319 @Override
320 public void onShown(IBinder windowToken) {
321 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
322 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
323 }
324 };
325
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800326 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800327 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900328 WindowState mLastInputMethodWindow = null;
329 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800330
Jeff Brown13f00f02014-10-31 14:45:50 -0700331 // FIXME This state is shared between the input reader and handler thread.
332 // Technically it's broken and buggy but it has been like this for many years
333 // and we have not yet seen any problems. Someday we'll rewrite this logic
334 // so that only one thread is involved in handling input policy. Unfortunately
335 // it's on a critical path for power management so we can't just post the work to the
336 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
337 // to hold wakelocks during dispatch and eliminating the critical path.
338 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800339 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700340 volatile int mPowerKeyPressCounter;
341 volatile boolean mEndCallKeyHandled;
342
Winson Chungd42a6cf2014-06-03 16:24:04 -0700343 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700344 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700345 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800346
Jeff Brown2e7760e2012-04-11 15:14:55 -0700347 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700348 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700349 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800350
Dianne Hackbornc777e072010-02-12 13:07:59 -0800351 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700352 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800353 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700354 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400355 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700356 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700357 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400358 int mCarDockRotation;
359 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700360 int mUndockedHdmiRotation;
361 int mDemoHdmiRotation;
362 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800363 int mDemoRotation;
364 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400365
Jeff Browna20dda42014-05-27 20:57:24 -0700366 boolean mWakeGestureEnabledSetting;
367 MyWakeGestureListener mWakeGestureListener;
368
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700369 // Default display does not rotate, apps that require non-default orientation will have to
370 // have the orientation emulated.
371 private boolean mForceDefaultOrientation = false;
372
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400373 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
374 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700375 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400376
Jeff Brownbcdfc622014-03-06 19:13:04 -0800377 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700378 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400379 boolean mCarDockEnablesAccelerometer;
380 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700381 int mLidKeyboardAccessibility;
382 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700383 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700384 int mShortPressOnPowerBehavior;
385 int mLongPressOnPowerBehavior;
386 int mDoublePressOnPowerBehavior;
387 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000388 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700389 boolean mAwake;
390 boolean mScreenOnEarly;
391 boolean mScreenOnFully;
392 ScreenOnListener mScreenOnListener;
393 boolean mKeyguardDrawComplete;
394 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800395 boolean mOrientationSensorEnabled = false;
396 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800397 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400398 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800399 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700400
Jeff Brown70825162012-03-28 17:27:48 -0700401 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800402
403 // The last window we were told about in focusChanged.
404 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800405 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800406
Jeff Brown70825162012-03-28 17:27:48 -0700407 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800408
Dianne Hackbornc652de82013-02-15 16:32:56 -0800409 // The current size of the screen; really; extends into the overscan area of
410 // the screen and doesn't account for any system elements like the status bar.
411 int mOverscanScreenLeft, mOverscanScreenTop;
412 int mOverscanScreenWidth, mOverscanScreenHeight;
413 // The current visible size of the screen; really; (ir)regardless of whether the status
414 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800415 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
416 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800417 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
418 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
419 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700420 // The current size of the screen; these may be different than (0,0)-(dw,dh)
421 // if the status bar can't be hidden; in that case it effectively carves out
422 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800423 int mRestrictedScreenLeft, mRestrictedScreenTop;
424 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700425 // During layout, the current screen borders accounting for any currently
426 // visible system UI elements.
427 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700428 // For applications requesting stable content insets, these are them.
429 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700430 // For applications requesting stable content insets but have also set the
431 // fullscreen window flag, these are the stable dimensions without the status bar.
432 int mStableFullscreenLeft, mStableFullscreenTop;
433 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800434 // During layout, the current screen borders with all outer decoration
435 // (status bar, input method dock) accounted for.
436 int mCurLeft, mCurTop, mCurRight, mCurBottom;
437 // During layout, the frame in which content should be displayed
438 // to the user, accounting for all screen decoration except for any
439 // space they deem as available for other content. This is usually
440 // the same as mCur*, but may be larger if the screen decor has supplied
441 // content insets.
442 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700443 // During layout, the frame in which voice content should be displayed
444 // to the user, accounting for all screen decoration except for any
445 // space they deem as available for other content.
446 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800447 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800448 // windows are placed.
449 int mDockLeft, mDockTop, mDockRight, mDockBottom;
450 // During layout, the layer at which the doc window is placed.
451 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700452 // During layout, this is the layer of the status bar.
453 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700454 int mLastSystemUiFlags;
455 // Bits that we are in the process of clearing, so we want to prevent
456 // them from being set by applications until everything has been updated
457 // to have them clear.
458 int mResettingSystemUiFlags = 0;
459 // Bits that we are currently always keeping cleared.
460 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800461 // What we last reported to system UI about whether the compatibility
462 // menu needs to be displayed.
463 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700464 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
465 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700466
Selim Cinekf83e8242015-05-19 18:08:14 -0700467 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700468
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800469 static final Rect mTmpParentFrame = new Rect();
470 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800471 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800472 static final Rect mTmpContentFrame = new Rect();
473 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400474 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700475 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700476 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700477 static final Rect mTmpOutsetFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700478
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800479 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100480 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700481 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200482 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400483 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800484 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700485 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700486 private boolean mForceStatusBarTransparent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700487 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800488 boolean mForcingShowNavBar;
489 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700490
491 // States of keyguard dismiss.
492 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
493 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
494 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
495 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
496
497 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
498 * be done once per window. */
499 private WindowState mWinDismissingKeyguard;
500
tingna_sunge785ffa2015-05-12 13:23:15 +0800501 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
502 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
503 * lock SIM card. This variable is used to record the previous keyguard secure state for
504 * monitoring secure state change on window dismissing keyguard. */
505 private boolean mSecureDismissingKeyguard;
506
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700507 /** The window that is currently showing "over" the keyguard. If there is an app window
508 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
509 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
510 * the wallpaper. */
511 private WindowState mWinShowWhenLocked;
512
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700513 boolean mShowingLockscreen;
514 boolean mShowingDream;
515 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700516 boolean mDreamingSleepTokenNeeded;
517 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700518 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700519 boolean mKeyguardSecure;
520 boolean mKeyguardSecureIncludingHidden;
521 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800522 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700523 boolean mHomeConsumed;
524 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800525 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700526 Intent mCarDockIntent;
527 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700528 boolean mSearchKeyShortcutPending;
529 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700530 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700531 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800532
Mike Lockwood28569302010-01-28 11:54:40 -0500533 // support for activating the lock screen while the screen is on
534 boolean mAllowLockscreenWhenOn;
535 int mLockScreenTimeout;
536 boolean mLockScreenTimerActive;
537
David Brownbaf8d092010-03-08 21:52:59 -0800538 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800539 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800540
541 // Behavior of POWER button while in-call and screen on.
542 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
543 int mIncallPowerBehavior;
544
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700545 Display mDisplay;
546
Dianne Hackborn9d132642011-04-21 17:26:39 -0700547 int mLandscapeRotation = 0; // default landscape rotation
548 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
549 int mPortraitRotation = 0; // default portrait rotation
550 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700551
Dianne Hackbornc652de82013-02-15 16:32:56 -0800552 int mOverscanLeft = 0;
553 int mOverscanTop = 0;
554 int mOverscanRight = 0;
555 int mOverscanBottom = 0;
556
Joe Onorato46b0d682010-11-22 17:37:27 -0800557 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700558 private int mLongPressOnHomeBehavior;
559
560 // What we do when the user double-taps on home
561 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800562
Bryce Lee584a4452014-10-21 15:55:55 -0700563 // Allowed theater mode wake actions
564 private boolean mAllowTheaterModeWakeFromKey;
565 private boolean mAllowTheaterModeWakeFromPowerKey;
566 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800567 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700568 private boolean mAllowTheaterModeWakeFromCameraLens;
569 private boolean mAllowTheaterModeWakeFromLidSwitch;
570 private boolean mAllowTheaterModeWakeFromWakeGesture;
571
Bryce Leed3b28402015-03-09 15:49:13 +0000572 // Whether to support long press from power button in non-interactive mode
573 private boolean mSupportLongPressPowerWhenNonInteractive;
574
Bryce Lee55e846d2014-11-04 12:43:44 -0800575 // Whether to go to sleep entering theater mode from power button
576 private boolean mGoToSleepOnButtonPressTheaterMode;
577
Winson Chung9112ec32011-06-27 13:15:32 -0700578 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700579 // Time to volume and power must be pressed within this interval of each other.
580 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700581 // Increase the chord delay when taking a screenshot from the keyguard
582 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800583 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700584 private boolean mScreenshotChordVolumeDownKeyTriggered;
585 private long mScreenshotChordVolumeDownKeyTime;
586 private boolean mScreenshotChordVolumeDownKeyConsumed;
587 private boolean mScreenshotChordVolumeUpKeyTriggered;
588 private boolean mScreenshotChordPowerKeyTriggered;
589 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700590
Michael Wrightb854e242013-02-05 17:54:02 -0800591 /* The number of steps between min and max brightness */
592 private static final int BRIGHTNESS_STEPS = 10;
593
Christopher Tate5e08af02012-09-21 17:17:22 -0700594 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800595 ShortcutManager mShortcutManager;
596 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700597 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700598 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800599
Craig Mautnerd625ab22013-09-06 13:40:31 -0700600 private int mCurrentUserId;
601
Justin Kohd378ad72013-04-01 12:18:26 -0700602 // Maps global key codes to the components that will handle them.
603 private GlobalKeyManager mGlobalKeyManager;
604
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700605 // Fallback actions by key code.
606 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
607 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800608
Jorim Jaggi76a16232014-08-08 17:00:47 +0200609 private final LogDecelerateInterpolator mLogDecelerateInterpolator
610 = new LogDecelerateInterpolator(100, 0);
611
Jeff Brown70825162012-03-28 17:27:48 -0700612 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
613 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700614 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
615 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700616 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
617 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
618 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700619 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700620 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700621 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700622 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700623 private static final int MSG_POWER_DELAYED_PRESS = 13;
624 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700625 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jeff Brown70825162012-03-28 17:27:48 -0700626
627 private class PolicyHandler extends Handler {
628 @Override
629 public void handleMessage(Message msg) {
630 switch (msg.what) {
631 case MSG_ENABLE_POINTER_LOCATION:
632 enablePointerLocation();
633 break;
634 case MSG_DISABLE_POINTER_LOCATION:
635 disablePointerLocation();
636 break;
Jeff Brown40013652012-05-16 21:22:36 -0700637 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
638 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
639 break;
640 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
641 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
642 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700643 case MSG_DISPATCH_SHOW_RECENTS:
644 showRecentApps(false);
645 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700646 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
647 showGlobalActionsInternal();
648 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700649 case MSG_KEYGUARD_DRAWN_COMPLETE:
650 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700651 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700652 break;
653 case MSG_KEYGUARD_DRAWN_TIMEOUT:
654 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700655 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700656 break;
657 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
658 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700659 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700660 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700661 case MSG_HIDE_BOOT_MESSAGE:
662 handleHideBootMessage();
663 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700664 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
665 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
666 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700667 case MSG_POWER_DELAYED_PRESS:
668 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
669 finishPowerKeyPress();
670 break;
671 case MSG_POWER_LONG_PRESS:
672 powerLongPress();
673 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700674 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
675 updateDreamingSleepToken(msg.arg1 != 0);
676 break;
Jeff Brown70825162012-03-28 17:27:48 -0700677 }
678 }
679 }
680
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800681 private UEventObserver mHDMIObserver = new UEventObserver() {
682 @Override
683 public void onUEvent(UEventObserver.UEvent event) {
684 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
685 }
686 };
687
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800688 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800689 SettingsObserver(Handler handler) {
690 super(handler);
691 }
David Brownbaf8d092010-03-08 21:52:59 -0800692
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800693 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700694 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800695 ContentResolver resolver = mContext.getContentResolver();
696 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700697 Settings.System.END_BUTTON_BEHAVIOR), false, this,
698 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800699 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700700 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
701 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700702 resolver.registerContentObserver(Settings.Secure.getUriFor(
703 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
704 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800705 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700706 Settings.System.ACCELEROMETER_ROTATION), false, this,
707 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500708 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700709 Settings.System.USER_ROTATION), false, this,
710 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400711 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700712 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
713 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800714 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700715 Settings.System.POINTER_LOCATION), false, this,
716 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800717 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700718 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
719 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500720 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400721 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700722 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500723 resolver.registerContentObserver(Settings.Global.getUriFor(
724 Settings.Global.POLICY_CONTROL), false, this,
725 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800726 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800727 }
728
729 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800730 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700731 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800732 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800733 }
Craig Mautner967212c2013-04-13 21:10:58 -0700734
Jeff Browna20dda42014-05-27 20:57:24 -0700735 class MyWakeGestureListener extends WakeGestureListener {
736 MyWakeGestureListener(Context context, Handler handler) {
737 super(context, handler);
738 }
739
740 @Override
741 public void onWakeUp() {
742 synchronized (mLock) {
743 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700744 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700745 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700746 }
747 }
748 }
749 }
750
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800751 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800752 MyOrientationListener(Context context, Handler handler) {
753 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800754 }
Craig Mautner967212c2013-04-13 21:10:58 -0700755
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800756 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700757 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700758 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700759 updateRotation(false);
760 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800761 }
762 MyOrientationListener mOrientationListener;
763
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100764 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400765
John Spurlock27735a42013-08-14 17:57:38 -0400766 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400767 View.NAVIGATION_BAR_TRANSIENT,
768 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400769 View.NAVIGATION_BAR_TRANSLUCENT,
770 StatusBarManager.WINDOW_NAVIGATION_BAR,
771 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400772
John Spurlockf1a36642013-10-12 17:50:42 -0400773 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400774
Craig Mautner037aa8d2013-06-07 10:35:44 -0700775 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400776
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700777 IStatusBarService getStatusBarService() {
778 synchronized (mServiceAquireLock) {
779 if (mStatusBarService == null) {
780 mStatusBarService = IStatusBarService.Stub.asInterface(
781 ServiceManager.getService("statusbar"));
782 }
783 return mStatusBarService;
784 }
785 }
786
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700787 /*
788 * We always let the sensor be switched on by default except when
789 * the user has explicitly disabled sensor based rotation or when the
790 * screen is switched off.
791 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700792 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800793 if (mSupportAutoRotation) {
794 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
795 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
796 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
797 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
798 // If the application has explicitly requested to follow the
799 // orientation, then we need to turn the sensor on.
800 return true;
801 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800802 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700803 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800804 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
805 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
806 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400807 // enable accelerometer if we are docked in a dock that enables accelerometer
808 // orientation management,
809 return true;
810 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700811 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800812 // If the setting for using the sensor by default is enabled, then
813 // we will always leave it on. Note that the user could go to
814 // a window that forces an orientation that does not use the
815 // sensor and in theory we could turn it off... however, when next
816 // turning it on we won't have a good value for the current
817 // orientation for a little bit, which can cause orientation
818 // changes to lag, so we'd like to keep it always on. (It will
819 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700820 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800821 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800822 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800823 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700824
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800825 /*
826 * Various use cases for invoking this function
827 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700828 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800829 * if not already enabled
830 * screen turned on and current app does not have sensor orientation, disable listeners if
831 * already enabled
832 * screen turning on and current app has sensor based orientation, enable listeners if needed
833 * screen turning on and current app has nosensor based orientation, do nothing
834 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700835 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800836 if (!mOrientationListener.canDetectOrientation()) {
837 // If sensor is turned off or nonexistent for some reason
838 return;
839 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000840 // Could have been invoked due to screen turning on or off or
841 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -0700842 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
843 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000844 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
845 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
846 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800847 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000848 // Note: We postpone the rotating of the screen until the keyguard as well as the
849 // window manager have reported a draw complete.
850 if (mScreenOnEarly && mAwake &&
851 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700852 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800853 disable = false;
854 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700855 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800856 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700857 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800858 mOrientationSensorEnabled = true;
859 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700860 }
861 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800862 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700863 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800864 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700865 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800866 mOrientationSensorEnabled = false;
867 }
868 }
869
Jeff Brown13f00f02014-10-31 14:45:50 -0700870 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
871 // Hold a wake lock until the power key is released.
872 if (!mPowerKeyWakeLock.isHeld()) {
873 mPowerKeyWakeLock.acquire();
874 }
875
876 // Cancel multi-press detection timeout.
877 if (mPowerKeyPressCounter != 0) {
878 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
879 }
880
881 // Detect user pressing the power button in panic when an application has
882 // taken over the whole screen.
883 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800884 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700885 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700886 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700887 }
888
889 // Latch power key state to detect screenshot chord.
890 if (interactive && !mScreenshotChordPowerKeyTriggered
891 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
892 mScreenshotChordPowerKeyTriggered = true;
893 mScreenshotChordPowerKeyTime = event.getDownTime();
894 interceptScreenshotChord();
895 }
896
897 // Stop ringing or end call if configured to do so when power is pressed.
898 TelecomManager telecomManager = getTelecommService();
899 boolean hungUp = false;
900 if (telecomManager != null) {
901 if (telecomManager.isRinging()) {
902 // Pressing Power while there's a ringing incoming
903 // call should silence the ringer.
904 telecomManager.silenceRinger();
905 } else if ((mIncallPowerBehavior
906 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
907 && telecomManager.isInCall() && interactive) {
908 // Otherwise, if "Power button ends call" is enabled,
909 // the Power button will hang up any current active call.
910 hungUp = telecomManager.endCall();
911 }
912 }
913
914 // If the power key has still not yet been handled, then detect short
915 // press, long press, or multi press and decide what to do.
916 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
917 || mScreenshotChordVolumeUpKeyTriggered;
918 if (!mPowerKeyHandled) {
919 if (interactive) {
920 // When interactive, we're already awake.
921 // Wait for a long press or for the button to be released to decide what to do.
922 if (hasLongPressOnPowerBehavior()) {
923 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
924 msg.setAsynchronous(true);
925 mHandler.sendMessageDelayed(msg,
926 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
927 }
928 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800929 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800930
Bryce Leed3b28402015-03-09 15:49:13 +0000931 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
932 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
933 msg.setAsynchronous(true);
934 mHandler.sendMessageDelayed(msg,
935 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800936 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000937 } else {
938 final int maxCount = getMaxMultiPressPowerCount();
939
940 if (maxCount <= 1) {
941 mPowerKeyHandled = true;
942 } else {
943 mBeganFromNonInteractive = true;
944 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700945 }
946 }
Jeff Brown4d396052010-10-29 21:50:21 -0700947 }
948 }
949
Jeff Brown13f00f02014-10-31 14:45:50 -0700950 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
951 final boolean handled = canceled || mPowerKeyHandled;
952 mScreenshotChordPowerKeyTriggered = false;
953 cancelPendingScreenshotChordAction();
954 cancelPendingPowerKeyAction();
955
956 if (!handled) {
957 // Figure out how to handle the key now that it has been released.
958 mPowerKeyPressCounter += 1;
959
960 final int maxCount = getMaxMultiPressPowerCount();
961 final long eventTime = event.getDownTime();
962 if (mPowerKeyPressCounter < maxCount) {
963 // This could be a multi-press. Wait a little bit longer to confirm.
964 // Continue holding the wake lock.
965 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
966 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
967 msg.setAsynchronous(true);
968 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
969 return;
970 }
971
972 // No other actions. Handle it immediately.
973 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700974 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700975
976 // Done. Reset our state.
977 finishPowerKeyPress();
978 }
979
980 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800981 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700982 mPowerKeyPressCounter = 0;
983 if (mPowerKeyWakeLock.isHeld()) {
984 mPowerKeyWakeLock.release();
985 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700986 }
987
988 private void cancelPendingPowerKeyAction() {
989 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700990 mPowerKeyHandled = true;
991 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700992 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700993 }
994
995 private void powerPress(long eventTime, boolean interactive, int count) {
996 if (mScreenOnEarly && !mScreenOnFully) {
997 Slog.i(TAG, "Suppressed redundant power key press while "
998 + "already in the process of turning the screen on.");
999 return;
Jeff Brownff204712011-10-25 21:27:54 -07001000 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001001
1002 if (count == 2) {
1003 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1004 } else if (count == 3) {
1005 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001006 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001007 switch (mShortPressOnPowerBehavior) {
1008 case SHORT_PRESS_POWER_NOTHING:
1009 break;
1010 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1011 mPowerManager.goToSleep(eventTime,
1012 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1013 break;
1014 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1015 mPowerManager.goToSleep(eventTime,
1016 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1017 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1018 break;
1019 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1020 mPowerManager.goToSleep(eventTime,
1021 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1022 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1023 launchHomeFromHotKey();
1024 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001025 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001026 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001027 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001028 }
1029 }
1030 }
1031
1032 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1033 switch (behavior) {
1034 case MULTI_PRESS_POWER_NOTHING:
1035 break;
1036 case MULTI_PRESS_POWER_THEATER_MODE:
1037 if (isTheaterModeEnabled()) {
1038 Slog.i(TAG, "Toggling theater mode off.");
1039 Settings.Global.putInt(mContext.getContentResolver(),
1040 Settings.Global.THEATER_MODE_ON, 0);
1041 if (!interactive) {
1042 wakeUpFromPowerKey(eventTime);
1043 }
1044 } else {
1045 Slog.i(TAG, "Toggling theater mode on.");
1046 Settings.Global.putInt(mContext.getContentResolver(),
1047 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001048
1049 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001050 mPowerManager.goToSleep(eventTime,
1051 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1052 }
1053 }
1054 break;
1055 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001056 Slog.i(TAG, "Starting brightness boost.");
1057 if (!interactive) {
1058 wakeUpFromPowerKey(eventTime);
1059 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001060 mPowerManager.boostScreenBrightness(eventTime);
1061 break;
1062 }
1063 }
1064
1065 private int getMaxMultiPressPowerCount() {
1066 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1067 return 3;
1068 }
1069 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1070 return 2;
1071 }
1072 return 1;
1073 }
1074
1075 private void powerLongPress() {
1076 final int behavior = getResolvedLongPressOnPowerBehavior();
1077 switch (behavior) {
1078 case LONG_PRESS_POWER_NOTHING:
1079 break;
1080 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1081 mPowerKeyHandled = true;
1082 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1083 performAuditoryFeedbackForAccessibilityIfNeed();
1084 }
1085 showGlobalActionsInternal();
1086 break;
1087 case LONG_PRESS_POWER_SHUT_OFF:
1088 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1089 mPowerKeyHandled = true;
1090 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1091 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1092 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1093 break;
1094 }
1095 }
1096
Nick Vaccarob593a812015-05-15 11:23:05 -07001097 private void sleepPress(long eventTime) {
1098 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1099 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1100 }
1101 }
1102
1103 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001104 switch (mShortPressOnSleepBehavior) {
1105 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001106 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001107 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1108 mPowerManager.goToSleep(eventTime,
1109 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001110 break;
1111 }
1112 }
1113
Jeff Brown13f00f02014-10-31 14:45:50 -07001114 private int getResolvedLongPressOnPowerBehavior() {
1115 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1116 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1117 }
1118 return mLongPressOnPowerBehavior;
1119 }
1120
1121 private boolean hasLongPressOnPowerBehavior() {
1122 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001123 }
1124
1125 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001126 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001127 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1128 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001129 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001130 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1131 && now <= mScreenshotChordPowerKeyTime
1132 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1133 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001134 cancelPendingPowerKeyAction();
1135
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001136 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001137 }
1138 }
1139 }
1140
Winson Chung1cea2f32012-10-08 20:42:01 -07001141 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001142 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001143 // Double the time it takes to take a screenshot from the keyguard
1144 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001145 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001146 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001147 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001148 }
1149
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001150 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001151 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001152 }
1153
Jeff Brown13f00f02014-10-31 14:45:50 -07001154 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001155 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001156 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001157 mEndCallKeyHandled = true;
1158 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1159 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001160 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001161 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001162 }
1163 };
1164
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001165 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001166 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001167 public void run() {
1168 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001169 }
1170 };
1171
Alan Viverettee34560b22014-07-10 14:50:06 -07001172 @Override
1173 public void showGlobalActions() {
1174 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1175 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1176 }
1177
1178 void showGlobalActionsInternal() {
1179 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001180 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001181 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001182 }
Jim Millerab954542014-10-10 18:21:49 -07001183 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001184 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1185 if (keyguardShowing) {
1186 // since it took two seconds of long press to bring this up,
1187 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001188 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001189 }
1190 }
1191
1192 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001193 return Settings.Global.getInt(
1194 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001195 }
1196
Maurice Lam99c6e072014-04-28 18:24:28 -07001197 boolean isUserSetupComplete() {
1198 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1199 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1200 }
1201
Jeff Brown13f00f02014-10-31 14:45:50 -07001202 private void handleShortPressOnHome() {
1203 // If there's a dream running then use home to escape the dream
1204 // but don't actually go home.
1205 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1206 mDreamManagerInternal.stopDream(false /*immediate*/);
1207 return;
1208 }
1209
1210 // Go home!
1211 launchHomeFromHotKey();
1212 }
1213
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001214 private void handleLongPressOnHome(int deviceId) {
Joe Onorato46b0d682010-11-22 17:37:27 -08001215 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001216 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001217 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001218
Jeff Browncaca8812013-05-09 13:34:33 -07001219 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1220 toggleRecentApps();
1221 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001222 launchAssistAction(null, deviceId);
Jim Millere6ad1a82010-08-20 19:25:39 -07001223 }
1224 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001225 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001226
Jeff Browncaca8812013-05-09 13:34:33 -07001227 private void handleDoubleTapOnHome() {
1228 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1229 mHomeConsumed = true;
1230 toggleRecentApps();
1231 }
1232 }
1233
1234 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1235 @Override
1236 public void run() {
1237 if (mHomeDoubleTapPending) {
1238 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001239 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001240 }
1241 }
1242 };
1243
Mark Renoufc1256912015-03-11 14:38:23 -04001244 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001245 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001246 }
1247
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001248 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001249 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001250 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001251 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001252 mContext = context;
1253 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001254 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001255 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001256 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001257 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Mark Renoufc1256912015-03-11 14:38:23 -04001258
1259 // Init display burn-in protection
1260 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1261 com.android.internal.R.bool.config_enableBurnInProtection);
1262 // Allow a system property to override this. Used by developer settings.
1263 boolean burnInProtectionDevMode =
1264 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1265 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1266 final int minHorizontal;
1267 final int maxHorizontal;
1268 final int minVertical;
1269 final int maxVertical;
1270 final int maxRadius;
1271 if (burnInProtectionDevMode) {
1272 minHorizontal = -8;
1273 maxHorizontal = 8;
1274 minVertical = -8;
1275 maxVertical = -4;
1276 maxRadius = (isRoundWindow()) ? 6 : -1;
1277 } else {
1278 Resources resources = context.getResources();
1279 minHorizontal = resources.getInteger(
1280 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1281 maxHorizontal = resources.getInteger(
1282 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1283 minVertical = resources.getInteger(
1284 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1285 maxVertical = resources.getInteger(
1286 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1287 maxRadius = resources.getInteger(
1288 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1289 }
1290 mBurnInProtectionHelper = new BurnInProtectionHelper(
1291 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001292 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001293
Jeff Brown70825162012-03-28 17:27:48 -07001294 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001295 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001296 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001297 try {
1298 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1299 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001300 mSettingsObserver = new SettingsObserver(mHandler);
1301 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001302 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001303 mUiMode = context.getResources().getInteger(
1304 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001305 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1306 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1307 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1308 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001309 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1310 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1311 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1312 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1313 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1314 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1315 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1316 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001317
Jeff Brown96307042012-07-27 15:51:34 -07001318 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1319 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001320 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001321 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1322 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001323 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001324 mSupportAutoRotation = mContext.getResources().getBoolean(
1325 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001326 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001327 com.android.internal.R.integer.config_lidOpenRotation);
1328 mCarDockRotation = readRotation(
1329 com.android.internal.R.integer.config_carDockRotation);
1330 mDeskDockRotation = readRotation(
1331 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001332 mUndockedHdmiRotation = readRotation(
1333 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001334 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1335 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1336 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1337 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001338 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1339 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1340 mLidNavigationAccessibility = mContext.getResources().getInteger(
1341 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001342 mLidControlsSleep = mContext.getResources().getBoolean(
1343 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001344 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1345 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001346
1347 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1348 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1349 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1350 || mContext.getResources().getBoolean(
1351 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1352 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1353 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001354 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1355 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001356 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1357 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1358 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1359 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1360 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1361 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1362
Bryce Lee55e846d2014-11-04 12:43:44 -08001363 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1364 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1365
Bryce Leed3b28402015-03-09 15:49:13 +00001366 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1367 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1368
Jeff Brown13f00f02014-10-31 14:45:50 -07001369 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1370 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1371 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1372 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1373 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1374 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1375 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1376 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001377 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1378 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001379
John Spurlock61560172015-02-06 19:46:04 -05001380 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001381
Jeff Brownf71343d2013-05-31 17:59:11 -07001382 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001383
Svetoslav8e3feb12014-02-24 13:46:47 -08001384 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1385 Context.ACCESSIBILITY_SERVICE);
1386
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001387 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001388 IntentFilter filter = new IntentFilter();
1389 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1390 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1391 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1392 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001393 filter.addAction(Intent.ACTION_DOCK_EVENT);
1394 Intent intent = context.registerReceiver(mDockReceiver, filter);
1395 if (intent != null) {
1396 // Retrieve current sticky dock event broadcast.
1397 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1398 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1399 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001400
Jeff Brown6aaf2952012-10-05 16:01:08 -07001401 // register for dream-related broadcasts
1402 filter = new IntentFilter();
1403 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1404 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1405 context.registerReceiver(mDreamReceiver, filter);
1406
Christopher Tate5e08af02012-09-21 17:17:22 -07001407 // register for multiuser-relevant broadcasts
1408 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1409 context.registerReceiver(mMultiuserReceiver, filter);
1410
John Spurlock57306e62013-04-22 09:48:49 -04001411 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001412 mSystemGestures = new SystemGesturesPointerEventListener(context,
1413 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001414 @Override
1415 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001416 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001417 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001418 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001419 }
1420 @Override
1421 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001422 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001423 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001424 }
1425 }
1426 @Override
1427 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001428 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001429 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001430 }
1431 }
1432 @Override
1433 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001434 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001435 }
Adrian Roos3595be42015-03-05 16:31:15 +01001436 @Override
1437 public void onDown() {
1438 mOrientationListener.onTouchStart();
1439 }
1440 @Override
1441 public void onUpOrCancel() {
1442 mOrientationListener.onTouchEnd();
1443 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001444 });
John Spurlockf1a36642013-10-12 17:50:42 -04001445 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001446 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001447
Jeff Brownc2346132012-04-13 01:55:38 -07001448 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001449 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1450 com.android.internal.R.array.config_longPressVibePattern);
1451 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1452 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001453 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1454 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001455 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1456 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001457 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1458 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001459 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1460 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1461 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1462 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001463 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1464 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001465
Christopher Tatee90585f2012-03-05 18:56:25 -08001466 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1467 com.android.internal.R.bool.config_enableScreenshotChord);
1468
Justin Kohd378ad72013-04-01 12:18:26 -07001469 mGlobalKeyManager = new GlobalKeyManager(mContext);
1470
Joe Onoratoea495d42011-04-06 11:41:11 -07001471 // Controls rotation and the like.
1472 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001473
1474 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001475 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001476 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1477 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001478 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001479
1480 mWindowManagerInternal.registerAppTransitionListener(
1481 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001482 }
1483
Jeff Brownf71343d2013-05-31 17:59:11 -07001484 /**
1485 * Read values from config.xml that may be overridden depending on
1486 * the configuration of the device.
1487 * eg. Disable long press on home goes to recents on sw600dp.
1488 */
1489 private void readConfigurationDependentBehaviors() {
1490 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1491 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1492 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1493 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1494 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1495 }
1496
1497 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1498 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1499 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1500 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1501 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1502 }
1503 }
1504
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001505 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001506 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001507 // This method might be called before the policy has been fully initialized
1508 // or for other displays we don't care about.
1509 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1510 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001511 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001512 mDisplay = display;
1513
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001514 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001515 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001516 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001517 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001518 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001519 mLandscapeRotation = Surface.ROTATION_0;
1520 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001521 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001522 mPortraitRotation = Surface.ROTATION_90;
1523 mUpsideDownRotation = Surface.ROTATION_270;
1524 } else {
1525 mPortraitRotation = Surface.ROTATION_270;
1526 mUpsideDownRotation = Surface.ROTATION_90;
1527 }
1528 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001529 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001530 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001531 mPortraitRotation = Surface.ROTATION_0;
1532 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001533 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001534 mLandscapeRotation = Surface.ROTATION_270;
1535 mSeascapeRotation = Surface.ROTATION_90;
1536 } else {
1537 mLandscapeRotation = Surface.ROTATION_90;
1538 mSeascapeRotation = Surface.ROTATION_270;
1539 }
1540 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001541
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001542 mStatusBarHeight =
1543 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001544
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001545 // Height of the navigation bar when presented horizontally at bottom
1546 mNavigationBarHeightForRotation[mPortraitRotation] =
1547 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001548 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001549 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001550 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1551 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001552
1553 // Width of the navigation bar when presented vertically along one side
1554 mNavigationBarWidthForRotation[mPortraitRotation] =
1555 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1556 mNavigationBarWidthForRotation[mLandscapeRotation] =
1557 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001558 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001559
1560 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001561 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001562 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001563
Devin Kimd7b12b42014-05-05 14:34:58 -07001564 // Allow the navigation bar to move on non-square small devices (phones).
1565 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001566
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001567 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001568 // Allow a system property to override this. Used by the emulator.
1569 // See also hasNavigationBar().
1570 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1571 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001572 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001573 } else if ("0".equals(navBarOverride)) {
1574 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001575 }
1576
Jeff Brown27f1d672012-10-17 18:32:34 -07001577 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1578 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001579 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001580 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001581 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001582 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001583 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001584 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001585
Chong Zhangae6119ff2014-11-11 18:54:39 -08001586 // For demo purposes, allow the rotation of the remote display to be controlled.
1587 // By default, remote display locks rotation to landscape.
1588 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1589 mDemoRotation = mPortraitRotation;
1590 } else {
1591 mDemoRotation = mLandscapeRotation;
1592 }
1593 mDemoRotationLock = SystemProperties.getBoolean(
1594 "persist.demo.rotationlock", false);
1595
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001596 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1597 // http://developer.android.com/guide/practices/screens_support.html#range
1598 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1599 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1600 // For debug purposes the next line turns this feature off with:
1601 // $ adb shell setprop config.override_forced_orient true
1602 // $ adb shell wm size reset
1603 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1604 }
1605
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001606 /**
1607 * @return whether the navigation bar can be hidden, e.g. the device has a
1608 * navigation bar and touch exploration is not enabled
1609 */
1610 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001611 return mHasNavigationBar
1612 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001613 }
1614
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001615 @Override
1616 public boolean isDefaultOrientationForced() {
1617 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001618 }
1619
Dianne Hackbornc652de82013-02-15 16:32:56 -08001620 @Override
1621 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1622 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1623 mOverscanLeft = left;
1624 mOverscanTop = top;
1625 mOverscanRight = right;
1626 mOverscanBottom = bottom;
1627 }
1628 }
1629
Dianne Hackbornc777e072010-02-12 13:07:59 -08001630 public void updateSettings() {
1631 ContentResolver resolver = mContext.getContentResolver();
1632 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001633 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001634 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001635 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001636 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1637 UserHandle.USER_CURRENT);
1638 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001639 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001640 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1641 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001642
Jeff Browna20dda42014-05-27 20:57:24 -07001643 // Configure wake gesture.
1644 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1645 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1646 UserHandle.USER_CURRENT) != 0;
1647 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1648 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1649 updateWakeGestureListenerLp();
1650 }
1651
Jeff Brown207673cd2012-06-05 17:47:11 -07001652 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001653 int userRotation = Settings.System.getIntForUser(resolver,
1654 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1655 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001656 if (mUserRotation != userRotation) {
1657 mUserRotation = userRotation;
1658 updateRotation = true;
1659 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001660 int userRotationMode = Settings.System.getIntForUser(resolver,
1661 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001662 WindowManagerPolicy.USER_ROTATION_FREE :
1663 WindowManagerPolicy.USER_ROTATION_LOCKED;
1664 if (mUserRotationMode != userRotationMode) {
1665 mUserRotationMode = userRotationMode;
1666 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001667 updateOrientationListenerLp();
1668 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001669
Dianne Hackbornc777e072010-02-12 13:07:59 -08001670 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001671 int pointerLocation = Settings.System.getIntForUser(resolver,
1672 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001673 if (mPointerLocationMode != pointerLocation) {
1674 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001675 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1676 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001677 }
1678 }
1679 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001680 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1681 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1682 String imId = Settings.Secure.getStringForUser(resolver,
1683 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001684 boolean hasSoftInput = imId != null && imId.length() > 0;
1685 if (mHasSoftInput != hasSoftInput) {
1686 mHasSoftInput = hasSoftInput;
1687 updateRotation = true;
1688 }
John Spurlockf1a36642013-10-12 17:50:42 -04001689 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001690 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001691 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001692 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001693 }
1694 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001695 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001696 }
Jeff Brown70825162012-03-28 17:27:48 -07001697 }
1698
Jeff Browna20dda42014-05-27 20:57:24 -07001699 private void updateWakeGestureListenerLp() {
1700 if (shouldEnableWakeGestureLp()) {
1701 mWakeGestureListener.requestWakeUpTrigger();
1702 } else {
1703 mWakeGestureListener.cancelWakeUpTrigger();
1704 }
1705 }
1706
1707 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001708 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001709 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1710 && mWakeGestureListener.isSupported();
1711 }
1712
Jeff Brown70825162012-03-28 17:27:48 -07001713 private void enablePointerLocation() {
1714 if (mPointerLocationView == null) {
1715 mPointerLocationView = new PointerLocationView(mContext);
1716 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001717 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1718 WindowManager.LayoutParams.MATCH_PARENT,
1719 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001720 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001721 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1722 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1723 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1724 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001725 if (ActivityManager.isHighEndGfx()) {
1726 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1727 lp.privateFlags |=
1728 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1729 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001730 lp.format = PixelFormat.TRANSLUCENT;
1731 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001732 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001733 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001734 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001735 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001736 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001737 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001738 }
Jeff Brown70825162012-03-28 17:27:48 -07001739
1740 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001741 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001742 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1743 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001744 wm.removeView(mPointerLocationView);
1745 mPointerLocationView = null;
1746 }
1747 }
1748
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001749 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001750 try {
1751 int rotation = mContext.getResources().getInteger(resID);
1752 switch (rotation) {
1753 case 0:
1754 return Surface.ROTATION_0;
1755 case 90:
1756 return Surface.ROTATION_90;
1757 case 180:
1758 return Surface.ROTATION_180;
1759 case 270:
1760 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001761 }
1762 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001763 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001764 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001765 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001766 }
1767
1768 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001769 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001770 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001771 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001772
1773 outAppOp[0] = AppOpsManager.OP_NONE;
1774
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001775 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1776 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1777 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1778 return WindowManagerGlobal.ADD_INVALID_TYPE;
1779 }
1780
1781 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1782 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001783 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001784 }
1785 String permission = null;
1786 switch (type) {
1787 case TYPE_TOAST:
1788 // XXX right now the app process has complete control over
1789 // this... should introduce a token to let the system
1790 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001791 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001792 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001793 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001794 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001795 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001796 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001797 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001798 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001799 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001800 break;
1801 case TYPE_PHONE:
1802 case TYPE_PRIORITY_PHONE:
1803 case TYPE_SYSTEM_ALERT:
1804 case TYPE_SYSTEM_ERROR:
1805 case TYPE_SYSTEM_OVERLAY:
1806 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001807 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001808 break;
1809 default:
1810 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1811 }
1812 if (permission != null) {
1813 if (mContext.checkCallingOrSelfPermission(permission)
1814 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001815 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001816 }
1817 }
Jeff Brown98365d72012-08-19 20:30:52 -07001818 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001819 }
Craig Mautner88400d32012-09-30 12:35:45 -07001820
1821 @Override
1822 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1823
1824 // If this switch statement is modified, modify the comment in the declarations of
1825 // the type in {@link WindowManager.LayoutParams} as well.
1826 switch (attrs.type) {
1827 default:
1828 // These are the windows that by default are shown only to the user that created
1829 // them. If this needs to be overridden, set
1830 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1831 // {@link WindowManager.LayoutParams}. Note that permission
1832 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1833 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1834 return true;
1835 }
1836 break;
1837
1838 // These are the windows that by default are shown to all users. However, to
1839 // protect against spoofing, check permissions below.
1840 case TYPE_APPLICATION_STARTING:
1841 case TYPE_BOOT_PROGRESS:
1842 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07001843 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001844 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001845 case TYPE_KEYGUARD_DIALOG:
1846 case TYPE_MAGNIFICATION_OVERLAY:
1847 case TYPE_NAVIGATION_BAR:
1848 case TYPE_NAVIGATION_BAR_PANEL:
1849 case TYPE_PHONE:
1850 case TYPE_POINTER:
1851 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001852 case TYPE_SEARCH_BAR:
1853 case TYPE_STATUS_BAR:
1854 case TYPE_STATUS_BAR_PANEL:
1855 case TYPE_STATUS_BAR_SUB_PANEL:
1856 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001857 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001858 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001859 break;
1860 }
1861
1862 // Check if third party app has set window to system window type.
1863 return mContext.checkCallingOrSelfPermission(
1864 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1865 != PackageManager.PERMISSION_GRANTED;
1866 }
1867
Craig Mautner967212c2013-04-13 21:10:58 -07001868 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001869 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1870 switch (attrs.type) {
1871 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001872 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001873 // These types of windows can't receive input events.
1874 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1875 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001876 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001877 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001878 case TYPE_STATUS_BAR:
1879
1880 // If the Keyguard is in a hidden state (occluded by another window), we force to
1881 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1882 // the keyguard as occluded wouldn't set these flags again.
1883 // See {@link #processKeyguardSetHiddenResultLw}.
1884 if (mKeyguardHidden) {
1885 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1886 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1887 }
1888 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001889 }
Adrian Roos38502112014-04-09 21:04:11 +02001890
1891 if (attrs.type != TYPE_STATUS_BAR) {
1892 // The status bar is the only window allowed to exhibit keyguard behavior.
1893 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1894 }
Adrian Roosea562512014-05-05 13:33:03 +02001895
1896 if (ActivityManager.isHighEndGfx()
1897 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001898 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001899 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1900 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001901 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001902
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001903 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001904 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001905 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001906
Michael Wright3818c922014-09-02 13:59:07 -07001907 private void readCameraLensCoverState() {
1908 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1909 }
1910
Jeff Browndaa37532012-05-01 15:54:03 -07001911 private boolean isHidden(int accessibilityMode) {
1912 switch (accessibilityMode) {
1913 case 1:
1914 return mLidState == LID_CLOSED;
1915 case 2:
1916 return mLidState == LID_OPEN;
1917 default:
1918 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001919 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001920 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001921
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001922 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001923 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001924 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1925 int navigationPresence) {
1926 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1927
Jeff Brownf71343d2013-05-31 17:59:11 -07001928 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001929 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001930 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001931
Jeff Browndaa37532012-05-01 15:54:03 -07001932 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1933 || (keyboardPresence == PRESENCE_INTERNAL
1934 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001935 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001936 if (!mHasSoftInput) {
1937 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1938 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001939 }
1940
Jeff Browndaa37532012-05-01 15:54:03 -07001941 if (config.navigation == Configuration.NAVIGATION_NONAV
1942 || (navigationPresence == PRESENCE_INTERNAL
1943 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001944 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001945 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001946 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001947
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001948 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001949 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001950 public int windowTypeToLayerLw(int type) {
1951 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001952 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001953 }
1954 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001955 case TYPE_PRIVATE_PRESENTATION:
1956 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001957 case TYPE_WALLPAPER:
1958 // wallpaper is at the bottom, though the window manager may move it.
1959 return 2;
1960 case TYPE_PHONE:
1961 return 3;
1962 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07001963 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001964 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001965 case TYPE_VOICE_INTERACTION:
1966 // voice interaction layer is almost immediately above apps.
1967 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07001968 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001969 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07001970 case TYPE_SYSTEM_DIALOG:
1971 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001972 case TYPE_TOAST:
1973 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07001974 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001975 case TYPE_PRIORITY_PHONE:
1976 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07001977 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001978 case TYPE_DREAM:
1979 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07001980 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001981 case TYPE_SYSTEM_ALERT:
1982 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07001983 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001984 case TYPE_INPUT_METHOD:
1985 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07001986 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001987 case TYPE_INPUT_METHOD_DIALOG:
1988 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07001989 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08001990 case TYPE_KEYGUARD_SCRIM:
1991 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001992 return 14;
Selim Cinekf83e8242015-05-19 18:08:14 -07001993 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001994 return 15;
Selim Cinekf83e8242015-05-19 18:08:14 -07001995 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001996 return 16;
Selim Cinekf83e8242015-05-19 18:08:14 -07001997 case TYPE_STATUS_BAR_PANEL:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001998 return 17;
Selim Cinekf83e8242015-05-19 18:08:14 -07001999 case TYPE_KEYGUARD_DIALOG:
2000 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002001 case TYPE_VOLUME_OVERLAY:
2002 // the on-screen volume indicator and controller shown when the user
2003 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07002004 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002005 case TYPE_SYSTEM_OVERLAY:
2006 // the on-screen volume indicator and controller shown when the user
2007 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07002008 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002009 case TYPE_NAVIGATION_BAR:
2010 // the navigation bar, if available, shows atop most things
Selim Cinekf83e8242015-05-19 18:08:14 -07002011 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002012 case TYPE_NAVIGATION_BAR_PANEL:
2013 // some panels (e.g. search) need to show on top of the navigation bar
Selim Cinekf83e8242015-05-19 18:08:14 -07002014 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002015 case TYPE_SYSTEM_ERROR:
2016 // system-level error dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002017 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002018 case TYPE_MAGNIFICATION_OVERLAY:
2019 // used to highlight the magnified portion of a display
Selim Cinekf83e8242015-05-19 18:08:14 -07002020 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002021 case TYPE_DISPLAY_OVERLAY:
2022 // used to simulate secondary display devices
Selim Cinekf83e8242015-05-19 18:08:14 -07002023 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002024 case TYPE_DRAG:
2025 // the drag layer: input for drag-and-drop is associated with this window,
2026 // which sits above all other focusable windows
Selim Cinekf83e8242015-05-19 18:08:14 -07002027 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002028 case TYPE_ACCESSIBILITY_OVERLAY:
2029 // overlay put by accessibility services to intercept user interaction
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002030 return 27;
Selim Cinekf83e8242015-05-19 18:08:14 -07002031 case TYPE_SECURE_SYSTEM_OVERLAY:
Svetoslav3a5c7212014-10-14 09:54:26 -07002032 return 28;
Selim Cinekf83e8242015-05-19 18:08:14 -07002033 case TYPE_BOOT_PROGRESS:
2034 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002035 case TYPE_POINTER:
2036 // the (mouse) pointer layer
Svetoslav3a5c7212014-10-14 09:54:26 -07002037 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002038 }
2039 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002040 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002041 }
2042
2043 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002044 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002045 public int subWindowTypeToLayerLw(int type) {
2046 switch (type) {
2047 case TYPE_APPLICATION_PANEL:
2048 case TYPE_APPLICATION_ATTACHED_DIALOG:
2049 return APPLICATION_PANEL_SUBLAYER;
2050 case TYPE_APPLICATION_MEDIA:
2051 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002052 case TYPE_APPLICATION_MEDIA_OVERLAY:
2053 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002054 case TYPE_APPLICATION_SUB_PANEL:
2055 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002056 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2057 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002058 }
2059 Log.e(TAG, "Unknown sub-window type: " + type);
2060 return 0;
2061 }
2062
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002063 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002064 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002065 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002066 }
2067
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002068 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002069 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002070 if (mHasNavigationBar) {
2071 // For a basic navigation bar, when we are in landscape mode we place
2072 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002073 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2074 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002075 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002076 }
2077 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002078 }
2079
Jose Lima9546b202014-07-02 17:21:51 -07002080 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002081 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002082 if (mHasNavigationBar) {
2083 // For a basic navigation bar, when we are in portrait mode we place
2084 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002085 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2086 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002087 }
2088 }
2089 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002090 }
2091
Jose Lima9546b202014-07-02 17:21:51 -07002092 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002093 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2094 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002095 }
2096
Jose Lima9546b202014-07-02 17:21:51 -07002097 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002098 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002099 // There is a separate status bar at the top of the display. We don't count that as part
2100 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002101 // we do want to exclude it since applications can't generally use that part
2102 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002103 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002104 }
2105
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002106 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002107 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2108 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002109 (isKeyguardHostWindow(attrs) &&
2110 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002111 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002112 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002113
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002114 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002115 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2116 return attrs.type == TYPE_STATUS_BAR;
2117 }
2118
2119 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002120 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002121 switch (attrs.type) {
2122 case TYPE_STATUS_BAR:
2123 case TYPE_NAVIGATION_BAR:
2124 case TYPE_WALLPAPER:
2125 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002126 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002127 return false;
2128 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002129 // Hide only windows below the keyguard host window.
2130 return windowTypeToLayerLw(win.getBaseType())
2131 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002132 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002133 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002134
Craig Mautner7d7808f2014-09-11 18:02:38 -07002135 @Override
2136 public WindowState getWinShowWhenLockedLw() {
2137 return mWinShowWhenLocked;
2138 }
2139
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002140 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002141 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002142 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2143 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002144 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002145 if (!SHOW_STARTING_ANIMATIONS) {
2146 return null;
2147 }
2148 if (packageName == null) {
2149 return null;
2150 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002151
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002152 WindowManager wm = null;
2153 View view = null;
2154
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002155 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002156 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002157 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2158 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2159 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002160 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002161 try {
2162 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002163 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002164 } catch (PackageManager.NameNotFoundException e) {
2165 // Ignore
2166 }
2167 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002168
Jorim Jaggia16cc152015-06-01 16:55:05 -07002169 PhoneWindow win = new PhoneWindow(context);
2170 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002171 final TypedArray ta = win.getWindowStyle();
2172 if (ta.getBoolean(
2173 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2174 || ta.getBoolean(
2175 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002176 return null;
2177 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002178
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002179 Resources r = context.getResources();
2180 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002181
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002182 win.setType(
2183 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002184
2185 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2186 // Assumes it's safe to show starting windows of launched apps while
2187 // the keyguard is being hidden. This is okay because starting windows never show
2188 // secret information.
2189 if (mKeyguardHidden) {
2190 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2191 }
2192 }
2193
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002194 // Force the window flags: this is a fake window, so it is not really
2195 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2196 // flag because we do know that the next window will take input
2197 // focus, so we want to get the IME window up on top of us right away.
2198 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002199 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002200 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2201 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2202 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002203 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002204 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2205 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2206 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002207
Adam Powell04fe6eb2013-05-31 14:39:48 -07002208 win.setDefaultIcon(icon);
2209 win.setDefaultLogo(logo);
2210
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002211 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002212 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002213
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002214 final WindowManager.LayoutParams params = win.getAttributes();
2215 params.token = appToken;
2216 params.packageName = packageName;
2217 params.windowAnimations = win.getWindowStyle().getResourceId(
2218 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002219 params.privateFlags |=
2220 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002221 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002222
2223 if (!compatInfo.supportsScreen()) {
2224 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2225 }
2226
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002227 params.setTitle("Starting " + packageName);
2228
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002229 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2230 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002231
2232 if (win.isFloating()) {
2233 // Whoops, there is no way to display an animation/preview
2234 // of such a thing! After all that work... let's skip it.
2235 // (Note that we must do this here because it is in
2236 // getDecorView() where the theme is evaluated... maybe
2237 // we should peek the floating attribute from the theme
2238 // earlier.)
2239 return null;
2240 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002241
Craig Mautner6fbda632012-07-03 09:26:39 -07002242 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002243 TAG, "Adding starting window for " + packageName
2244 + " / " + appToken + ": "
2245 + (view.getParent() != null ? view : null));
2246
2247 wm.addView(view, params);
2248
2249 // Only return the view if it was successfully added to the
2250 // window manager... which we can tell by it having a parent.
2251 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002252 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002253 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002254 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2255 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002256 } catch (RuntimeException e) {
2257 // don't crash if something else bad happens, for example a
2258 // failure loading resources because we are loading from an app
2259 // on external storage that has been unmounted.
2260 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002261 } finally {
2262 if (view != null && view.getParent() == null) {
2263 Log.w(TAG, "view not successfully added to wm, removing view");
2264 wm.removeViewImmediate(view);
2265 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002266 }
2267
2268 return null;
2269 }
2270
2271 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002272 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002273 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002274 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2275 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002276
2277 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002278 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002279 wm.removeView(window);
2280 }
2281 }
2282
2283 /**
2284 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002285 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002286 * Currently enforces that three window types are singletons:
2287 * <ul>
2288 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002289 * <li>KEYGUARD_TYPE</li>
2290 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002291 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002292 * @param win The window to be added
2293 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002294 *
Jeff Brown98365d72012-08-19 20:30:52 -07002295 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2296 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002297 */
Jose Lima9546b202014-07-02 17:21:51 -07002298 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002299 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2300 switch (attrs.type) {
2301 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002302 mContext.enforceCallingOrSelfPermission(
2303 android.Manifest.permission.STATUS_BAR_SERVICE,
2304 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002305 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002306 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002307 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002308 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002309 }
2310 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002311 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002312 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002313 case TYPE_NAVIGATION_BAR:
2314 mContext.enforceCallingOrSelfPermission(
2315 android.Manifest.permission.STATUS_BAR_SERVICE,
2316 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002317 if (mNavigationBar != null) {
2318 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002319 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002320 }
2321 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002322 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002323 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002324 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002325 break;
Jim Millere898ac52012-04-06 17:10:57 -07002326 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002327 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002328 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002329 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002330 mContext.enforceCallingOrSelfPermission(
2331 android.Manifest.permission.STATUS_BAR_SERVICE,
2332 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002333 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002334 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002335 if (mKeyguardScrim != null) {
2336 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2337 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002338 mKeyguardScrim = win;
2339 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002340 }
Jeff Brown98365d72012-08-19 20:30:52 -07002341 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002342 }
2343
2344 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002345 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002346 public void removeWindowLw(WindowState win) {
2347 if (mStatusBar == win) {
2348 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002349 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002350 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002351 } else if (mKeyguardScrim == win) {
2352 Log.v(TAG, "Removing keyguard scrim");
2353 mKeyguardScrim = null;
2354 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002355 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002356 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002357 }
2358 }
2359
2360 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002361
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002362 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002363 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002364 public int selectAnimationLw(WindowState win, int transit) {
2365 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2366 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002367 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002368 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002369 if (transit == TRANSIT_EXIT
2370 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002371 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002372 } else if (transit == TRANSIT_ENTER
2373 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002374 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002375 }
2376 } else if (win == mNavigationBar) {
2377 // This can be on either the bottom or the right.
2378 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002379 if (transit == TRANSIT_EXIT
2380 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002381 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002382 } else if (transit == TRANSIT_ENTER
2383 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002384 return R.anim.dock_bottom_enter;
2385 }
2386 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002387 if (transit == TRANSIT_EXIT
2388 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002389 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002390 } else if (transit == TRANSIT_ENTER
2391 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002392 return R.anim.dock_right_enter;
2393 }
2394 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002395 }
2396
2397 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002398 if (win.hasAppShownWindows()) {
2399 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2400 return com.android.internal.R.anim.app_starting_exit;
2401 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002402 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002403 && transit == TRANSIT_ENTER) {
2404 // Special case: we are animating in a dream, while the keyguard
2405 // is shown. We don't want an animation on the dream, because
2406 // we need it shown immediately with the keyguard animating away
2407 // to reveal it.
2408 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002409 }
2410
2411 return 0;
2412 }
2413
Craig Mautner3c174372013-02-21 17:54:37 -08002414 @Override
2415 public void selectRotationAnimationLw(int anim[]) {
2416 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2417 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2418 + (mTopFullscreenOpaqueWindowState == null ?
2419 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2420 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2421 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2422 case ROTATION_ANIMATION_CROSSFADE:
2423 anim[0] = R.anim.rotation_animation_xfade_exit;
2424 anim[1] = R.anim.rotation_animation_enter;
2425 break;
2426 case ROTATION_ANIMATION_JUMPCUT:
2427 anim[0] = R.anim.rotation_animation_jump_exit;
2428 anim[1] = R.anim.rotation_animation_enter;
2429 break;
2430 case ROTATION_ANIMATION_ROTATE:
2431 default:
2432 anim[0] = anim[1] = 0;
2433 break;
2434 }
2435 } else {
2436 anim[0] = anim[1] = 0;
2437 }
2438 }
2439
2440 @Override
2441 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2442 boolean forceDefault) {
2443 switch (exitAnimId) {
2444 case R.anim.rotation_animation_xfade_exit:
2445 case R.anim.rotation_animation_jump_exit:
2446 // These are the only cases that matter.
2447 if (forceDefault) {
2448 return false;
2449 }
2450 int anim[] = new int[2];
2451 selectRotationAnimationLw(anim);
2452 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2453 default:
2454 return true;
2455 }
2456 }
2457
2458 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002459 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2460 boolean goingToNotificationShade) {
2461 if (goingToNotificationShade) {
2462 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002463 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002464
2465 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2466 R.anim.lock_screen_behind_enter_wallpaper :
2467 R.anim.lock_screen_behind_enter);
2468
2469 // TODO: Use XML interpolators when we have log interpolators available in XML.
2470 final List<Animation> animations = set.getAnimations();
2471 for (int i = animations.size() - 1; i >= 0; --i) {
2472 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2473 }
2474
2475 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002476 }
2477
2478
2479 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002480 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2481 if (goingToNotificationShade) {
2482 return null;
2483 } else {
2484 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2485 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002486 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002487
2488 private static void awakenDreams() {
2489 IDreamManager dreamManager = getDreamManager();
2490 if (dreamManager != null) {
2491 try {
2492 dreamManager.awaken();
2493 } catch (RemoteException e) {
2494 // fine, stay asleep then
2495 }
2496 }
2497 }
2498
2499 static IDreamManager getDreamManager() {
2500 return IDreamManager.Stub.asInterface(
2501 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2502 }
2503
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002504 TelecomManager getTelecommService() {
2505 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002506 }
2507
Jeff Brown4d396052010-10-29 21:50:21 -07002508 static IAudioService getAudioService() {
2509 IAudioService audioService = IAudioService.Stub.asInterface(
2510 ServiceManager.checkService(Context.AUDIO_SERVICE));
2511 if (audioService == null) {
2512 Log.w(TAG, "Unable to find IAudioService interface.");
2513 }
2514 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002515 }
2516
2517 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002518 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002519 }
2520
2521 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2522 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2523 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2524 };
2525
2526 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002527 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002528 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002529 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002530 final int keyCode = event.getKeyCode();
2531 final int repeatCount = event.getRepeatCount();
2532 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002533 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002534 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2535 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002536
Jeff Brown40013652012-05-16 21:22:36 -07002537 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002538 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002539 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2540 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002541 }
2542
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002543 // If we think we might have a volume down & power key chord on the way
2544 // but we're not sure, then tell the dispatcher to wait a little while and
2545 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002546 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002547 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002548 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002549 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2550 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002551 if (now < timeoutTime) {
2552 return timeoutTime - now;
2553 }
2554 }
2555 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002556 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002557 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002558 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002559 }
2560 return -1;
2561 }
2562 }
2563
Michael Wright6a62e552014-06-03 19:19:48 -07002564 // Cancel any pending meta actions if we see any other keys being pressed between the down
2565 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002566 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002567 mPendingMetaAction = false;
2568 }
2569
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002570 // First we always handle the home key here, so applications
2571 // can never break it, although if keyguard is on, we do let
2572 // it handle it, because that gives us the correct 5 second
2573 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002574 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002575
Jeff Brown49ed71d2010-12-06 17:13:33 -08002576 // If we have released the home key, and didn't do anything else
2577 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002578 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002579 cancelPreloadRecentApps();
2580
Jeff Brown49ed71d2010-12-06 17:13:33 -08002581 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002582 if (mHomeConsumed) {
2583 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002584 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002585 }
Jeff Browncaca8812013-05-09 13:34:33 -07002586
2587 if (canceled) {
2588 Log.i(TAG, "Ignoring HOME; event canceled.");
2589 return -1;
2590 }
2591
Yorke Lee4f803242014-12-15 23:22:06 +00002592 // If an incoming call is ringing, HOME is totally disabled.
2593 // (The user is already on the InCallUI at this point,
2594 // and his ONLY options are to answer or reject the call.)
2595 TelecomManager telecomManager = getTelecommService();
2596 if (telecomManager != null && telecomManager.isRinging()) {
2597 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2598 return -1;
2599 }
2600
Jeff Browncaca8812013-05-09 13:34:33 -07002601 // Delay handling home if a double-tap is possible.
2602 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2603 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2604 mHomeDoubleTapPending = true;
2605 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2606 ViewConfiguration.getDoubleTapTimeout());
2607 return -1;
2608 }
2609
Jeff Brown13f00f02014-10-31 14:45:50 -07002610 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002611 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002612 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002613
2614 // If a system window has focus, then it doesn't make sense
2615 // right now to interact with applications.
2616 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2617 if (attrs != null) {
2618 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002619 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2620 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2621 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002622 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002623 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002624 }
2625 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2626 for (int i=0; i<typeCount; i++) {
2627 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2628 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002629 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002630 }
2631 }
2632 }
Jeff Browncaca8812013-05-09 13:34:33 -07002633
2634 // Remember that home is pressed and handle special actions.
2635 if (repeatCount == 0) {
2636 mHomePressed = true;
2637 if (mHomeDoubleTapPending) {
2638 mHomeDoubleTapPending = false;
2639 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2640 handleDoubleTapOnHome();
2641 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2642 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2643 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002644 }
Jeff Browncaca8812013-05-09 13:34:33 -07002645 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2646 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002647 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002648 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002649 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002650 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002651 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002652 // Hijack modified menu keys for debugging features
2653 final int chordBug = KeyEvent.META_SHIFT_ON;
2654
2655 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002656 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002657 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002658 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2659 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002660 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002661 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002662 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002663 Intent service = new Intent();
2664 service.setClassName(mContext, "com.android.server.LoadAverageService");
2665 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002666 boolean shown = Settings.Global.getInt(
2667 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002668 if (!shown) {
2669 mContext.startService(service);
2670 } else {
2671 mContext.stopService(service);
2672 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002673 Settings.Global.putInt(
2674 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002675 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002676 }
2677 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002678 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002679 if (down) {
2680 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002681 mSearchKeyShortcutPending = true;
2682 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002683 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002684 } else {
2685 mSearchKeyShortcutPending = false;
2686 if (mConsumeSearchKeyUp) {
2687 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002688 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002689 }
2690 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002691 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002692 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002693 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002694 if (down && repeatCount == 0) {
2695 preloadRecentApps();
2696 } else if (!down) {
2697 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002698 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002699 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002700 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002701 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2702 if (down) {
2703 IStatusBarService service = getStatusBarService();
2704 if (service != null) {
2705 try {
2706 service.expandNotificationsPanel();
2707 } catch (RemoteException e) {
2708 // do nothing.
2709 }
2710 }
2711 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002712 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2713 if (down) {
2714 if (repeatCount == 0) {
2715 mAssistKeyLongPressed = false;
2716 } else if (repeatCount == 1) {
2717 mAssistKeyLongPressed = true;
2718 if (!keyguardOn) {
2719 launchAssistLongPressAction();
2720 }
2721 }
2722 } else {
2723 if (mAssistKeyLongPressed) {
2724 mAssistKeyLongPressed = false;
2725 } else {
2726 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002727 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002728 }
2729 }
2730 }
2731 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002732 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2733 if (!down) {
2734 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002735 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002736 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2737 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07002738 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
2739 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
2740 if (dic != null) {
2741 try {
2742 dic.exitIdle("voice-search");
2743 } catch (RemoteException e) {
2744 }
2745 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002746 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002747 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002748 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002749 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002750 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002751 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2752 if (down && repeatCount == 0) {
2753 mHandler.post(mScreenshotRunnable);
2754 }
2755 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002756 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2757 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2758 if (down) {
2759 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2760
2761 // Disable autobrightness if it's on
2762 int auto = Settings.System.getIntForUser(
2763 mContext.getContentResolver(),
2764 Settings.System.SCREEN_BRIGHTNESS_MODE,
2765 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2766 UserHandle.USER_CURRENT_OR_SELF);
2767 if (auto != 0) {
2768 Settings.System.putIntForUser(mContext.getContentResolver(),
2769 Settings.System.SCREEN_BRIGHTNESS_MODE,
2770 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2771 UserHandle.USER_CURRENT_OR_SELF);
2772 }
2773
2774 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2775 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2776 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2777 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2778 Settings.System.SCREEN_BRIGHTNESS,
2779 mPowerManager.getDefaultScreenBrightnessSetting(),
2780 UserHandle.USER_CURRENT_OR_SELF);
2781 brightness += step;
2782 // Make sure we don't go beyond the limits.
2783 brightness = Math.min(max, brightness);
2784 brightness = Math.max(min, brightness);
2785
2786 Settings.System.putIntForUser(mContext.getContentResolver(),
2787 Settings.System.SCREEN_BRIGHTNESS, brightness,
2788 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002789 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002790 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002791 }
2792 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002793 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002794 if (down) {
2795 mPendingMetaAction = true;
2796 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002797 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07002798 }
2799 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002800 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002801
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002802 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002803 // Any printing key that is chorded with Search should be consumed
2804 // even if no shortcut was invoked. This prevents text from being
2805 // inadvertently inserted when using a keyboard that has built-in macro
2806 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002807 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002808 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2809 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002810 mConsumeSearchKeyUp = true;
2811 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002812 if (down && repeatCount == 0 && !keyguardOn) {
2813 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2814 if (shortcutIntent != null) {
2815 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002816 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002817 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002818 } catch (ActivityNotFoundException ex) {
2819 Slog.w(TAG, "Dropping shortcut key combination because "
2820 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002821 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002822 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002823 } else {
2824 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002825 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002826 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002827 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002828 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002829 }
2830 }
2831
Jeff Brown68b909d2011-12-07 16:36:01 -08002832 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002833 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002834 && (metaState & KeyEvent.META_META_ON) != 0) {
2835 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002836 if (kcm.isPrintingKey(keyCode)) {
2837 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2838 metaState & ~(KeyEvent.META_META_ON
2839 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2840 if (shortcutIntent != null) {
2841 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2842 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002843 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002844 } catch (ActivityNotFoundException ex) {
2845 Slog.w(TAG, "Dropping shortcut key combination because "
2846 + "the activity to which it is registered was not found: "
2847 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2848 }
2849 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002850 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002851 }
2852 }
2853
Jeff Brown6651a632011-11-28 12:59:11 -08002854 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002855 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002856 String category = sApplicationLaunchKeyCategories.get(keyCode);
2857 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002858 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002859 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2860 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002861 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002862 } catch (ActivityNotFoundException ex) {
2863 Slog.w(TAG, "Dropping application launch key because "
2864 + "the activity to which it is registered was not found: "
2865 + "keyCode=" + keyCode + ", category=" + category, ex);
2866 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002867 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002868 }
2869 }
2870
Michael Wright61c46752014-08-21 16:57:33 -07002871 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002872 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002873 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002874 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002875 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002876 mRecentAppsHeldModifiers = shiftlessModifiers;
2877 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002878 return -1;
2879 }
2880 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002881 } else if (!down && mRecentAppsHeldModifiers != 0
2882 && (metaState & mRecentAppsHeldModifiers) == 0) {
2883 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002884 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002885 }
2886
Jeff Browncf39bdf2012-05-18 14:41:19 -07002887 // Handle keyboard language switching.
2888 if (down && repeatCount == 0
2889 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2890 || (keyCode == KeyEvent.KEYCODE_SPACE
2891 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2892 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2893 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2894 return -1;
2895 }
2896 if (mLanguageSwitchKeyPressed && !down
2897 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2898 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2899 mLanguageSwitchKeyPressed = false;
2900 return -1;
2901 }
2902
Jeff Brown13f00f02014-10-31 14:45:50 -07002903 if (isValidGlobalKey(keyCode)
2904 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002905 return -1;
2906 }
2907
Michael Wright6a62e552014-06-03 19:19:48 -07002908 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002909 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002910 return -1;
2911 }
2912
Jeff Brown68b909d2011-12-07 16:36:01 -08002913 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002914 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002915 }
2916
Jeff Brown3915bb82010-11-05 15:02:16 -07002917 /** {@inheritDoc} */
2918 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002919 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002920 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002921 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002922 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2923 + ", flags=" + event.getFlags()
2924 + ", keyCode=" + event.getKeyCode()
2925 + ", scanCode=" + event.getScanCode()
2926 + ", metaState=" + event.getMetaState()
2927 + ", repeatCount=" + event.getRepeatCount()
2928 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002929 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002930
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002931 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002932 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2933 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002934 final int keyCode = event.getKeyCode();
2935 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002936 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2937 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002938
Jeff Brown54875002011-04-06 15:33:01 -07002939 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002940 final FallbackAction fallbackAction;
2941 if (initialDown) {
2942 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2943 } else {
2944 fallbackAction = mFallbackActions.get(keyCode);
2945 }
2946
2947 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002948 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002949 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2950 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002951 }
2952
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002953 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2954 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002955 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002956 event.getAction(), fallbackAction.keyCode,
2957 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002958 event.getDeviceId(), event.getScanCode(),
2959 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002960
2961 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2962 fallbackEvent.recycle();
2963 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002964 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002965
2966 if (initialDown) {
2967 mFallbackActions.put(keyCode, fallbackAction);
2968 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2969 mFallbackActions.remove(keyCode);
2970 fallbackAction.recycle();
2971 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002972 }
2973 }
2974
Jeff Brown40013652012-05-16 21:22:36 -07002975 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002976 if (fallbackEvent == null) {
2977 Slog.d(TAG, "No fallback.");
2978 } else {
2979 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2980 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002981 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002982 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002983 }
2984
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002985 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002986 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002987 if ((actions & ACTION_PASS_TO_USER) != 0) {
2988 long delayMillis = interceptKeyBeforeDispatching(
2989 win, fallbackEvent, policyFlags);
2990 if (delayMillis == 0) {
2991 return true;
2992 }
2993 }
2994 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002995 }
2996
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002997 private void launchAssistLongPressAction() {
2998 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2999 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3000
3001 // launch the search activity
3002 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3003 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3004 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003005 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003006 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003007 SearchManager searchManager = getSearchManager();
3008 if (searchManager != null) {
3009 searchManager.stopSearch();
3010 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003011 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003012 } catch (ActivityNotFoundException e) {
3013 Slog.w(TAG, "No activity to handle assist long press action.", e);
3014 }
3015 }
3016
3017 private void launchAssistAction() {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003018 launchAssistAction(null, Integer.MIN_VALUE);
Michael Wright8ab940a2014-09-01 11:01:27 -07003019 }
3020
3021 private void launchAssistAction(String hint) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003022 launchAssistAction(hint, Integer.MIN_VALUE);
3023 }
3024
3025 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003026 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003027 Bundle args = null;
3028 if (deviceId > Integer.MIN_VALUE) {
3029 args = new Bundle();
3030 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003031 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003032 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3033 .launchAssistAction(hint, UserHandle.myUserId(), args);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003034 }
3035
Bart Sears8b1c27c2015-03-18 23:51:02 +00003036 private void startActivityAsUser(Intent intent, UserHandle handle) {
3037 if (isUserSetupComplete()) {
3038 mContext.startActivityAsUser(intent, handle);
3039 } else {
3040 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3041 }
3042 }
3043
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003044 private SearchManager getSearchManager() {
3045 if (mSearchManager == null) {
3046 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3047 }
3048 return mSearchManager;
3049 }
3050
Jeff Browncaca8812013-05-09 13:34:33 -07003051 private void preloadRecentApps() {
3052 mPreloadedRecentApps = true;
3053 try {
3054 IStatusBarService statusbar = getStatusBarService();
3055 if (statusbar != null) {
3056 statusbar.preloadRecentApps();
3057 }
3058 } catch (RemoteException e) {
3059 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3060 // re-acquire status bar service next time it is needed.
3061 mStatusBarService = null;
3062 }
3063 }
3064
3065 private void cancelPreloadRecentApps() {
3066 if (mPreloadedRecentApps) {
3067 mPreloadedRecentApps = false;
3068 try {
3069 IStatusBarService statusbar = getStatusBarService();
3070 if (statusbar != null) {
3071 statusbar.cancelPreloadRecentApps();
3072 }
3073 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003074 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003075 // re-acquire status bar service next time it is needed.
3076 mStatusBarService = null;
3077 }
3078 }
3079 }
3080
3081 private void toggleRecentApps() {
3082 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003083 try {
3084 IStatusBarService statusbar = getStatusBarService();
3085 if (statusbar != null) {
3086 statusbar.toggleRecentApps();
3087 }
3088 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003089 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3090 // re-acquire status bar service next time it is needed.
3091 mStatusBarService = null;
3092 }
3093 }
3094
Craig Mautner84984fa2014-06-19 11:19:20 -07003095 @Override
3096 public void showRecentApps() {
3097 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3098 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3099 }
3100
Winson Chung1e8d71b2014-05-16 17:05:22 -07003101 private void showRecentApps(boolean triggeredFromAltTab) {
3102 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3103 try {
3104 IStatusBarService statusbar = getStatusBarService();
3105 if (statusbar != null) {
3106 statusbar.showRecentApps(triggeredFromAltTab);
3107 }
3108 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003109 Slog.e(TAG, "RemoteException when showing recent apps", e);
3110 // re-acquire status bar service next time it is needed.
3111 mStatusBarService = null;
3112 }
3113 }
3114
Winson Chungcdcd4872014-08-05 18:00:13 -07003115 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003116 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3117 try {
3118 IStatusBarService statusbar = getStatusBarService();
3119 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003120 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003121 }
3122 } catch (RemoteException e) {
3123 Slog.e(TAG, "RemoteException when closing recent apps", e);
3124 // re-acquire status bar service next time it is needed.
3125 mStatusBarService = null;
3126 }
3127 }
3128
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003129 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003130 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003131 }
3132
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003133 /**
3134 * A home key -> launch home action was detected. Take the appropriate action
3135 * given the situation with the keyguard.
3136 */
Bryce Lee662ed802015-04-10 20:11:39 +00003137 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3138 if (respectKeyguard) {
3139 if (isKeyguardShowingAndNotOccluded()) {
3140 // don't launch home if keyguard showing
3141 return;
3142 }
3143
3144 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3145 // when in keyguard restricted mode, must first verify unlock
3146 // before launching home
3147 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3148 @Override
3149 public void onKeyguardExitResult(boolean success) {
3150 if (success) {
3151 try {
3152 ActivityManagerNative.getDefault().stopAppSwitches();
3153 } catch (RemoteException e) {
3154 }
3155 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3156 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003157 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003158 }
Bryce Lee662ed802015-04-10 20:11:39 +00003159 });
3160 return;
3161 }
3162 }
3163
3164 // no keyguard stuff to worry about, just launch home!
3165 try {
3166 ActivityManagerNative.getDefault().stopAppSwitches();
3167 } catch (RemoteException e) {
3168 }
3169 if (mRecentsVisible) {
3170 // Hide Recents and notify it to launch Home
3171 if (awakenFromDreams) {
3172 awakenDreams();
3173 }
3174 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3175 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003176 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003177 // Otherwise, just launch Home
3178 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3179 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003180 }
3181 }
3182
John Spurlock04db1762013-05-13 12:46:41 -04003183 private final Runnable mClearHideNavigationFlag = new Runnable() {
3184 @Override
3185 public void run() {
3186 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3187 // Clear flags.
3188 mForceClearedSystemUiFlags &=
3189 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3190 }
3191 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003192 }
3193 };
3194
3195 /**
3196 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3197 * to determine when the nav bar should be shown and prevent applications from
3198 * receiving those touches.
3199 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003200 final class HideNavInputEventReceiver extends InputEventReceiver {
3201 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3202 super(inputChannel, looper);
3203 }
3204
Dianne Hackborndf89e652011-10-06 22:35:11 -07003205 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003206 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003207 boolean handled = false;
3208 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003209 if (event instanceof MotionEvent
3210 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3211 final MotionEvent motionEvent = (MotionEvent)event;
3212 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003213 // When the user taps down, we re-show the nav bar.
3214 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003215 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003216 // Any user activity always causes us to show the
3217 // navigation controls, if they had been hidden.
3218 // We also clear the low profile and only content
3219 // flags so that tapping on the screen will atomically
3220 // restore all currently hidden screen decorations.
3221 int newVal = mResettingSystemUiFlags |
3222 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3223 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3224 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003225 if (mResettingSystemUiFlags != newVal) {
3226 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003227 changed = true;
3228 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003229 // We don't allow the system's nav bar to be hidden
3230 // again for 1 second, to prevent applications from
3231 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003232 newVal = mForceClearedSystemUiFlags |
3233 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003234 if (mForceClearedSystemUiFlags != newVal) {
3235 mForceClearedSystemUiFlags = newVal;
3236 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003237 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003238 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003239 }
3240 if (changed) {
3241 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3242 }
3243 }
3244 }
3245 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003246 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003247 }
3248 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003249 }
3250 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3251 new InputEventReceiver.Factory() {
3252 @Override
3253 public InputEventReceiver createInputEventReceiver(
3254 InputChannel inputChannel, Looper looper) {
3255 return new HideNavInputEventReceiver(inputChannel, looper);
3256 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003257 };
3258
3259 @Override
3260 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003261 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3262 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003263 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003264
Dianne Hackborndf89e652011-10-06 22:35:11 -07003265 // Reset any bits in mForceClearingStatusBarVisibility that
3266 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003267 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003268 // Clear any bits in the new visibility that are currently being
3269 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003270 return visibility & ~mResettingSystemUiFlags
3271 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003272 }
3273
Craig Mautner69b08182012-09-05 13:07:13 -07003274 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003275 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3276 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003277 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003278 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3279 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003280
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003281 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003282 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003283 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003284 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003285 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003286 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3287 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3288 } else {
3289 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3290 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3291 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003292 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3293 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003294 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003295 availRight - mStableFullscreenRight,
3296 availBottom - mStableFullscreenBottom);
3297 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003298 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003299 availRight - mStableRight, availBottom - mStableBottom);
3300 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003301 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003302 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003303 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003304 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003305 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003306 availRight - mCurRight, availBottom - mCurBottom);
3307 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003308 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003309 availRight - mCurRight, availBottom - mCurBottom);
3310 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003311
3312 outStableInsets.set(mStableLeft, mStableTop,
3313 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003314 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003315 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003316 outContentInsets.setEmpty();
3317 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003318 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003319
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003320 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003321 @Override
3322 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3323 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003324 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3325 if (isDefaultDisplay) {
3326 switch (displayRotation) {
3327 case Surface.ROTATION_90:
3328 overscanLeft = mOverscanTop;
3329 overscanTop = mOverscanRight;
3330 overscanRight = mOverscanBottom;
3331 overscanBottom = mOverscanLeft;
3332 break;
3333 case Surface.ROTATION_180:
3334 overscanLeft = mOverscanRight;
3335 overscanTop = mOverscanBottom;
3336 overscanRight = mOverscanLeft;
3337 overscanBottom = mOverscanTop;
3338 break;
3339 case Surface.ROTATION_270:
3340 overscanLeft = mOverscanBottom;
3341 overscanTop = mOverscanLeft;
3342 overscanRight = mOverscanTop;
3343 overscanBottom = mOverscanRight;
3344 break;
3345 default:
3346 overscanLeft = mOverscanLeft;
3347 overscanTop = mOverscanTop;
3348 overscanRight = mOverscanRight;
3349 overscanBottom = mOverscanBottom;
3350 break;
3351 }
3352 } else {
3353 overscanLeft = 0;
3354 overscanTop = 0;
3355 overscanRight = 0;
3356 overscanBottom = 0;
3357 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003358 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3359 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3360 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3361 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003362 mSystemLeft = 0;
3363 mSystemTop = 0;
3364 mSystemRight = displayWidth;
3365 mSystemBottom = displayHeight;
3366 mUnrestrictedScreenLeft = overscanLeft;
3367 mUnrestrictedScreenTop = overscanTop;
3368 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3369 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3370 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3371 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003372 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3373 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003374 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003375 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003376 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003377 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003378 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003379 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003380 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003381 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003382 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003383 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003384
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003385 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3386 final Rect pf = mTmpParentFrame;
3387 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003388 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003389 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003390 final Rect dcf = mTmpDecorFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003391 final Rect osf = mTmpOutsetFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003392 pf.left = df.left = of.left = vf.left = mDockLeft;
3393 pf.top = df.top = of.top = vf.top = mDockTop;
3394 pf.right = df.right = of.right = vf.right = mDockRight;
3395 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003396 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003397
Craig Mautner69b08182012-09-05 13:07:13 -07003398 if (isDefaultDisplay) {
3399 // For purposes of putting out fake window up to steal focus, we will
3400 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003401 final int sysui = mLastSystemUiFlags;
3402 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003403 boolean navTranslucent = (sysui
3404 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003405 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3406 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3407 boolean navAllowedHidden = immersive || immersiveSticky;
3408 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003409 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3410 if (!isKeyguardShowing) {
3411 navTranslucent &= areTranslucentBarsAllowed();
3412 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003413
Craig Mautner69b08182012-09-05 13:07:13 -07003414 // When the navigation bar isn't visible, we put up a fake
3415 // input window to catch all touch events. This way we can
3416 // detect when the user presses anywhere to bring back the nav
3417 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003418 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003419 if (mInputConsumer != null) {
3420 mInputConsumer.dismiss();
3421 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003422 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003423 } else if (mInputConsumer == null) {
3424 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3425 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003426 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003427
Craig Mautner69b08182012-09-05 13:07:13 -07003428 // For purposes of positioning and showing the nav bar, if we have
3429 // decided that it can't be hidden (because of the screen aspect ratio),
3430 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003431 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003432
John Spurlockad3e6cb2013-04-30 08:47:43 -04003433 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003434 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003435 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003436 // Force the navigation bar to its appropriate place and
3437 // size. We need to do this directly, instead of relying on
3438 // it to bubble up from the nav bar, because this needs to
3439 // change atomically with screen rotations.
3440 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3441 if (mNavigationBarOnBottom) {
3442 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003443 int top = displayHeight - overscanBottom
3444 - mNavigationBarHeightForRotation[displayRotation];
3445 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003446 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003447 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003448 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003449 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003450 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003451 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003452 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3453 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003454 } else {
3455 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003456 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003457 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003458 if (navVisible && !navTranslucent && !navAllowedHidden
3459 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003460 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003461 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003462 // and not in the process of animating on or off, then
3463 // we can tell the app that it is covered by it.
3464 mSystemBottom = mTmpNavigationFrame.top;
3465 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003466 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003467 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003468 int left = displayWidth - overscanRight
3469 - mNavigationBarWidthForRotation[displayRotation];
3470 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003471 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003472 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003473 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003474 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003475 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003476 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003477 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3478 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003479 } else {
3480 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003481 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003482 }
John Spurlockbd957402013-10-03 11:38:39 -04003483 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3484 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003485 // If the nav bar is currently requested to be visible,
3486 // and not in the process of animating on or off, then
3487 // we can tell the app that it is covered by it.
3488 mSystemRight = mTmpNavigationFrame.left;
3489 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003490 }
Craig Mautner69b08182012-09-05 13:07:13 -07003491 // Make sure the content and current rectangles are updated to
3492 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003493 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3494 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3495 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3496 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003497 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3498 // And compute the final frame.
3499 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003500 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003501 mTmpNavigationFrame, mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003502 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003503 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003504 updateSysUiVisibility = true;
3505 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003506 }
Craig Mautnereda67292013-04-28 13:50:14 -07003507 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003508 mDockLeft, mDockTop, mDockRight, mDockBottom));
3509
3510 // decide where the status bar goes ahead of time
3511 if (mStatusBar != null) {
3512 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003513 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3514 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3515 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3516 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3517 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003518 vf.left = mStableLeft;
3519 vf.top = mStableTop;
3520 vf.right = mStableRight;
3521 vf.bottom = mStableBottom;
3522
3523 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3524
3525 // Let the status bar determine its size.
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003526 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3527 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3528 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
Craig Mautner69b08182012-09-05 13:07:13 -07003529
3530 // For layout, the status bar is always at the top with our fixed height.
3531 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3532
John Spurlocke1f366f2013-08-05 12:22:40 -04003533 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003534 boolean statusBarTranslucent = (sysui
3535 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003536 if (!isKeyguardShowing) {
3537 statusBarTranslucent &= areTranslucentBarsAllowed();
3538 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003539
Craig Mautner69b08182012-09-05 13:07:13 -07003540 // If the status bar is hidden, we don't want to cause
3541 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003542 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003543 // Status bar may go away, so the screen area it occupies
3544 // is available to apps but just covering them when the
3545 // status bar is visible.
3546 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3547
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003548 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3549 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3550 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3551 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003552
Craig Mautnereda67292013-04-28 13:50:14 -07003553 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003554 String.format(
3555 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3556 mDockLeft, mDockTop, mDockRight, mDockBottom,
3557 mContentLeft, mContentTop, mContentRight, mContentBottom,
3558 mCurLeft, mCurTop, mCurRight, mCurBottom));
3559 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003560 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003561 && !statusBarTransient && !statusBarTranslucent
3562 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003563 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003564 // and not in the process of animating on or off, then
3565 // we can tell the app that it is covered by it.
3566 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3567 }
John Spurlock27735a42013-08-14 17:57:38 -04003568 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003569 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003570 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003571 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003572 if (updateSysUiVisibility) {
3573 updateSystemUiVisibilityLw();
3574 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003575 }
3576 }
3577
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003578 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003579 @Override
John Spurlock46646232013-09-30 22:32:42 -04003580 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003581 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3582 return mStatusBar.getSurfaceLayer();
3583 }
3584
3585 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3586 return mNavigationBar.getSurfaceLayer();
3587 }
3588
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003589 return 0;
3590 }
3591
Craig Mautner967212c2013-04-13 21:10:58 -07003592 @Override
3593 public void getContentRectLw(Rect r) {
3594 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3595 }
3596
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003597 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3598 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003599 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3600 // Here's a special case: if this attached window is a panel that is
3601 // above the dock window, and the window it is attached to is below
3602 // the dock window, then the frames we computed for the window it is
3603 // attached to can not be used because the dock is effectively part
3604 // of the underlying window and the attached window is floating on top
3605 // of the whole thing. So, we ignore the attached window and explicitly
3606 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003607 df.left = of.left = cf.left = vf.left = mDockLeft;
3608 df.top = of.top = cf.top = vf.top = mDockTop;
3609 df.right = of.right = cf.right = vf.right = mDockRight;
3610 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003611 } else {
3612 // The effective display frame of the attached window depends on
3613 // whether it is taking care of insetting its content. If not,
3614 // we need to use the parent's content frame so that the entire
3615 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003616 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003617 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003618 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003619 // Set the content frame of the attached window to the parent's decor frame
3620 // (same as content frame when IME isn't present) if specifically requested by
3621 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3622 // Otherwise, use the overscan frame.
3623 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3624 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003625 } else {
3626 // If the window is resizing, then we want to base the content
3627 // frame on our attached content frame to resize... however,
3628 // things can be tricky if the attached window is NOT in resize
3629 // mode, in which case its content frame will be larger.
3630 // Ungh. So to deal with that, make sure the content frame
3631 // we end up using is not covering the IM dock.
3632 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003633 if (attached.isVoiceInteraction()) {
3634 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3635 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3636 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3637 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3638 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003639 if (cf.left < mContentLeft) cf.left = mContentLeft;
3640 if (cf.top < mContentTop) cf.top = mContentTop;
3641 if (cf.right > mContentRight) cf.right = mContentRight;
3642 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3643 }
3644 }
3645 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003646 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003647 vf.set(attached.getVisibleFrameLw());
3648 }
3649 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3650 // window should be positioned relative to its parent or the entire
3651 // screen.
3652 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3653 ? attached.getFrameLw() : df);
3654 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003655
3656 private void applyStableConstraints(int sysui, int fl, Rect r) {
3657 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3658 // If app is requesting a stable layout, don't let the
3659 // content insets go below the stable values.
3660 if ((fl & FLAG_FULLSCREEN) != 0) {
3661 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3662 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3663 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3664 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3665 } else {
3666 if (r.left < mStableLeft) r.left = mStableLeft;
3667 if (r.top < mStableTop) r.top = mStableTop;
3668 if (r.right > mStableRight) r.right = mStableRight;
3669 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3670 }
3671 }
3672 }
3673
Jorim Jaggiaa806142015-05-20 18:04:16 -07003674 private boolean canReceiveInput(WindowState win) {
3675 boolean notFocusable =
3676 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
3677 boolean altFocusableIm =
3678 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
3679 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
3680 return !notFocusableForIm;
3681 }
3682
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003683 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003684 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003685 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07003686 // We've already done the navigation bar and status bar. If the status bar can receive
3687 // input, we need to layout it again to accomodate for the IME window.
3688 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003689 return;
3690 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07003691 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07003692 final boolean isDefaultDisplay = win.isDefaultDisplay();
3693 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003694 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3695 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003696 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003697 offsetInputMethodWindowLw(mLastInputMethodWindow);
3698 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003699
John Spurlockc6d1c602014-01-17 15:22:06 -05003700 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003701 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003702 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003703
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003704 final Rect pf = mTmpParentFrame;
3705 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003706 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003707 final Rect cf = mTmpContentFrame;
3708 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003709 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003710 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003711 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04003712 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003713
3714 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003715 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003716
Craig Mautnerf683b562012-10-02 11:10:57 -07003717 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3718
Adrian Roosfa104232014-06-20 16:10:14 -07003719 if (isDefaultDisplay) {
3720 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3721 } else {
3722 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3723 }
3724
Craig Mautner69b08182012-09-05 13:07:13 -07003725 if (!isDefaultDisplay) {
3726 if (attached != null) {
3727 // If this window is attached to another, our display
3728 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003729 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003730 } else {
3731 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003732 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3733 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3734 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003735 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003736 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003737 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003738 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003739 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003740 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3741 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3742 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003743 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003744 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003745 // ...with content insets above the nav bar
3746 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003747 // IM dock windows always go to the bottom of the screen.
3748 attrs.gravity = Gravity.BOTTOM;
3749 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003750 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003751 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003752 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003753 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3754 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003755 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003756 // Note: In Phone landscape mode, the button bar should also be excluded.
3757 cf.right = vf.right = mStableRight;
3758 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003759 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07003760 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02003761 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3762 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3763 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3764 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3765 cf.left = vf.left = mStableLeft;
3766 cf.top = vf.top = mStableTop;
3767 cf.right = vf.right = mStableRight;
3768 vf.bottom = mStableBottom;
3769 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003770 } else {
John Spurlock46646232013-09-30 22:32:42 -04003771
3772 // Default policy decor for the default display
3773 dcf.left = mSystemLeft;
3774 dcf.top = mSystemTop;
3775 dcf.right = mSystemRight;
3776 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003777 final boolean inheritTranslucentDecor = (attrs.privateFlags
3778 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003779 final boolean isAppWindow =
3780 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3781 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3782 final boolean topAtRest =
3783 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3784 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003785 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3786 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003787 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3788 && (fl & WindowManager.LayoutParams.
3789 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003790 // Ensure policy decor includes status bar
3791 dcf.top = mStableTop;
3792 }
John Spurlockbd957402013-10-03 11:38:39 -04003793 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003794 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3795 && (fl & WindowManager.LayoutParams.
3796 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003797 // Ensure policy decor includes navigation bar
3798 dcf.bottom = mStableBottom;
3799 dcf.right = mStableRight;
3800 }
3801 }
3802
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003803 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3804 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003805 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003806 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003807 // This is the case for a normal activity window: we want it
3808 // to cover all of the screen space, and it can take care of
3809 // moving its contents to account for screen decorations that
3810 // intrude into that space.
3811 if (attached != null) {
3812 // If this window is attached to another, our display
3813 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003814 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003815 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003816 if (attrs.type == TYPE_STATUS_BAR_PANEL
3817 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003818 // Status bar panels are the only windows who can go on top of
3819 // the status bar. They are protected by the STATUS_BAR_SERVICE
3820 // permission, so they have the same privileges as the status
3821 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003822 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003823 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003824
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003825 pf.left = df.left = of.left = hasNavBar
3826 ? mDockLeft : mUnrestrictedScreenLeft;
3827 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3828 pf.right = df.right = of.right = hasNavBar
3829 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3830 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3831 pf.bottom = df.bottom = of.bottom = hasNavBar
3832 ? mRestrictedScreenTop+mRestrictedScreenHeight
3833 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003834
Craig Mautnereda67292013-04-28 13:50:14 -07003835 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003836 "Laying out status bar window: (%d,%d - %d,%d)",
3837 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003838 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003839 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3840 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3841 // Asking to layout into the overscan region, so give it that pure
3842 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003843 pf.left = df.left = of.left = mOverscanScreenLeft;
3844 pf.top = df.top = of.top = mOverscanScreenTop;
3845 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3846 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3847 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003848 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003849 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003850 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3851 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003852 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003853 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003854 // only do this for application windows to ensure no window that
3855 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003856 pf.left = df.left = mOverscanScreenLeft;
3857 pf.top = df.top = mOverscanScreenTop;
3858 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3859 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003860 // We need to tell the app about where the frame inside the overscan
3861 // is, so it can inset its content by that amount -- it didn't ask
3862 // to actually extend itself into the overscan region.
3863 of.left = mUnrestrictedScreenLeft;
3864 of.top = mUnrestrictedScreenTop;
3865 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3866 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003867 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003868 pf.left = df.left = mRestrictedOverscanScreenLeft;
3869 pf.top = df.top = mRestrictedOverscanScreenTop;
3870 pf.right = df.right = mRestrictedOverscanScreenLeft
3871 + mRestrictedOverscanScreenWidth;
3872 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3873 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003874 // We need to tell the app about where the frame inside the overscan
3875 // is, so it can inset its content by that amount -- it didn't ask
3876 // to actually extend itself into the overscan region.
3877 of.left = mUnrestrictedScreenLeft;
3878 of.top = mUnrestrictedScreenTop;
3879 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3880 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003881 }
Craig Mautner69b08182012-09-05 13:07:13 -07003882
John Spurlock46646232013-09-30 22:32:42 -04003883 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003884 if (win.isVoiceInteraction()) {
3885 cf.left = mVoiceContentLeft;
3886 cf.top = mVoiceContentTop;
3887 cf.right = mVoiceContentRight;
3888 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003889 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003890 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3891 cf.left = mDockLeft;
3892 cf.top = mDockTop;
3893 cf.right = mDockRight;
3894 cf.bottom = mDockBottom;
3895 } else {
3896 cf.left = mContentLeft;
3897 cf.top = mContentTop;
3898 cf.right = mContentRight;
3899 cf.bottom = mContentBottom;
3900 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003901 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003902 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003903 // Full screen windows are always given a layout that is as if the
3904 // status bar and other transient decors are gone. This is to avoid
3905 // bad states when moving from a window that is not hding the
3906 // status bar to one that is.
3907 cf.left = mRestrictedScreenLeft;
3908 cf.top = mRestrictedScreenTop;
3909 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3910 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003911 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003912 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003913 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3914 vf.left = mCurLeft;
3915 vf.top = mCurTop;
3916 vf.right = mCurRight;
3917 vf.bottom = mCurBottom;
3918 } else {
3919 vf.set(cf);
3920 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003921 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003922 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3923 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3924 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003925 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3926 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003927 // A window that has requested to fill the entire screen just
3928 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003929 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04003930 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
3931 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003932 pf.left = df.left = of.left = cf.left = hasNavBar
3933 ? mDockLeft : mUnrestrictedScreenLeft;
3934 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3935 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003936 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003937 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003938 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003939 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003940 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003941 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003942 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3943 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003944 } else if (attrs.type == TYPE_NAVIGATION_BAR
3945 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003946 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003947 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3948 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3949 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3950 + mUnrestrictedScreenWidth;
3951 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3952 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003953 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003954 "Laying out navigation bar window: (%d,%d - %d,%d)",
3955 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003956 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3957 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003958 && ((fl & FLAG_FULLSCREEN) != 0)) {
3959 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003960 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3961 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3962 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3963 + mOverscanScreenWidth;
3964 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3965 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003966 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003967 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003968 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3969 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3970 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3971 + mOverscanScreenWidth;
3972 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3973 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003974 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003975 // The wallpaper also has Real Ultimate Power, but we want to tell
3976 // it about the overscan area.
3977 pf.left = df.left = mOverscanScreenLeft;
3978 pf.top = df.top = mOverscanScreenTop;
3979 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3980 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3981 of.left = cf.left = mUnrestrictedScreenLeft;
3982 of.top = cf.top = mUnrestrictedScreenTop;
3983 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3984 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003985 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003986 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3987 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3988 // Asking to layout into the overscan region, so give it that pure
3989 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003990 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3991 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3992 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003993 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003994 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003995 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003996 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003997 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003998 && (attrs.type == TYPE_STATUS_BAR
3999 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004000 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004001 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4002 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004003 // Asking for layout as if the nav bar is hidden, lets the
4004 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004005 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004006 // can be above the nav bar can do this.
4007 // XXX This assumes that an app asking for this will also
4008 // ask for layout in only content. We can't currently figure out
4009 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004010 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4011 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4012 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4013 + mUnrestrictedScreenWidth;
4014 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4015 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004016 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004017 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4018 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4019 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4020 + mRestrictedScreenWidth;
4021 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4022 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004023 }
Craig Mautner69b08182012-09-05 13:07:13 -07004024
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004025 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004026
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004027 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4028 vf.left = mCurLeft;
4029 vf.top = mCurTop;
4030 vf.right = mCurRight;
4031 vf.bottom = mCurBottom;
4032 } else {
4033 vf.set(cf);
4034 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004035 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004036 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4037 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004038 // A child window should be placed inside of the same visible
4039 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004040 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004041 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004042 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4043 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004044 // Otherwise, a normal window must be placed inside the content
4045 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004046 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4047 // Status bar panels and the volume dialog are the only windows who can go on
4048 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004049 // permission, so they have the same privileges as the status
4050 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004051 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4052 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4053 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4054 + mRestrictedScreenWidth;
4055 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4056 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004057 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004058 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004059 pf.left = df.left = of.left = cf.left = mStableLeft;
4060 pf.top = df.top = of.top = cf.top = mStableTop;
4061 pf.right = df.right = of.right = cf.right = mStableRight;
4062 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004063 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004064 pf.left = mContentLeft;
4065 pf.top = mContentTop;
4066 pf.right = mContentRight;
4067 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004068 if (win.isVoiceInteraction()) {
4069 df.left = of.left = cf.left = mVoiceContentLeft;
4070 df.top = of.top = cf.top = mVoiceContentTop;
4071 df.right = of.right = cf.right = mVoiceContentRight;
4072 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4073 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004074 df.left = of.left = cf.left = mDockLeft;
4075 df.top = of.top = cf.top = mDockTop;
4076 df.right = of.right = cf.right = mDockRight;
4077 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004078 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004079 df.left = of.left = cf.left = mContentLeft;
4080 df.top = of.top = cf.top = mContentTop;
4081 df.right = of.right = cf.right = mContentRight;
4082 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004083 }
4084 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4085 vf.left = mCurLeft;
4086 vf.top = mCurTop;
4087 vf.right = mCurRight;
4088 vf.bottom = mCurBottom;
4089 } else {
4090 vf.set(cf);
4091 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004092 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004093 }
4094 }
Craig Mautner69b08182012-09-05 13:07:13 -07004095
Craig Mautnerb816bed2013-07-23 10:26:17 -07004096 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4097 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004098 df.left = df.top = -10000;
4099 df.right = df.bottom = 10000;
4100 if (attrs.type != TYPE_WALLPAPER) {
4101 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4102 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4103 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004104 }
4105
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004106 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4107 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004108 // We only want to apply outsets to certain types of windows. For example, we never want to
4109 // apply the outsets to floating dialogs, because they wouldn't make sense there.
4110 final boolean useOutsets = attrs.type == TYPE_WALLPAPER
4111 || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
4112 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
4113 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004114 osf = mTmpOutsetFrame;
4115 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4116 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4117 if (outset > 0) {
4118 int rotation = Surface.ROTATION_0;
4119 try {
4120 rotation = mWindowManager.getRotation();
4121 } catch (RemoteException e) {
4122 }
4123 if (rotation == Surface.ROTATION_0) {
4124 osf.bottom += outset;
4125 } else if (rotation == Surface.ROTATION_90) {
4126 osf.right += outset;
4127 } else if (rotation == Surface.ROTATION_180) {
4128 osf.top -= outset;
4129 } else if (rotation == Surface.ROTATION_270) {
4130 osf.left -= outset;
4131 }
4132 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4133 + " with rotation " + rotation + ", result: " + osf);
4134 }
4135 }
4136
Craig Mautnereda67292013-04-28 13:50:14 -07004137 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004138 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004139 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004140 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004141 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004142 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004143 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004144 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004145 + " sf=" + sf.toShortString()
4146 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004147
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004148 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004149
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004150 // Dock windows carve out the bottom of the screen, so normal windows
4151 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004152 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4153 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004154 setLastInputMethodWindowLw(null, null);
4155 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004156 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004157 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4158 && !win.getGivenInsetsPendingLw()) {
4159 offsetVoiceInputWindowLw(win);
4160 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004161 }
4162
satok1bc0a492012-04-25 22:47:12 +09004163 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004164 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004165 top += win.getGivenContentInsetsLw().top;
4166 if (mContentBottom > top) {
4167 mContentBottom = top;
4168 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004169 if (mVoiceContentBottom > top) {
4170 mVoiceContentBottom = top;
4171 }
satok1bc0a492012-04-25 22:47:12 +09004172 top = win.getVisibleFrameLw().top;
4173 top += win.getGivenVisibleInsetsLw().top;
4174 if (mCurBottom > top) {
4175 mCurBottom = top;
4176 }
Craig Mautnereda67292013-04-28 13:50:14 -07004177 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004178 + mDockBottom + " mContentBottom="
4179 + mContentBottom + " mCurBottom=" + mCurBottom);
4180 }
4181
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004182 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004183 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004184 top += win.getGivenContentInsetsLw().top;
4185 if (mVoiceContentBottom > top) {
4186 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004187 }
4188 }
4189
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004190 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004191 @Override
4192 public void finishLayoutLw() {
4193 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004194 }
4195
4196 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004197 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004198 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004199 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004200 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004201 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004202 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004203 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004204 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004205 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004206 mForcingShowNavBar = false;
4207 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004208
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004209 mHideLockScreen = false;
4210 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004211 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004212 mShowingLockscreen = false;
4213 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004214 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004215 mKeyguardSecure = isKeyguardSecure();
4216 mKeyguardSecureIncludingHidden = mKeyguardSecure
4217 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004218 }
4219
4220 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004221 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004222 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004223 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4224 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004225 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004226 if (mTopFullscreenOpaqueWindowState == null
4227 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4228 mForcingShowNavBar = true;
4229 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004230 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004231 if (attrs.type == TYPE_STATUS_BAR) {
4232 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4233 mForceStatusBarFromKeyguard = true;
4234 }
4235 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4236 mForceStatusBarTransparent = true;
4237 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004238 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004239
4240 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4241 && attrs.type < FIRST_SYSTEM_WINDOW;
4242 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4243 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4244
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004245 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004246 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004247 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004248 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004249 mForceStatusBarFromKeyguard = true;
4250 } else {
4251 mForceStatusBar = true;
4252 }
4253 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004254 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004255 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004256 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004257 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004258 // If the lockscreen was showing when the dream started then wait
4259 // for the dream to draw before hiding the lockscreen.
4260 if (!mDreamingLockscreen
4261 || (win.isVisibleLw() && win.hasDrawnLw())) {
4262 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004263 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004264 }
4265 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004266
Craig Mautnerab55e522014-03-03 13:26:03 -08004267 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004268 final IApplicationToken appToken = win.getAppToken();
4269 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004270 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004271 mAppsToBeHidden.remove(appToken);
4272 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004273 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004274 if (dismissKeyguard && !mKeyguardSecure) {
4275 mAppsThatDismissKeyguard.add(appToken);
4276 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004277 mWinShowWhenLocked = win;
4278 mHideLockScreen = true;
4279 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004280 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004281 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004282 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004283 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004284 mAppsToBeHidden.add(appToken);
4285 } else {
4286 mAppsToBeHidden.remove(appToken);
4287 }
4288 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004289 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004290 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004291 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004292 if (attrs.x == 0 && attrs.y == 0
4293 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4294 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4295 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4296 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004297 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4298 mTopFullscreenOpaqueOrDimmingWindowState = win;
4299 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004300 if (!mAppsThatDismissKeyguard.isEmpty() &&
4301 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4302 if (DEBUG_LAYOUT) Slog.v(TAG,
4303 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004304 mDismissKeyguard = (mWinDismissingKeyguard == win
4305 && mSecureDismissingKeyguard == mKeyguardSecure)
4306 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004307 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004308 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004309 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004310 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4311 if (DEBUG_LAYOUT) Slog.v(TAG,
4312 "Setting mHideLockScreen to true by win " + win);
4313 mHideLockScreen = true;
4314 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004315 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004316 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004317 mAllowLockscreenWhenOn = true;
4318 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004319 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004320
4321 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004322 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4323 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004324 win.hideLw(false);
4325 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004326 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004327 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4328 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4329 // that is being hidden in an animation - keep the
4330 // keyguard hidden until the new window shows up and
4331 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004332 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004333 mHideLockScreen = true;
4334 mWinShowWhenLocked = win;
4335 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004336 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004337 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4338 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4339 && win.isDimming()) {
4340 mTopFullscreenOpaqueOrDimmingWindowState = win;
4341 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004342 }
4343
4344 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004345 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004346 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004347 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4348 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4349 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004350 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4351 // fullscreen window.
4352 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4353 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4354 mTopFullscreenOpaqueWindowState.hideLw(false);
4355 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4356 }
4357
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004358 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004359 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004360
4361 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4362 ? mTopFullscreenOpaqueWindowState.getAttrs()
4363 : null;
4364
Jeff Brownc8018eb2012-10-29 21:33:27 -07004365 // If we are not currently showing a dream then remember the current
4366 // lockscreen state. We will use this to determine whether the dream
4367 // started while the lockscreen was showing and remember this state
4368 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004369 if (!mShowingDream) {
4370 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004371 if (mDreamingSleepTokenNeeded) {
4372 mDreamingSleepTokenNeeded = false;
4373 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4374 }
4375 } else {
4376 if (!mDreamingSleepTokenNeeded) {
4377 mDreamingSleepTokenNeeded = true;
4378 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4379 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004380 }
4381
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004382 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004383 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004384 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004385 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004386 boolean shouldBeTransparent = mForceStatusBarTransparent
4387 && !mForceStatusBar
4388 && !mForceStatusBarFromKeyguard;
4389 if (!shouldBeTransparent) {
4390 mStatusBarController.setShowTransparent(false /* transparent */);
4391 } else if (!mStatusBar.isVisibleLw()) {
4392 mStatusBarController.setShowTransparent(true /* transparent */);
4393 }
4394 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004395 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004396 if (mStatusBarController.setBarShowingLw(true)) {
4397 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4398 }
Craig Mautner81defc72013-10-29 11:10:42 -07004399 // Maintain fullscreen layout until incoming animation is complete.
4400 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004401 // Transient status bar on the lockscreen is not allowed
4402 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4403 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4404 mLastSystemUiFlags, mLastSystemUiFlags);
4405 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004406 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004407 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004408 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004409 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004410 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004411 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004412 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004413 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004414 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004415 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004416 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004417 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004418 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4419 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004420 if (mStatusBarController.isTransientShowing()) {
4421 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004422 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4423 }
4424 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004425 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004426 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004427 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004428 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004429 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004430 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004431 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004432 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004433 if (mStatusBarController.setBarShowingLw(true)) {
4434 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4435 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004436 }
4437 }
4438 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004439
Craig Mautner81defc72013-10-29 11:10:42 -07004440 if (mTopIsFullscreen != topIsFullscreen) {
4441 if (!topIsFullscreen) {
4442 // Force another layout when status bar becomes fully shown.
4443 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4444 }
4445 mTopIsFullscreen = topIsFullscreen;
4446 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004447
Craig Mautner39834192012-09-02 07:47:24 -07004448 // Hide the key guard if a visible window explicitly specifies that it wants to be
4449 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004450 if (mKeyguardDelegate != null && mStatusBar != null) {
4451 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4452 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004453 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004454 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004455 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004456 changes |= FINISH_LAYOUT_REDO_LAYOUT
4457 | FINISH_LAYOUT_REDO_CONFIG
4458 | FINISH_LAYOUT_REDO_WALLPAPER;
4459 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004460 if (mKeyguardDelegate.isShowing()) {
4461 mHandler.post(new Runnable() {
4462 @Override
4463 public void run() {
4464 mKeyguardDelegate.keyguardDone(false, false);
4465 }
4466 });
4467 }
4468 } else if (mHideLockScreen) {
4469 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004470 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004471 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004472 changes |= FINISH_LAYOUT_REDO_LAYOUT
4473 | FINISH_LAYOUT_REDO_CONFIG
4474 | FINISH_LAYOUT_REDO_WALLPAPER;
4475 }
4476 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004477 mKeyguardHidden = false;
4478 if (setKeyguardOccludedLw(false)) {
4479 changes |= FINISH_LAYOUT_REDO_LAYOUT
4480 | FINISH_LAYOUT_REDO_CONFIG
4481 | FINISH_LAYOUT_REDO_WALLPAPER;
4482 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004483 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4484 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004485 mHandler.post(new Runnable() {
4486 @Override
4487 public void run() {
4488 mKeyguardDelegate.dismiss();
4489 }
4490 });
4491 }
4492 } else {
4493 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004494 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004495 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004496 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004497 changes |= FINISH_LAYOUT_REDO_LAYOUT
4498 | FINISH_LAYOUT_REDO_CONFIG
4499 | FINISH_LAYOUT_REDO_WALLPAPER;
4500 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004501 }
4502 }
Joe Onorato664644d2011-01-23 17:53:23 -08004503
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004504 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004505 // If the navigation bar has been hidden or shown, we need to do another
4506 // layout pass to update that window.
4507 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4508 }
Joe Onorato664644d2011-01-23 17:53:23 -08004509
Mike Lockwood28569302010-01-28 11:54:40 -05004510 // update since mAllowLockscreenWhenOn might have changed
4511 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004512 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004513 }
4514
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004515 /**
Jim Millerab954542014-10-10 18:21:49 -07004516 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004517 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004518 * @return Whether the flags have changed and we have to redo the layout.
4519 */
Jim Millerab954542014-10-10 18:21:49 -07004520 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4521 boolean wasOccluded = mKeyguardOccluded;
4522 boolean showing = mKeyguardDelegate.isShowing();
4523 if (wasOccluded && !isOccluded && showing) {
4524 mKeyguardOccluded = false;
4525 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004526 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4527 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4528 return true;
Jim Millerab954542014-10-10 18:21:49 -07004529 } else if (!wasOccluded && isOccluded && showing) {
4530 mKeyguardOccluded = true;
4531 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004532 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4533 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4534 return true;
4535 } else {
4536 return false;
4537 }
4538 }
4539
4540 private boolean isStatusBarKeyguard() {
4541 return mStatusBar != null
4542 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4543 }
4544
Jose Lima9546b202014-07-02 17:21:51 -07004545 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004546 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004547 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004548 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004549 return false;
4550 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004551 return true;
4552 }
4553
Jose Lima9546b202014-07-02 17:21:51 -07004554 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004555 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004556 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004557 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004558 // If the navigation bar has been hidden or shown, we need to do another
4559 // layout pass to update that window.
4560 return FINISH_LAYOUT_REDO_LAYOUT;
4561 }
4562 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004563 }
4564
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004565 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004566 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004567 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4568 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004569 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4570 if (newLidState == mLidState) {
4571 return;
4572 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004573
Jeff Brownc458ce92012-04-30 14:58:40 -07004574 mLidState = newLidState;
4575 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004576 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004577
4578 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004579 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004580 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004581 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004582 }
4583 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004584
Michael Wright3818c922014-09-02 13:59:07 -07004585 @Override
4586 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4587 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4588 if (mCameraLensCoverState == lensCoverState) {
4589 return;
4590 }
4591 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4592 lensCoverState == CAMERA_LENS_UNCOVERED) {
4593 Intent intent;
4594 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4595 mKeyguardDelegate.isShowing();
4596 if (keyguardActive) {
4597 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4598 } else {
4599 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4600 }
Bryce Lee584a4452014-10-21 15:55:55 -07004601 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004602 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004603 }
4604 mCameraLensCoverState = lensCoverState;
4605 }
4606
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004607 void setHdmiPlugged(boolean plugged) {
4608 if (mHdmiPlugged != plugged) {
4609 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004610 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004611 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004612 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004613 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004614 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004615 }
4616 }
4617
Joe Onoratoea495d42011-04-06 11:41:11 -07004618 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004619 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004620 // watch for HDMI plug messages if the hdmi switch exists
4621 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4622 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4623
Joe Onoratoea495d42011-04-06 11:41:11 -07004624 final String filename = "/sys/class/switch/hdmi/state";
4625 FileReader reader = null;
4626 try {
4627 reader = new FileReader(filename);
4628 char[] buf = new char[15];
4629 int n = reader.read(buf);
4630 if (n > 1) {
4631 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4632 }
4633 } catch (IOException ex) {
4634 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4635 } catch (NumberFormatException ex) {
4636 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4637 } finally {
4638 if (reader != null) {
4639 try {
4640 reader.close();
4641 } catch (IOException ex) {
4642 }
Joe Onoratodc100302011-01-11 17:07:41 -08004643 }
4644 }
4645 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004646 // This dance forces the code in setHdmiPlugged to run.
4647 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4648 mHdmiPlugged = !plugged;
4649 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004650 }
4651
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004652 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004653 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004654
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004655 final Runnable mScreenshotTimeout = new Runnable() {
4656 @Override public void run() {
4657 synchronized (mScreenshotLock) {
4658 if (mScreenshotConnection != null) {
4659 mContext.unbindService(mScreenshotConnection);
4660 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004661 }
Winson Chung9112ec32011-06-27 13:15:32 -07004662 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004663 }
4664 };
4665
4666 // Assume this is called from the Handler thread.
4667 private void takeScreenshot() {
4668 synchronized (mScreenshotLock) {
4669 if (mScreenshotConnection != null) {
4670 return;
4671 }
4672 ComponentName cn = new ComponentName("com.android.systemui",
4673 "com.android.systemui.screenshot.TakeScreenshotService");
4674 Intent intent = new Intent();
4675 intent.setComponent(cn);
4676 ServiceConnection conn = new ServiceConnection() {
4677 @Override
4678 public void onServiceConnected(ComponentName name, IBinder service) {
4679 synchronized (mScreenshotLock) {
4680 if (mScreenshotConnection != this) {
4681 return;
4682 }
4683 Messenger messenger = new Messenger(service);
4684 Message msg = Message.obtain(null, 1);
4685 final ServiceConnection myConn = this;
4686 Handler h = new Handler(mHandler.getLooper()) {
4687 @Override
4688 public void handleMessage(Message msg) {
4689 synchronized (mScreenshotLock) {
4690 if (mScreenshotConnection == myConn) {
4691 mContext.unbindService(mScreenshotConnection);
4692 mScreenshotConnection = null;
4693 mHandler.removeCallbacks(mScreenshotTimeout);
4694 }
4695 }
4696 }
4697 };
4698 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004699 msg.arg1 = msg.arg2 = 0;
4700 if (mStatusBar != null && mStatusBar.isVisibleLw())
4701 msg.arg1 = 1;
4702 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4703 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004704 try {
4705 messenger.send(msg);
4706 } catch (RemoteException e) {
4707 }
4708 }
4709 }
4710 @Override
4711 public void onServiceDisconnected(ComponentName name) {}
4712 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004713 if (mContext.bindServiceAsUser(
4714 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004715 mScreenshotConnection = conn;
4716 mHandler.postDelayed(mScreenshotTimeout, 10000);
4717 }
4718 }
Winson Chung9112ec32011-06-27 13:15:32 -07004719 }
4720
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004721 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004722 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004723 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004724 if (!mSystemBooted) {
4725 // If we have not yet booted, don't let key events do anything.
4726 return 0;
4727 }
4728
Jeff Brown037c33e2014-04-09 00:31:55 -07004729 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004730 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4731 final boolean canceled = event.isCanceled();
4732 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004733
Jeff Brown3122e442010-10-11 23:32:49 -07004734 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004735
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004736 // If screen is off then we treat the case where the keyguard is open but hidden
4737 // the same as if it were open and in front.
4738 // This will prevent any keys other than the power button from waking the screen
4739 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004740 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004741 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004742 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004743 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004744
Jeff Brown40013652012-05-16 21:22:36 -07004745 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004746 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004747 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004748 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004749 }
4750
Jeff Brown037c33e2014-04-09 00:31:55 -07004751 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004752 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004753 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4754 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004755 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004756 // When the device is interactive or the key is injected pass the
4757 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004758 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004759 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004760 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4761 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4762 // to the application but preserve its wake key status to make sure we still move
4763 // from dozing to fully interactive if we would normally go from off to fully
4764 // interactive.
4765 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004766 } else {
4767 // When the screen is off and the key is not injected, determine whether
4768 // to wake the device but don't pass the key to the application.
4769 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004770 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4771 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004772 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004773 }
4774
Justin Kohd378ad72013-04-01 12:18:26 -07004775 // If the key would be handled globally, just return the result, don't worry about special
4776 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004777 if (isValidGlobalKey(keyCode)
4778 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004779 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004780 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004781 }
Justin Kohd378ad72013-04-01 12:18:26 -07004782 return result;
4783 }
4784
Jeff Brownbae8e772014-06-12 19:59:45 -07004785 boolean useHapticFeedback = down
4786 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4787 && event.getRepeatCount() == 0;
4788
Jeff Brown4d396052010-10-29 21:50:21 -07004789 // Handle special keys.
4790 switch (keyCode) {
4791 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004792 case KeyEvent.KEYCODE_VOLUME_UP:
4793 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004794 if (mUseTvRouting) {
4795 // On TVs volume keys never go to the foreground app
4796 result &= ~ACTION_PASS_TO_USER;
4797 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004798 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4799 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004800 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004801 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004802 mScreenshotChordVolumeDownKeyTriggered = true;
4803 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4804 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004805 cancelPendingPowerKeyAction();
4806 interceptScreenshotChord();
4807 }
4808 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004809 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004810 cancelPendingScreenshotChordAction();
4811 }
4812 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4813 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004814 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004815 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004816 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004817 cancelPendingPowerKeyAction();
4818 cancelPendingScreenshotChordAction();
4819 }
4820 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004821 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004822 cancelPendingScreenshotChordAction();
4823 }
4824 }
Jeff Brown4d396052010-10-29 21:50:21 -07004825 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004826 TelecomManager telecomManager = getTelecommService();
4827 if (telecomManager != null) {
4828 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004829 // If an incoming call is ringing, either VOLUME key means
4830 // "silence ringer". We handle these keys here, rather than
4831 // in the InCallScreen, to make sure we'll respond to them
4832 // even if the InCallScreen hasn't come to the foreground yet.
4833 // Look for the DOWN event here, to agree with the "fallback"
4834 // behavior in the InCallScreen.
4835 Log.i(TAG, "interceptKeyBeforeQueueing:"
4836 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004837
Santos Cordon6848f722014-05-21 15:22:12 -07004838 // Silence the ringer. (It's safe to call this
4839 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004840 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004841
Santos Cordon6848f722014-05-21 15:22:12 -07004842 // And *don't* pass this key thru to the current activity
4843 // (which is probably the InCallScreen.)
4844 result &= ~ACTION_PASS_TO_USER;
4845 break;
4846 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004847 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004848 && (result & ACTION_PASS_TO_USER) == 0) {
4849 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004850 // the application, just pass it to the session service.
4851
4852 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004853 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004854 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004855 }
4856 }
4857
RoboErik430fc482014-06-12 15:49:20 -07004858 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004859 if (mUseTvRouting) {
4860 dispatchDirectAudioEvent(event);
4861 } else {
4862 // If we aren't passing to the user and no one else
4863 // handled it send it to the session manager to
4864 // figure out.
4865 MediaSessionLegacyHelper.getHelper(mContext)
4866 .sendVolumeKeyEvent(event, true);
4867 }
Jeff Brown4d396052010-10-29 21:50:21 -07004868 break;
4869 }
4870 }
4871 break;
4872 }
4873
4874 case KeyEvent.KEYCODE_ENDCALL: {
4875 result &= ~ACTION_PASS_TO_USER;
4876 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004877 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004878 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004879 if (telecomManager != null) {
4880 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004881 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004882 if (interactive && !hungUp) {
4883 mEndCallKeyHandled = false;
4884 mHandler.postDelayed(mEndCallLongPress,
4885 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4886 } else {
4887 mEndCallKeyHandled = true;
4888 }
Jeff Brown4d396052010-10-29 21:50:21 -07004889 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004890 if (!mEndCallKeyHandled) {
4891 mHandler.removeCallbacks(mEndCallLongPress);
4892 if (!canceled) {
4893 if ((mEndcallBehavior
4894 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4895 if (goHome()) {
4896 break;
4897 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004898 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004899 if ((mEndcallBehavior
4900 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4901 mPowerManager.goToSleep(event.getEventTime(),
4902 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4903 isWakeKey = false;
4904 }
Jeff Brown4d396052010-10-29 21:50:21 -07004905 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004906 }
Jeff Brown4d396052010-10-29 21:50:21 -07004907 }
4908 break;
4909 }
4910
4911 case KeyEvent.KEYCODE_POWER: {
4912 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004913 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004914 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004915 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004916 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004917 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004918 }
4919 break;
4920 }
4921
Jeff Brown6212a492014-03-07 13:58:47 -08004922 case KeyEvent.KEYCODE_SLEEP: {
4923 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004924 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004925 if (!mPowerManager.isInteractive()) {
4926 useHapticFeedback = false; // suppress feedback if already non-interactive
4927 }
Nick Vaccarob593a812015-05-15 11:23:05 -07004928 if (down) {
4929 sleepPress(event.getEventTime());
4930 } else {
4931 sleepRelease(event.getEventTime());
4932 }
Jeff Brown6212a492014-03-07 13:58:47 -08004933 break;
4934 }
4935
4936 case KeyEvent.KEYCODE_WAKEUP: {
4937 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004938 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004939 break;
4940 }
4941
Jeff Brown4d396052010-10-29 21:50:21 -07004942 case KeyEvent.KEYCODE_MEDIA_PLAY:
4943 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4944 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004945 case KeyEvent.KEYCODE_HEADSETHOOK:
4946 case KeyEvent.KEYCODE_MUTE:
4947 case KeyEvent.KEYCODE_MEDIA_STOP:
4948 case KeyEvent.KEYCODE_MEDIA_NEXT:
4949 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4950 case KeyEvent.KEYCODE_MEDIA_REWIND:
4951 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004952 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4953 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004954 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4955 // If the global session is active pass all media keys to it
4956 // instead of the active window.
4957 result &= ~ACTION_PASS_TO_USER;
4958 }
Jeff Brown4d396052010-10-29 21:50:21 -07004959 if ((result & ACTION_PASS_TO_USER) == 0) {
4960 // Only do this if we would otherwise not pass it to the user. In that
4961 // case, the PhoneWindow class will do the same thing, except it will
4962 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004963 // Note that we need to make a copy of the key event here because the
4964 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004965 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004966 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4967 new KeyEvent(event));
4968 msg.setAsynchronous(true);
4969 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004970 }
4971 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004972 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004973
Jeff Brown4d396052010-10-29 21:50:21 -07004974 case KeyEvent.KEYCODE_CALL: {
4975 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004976 TelecomManager telecomManager = getTelecommService();
4977 if (telecomManager != null) {
4978 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004979 Log.i(TAG, "interceptKeyBeforeQueueing:"
4980 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004981 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004982
Santos Cordon6848f722014-05-21 15:22:12 -07004983 // And *don't* pass this key thru to the current activity
4984 // (which is presumably the InCallScreen.)
4985 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004986 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004987 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004988 }
Jeff Brown4d396052010-10-29 21:50:21 -07004989 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004990 }
Michael Wright869a67c2014-08-26 19:33:06 -07004991 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4992 // Only do this if we would otherwise not pass it to the user. In that case,
4993 // interceptKeyBeforeDispatching would apply a similar but different policy in
4994 // order to invoke voice assist actions. Note that we need to make a copy of the
4995 // key event here because the original key event will be recycled when we return.
4996 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4997 mBroadcastWakeLock.acquire();
4998 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4999 keyguardActive ? 1 : 0, 0);
5000 msg.setAsynchronous(true);
5001 msg.sendToTarget();
5002 }
5003 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005004 }
Jeff Brown26875502014-01-30 21:47:47 -08005005
Jeff Brownbae8e772014-06-12 19:59:45 -07005006 if (useHapticFeedback) {
5007 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5008 }
5009
Jeff Brown26875502014-01-30 21:47:47 -08005010 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005011 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08005012 }
Bryce Lee584a4452014-10-21 15:55:55 -07005013
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005014 return result;
5015 }
5016
Jeff Brown1c2e4942012-11-06 16:32:01 -08005017 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005018 * Returns true if the key can have global actions attached to it.
5019 * We reserve all power management keys for the system since they require
5020 * very careful handling.
5021 */
5022 private static boolean isValidGlobalKey(int keyCode) {
5023 switch (keyCode) {
5024 case KeyEvent.KEYCODE_POWER:
5025 case KeyEvent.KEYCODE_WAKEUP:
5026 case KeyEvent.KEYCODE_SLEEP:
5027 return false;
5028 default:
5029 return true;
5030 }
5031 }
5032
5033 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005034 * When the screen is off we ignore some keys that might otherwise typically
5035 * be considered wake keys. We filter them out here.
5036 *
5037 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5038 * is always considered a wake key.
5039 */
5040 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5041 switch (keyCode) {
5042 // ignore volume keys unless docked
5043 case KeyEvent.KEYCODE_VOLUME_UP:
5044 case KeyEvent.KEYCODE_VOLUME_DOWN:
5045 case KeyEvent.KEYCODE_VOLUME_MUTE:
5046 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5047
5048 // ignore media and camera keys
5049 case KeyEvent.KEYCODE_MUTE:
5050 case KeyEvent.KEYCODE_HEADSETHOOK:
5051 case KeyEvent.KEYCODE_MEDIA_PLAY:
5052 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5053 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5054 case KeyEvent.KEYCODE_MEDIA_STOP:
5055 case KeyEvent.KEYCODE_MEDIA_NEXT:
5056 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5057 case KeyEvent.KEYCODE_MEDIA_REWIND:
5058 case KeyEvent.KEYCODE_MEDIA_RECORD:
5059 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005060 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005061 case KeyEvent.KEYCODE_CAMERA:
5062 return false;
5063 }
5064 return true;
5065 }
5066
5067
Jeff Brown56194eb2011-03-02 19:23:13 -08005068 /** {@inheritDoc} */
5069 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005070 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5071 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08005072 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
5073 return 0;
5074 }
Michael Wright70af00a2014-09-03 19:30:20 -07005075 }
Bryce Lee5c138322014-11-03 08:26:09 -08005076
Michael Wright70af00a2014-09-03 19:30:20 -07005077 if (shouldDispatchInputWhenNonInteractive()) {
5078 return ACTION_PASS_TO_USER;
5079 }
Bryce Lee5c138322014-11-03 08:26:09 -08005080
Bryce Lee812d7022014-11-10 13:33:28 -08005081 // If we have not passed the action up and we are in theater mode without dreaming,
5082 // there will be no dream to intercept the touch and wake into ambient. The device should
5083 // wake up in this case.
5084 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
5085 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
5086 }
5087
Jeff Brown037c33e2014-04-09 00:31:55 -07005088 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005089 }
5090
Michael Wright70af00a2014-09-03 19:30:20 -07005091 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08005092 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07005093 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5094 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005095 return true;
5096 }
5097
5098 // Send events to a dozing dream even if the screen is off since the dream
5099 // is in control of the state of the screen.
5100 IDreamManager dreamManager = getDreamManager();
5101
5102 try {
5103 if (dreamManager != null && dreamManager.isDreaming()) {
5104 return true;
5105 }
5106 } catch (RemoteException e) {
5107 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5108 }
5109
5110 // Otherwise, consume events since the user can't see what is being
5111 // interacted with.
5112 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005113 }
5114
RoboErik001c59c2015-01-26 15:53:51 -08005115 private void dispatchDirectAudioEvent(KeyEvent event) {
5116 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5117 return;
5118 }
5119 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005120 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5121 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005122 String pkgName = mContext.getOpPackageName();
5123 switch (keyCode) {
5124 case KeyEvent.KEYCODE_VOLUME_UP:
5125 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005126 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005127 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005128 } catch (RemoteException e) {
5129 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5130 }
5131 break;
5132 case KeyEvent.KEYCODE_VOLUME_DOWN:
5133 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005134 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005135 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005136 } catch (RemoteException e) {
5137 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5138 }
5139 break;
5140 case KeyEvent.KEYCODE_VOLUME_MUTE:
5141 try {
5142 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005143 getAudioService().adjustSuggestedStreamVolume(
5144 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005145 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005146 }
5147 } catch (RemoteException e) {
5148 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5149 }
5150 break;
5151 }
5152 }
5153
Jeff Brown40013652012-05-16 21:22:36 -07005154 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5155 if (DEBUG_INPUT) {
5156 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005157 }
5158
Jeff Brown40013652012-05-16 21:22:36 -07005159 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5160 if (DEBUG_INPUT) {
5161 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5162 }
5163
5164 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5165 mHavePendingMediaKeyRepeatWithWakeLock = false;
5166 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5167 }
5168
5169 dispatchMediaKeyWithWakeLockToAudioService(event);
5170
5171 if (event.getAction() == KeyEvent.ACTION_DOWN
5172 && event.getRepeatCount() == 0) {
5173 mHavePendingMediaKeyRepeatWithWakeLock = true;
5174
5175 Message msg = mHandler.obtainMessage(
5176 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5177 msg.setAsynchronous(true);
5178 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5179 } else {
5180 mBroadcastWakeLock.release();
5181 }
5182 }
5183
5184 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5185 mHavePendingMediaKeyRepeatWithWakeLock = false;
5186
5187 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5188 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5189 if (DEBUG_INPUT) {
5190 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5191 }
5192
5193 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5194 mBroadcastWakeLock.release();
5195 }
5196
5197 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5198 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005199 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005200 }
5201 }
5202
Michael Wright869a67c2014-08-26 19:33:06 -07005203 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005204 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5205 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5206 if (dic != null) {
5207 try {
5208 dic.exitIdle("voice-search");
5209 } catch (RemoteException e) {
5210 }
5211 }
Michael Wright869a67c2014-08-26 19:33:06 -07005212 Intent voiceIntent =
5213 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5214 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005215 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005216 mBroadcastWakeLock.release();
5217 }
5218
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005219 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005220 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005221 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005222 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5223 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5224 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005225 } else {
5226 try {
5227 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5228 ServiceManager.getService(Context.UI_MODE_SERVICE));
5229 mUiMode = uiModeService.getCurrentModeType();
5230 } catch (RemoteException e) {
5231 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005232 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005233 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005234 synchronized (mLock) {
5235 updateOrientationListenerLp();
5236 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005237 }
5238 };
5239
Jeff Brown6aaf2952012-10-05 16:01:08 -07005240 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5241 @Override
5242 public void onReceive(Context context, Intent intent) {
5243 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005244 if (mKeyguardDelegate != null) {
5245 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005246 }
5247 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005248 if (mKeyguardDelegate != null) {
5249 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005250 }
5251 }
5252 }
5253 };
5254
Christopher Tate5e08af02012-09-21 17:17:22 -07005255 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5256 @Override
5257 public void onReceive(Context context, Intent intent) {
5258 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5259 // tickle the settings observer: this first ensures that we're
5260 // observing the relevant settings for the newly-active user,
5261 // and then updates our own bookkeeping based on the now-
5262 // current user.
5263 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005264
5265 // force a re-application of focused window sysui visibility.
5266 // the window may never have been shown for this user
5267 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005268 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005269 mLastSystemUiFlags = 0;
5270 updateSystemUiVisibilityLw();
5271 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005272 }
5273 }
5274 };
5275
Adrian Roosddc8b272015-05-21 16:28:27 -07005276 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005277 @Override
5278 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005279 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5280 if (!isUserSetupComplete()) {
5281 // Swipe-up for navigation bar is disabled during setup
5282 return;
5283 }
5284 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5285 mNavigationBarController.showTransient();
5286 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005287 }
5288 };
5289
John Spurlocke1f366f2013-08-05 12:22:40 -04005290 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005291 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005292 if (!isUserSetupComplete()) {
5293 // Swipe-up for navigation bar is disabled during setup
5294 return;
5295 }
John Spurlock27735a42013-08-14 17:57:38 -04005296 boolean sb = mStatusBarController.checkShowTransientBarLw();
5297 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005298 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005299 // Don't show status bar when swiping on already visible navigation bar
5300 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005301 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005302 return;
5303 }
John Spurlock27735a42013-08-14 17:57:38 -04005304 if (sb) mStatusBarController.showTransient();
5305 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005306 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005307 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005308 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005309 }
5310 }
5311
Jeff Brown3ee549c2014-09-22 20:14:39 -07005312 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005313 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005314 public void startedGoingToSleep(int why) {
5315 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005316 if (mKeyguardDelegate != null) {
5317 mKeyguardDelegate.onStartedGoingToSleep(why);
5318 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005319 }
5320
5321 // Called on the PowerManager's Notifier thread.
5322 @Override
5323 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005324 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005325 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005326
5327 // We must get this work done here because the power manager will drop
5328 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005329 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005330 mAwake = false;
5331 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005332 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005333 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005334 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005335 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005336 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005337 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005338 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005339 }
5340
Jeff Brown3ee549c2014-09-22 20:14:39 -07005341 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005342 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005343 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005344 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005345 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005346
Jeff Brown3ee549c2014-09-22 20:14:39 -07005347 // Since goToSleep performs these functions synchronously, we must
5348 // do the same here. We cannot post this work to a handler because
5349 // that might cause it to become reordered with respect to what
5350 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005351 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005352 mAwake = true;
5353 mKeyguardDrawComplete = false;
5354 if (mKeyguardDelegate != null) {
5355 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5356 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5357 }
5358
Jeff Browna20dda42014-05-27 20:57:24 -07005359 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005360 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005361 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005362 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005363
Jim Miller5ecd8112013-01-09 18:50:26 -08005364 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005365 mKeyguardDelegate.onStartedWakingUp(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005366 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005367 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005368 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005369 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005370 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005371 }
5372
Jeff Brown416c49c2015-05-26 19:50:18 -07005373 // Called on the PowerManager's Notifier thread.
5374 @Override
5375 public void finishedWakingUp() {
5376 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5377 }
5378
5379 private void wakeUpFromPowerKey(long eventTime) {
5380 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5381 }
5382
5383 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Leed3896842015-06-23 17:06:51 -07005384 final boolean theaterModeEnabled = isTheaterModeEnabled();
5385 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07005386 return false;
5387 }
5388
Bryce Leed3896842015-06-23 17:06:51 -07005389 if (theaterModeEnabled) {
5390 Settings.Global.putInt(mContext.getContentResolver(),
5391 Settings.Global.THEATER_MODE_ON, 0);
5392 }
5393
Jeff Brown416c49c2015-05-26 19:50:18 -07005394 mPowerManager.wakeUp(wakeTime);
5395 return true;
5396 }
5397
Jeff Brown36c4db82014-09-19 12:05:31 -07005398 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005399 synchronized (mLock) {
5400 if (!mAwake || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005401 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005402 }
5403
Jeff Brown36c4db82014-09-19 12:05:31 -07005404 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005405 if (mKeyguardDelegate != null) {
5406 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5407 }
5408 }
5409
5410 finishScreenTurningOn();
5411 }
5412
5413 // Called on the DisplayManager's DisplayPowerController thread.
5414 @Override
5415 public void screenTurnedOff() {
5416 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5417
Jeff Brown48d1b142015-06-10 16:36:03 -07005418 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005419 synchronized (mLock) {
5420 mScreenOnEarly = false;
5421 mScreenOnFully = false;
5422 mWindowManagerDrawComplete = false;
5423 mScreenOnListener = null;
5424 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005425 }
5426 }
5427
Jeff Brown3ee549c2014-09-22 20:14:39 -07005428 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005429 @Override
5430 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005431 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005432
Jeff Brown48d1b142015-06-10 16:36:03 -07005433 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005434 synchronized (mLock) {
5435 mScreenOnEarly = true;
5436 mScreenOnFully = false;
5437 mWindowManagerDrawComplete = false;
5438 mScreenOnListener = screenOnListener;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005439 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005440
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005441 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5442 WAITING_FOR_DRAWN_TIMEOUT);
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005443 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
5444 // as well as enabling the orientation change logic/sensor.
Jeff Brown36c4db82014-09-19 12:05:31 -07005445 }
5446
Jeff Brown36c4db82014-09-19 12:05:31 -07005447 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005448 synchronized (mLock) {
5449 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005450 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005451 }
5452
Jeff Brown36c4db82014-09-19 12:05:31 -07005453 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005454 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005455
5456 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005457 }
5458
Craig Mautner8a0da012014-05-31 15:13:37 -07005459 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005460 synchronized (mLock) {
5461 // We have just finished drawing screen content. Since the orientation listener
5462 // gets only installed when all windows are drawn, we try to install it again.
5463 updateOrientationListenerLp();
5464 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005465 final ScreenOnListener listener;
5466 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005467 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005468 if (DEBUG_WAKEUP) Slog.d(TAG,
5469 "finishScreenTurningOn: mAwake=" + mAwake
5470 + ", mScreenOnEarly=" + mScreenOnEarly
5471 + ", mScreenOnFully=" + mScreenOnFully
5472 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5473 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5474
5475 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5476 || (mAwake && !mKeyguardDrawComplete)) {
5477 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005478 }
5479
Jeff Brown3ee549c2014-09-22 20:14:39 -07005480 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5481 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005482 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005483 mScreenOnFully = true;
5484
5485 // Remember the first time we draw the keyguard so we know when we're done with
5486 // the main part of booting and can enable the screen and hide boot messages.
5487 if (!mKeyguardDrawnOnce && mAwake) {
5488 mKeyguardDrawnOnce = true;
5489 enableScreen = true;
5490 if (mBootMessageNeedsHiding) {
5491 mBootMessageNeedsHiding = false;
5492 hideBootMessages();
5493 }
5494 } else {
5495 enableScreen = false;
5496 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005497 }
5498
Jeff Brown3ee549c2014-09-22 20:14:39 -07005499 if (listener != null) {
5500 listener.onScreenOn();
5501 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005502
Jeff Brown3ee549c2014-09-22 20:14:39 -07005503 if (enableScreen) {
5504 try {
5505 mWindowManager.enableScreenIfNeeded();
5506 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005507 }
Craig Mautnera631d492014-08-05 15:16:01 -07005508 }
5509 }
5510
5511 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005512 synchronized (mLock) {
5513 if (!mKeyguardDrawnOnce) {
5514 mBootMessageNeedsHiding = true;
5515 return; // keyguard hasn't drawn the first time yet, not done booting
5516 }
Craig Mautnera631d492014-08-05 15:16:01 -07005517 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005518
5519 if (mBootMsgDialog != null) {
5520 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5521 mBootMsgDialog.dismiss();
5522 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005523 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005524 }
5525
5526 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005527 public boolean isScreenOn() {
5528 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005529 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005530
Dianne Hackborn08743722009-12-21 12:16:51 -08005531 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005532 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005533 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005534 if (mKeyguardDelegate != null) {
5535 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005536 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005537 }
5538
5539 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005540 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005541 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005542 if (mKeyguardDelegate != null) {
5543 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005544 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005545 }
5546
Jim Millerab954542014-10-10 18:21:49 -07005547 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005548 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005549 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005550 }
5551
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005552 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005553 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005554 public boolean isKeyguardLocked() {
5555 return keyguardOn();
5556 }
5557
5558 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005559 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005560 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005561 if (mKeyguardDelegate == null) return false;
5562 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005563 }
5564
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005565 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005566 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07005567 public boolean isKeyguardShowingOrOccluded() {
5568 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
5569 }
5570
5571 /** {@inheritDoc} */
5572 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005573 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005574 if (mKeyguardDelegate == null) return false;
5575 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005576 }
5577
Jose Lima9546b202014-07-02 17:21:51 -07005578 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005579 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005580 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005581 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005582 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005583 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005584 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005585 // ask the keyguard to prompt the user to authenticate if necessary
5586 mKeyguardDelegate.dismiss();
5587 }
5588 });
5589 }
5590 }
5591
5592 public void notifyActivityDrawnForKeyguardLw() {
5593 if (mKeyguardDelegate != null) {
5594 mHandler.post(new Runnable() {
5595 @Override
5596 public void run() {
5597 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005598 }
5599 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005600 }
5601 }
5602
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005603 @Override
5604 public boolean isKeyguardDrawnLw() {
5605 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005606 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005607 }
5608 }
5609
Jorim Jaggi0d674622014-05-21 01:34:15 +02005610 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005611 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005612 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005613 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005614 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005615 }
5616 }
5617
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005618 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005619 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005620 }
5621
5622 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005623 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005624 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005625
Jeff Brown01a98dd2011-09-20 15:08:29 -07005626 @Override
5627 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005628 if (false) {
5629 Slog.v(TAG, "rotationForOrientationLw(orient="
5630 + orientation + ", last=" + lastRotation
5631 + "); user=" + mUserRotation + " "
5632 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5633 ? "USER_ROTATION_LOCKED" : "")
5634 );
5635 }
5636
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005637 if (mForceDefaultOrientation) {
5638 return Surface.ROTATION_0;
5639 }
5640
The Android Open Source Project0727d222009-03-11 12:11:58 -07005641 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005642 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5643 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005644 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005645 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005646
Jeff Browndec6cf42011-11-15 14:08:20 -08005647 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005648 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005649 // Ignore sensor when lid switch is open and rotation is forced.
5650 preferredRotation = mLidOpenRotation;
5651 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005652 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005653 // Ignore sensor when in car dock unless explicitly enabled.
5654 // This case can override the behavior of NOSENSOR, and can also
5655 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005656 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005657 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005658 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5659 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5660 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005661 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005662 // Ignore sensor when in desk dock unless explicitly enabled.
5663 // This case can override the behavior of NOSENSOR, and can also
5664 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005665 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005666 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005667 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5668 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005669 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005670 preferredRotation = mDemoHdmiRotation;
5671 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5672 && mUndockedHdmiRotation >= 0) {
5673 // Ignore sensor when plugged into HDMI and an undocked orientation has
5674 // been specified in the configuration (only for legacy devices without
5675 // full multi-display support).
5676 // Note that the dock orientation overrides the HDMI orientation.
5677 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005678 } else if (mDemoRotationLock) {
5679 // Ignore sensor when demo rotation lock is enabled.
5680 // Note that the dock orientation and HDMI rotation lock override this.
5681 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005682 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5683 // Application just wants to remain locked in the last rotation.
5684 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005685 } else if (!mSupportAutoRotation) {
5686 // If we don't support auto-rotation then bail out here and ignore
5687 // the sensor and any rotation lock settings.
5688 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005689 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005690 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005691 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5692 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5693 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5694 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005695 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5696 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5697 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5698 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5699 // Otherwise, use sensor only if requested by the application or enabled
5700 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005701 if (mAllowAllRotations < 0) {
5702 // Can't read this during init() because the context doesn't
5703 // have display metrics at that time so we cannot determine
5704 // tablet vs. phone then.
5705 mAllowAllRotations = mContext.getResources().getBoolean(
5706 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5707 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005708 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005709 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005710 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5711 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005712 preferredRotation = sensorRotation;
5713 } else {
5714 preferredRotation = lastRotation;
5715 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005716 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5717 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5718 // Apply rotation lock. Does not apply to NOSENSOR.
5719 // The idea is that the user rotation expresses a weak preference for the direction
5720 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5721 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005722 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005723 } else {
5724 // No overriding preference.
5725 // We will do exactly what the application asked us to do.
5726 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005727 }
5728
Dianne Hackborne5439f22010-10-02 16:53:50 -07005729 switch (orientation) {
5730 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005731 // Return portrait unless overridden.
5732 if (isAnyPortrait(preferredRotation)) {
5733 return preferredRotation;
5734 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005735 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005736
Jeff Brown01a98dd2011-09-20 15:08:29 -07005737 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005738 // Return landscape unless overridden.
5739 if (isLandscapeOrSeascape(preferredRotation)) {
5740 return preferredRotation;
5741 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005742 return mLandscapeRotation;
5743
5744 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005745 // Return reverse portrait unless overridden.
5746 if (isAnyPortrait(preferredRotation)) {
5747 return preferredRotation;
5748 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005749 return mUpsideDownRotation;
5750
5751 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005752 // Return seascape unless overridden.
5753 if (isLandscapeOrSeascape(preferredRotation)) {
5754 return preferredRotation;
5755 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005756 return mSeascapeRotation;
5757
5758 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005759 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005760 // Return either landscape rotation.
5761 if (isLandscapeOrSeascape(preferredRotation)) {
5762 return preferredRotation;
5763 }
5764 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005765 return lastRotation;
5766 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005767 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005768
Jeff Brown01a98dd2011-09-20 15:08:29 -07005769 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005770 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005771 // Return either portrait rotation.
5772 if (isAnyPortrait(preferredRotation)) {
5773 return preferredRotation;
5774 }
5775 if (isAnyPortrait(lastRotation)) {
5776 return lastRotation;
5777 }
5778 return mPortraitRotation;
5779
5780 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005781 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5782 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005783 if (preferredRotation >= 0) {
5784 return preferredRotation;
5785 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005786 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005787 }
5788 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005789 }
5790
Jeff Brown01a98dd2011-09-20 15:08:29 -07005791 @Override
5792 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5793 switch (orientation) {
5794 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5795 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5796 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5797 return isAnyPortrait(rotation);
5798
5799 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5800 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5801 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5802 return isLandscapeOrSeascape(rotation);
5803
5804 default:
5805 return true;
5806 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005807 }
5808
Jeff Brownc0347aa2011-09-23 17:26:09 -07005809 @Override
5810 public void setRotationLw(int rotation) {
5811 mOrientationListener.setCurrentRotation(rotation);
5812 }
5813
Jeff Brown01a98dd2011-09-20 15:08:29 -07005814 private boolean isLandscapeOrSeascape(int rotation) {
5815 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005816 }
5817
Jeff Brown01a98dd2011-09-20 15:08:29 -07005818 private boolean isAnyPortrait(int rotation) {
5819 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005820 }
5821
Jose Lima9546b202014-07-02 17:21:51 -07005822 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005823 public int getUserRotationMode() {
5824 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005825 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5826 WindowManagerPolicy.USER_ROTATION_FREE :
5827 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005828 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005829
5830 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005831 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005832 public void setUserRotationMode(int mode, int rot) {
5833 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005834
5835 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005836 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005837 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005838 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005839 rot,
5840 UserHandle.USER_CURRENT);
5841 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005842 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005843 0,
5844 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005845 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005846 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005847 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005848 1,
5849 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005850 }
5851 }
5852
Jose Lima9546b202014-07-02 17:21:51 -07005853 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005854 public void setSafeMode(boolean safeMode) {
5855 mSafeMode = safeMode;
5856 performHapticFeedbackLw(null, safeMode
5857 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5858 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005859 }
Craig Mautnereda67292013-04-28 13:50:14 -07005860
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005861 static long[] getLongIntArray(Resources r, int resid) {
5862 int[] ar = r.getIntArray(resid);
5863 if (ar == null) {
5864 return null;
5865 }
5866 long[] out = new long[ar.length];
5867 for (int i=0; i<ar.length; i++) {
5868 out[i] = ar[i];
5869 }
5870 return out;
5871 }
Craig Mautnereda67292013-04-28 13:50:14 -07005872
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005873 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005874 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005875 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005876 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005877 mKeyguardDelegate.onSystemReady();
5878
Michael Wright3818c922014-09-02 13:59:07 -07005879 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005880 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005881 synchronized (mLock) {
5882 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005883 mSystemReady = true;
5884 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005885 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005886 public void run() {
5887 updateSettings();
5888 }
5889 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005890 }
5891 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005892
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005893 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005894 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005895 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005896 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005897 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005898 mKeyguardDelegate.onBootCompleted();
5899 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005900 synchronized (mLock) {
5901 mSystemBooted = true;
5902 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005903 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005904 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005905 }
5906
Dianne Hackborn661cd522011-08-22 00:26:20 -07005907 ProgressDialog mBootMsgDialog = null;
5908
5909 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005910 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005911 public void showBootMessage(final CharSequence msg, final boolean always) {
5912 mHandler.post(new Runnable() {
5913 @Override public void run() {
5914 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005915 int theme;
5916 if (mContext.getPackageManager().hasSystemFeature(
5917 PackageManager.FEATURE_WATCH)) {
5918 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5919 } else if (mContext.getPackageManager().hasSystemFeature(
5920 PackageManager.FEATURE_TELEVISION)) {
5921 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5922 } else {
5923 theme = 0;
5924 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005925
5926 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005927 // This dialog will consume all events coming in to
5928 // it, to avoid it trying to do things too early in boot.
5929 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5930 return true;
5931 }
5932 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5933 return true;
5934 }
5935 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5936 return true;
5937 }
5938 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5939 return true;
5940 }
5941 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5942 return true;
5943 }
5944 @Override public boolean dispatchPopulateAccessibilityEvent(
5945 AccessibilityEvent event) {
5946 return true;
5947 }
5948 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005949 if (mContext.getPackageManager().isUpgrade()) {
5950 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5951 } else {
5952 mBootMsgDialog.setTitle(R.string.android_start_title);
5953 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005954 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5955 mBootMsgDialog.setIndeterminate(true);
5956 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005957 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005958 mBootMsgDialog.getWindow().addFlags(
5959 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5960 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5961 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005962 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5963 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5964 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005965 mBootMsgDialog.setCancelable(false);
5966 mBootMsgDialog.show();
5967 }
5968 mBootMsgDialog.setMessage(msg);
5969 }
5970 });
5971 }
5972
5973 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005974 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005975 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005976 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005977 }
5978
Mike Lockwood28569302010-01-28 11:54:40 -05005979 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005980 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005981 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005982 // ***************************************
5983 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5984 // ***************************************
5985 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5986 // WITH ITS LOCKS HELD.
5987 //
5988 // This code must be VERY careful about the locks
5989 // it acquires.
5990 // In fact, the current code acquires way too many,
5991 // and probably has lurking deadlocks.
5992
Mike Lockwood28569302010-01-28 11:54:40 -05005993 synchronized (mScreenLockTimeout) {
5994 if (mLockScreenTimerActive) {
5995 // reset the timer
5996 mHandler.removeCallbacks(mScreenLockTimeout);
5997 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5998 }
5999 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006000 }
6001
Adam Cohenf7522022012-10-03 20:03:18 -07006002 class ScreenLockTimeout implements Runnable {
6003 Bundle options;
6004
6005 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006006 public void run() {
6007 synchronized (this) {
6008 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006009 if (mKeyguardDelegate != null) {
6010 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006011 }
Mike Lockwood28569302010-01-28 11:54:40 -05006012 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006013 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006014 }
6015 }
Mike Lockwood28569302010-01-28 11:54:40 -05006016
Adam Cohenf7522022012-10-03 20:03:18 -07006017 public void setLockOptions(Bundle options) {
6018 this.options = options;
6019 }
6020 }
6021
6022 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6023
Jose Lima9546b202014-07-02 17:21:51 -07006024 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006025 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006026 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6027 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006028 if (options != null) {
6029 // In case multiple calls are made to lockNow, we don't wipe out the options
6030 // until the runnable actually executes.
6031 mScreenLockTimeout.setLockOptions(options);
6032 }
Jim Miller93c518e2012-01-17 15:55:31 -08006033 mHandler.post(mScreenLockTimeout);
6034 }
6035
Mike Lockwood28569302010-01-28 11:54:40 -05006036 private void updateLockScreenTimeout() {
6037 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006038 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006039 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006040 if (mLockScreenTimerActive != enable) {
6041 if (enable) {
6042 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
6043 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6044 } else {
6045 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6046 mHandler.removeCallbacks(mScreenLockTimeout);
6047 }
6048 mLockScreenTimerActive = enable;
6049 }
6050 }
6051 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006052
Jeff Brown061ea992015-04-17 19:55:47 -07006053 private void updateDreamingSleepToken(boolean acquire) {
6054 if (acquire) {
6055 if (mDreamingSleepToken == null) {
6056 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6057 }
6058 } else {
6059 if (mDreamingSleepToken != null) {
6060 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006061 mDreamingSleepToken = null;
6062 }
6063 }
6064 }
6065
6066 private void updateScreenOffSleepToken(boolean acquire) {
6067 if (acquire) {
6068 if (mScreenOffSleepToken == null) {
6069 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6070 }
6071 } else {
6072 if (mScreenOffSleepToken != null) {
6073 mScreenOffSleepToken.release();
6074 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006075 }
6076 }
6077 }
6078
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006079 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006080 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006081 public void enableScreenAfterBoot() {
6082 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006083 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006084 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006085 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006086
Jeff Brownc458ce92012-04-30 14:58:40 -07006087 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006088 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006089 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006090 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006091 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07006092 }
Jeff Browna20dda42014-05-27 20:57:24 -07006093
6094 synchronized (mLock) {
6095 updateWakeGestureListenerLp();
6096 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006097 }
6098
Jeff Brown4f5fa282014-06-12 19:19:15 -07006099 void updateUiMode() {
6100 if (mUiModeManager == null) {
6101 mUiModeManager = IUiModeManager.Stub.asInterface(
6102 ServiceManager.getService(Context.UI_MODE_SERVICE));
6103 }
6104 try {
6105 mUiMode = mUiModeManager.getCurrentModeType();
6106 } catch (RemoteException e) {
6107 }
6108 }
6109
Jeff Brown01a98dd2011-09-20 15:08:29 -07006110 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006111 try {
6112 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006113 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6114 } catch (RemoteException e) {
6115 // Ignore
6116 }
6117 }
6118
6119 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6120 try {
6121 //set orientation on WindowManager
6122 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006123 } catch (RemoteException e) {
6124 // Ignore
6125 }
6126 }
6127
Daniel Sandler6396c722013-04-16 20:19:09 -04006128 /**
6129 * Return an Intent to launch the currently active dock app as home. Returns
6130 * null if the standard home should be launched, which is the case if any of the following is
6131 * true:
6132 * <ul>
6133 * <li>The device is not in either car mode or desk mode
6134 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
6135 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6136 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6137 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6138 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006139 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006140 */
6141 Intent createHomeDockIntent() {
6142 Intent intent = null;
6143
6144 // What home does is based on the mode, not the dock state. That
6145 // is, when in car mode you should be taken to car home regardless
6146 // of whether we are actually in a car dock.
6147 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6148 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
6149 intent = mCarDockIntent;
6150 }
6151 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6152 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6153 intent = mDeskDockIntent;
6154 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006155 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6156 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6157 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6158 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6159 // Always launch dock home from home when watch is docked, if it exists.
6160 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006161 }
6162
6163 if (intent == null) {
6164 return null;
6165 }
6166
6167 ActivityInfo ai = null;
6168 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6169 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006170 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006171 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006172 if (info != null) {
6173 ai = info.activityInfo;
6174 }
6175 if (ai != null
6176 && ai.metaData != null
6177 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6178 intent = new Intent(intent);
6179 intent.setClassName(ai.packageName, ai.name);
6180 return intent;
6181 }
6182
6183 return null;
6184 }
6185
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006186 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6187 if (awakenFromDreams) {
6188 awakenDreams();
6189 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006190
6191 Intent dock = createHomeDockIntent();
6192 if (dock != null) {
6193 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006194 if (fromHomeKey) {
6195 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6196 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006197 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006198 return;
6199 } catch (ActivityNotFoundException e) {
6200 }
6201 }
6202
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006203 Intent intent;
6204
6205 if (fromHomeKey) {
6206 intent = new Intent(mHomeIntent);
6207 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6208 } else {
6209 intent = mHomeIntent;
6210 }
6211
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006212 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006213 }
Craig Mautnereda67292013-04-28 13:50:14 -07006214
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006215 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006216 * goes to the home screen
6217 * @return whether it did anything
6218 */
6219 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006220 if (!isUserSetupComplete()) {
6221 Slog.i(TAG, "Not going home because user setup is in progress.");
6222 return false;
6223 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006224 if (false) {
6225 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006226 try {
6227 ActivityManagerNative.getDefault().stopAppSwitches();
6228 } catch (RemoteException e) {
6229 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006230 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006231 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006232 } else {
6233 // This code brings home to the front or, if it is already
6234 // at the front, puts the device to sleep.
6235 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006236 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6237 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6238 Log.d(TAG, "UTS-TEST-MODE");
6239 } else {
6240 ActivityManagerNative.getDefault().stopAppSwitches();
6241 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006242 Intent dock = createHomeDockIntent();
6243 if (dock != null) {
6244 int result = ActivityManagerNative.getDefault()
6245 .startActivityAsUser(null, null, dock,
6246 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6247 null, null, 0,
6248 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006249 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006250 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6251 return false;
6252 }
6253 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006254 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006255 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006256 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006257 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006258 null, null, 0,
6259 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006260 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006261 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006262 return false;
6263 }
6264 } catch (RemoteException ex) {
6265 // bummer, the activity manager, which is in this process, is dead
6266 }
6267 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006268 return true;
6269 }
Craig Mautnereda67292013-04-28 13:50:14 -07006270
6271 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006272 public void setCurrentOrientationLw(int newOrientation) {
6273 synchronized (mLock) {
6274 if (newOrientation != mCurrentAppOrientation) {
6275 mCurrentAppOrientation = newOrientation;
6276 updateOrientationListenerLp();
6277 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006278 }
6279 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006280
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006281 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6282 if (!isGlobalAccessibilityGestureEnabled()) {
6283 return;
6284 }
6285 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6286 Context.AUDIO_SERVICE);
6287 if (audioManager.isSilentMode()) {
6288 return;
6289 }
6290 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6291 Settings.System.DEFAULT_NOTIFICATION_URI);
6292 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6293 ringTone.play();
6294 }
Craig Mautnereda67292013-04-28 13:50:14 -07006295
Bryce Lee584a4452014-10-21 15:55:55 -07006296 private boolean isTheaterModeEnabled() {
6297 return Settings.Global.getInt(mContext.getContentResolver(),
6298 Settings.Global.THEATER_MODE_ON, 0) == 1;
6299 }
6300
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006301 private boolean isGlobalAccessibilityGestureEnabled() {
6302 return Settings.Global.getInt(mContext.getContentResolver(),
6303 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6304 }
6305
Craig Mautnereda67292013-04-28 13:50:14 -07006306 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006307 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006308 if (!mVibrator.hasVibrator()) {
6309 return false;
6310 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006311 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6312 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006313 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006314 return false;
6315 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006316 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006317 switch (effectId) {
6318 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006319 pattern = mLongPressVibePattern;
6320 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006321 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006322 pattern = mVirtualKeyVibePattern;
6323 break;
6324 case HapticFeedbackConstants.KEYBOARD_TAP:
6325 pattern = mKeyboardTapVibePattern;
6326 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006327 case HapticFeedbackConstants.CLOCK_TICK:
6328 pattern = mClockTickVibePattern;
6329 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006330 case HapticFeedbackConstants.CALENDAR_DATE:
6331 pattern = mCalendarDateVibePattern;
6332 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006333 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006334 pattern = mSafeModeDisabledVibePattern;
6335 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006336 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006337 pattern = mSafeModeEnabledVibePattern;
6338 break;
Mady Mellore8608912015-06-05 09:02:55 -07006339 case HapticFeedbackConstants.CONTEXT_CLICK:
6340 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006341 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006342 default:
6343 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006344 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006345 int owningUid;
6346 String owningPackage;
6347 if (win != null) {
6348 owningUid = win.getOwningUid();
6349 owningPackage = win.getOwningPackage();
6350 } else {
6351 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006352 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006353 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006354 if (pattern.length == 1) {
6355 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006356 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006357 } else {
6358 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006359 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006360 }
6361 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006362 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006363
6364 @Override
6365 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006366 }
6367
Jeff Brownc38c9be2012-10-04 13:16:19 -07006368 @Override
6369 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006370 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006371 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006372 }
6373 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006374
Dianne Hackborndf89e652011-10-06 22:35:11 -07006375 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006376 // If there is no window focused, there will be nobody to handle the events
6377 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006378 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6379 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006380 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006381 return 0;
6382 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006383 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006384 // We are updating at a point where the keyguard has gotten
6385 // focus, but we were last in a state where the top window is
6386 // hiding it. This is probably because the keyguard as been
6387 // shown while the top window was displayed, so we want to ignore
6388 // it here because this is just a very transient change and it
6389 // will quickly lose focus once it correctly gets hidden.
6390 return 0;
6391 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006392
John Spurlock1db8b682014-02-18 11:18:59 -05006393 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006394 & ~mResettingSystemUiFlags
6395 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006396 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006397 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006398 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006399 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006400 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006401 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006402 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006403 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006404 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006405 return 0;
6406 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006407 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006408 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006409 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006410 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006411 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006412 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006413 try {
6414 IStatusBarService statusbar = getStatusBarService();
6415 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006416 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006417 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006418 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006419 } catch (RemoteException e) {
6420 // re-acquire status bar service next time it is needed.
6421 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006422 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006423 }
6424 });
6425 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006426 }
6427
Adrian Rooscd3884d2015-02-18 17:25:23 +01006428 private int updateLightStatusBarLw(int vis) {
6429 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6430 ? mStatusBar
6431 : mTopFullscreenOpaqueOrDimmingWindowState;
6432
6433 if (statusColorWin != null) {
6434 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6435 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6436 // its light flag.
6437 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6438 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6439 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6440 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6441 // Otherwise if it's dimming, clear the light flag.
6442 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6443 }
6444 }
6445 return vis;
6446 }
6447
John Spurlock79da8332013-09-20 12:04:47 -04006448 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006449 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006450 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6451 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006452 : mTopFullscreenOpaqueWindowState;
6453 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6454 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6455
John Spurlock27735a42013-08-14 17:57:38 -04006456 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006457 int type = win.getAttrs().type;
6458 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006459 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006460 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6461 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006462 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006463 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6464 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006465 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006466 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6467 }
John Spurlockbd957402013-10-03 11:38:39 -04006468 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006469 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006470
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006471 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006472 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6473 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006474 }
6475
John Spurlock27735a42013-08-14 17:57:38 -04006476 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006477 boolean immersiveSticky =
6478 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006479 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006480 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006481 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006482 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6483 boolean hideStatusBarSysui =
6484 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006485 boolean hideNavBarSysui =
6486 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006487
John Spurlock27735a42013-08-14 17:57:38 -04006488 boolean transientStatusBarAllowed =
6489 mStatusBar != null && (
6490 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006491 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006492 || statusBarHasFocus);
6493
John Spurlockf1a36642013-10-12 17:50:42 -04006494 boolean transientNavBarAllowed =
6495 mNavigationBar != null &&
6496 hideNavBarSysui && immersiveSticky;
6497
Adrian Roosddc8b272015-05-21 16:28:27 -07006498 final long now = SystemClock.uptimeMillis();
6499 final boolean pendingPanic = mPendingPanicGestureUptime != 0
6500 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
6501 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
6502 // The user performed the panic gesture recently, we're about to hide the bars,
6503 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
6504 mPendingPanicGestureUptime = 0;
6505 mStatusBarController.showTransient();
6506 mNavigationBarController.showTransient();
6507 }
6508
John Spurlockf25706f2013-11-07 18:02:43 -05006509 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006510 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006511 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006512 && !transientNavBarAllowed;
6513 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006514 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006515 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006516 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006517 }
John Spurlock27735a42013-08-14 17:57:38 -04006518
Selim Cinekf98702e2015-05-20 22:48:40 -07006519 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
6520 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
6521 final boolean navAllowedHidden = immersive || immersiveSticky;
6522
Selim Cinekd6623612015-05-22 18:56:22 -07006523 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
6524 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07006525 // We can't hide the navbar from this window otherwise the input consumer would not get
6526 // the input events.
6527 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
6528 }
6529
John Spurlock27735a42013-08-14 17:57:38 -04006530 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6531
6532 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006533 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6534 boolean newImmersiveMode = isImmersiveMode(vis);
6535 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006536 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006537 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6538 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006539 }
John Spurlock27735a42013-08-14 17:57:38 -04006540
John Spurlockf1a36642013-10-12 17:50:42 -04006541 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6542
John Spurlocke1f366f2013-08-05 12:22:40 -04006543 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006544 }
6545
John Spurlockf1a36642013-10-12 17:50:42 -04006546 private void clearClearableFlagsLw() {
6547 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6548 if (newVal != mResettingSystemUiFlags) {
6549 mResettingSystemUiFlags = newVal;
6550 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6551 }
6552 }
6553
6554 private boolean isImmersiveMode(int vis) {
6555 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006556 return mNavigationBar != null
6557 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006558 && (vis & flags) != 0
6559 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006560 }
6561
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006562 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006563 * @return whether the navigation or status bar can be made translucent
6564 *
6565 * This should return true unless touch exploration is not enabled or
6566 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006567 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006568 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006569 return mTranslucentDecorEnabled
6570 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006571 }
6572
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006573 // Use this instead of checking config_showNavigationBar so that it can be consistently
6574 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006575 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006576 public boolean hasNavigationBar() {
6577 return mHasNavigationBar;
6578 }
6579
satok1bc0a492012-04-25 22:47:12 +09006580 @Override
6581 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6582 mLastInputMethodWindow = ime;
6583 mLastInputMethodTargetWindow = target;
6584 }
6585
Craig Mautnerf1b67412012-09-19 13:18:29 -07006586 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006587 public int getInputMethodWindowVisibleHeightLw() {
6588 return mDockBottom - mCurBottom;
6589 }
6590
6591 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006592 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006593 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006594 if (mKeyguardDelegate != null) {
6595 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006596 }
John Spurlock13451a22012-09-28 14:40:41 -04006597 if (mStatusBarService != null) {
6598 try {
6599 mStatusBarService.setCurrentUser(newUserId);
6600 } catch (RemoteException e) {
6601 // oh well
6602 }
6603 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006604 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006605 }
6606
6607 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006608 public boolean canMagnifyWindow(int windowType) {
6609 switch (windowType) {
6610 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6611 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6612 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6613 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6614 return false;
6615 }
6616 }
6617 return true;
6618 }
6619
6620 @Override
6621 public boolean isTopLevelWindow(int windowType) {
6622 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6623 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6624 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6625 }
6626 return true;
6627 }
6628
Jim Miller4eeb4f62012-11-08 00:04:29 -08006629 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006630 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006631 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006632 pw.print(" mSystemReady="); pw.print(mSystemReady);
6633 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006634 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006635 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006636 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006637 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006638 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6639 || mForceClearedSystemUiFlags != 0) {
6640 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6641 pw.print(Integer.toHexString(mLastSystemUiFlags));
6642 pw.print(" mResettingSystemUiFlags=0x");
6643 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6644 pw.print(" mForceClearedSystemUiFlags=0x");
6645 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006646 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006647 if (mLastFocusNeedsMenu) {
6648 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6649 pw.println(mLastFocusNeedsMenu);
6650 }
Jeff Browna20dda42014-05-27 20:57:24 -07006651 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6652 pw.println(mWakeGestureEnabledSetting);
6653
Jeff Brownbcdfc622014-03-06 19:13:04 -08006654 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006655 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6656 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006657 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6658 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6659 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6660 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006661 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006662 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006663 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6664 pw.print(mCarDockEnablesAccelerometer);
6665 pw.print(" mDeskDockEnablesAccelerometer=");
6666 pw.println(mDeskDockEnablesAccelerometer);
6667 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6668 pw.print(mLidKeyboardAccessibility);
6669 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006670 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006671 pw.print(prefix);
6672 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6673 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006674 pw.print(prefix);
6675 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6676 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006677 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006678 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6679 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6680 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6681 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6682 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6683 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6684 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006685 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6686 pw.print(","); pw.print(mOverscanScreenTop);
6687 pw.print(") "); pw.print(mOverscanScreenWidth);
6688 pw.print("x"); pw.println(mOverscanScreenHeight);
6689 if (mOverscanLeft != 0 || mOverscanTop != 0
6690 || mOverscanRight != 0 || mOverscanBottom != 0) {
6691 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6692 pw.print(" top="); pw.print(mOverscanTop);
6693 pw.print(" right="); pw.print(mOverscanRight);
6694 pw.print(" bottom="); pw.println(mOverscanBottom);
6695 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006696 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6697 pw.print(mRestrictedOverscanScreenLeft);
6698 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6699 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6700 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006701 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6702 pw.print(","); pw.print(mUnrestrictedScreenTop);
6703 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6704 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6705 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6706 pw.print(","); pw.print(mRestrictedScreenTop);
6707 pw.print(") "); pw.print(mRestrictedScreenWidth);
6708 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006709 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6710 pw.print(","); pw.print(mStableFullscreenTop);
6711 pw.print(")-("); pw.print(mStableFullscreenRight);
6712 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006713 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6714 pw.print(","); pw.print(mStableTop);
6715 pw.print(")-("); pw.print(mStableRight);
6716 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006717 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6718 pw.print(","); pw.print(mSystemTop);
6719 pw.print(")-("); pw.print(mSystemRight);
6720 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006721 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6722 pw.print(","); pw.print(mCurTop);
6723 pw.print(")-("); pw.print(mCurRight);
6724 pw.print(","); pw.print(mCurBottom); pw.println(")");
6725 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6726 pw.print(","); pw.print(mContentTop);
6727 pw.print(")-("); pw.print(mContentRight);
6728 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006729 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6730 pw.print(","); pw.print(mVoiceContentTop);
6731 pw.print(")-("); pw.print(mVoiceContentRight);
6732 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006733 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6734 pw.print(","); pw.print(mDockTop);
6735 pw.print(")-("); pw.print(mDockRight);
6736 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006737 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6738 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006739 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6740 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006741 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6742 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006743 if (mLastInputMethodWindow != null) {
6744 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6745 pw.println(mLastInputMethodWindow);
6746 }
6747 if (mLastInputMethodTargetWindow != null) {
6748 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6749 pw.println(mLastInputMethodTargetWindow);
6750 }
6751 if (mStatusBar != null) {
6752 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006753 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6754 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006755 }
6756 if (mNavigationBar != null) {
6757 pw.print(prefix); pw.print("mNavigationBar=");
6758 pw.println(mNavigationBar);
6759 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006760 if (mFocusedWindow != null) {
6761 pw.print(prefix); pw.print("mFocusedWindow=");
6762 pw.println(mFocusedWindow);
6763 }
6764 if (mFocusedApp != null) {
6765 pw.print(prefix); pw.print("mFocusedApp=");
6766 pw.println(mFocusedApp);
6767 }
6768 if (mWinDismissingKeyguard != null) {
6769 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6770 pw.println(mWinDismissingKeyguard);
6771 }
6772 if (mTopFullscreenOpaqueWindowState != null) {
6773 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6774 pw.println(mTopFullscreenOpaqueWindowState);
6775 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006776 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6777 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6778 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6779 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006780 if (mForcingShowNavBar) {
6781 pw.print(prefix); pw.print("mForcingShowNavBar=");
6782 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6783 pw.println(mForcingShowNavBarLayer);
6784 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006785 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006786 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006787 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6788 pw.print(" mForceStatusBarFromKeyguard=");
6789 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006790 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006791 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006792 pw.print(" mHomePressed="); pw.println(mHomePressed);
6793 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6794 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6795 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6796 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6797 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6798 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6799 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6800 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6801 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6802 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006803 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6804 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6805 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006806
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006807 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006808 mStatusBarController.dump(pw, prefix);
6809 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006810 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006811
Jeff Browna20dda42014-05-27 20:57:24 -07006812 if (mWakeGestureListener != null) {
6813 mWakeGestureListener.dump(pw, prefix);
6814 }
Jeff Brown600f0032014-05-22 17:06:00 -07006815 if (mOrientationListener != null) {
6816 mOrientationListener.dump(pw, prefix);
6817 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006818 if (mBurnInProtectionHelper != null) {
6819 mBurnInProtectionHelper.dump(prefix, pw);
6820 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006821 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006822}