blob: 79fe29b74e139584926cf1d5766c542747c70591 [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
Jeff Brown37df39a92015-02-25 15:42:31 -08002 * Copyright (C) 2006 The Android Open Source Project
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jorim Jaggib10e33f2015-02-04 21:57:40 +010017package com.android.server.policy;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080018
Dianne Hackborna4972e92012-03-14 10:38:05 -070019import android.app.ActivityManager;
Jeff Brown061ea992015-04-17 19:55:47 -070020import android.app.ActivityManagerInternal;
21import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080022import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080023import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040024import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070025import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070026import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040027import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080028import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070029import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080030import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040031import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080032import android.content.ContentResolver;
33import android.content.Context;
34import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070035import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070036import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080037import android.content.pm.ActivityInfo;
38import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040039import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070040import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.content.res.Configuration;
42import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070043import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080044import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080045import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080046import android.graphics.Rect;
John Spurlock7b414672014-07-18 13:02:39 -040047import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080048import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050049import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080050import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070051import android.media.Ringtone;
52import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070053import android.media.session.MediaSessionLegacyHelper;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070054import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080055import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070056import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080057import android.os.Handler;
58import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080059import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070060import android.os.Message;
61import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080062import android.os.PowerManager;
63import android.os.RemoteException;
64import android.os.ServiceManager;
65import android.os.SystemClock;
66import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080067import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070068import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080069import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070070import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080071import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070072import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040073import android.service.dreams.DreamService;
74import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070075import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070076import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070077import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080078import android.util.EventLog;
79import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070080import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080081import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070082import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080083import android.view.Gravity;
84import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080085import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080086import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070087import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070088import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080089import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080090import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080091import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080092import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080093import android.view.KeyEvent;
94import android.view.MotionEvent;
Adam Powell6711f3b2015-05-06 15:57:09 -070095import com.android.internal.policy.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080096import android.view.Surface;
97import android.view.View;
98import android.view.ViewConfiguration;
99import android.view.Window;
100import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800101import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700102import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800103import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800104import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800105import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800106import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200107import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800108import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800109import com.android.internal.R;
Craig Mautnerae446592012-12-06 19:05:05 -0800110import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700111import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800112import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700113import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100114import com.android.server.policy.keyguard.KeyguardServiceDelegate;
115import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800116
117import java.io.File;
118import java.io.FileReader;
119import java.io.IOException;
120import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700121import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800122import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800123
Dianne Hackbornc652de82013-02-15 16:32:56 -0800124import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700125import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
126import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
127import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700128import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
129import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
130import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800131
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800132/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700133 * WindowManagerPolicy implementation for the Android phone UI. This
134 * introduces a new method suffix, Lp, for an internal lock of the
135 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400136 * 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 -0700137 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800138 */
139public class PhoneWindowManager implements WindowManagerPolicy {
140 static final String TAG = "WindowManager";
141 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700142 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700143 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700144 static final boolean DEBUG_KEYGUARD = false;
145 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700146 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700147 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800148 static final boolean SHOW_STARTING_ANIMATIONS = true;
149 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400150
Daniel Sandler6396c722013-04-16 20:19:09 -0400151 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
152 // No longer recommended for desk docks; still useful in car docks.
153 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
154 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
155
Jeff Brown6d8fd272014-05-20 21:24:38 -0700156 static final int SHORT_PRESS_POWER_NOTHING = 0;
157 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
158 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
159 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800160 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700161
Joe Onoratod208e702010-10-08 16:22:43 -0400162 static final int LONG_PRESS_POWER_NOTHING = 0;
163 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
164 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700165 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700166
Jeff Brown13f00f02014-10-31 14:45:50 -0700167 static final int MULTI_PRESS_POWER_NOTHING = 0;
168 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
169 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
170
Michael Jurka3b1fc472011-06-13 10:54:40 -0700171 // These need to match the documentation/constant in
172 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800173 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800174 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700175 static final int LONG_PRESS_HOME_ASSIST = 2;
176
177 static final int DOUBLE_TAP_HOME_NOTHING = 0;
178 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800179
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000180 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
181 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
182
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700183 static final int APPLICATION_MEDIA_SUBLAYER = -2;
184 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800185 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800186 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700187 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700188
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800189 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
190 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
191 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500192 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700193 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800194
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700195 /**
196 * These are the system UI flags that, when changing, can cause the layout
197 * of the screen to change.
198 */
199 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400200 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400201 | View.SYSTEM_UI_FLAG_FULLSCREEN
202 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200203 | View.NAVIGATION_BAR_TRANSLUCENT
204 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700205
John Spurlock7b414672014-07-18 13:02:39 -0400206 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
207 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
208 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
209 .build();
210
Adrian Roosddc8b272015-05-21 16:28:27 -0700211 // The panic gesture may become active only after the keyguard is dismissed and the immersive
212 // app shows again. If that doesn't happen for 30s we drop the gesture.
213 private static final long PANIC_GESTURE_EXPIRATION = 30000;
214
Jim Miller5ecd8112013-01-09 18:50:26 -0800215 /**
216 * Keyguard stuff
217 */
218 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100219 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700220 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800221
Jeff Brown6651a632011-11-28 12:59:11 -0800222 /* Table of Application Launch keys. Maps from key codes to intent categories.
223 *
224 * These are special keys that are used to launch particular kinds of applications,
225 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
226 * usage page. We don't support quite that many yet...
227 */
228 static SparseArray<String> sApplicationLaunchKeyCategories;
229 static {
230 sApplicationLaunchKeyCategories = new SparseArray<String>();
231 sApplicationLaunchKeyCategories.append(
232 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
233 sApplicationLaunchKeyCategories.append(
234 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
235 sApplicationLaunchKeyCategories.append(
236 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
237 sApplicationLaunchKeyCategories.append(
238 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
239 sApplicationLaunchKeyCategories.append(
240 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
241 sApplicationLaunchKeyCategories.append(
242 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
243 }
244
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700245 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000246 static final int WAITING_FOR_DRAWN_TIMEOUT = 500;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700247
Dianne Hackborndf89e652011-10-06 22:35:11 -0700248 /**
249 * Lock protecting internal state. Must not call out into window
250 * manager with lock held. (This lock will be acquired in places
251 * where the window manager is calling in with its own lock held.)
252 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800253 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700254
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800255 Context mContext;
256 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700257 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700258 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700259 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700260 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700261 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400262 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700263 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700264 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800265 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700266 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800267 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000268 BurnInProtectionHelper mBurnInProtectionHelper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800269
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700270 // Vibrator pattern for haptic feedback of a long press.
271 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700272
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700273 // Vibrator pattern for haptic feedback of virtual key press.
274 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700275
Amith Yamasanic33cb712010-02-10 15:21:49 -0800276 // Vibrator pattern for a short vibration.
277 long[] mKeyboardTapVibePattern;
278
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700279 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
280 long[] mClockTickVibePattern;
281
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700282 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
283 long[] mCalendarDateVibePattern;
284
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700285 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
286 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700287
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700288 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
289 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700290
Mady Mellore8608912015-06-05 09:02:55 -0700291 // Vibrator pattern for haptic feedback of a context click.
292 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700293
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800294 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
295 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400296
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800297 boolean mSafeMode;
298 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700299 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400300 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400301 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700302 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400303 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
304 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
305 int[] mNavigationBarHeightForRotation = new int[4];
306 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400307
Craig Mautnera631d492014-08-05 15:16:01 -0700308 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800309 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700310 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700311 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700312 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700313 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
314 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
315 }
316 };
317 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
318 @Override
319 public void onShown(IBinder windowToken) {
320 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
321 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
322 }
323 };
324
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800325 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800326 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900327 WindowState mLastInputMethodWindow = null;
328 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800329
Jeff Brown13f00f02014-10-31 14:45:50 -0700330 // FIXME This state is shared between the input reader and handler thread.
331 // Technically it's broken and buggy but it has been like this for many years
332 // and we have not yet seen any problems. Someday we'll rewrite this logic
333 // so that only one thread is involved in handling input policy. Unfortunately
334 // it's on a critical path for power management so we can't just post the work to the
335 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
336 // to hold wakelocks during dispatch and eliminating the critical path.
337 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800338 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700339 volatile int mPowerKeyPressCounter;
340 volatile boolean mEndCallKeyHandled;
341
Winson Chungd42a6cf2014-06-03 16:24:04 -0700342 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700343 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700344 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800345
Jeff Brown2e7760e2012-04-11 15:14:55 -0700346 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700347 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700348 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800349
Dianne Hackbornc777e072010-02-12 13:07:59 -0800350 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700351 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800352 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700353 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400354 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700355 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700356 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400357 int mCarDockRotation;
358 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700359 int mUndockedHdmiRotation;
360 int mDemoHdmiRotation;
361 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800362 int mDemoRotation;
363 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400364
Jeff Browna20dda42014-05-27 20:57:24 -0700365 boolean mWakeGestureEnabledSetting;
366 MyWakeGestureListener mWakeGestureListener;
367
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700368 // Default display does not rotate, apps that require non-default orientation will have to
369 // have the orientation emulated.
370 private boolean mForceDefaultOrientation = false;
371
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400372 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
373 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700374 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400375
Jeff Brownbcdfc622014-03-06 19:13:04 -0800376 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700377 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400378 boolean mCarDockEnablesAccelerometer;
379 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700380 int mLidKeyboardAccessibility;
381 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700382 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700383 int mShortPressOnPowerBehavior;
384 int mLongPressOnPowerBehavior;
385 int mDoublePressOnPowerBehavior;
386 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000387 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700388 boolean mAwake;
389 boolean mScreenOnEarly;
390 boolean mScreenOnFully;
391 ScreenOnListener mScreenOnListener;
392 boolean mKeyguardDrawComplete;
393 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800394 boolean mOrientationSensorEnabled = false;
395 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800396 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400397 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800398 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700399
Jeff Brown70825162012-03-28 17:27:48 -0700400 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800401
402 // The last window we were told about in focusChanged.
403 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800404 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800405
Jeff Brown70825162012-03-28 17:27:48 -0700406 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800407
Dianne Hackbornc652de82013-02-15 16:32:56 -0800408 // The current size of the screen; really; extends into the overscan area of
409 // the screen and doesn't account for any system elements like the status bar.
410 int mOverscanScreenLeft, mOverscanScreenTop;
411 int mOverscanScreenWidth, mOverscanScreenHeight;
412 // The current visible size of the screen; really; (ir)regardless of whether the status
413 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800414 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
415 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800416 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
417 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
418 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700419 // The current size of the screen; these may be different than (0,0)-(dw,dh)
420 // if the status bar can't be hidden; in that case it effectively carves out
421 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800422 int mRestrictedScreenLeft, mRestrictedScreenTop;
423 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700424 // During layout, the current screen borders accounting for any currently
425 // visible system UI elements.
426 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700427 // For applications requesting stable content insets, these are them.
428 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700429 // For applications requesting stable content insets but have also set the
430 // fullscreen window flag, these are the stable dimensions without the status bar.
431 int mStableFullscreenLeft, mStableFullscreenTop;
432 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800433 // During layout, the current screen borders with all outer decoration
434 // (status bar, input method dock) accounted for.
435 int mCurLeft, mCurTop, mCurRight, mCurBottom;
436 // During layout, the frame in which content should be displayed
437 // to the user, accounting for all screen decoration except for any
438 // space they deem as available for other content. This is usually
439 // the same as mCur*, but may be larger if the screen decor has supplied
440 // content insets.
441 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700442 // During layout, the frame in which voice content should be displayed
443 // to the user, accounting for all screen decoration except for any
444 // space they deem as available for other content.
445 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800446 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800447 // windows are placed.
448 int mDockLeft, mDockTop, mDockRight, mDockBottom;
449 // During layout, the layer at which the doc window is placed.
450 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700451 // During layout, this is the layer of the status bar.
452 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700453 int mLastSystemUiFlags;
454 // Bits that we are in the process of clearing, so we want to prevent
455 // them from being set by applications until everything has been updated
456 // to have them clear.
457 int mResettingSystemUiFlags = 0;
458 // Bits that we are currently always keeping cleared.
459 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800460 // What we last reported to system UI about whether the compatibility
461 // menu needs to be displayed.
462 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700463 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
464 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700465
Selim Cinekf83e8242015-05-19 18:08:14 -0700466 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700467
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800468 static final Rect mTmpParentFrame = new Rect();
469 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800470 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800471 static final Rect mTmpContentFrame = new Rect();
472 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400473 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700474 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700475 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700476 static final Rect mTmpOutsetFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700477
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800478 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100479 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700480 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200481 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400482 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800483 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700484 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700485 private boolean mForceStatusBarTransparent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700486 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800487 boolean mForcingShowNavBar;
488 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700489
490 // States of keyguard dismiss.
491 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
492 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
493 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
494 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
495
496 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
497 * be done once per window. */
498 private WindowState mWinDismissingKeyguard;
499
tingna_sunge785ffa2015-05-12 13:23:15 +0800500 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
501 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
502 * lock SIM card. This variable is used to record the previous keyguard secure state for
503 * monitoring secure state change on window dismissing keyguard. */
504 private boolean mSecureDismissingKeyguard;
505
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700506 /** The window that is currently showing "over" the keyguard. If there is an app window
507 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
508 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
509 * the wallpaper. */
510 private WindowState mWinShowWhenLocked;
511
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700512 boolean mShowingLockscreen;
513 boolean mShowingDream;
514 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700515 boolean mDreamingSleepTokenNeeded;
516 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700517 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700518 boolean mKeyguardSecure;
519 boolean mKeyguardSecureIncludingHidden;
520 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800521 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700522 boolean mHomeConsumed;
523 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800524 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700525 Intent mCarDockIntent;
526 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700527 boolean mSearchKeyShortcutPending;
528 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700529 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700530 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800531
Mike Lockwood28569302010-01-28 11:54:40 -0500532 // support for activating the lock screen while the screen is on
533 boolean mAllowLockscreenWhenOn;
534 int mLockScreenTimeout;
535 boolean mLockScreenTimerActive;
536
David Brownbaf8d092010-03-08 21:52:59 -0800537 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800538 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800539
540 // Behavior of POWER button while in-call and screen on.
541 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
542 int mIncallPowerBehavior;
543
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700544 Display mDisplay;
545
Dianne Hackborn9d132642011-04-21 17:26:39 -0700546 int mLandscapeRotation = 0; // default landscape rotation
547 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
548 int mPortraitRotation = 0; // default portrait rotation
549 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700550
Dianne Hackbornc652de82013-02-15 16:32:56 -0800551 int mOverscanLeft = 0;
552 int mOverscanTop = 0;
553 int mOverscanRight = 0;
554 int mOverscanBottom = 0;
555
Joe Onorato46b0d682010-11-22 17:37:27 -0800556 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700557 private int mLongPressOnHomeBehavior;
558
559 // What we do when the user double-taps on home
560 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800561
Bryce Lee584a4452014-10-21 15:55:55 -0700562 // Allowed theater mode wake actions
563 private boolean mAllowTheaterModeWakeFromKey;
564 private boolean mAllowTheaterModeWakeFromPowerKey;
565 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800566 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700567 private boolean mAllowTheaterModeWakeFromCameraLens;
568 private boolean mAllowTheaterModeWakeFromLidSwitch;
569 private boolean mAllowTheaterModeWakeFromWakeGesture;
570
Bryce Leed3b28402015-03-09 15:49:13 +0000571 // Whether to support long press from power button in non-interactive mode
572 private boolean mSupportLongPressPowerWhenNonInteractive;
573
Bryce Lee55e846d2014-11-04 12:43:44 -0800574 // Whether to go to sleep entering theater mode from power button
575 private boolean mGoToSleepOnButtonPressTheaterMode;
576
Winson Chung9112ec32011-06-27 13:15:32 -0700577 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700578 // Time to volume and power must be pressed within this interval of each other.
579 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700580 // Increase the chord delay when taking a screenshot from the keyguard
581 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800582 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700583 private boolean mScreenshotChordVolumeDownKeyTriggered;
584 private long mScreenshotChordVolumeDownKeyTime;
585 private boolean mScreenshotChordVolumeDownKeyConsumed;
586 private boolean mScreenshotChordVolumeUpKeyTriggered;
587 private boolean mScreenshotChordPowerKeyTriggered;
588 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700589
Michael Wrightb854e242013-02-05 17:54:02 -0800590 /* The number of steps between min and max brightness */
591 private static final int BRIGHTNESS_STEPS = 10;
592
Christopher Tate5e08af02012-09-21 17:17:22 -0700593 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800594 ShortcutManager mShortcutManager;
595 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700596 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700597 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800598
Craig Mautnerd625ab22013-09-06 13:40:31 -0700599 private int mCurrentUserId;
600
Justin Kohd378ad72013-04-01 12:18:26 -0700601 // Maps global key codes to the components that will handle them.
602 private GlobalKeyManager mGlobalKeyManager;
603
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700604 // Fallback actions by key code.
605 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
606 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800607
Jorim Jaggi76a16232014-08-08 17:00:47 +0200608 private final LogDecelerateInterpolator mLogDecelerateInterpolator
609 = new LogDecelerateInterpolator(100, 0);
610
Jeff Brown70825162012-03-28 17:27:48 -0700611 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
612 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700613 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
614 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700615 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
616 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
617 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700618 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700619 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700620 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700621 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700622 private static final int MSG_POWER_DELAYED_PRESS = 13;
623 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700624 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jeff Brown70825162012-03-28 17:27:48 -0700625
626 private class PolicyHandler extends Handler {
627 @Override
628 public void handleMessage(Message msg) {
629 switch (msg.what) {
630 case MSG_ENABLE_POINTER_LOCATION:
631 enablePointerLocation();
632 break;
633 case MSG_DISABLE_POINTER_LOCATION:
634 disablePointerLocation();
635 break;
Jeff Brown40013652012-05-16 21:22:36 -0700636 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
637 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
638 break;
639 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
640 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
641 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700642 case MSG_DISPATCH_SHOW_RECENTS:
643 showRecentApps(false);
644 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700645 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
646 showGlobalActionsInternal();
647 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700648 case MSG_KEYGUARD_DRAWN_COMPLETE:
649 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700650 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700651 break;
652 case MSG_KEYGUARD_DRAWN_TIMEOUT:
653 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700654 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700655 break;
656 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
657 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700658 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700659 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700660 case MSG_HIDE_BOOT_MESSAGE:
661 handleHideBootMessage();
662 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700663 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
664 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
665 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700666 case MSG_POWER_DELAYED_PRESS:
667 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
668 finishPowerKeyPress();
669 break;
670 case MSG_POWER_LONG_PRESS:
671 powerLongPress();
672 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700673 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
674 updateDreamingSleepToken(msg.arg1 != 0);
675 break;
Jeff Brown70825162012-03-28 17:27:48 -0700676 }
677 }
678 }
679
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800680 private UEventObserver mHDMIObserver = new UEventObserver() {
681 @Override
682 public void onUEvent(UEventObserver.UEvent event) {
683 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
684 }
685 };
686
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800687 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800688 SettingsObserver(Handler handler) {
689 super(handler);
690 }
David Brownbaf8d092010-03-08 21:52:59 -0800691
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800692 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700693 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800694 ContentResolver resolver = mContext.getContentResolver();
695 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700696 Settings.System.END_BUTTON_BEHAVIOR), false, this,
697 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800698 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700699 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
700 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700701 resolver.registerContentObserver(Settings.Secure.getUriFor(
702 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
703 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800704 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700705 Settings.System.ACCELEROMETER_ROTATION), false, this,
706 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500707 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700708 Settings.System.USER_ROTATION), false, this,
709 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400710 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700711 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
712 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800713 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700714 Settings.System.POINTER_LOCATION), false, this,
715 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800716 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700717 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
718 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500719 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400720 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700721 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500722 resolver.registerContentObserver(Settings.Global.getUriFor(
723 Settings.Global.POLICY_CONTROL), false, this,
724 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800725 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800726 }
727
728 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800729 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700730 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800731 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800732 }
Craig Mautner967212c2013-04-13 21:10:58 -0700733
Jeff Browna20dda42014-05-27 20:57:24 -0700734 class MyWakeGestureListener extends WakeGestureListener {
735 MyWakeGestureListener(Context context, Handler handler) {
736 super(context, handler);
737 }
738
739 @Override
740 public void onWakeUp() {
741 synchronized (mLock) {
742 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700743 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700744 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700745 }
746 }
747 }
748 }
749
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800750 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800751 MyOrientationListener(Context context, Handler handler) {
752 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800753 }
Craig Mautner967212c2013-04-13 21:10:58 -0700754
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800755 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700756 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700757 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700758 updateRotation(false);
759 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800760 }
761 MyOrientationListener mOrientationListener;
762
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100763 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400764
John Spurlock27735a42013-08-14 17:57:38 -0400765 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400766 View.NAVIGATION_BAR_TRANSIENT,
767 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400768 View.NAVIGATION_BAR_TRANSLUCENT,
769 StatusBarManager.WINDOW_NAVIGATION_BAR,
770 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400771
John Spurlockf1a36642013-10-12 17:50:42 -0400772 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400773
Craig Mautner037aa8d2013-06-07 10:35:44 -0700774 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400775
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700776 IStatusBarService getStatusBarService() {
777 synchronized (mServiceAquireLock) {
778 if (mStatusBarService == null) {
779 mStatusBarService = IStatusBarService.Stub.asInterface(
780 ServiceManager.getService("statusbar"));
781 }
782 return mStatusBarService;
783 }
784 }
785
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700786 /*
787 * We always let the sensor be switched on by default except when
788 * the user has explicitly disabled sensor based rotation or when the
789 * screen is switched off.
790 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700791 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800792 if (mSupportAutoRotation) {
793 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
794 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
795 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
796 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
797 // If the application has explicitly requested to follow the
798 // orientation, then we need to turn the sensor on.
799 return true;
800 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800801 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700802 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800803 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
804 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
805 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400806 // enable accelerometer if we are docked in a dock that enables accelerometer
807 // orientation management,
808 return true;
809 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700810 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800811 // If the setting for using the sensor by default is enabled, then
812 // we will always leave it on. Note that the user could go to
813 // a window that forces an orientation that does not use the
814 // sensor and in theory we could turn it off... however, when next
815 // turning it on we won't have a good value for the current
816 // orientation for a little bit, which can cause orientation
817 // changes to lag, so we'd like to keep it always on. (It will
818 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700819 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800820 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800821 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800822 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700823
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800824 /*
825 * Various use cases for invoking this function
826 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700827 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800828 * if not already enabled
829 * screen turned on and current app does not have sensor orientation, disable listeners if
830 * already enabled
831 * screen turning on and current app has sensor based orientation, enable listeners if needed
832 * screen turning on and current app has nosensor based orientation, do nothing
833 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700834 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800835 if (!mOrientationListener.canDetectOrientation()) {
836 // If sensor is turned off or nonexistent for some reason
837 return;
838 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000839 // Could have been invoked due to screen turning on or off or
840 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -0700841 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
842 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000843 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
844 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
845 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800846 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000847 // Note: We postpone the rotating of the screen until the keyguard as well as the
848 // window manager have reported a draw complete.
849 if (mScreenOnEarly && mAwake &&
850 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700851 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800852 disable = false;
853 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700854 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800855 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700856 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800857 mOrientationSensorEnabled = true;
858 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700859 }
860 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800861 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700862 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800863 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700864 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800865 mOrientationSensorEnabled = false;
866 }
867 }
868
Jeff Brown13f00f02014-10-31 14:45:50 -0700869 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
870 // Hold a wake lock until the power key is released.
871 if (!mPowerKeyWakeLock.isHeld()) {
872 mPowerKeyWakeLock.acquire();
873 }
874
875 // Cancel multi-press detection timeout.
876 if (mPowerKeyPressCounter != 0) {
877 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
878 }
879
880 // Detect user pressing the power button in panic when an application has
881 // taken over the whole screen.
882 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800883 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700884 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700885 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700886 }
887
888 // Latch power key state to detect screenshot chord.
889 if (interactive && !mScreenshotChordPowerKeyTriggered
890 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
891 mScreenshotChordPowerKeyTriggered = true;
892 mScreenshotChordPowerKeyTime = event.getDownTime();
893 interceptScreenshotChord();
894 }
895
896 // Stop ringing or end call if configured to do so when power is pressed.
897 TelecomManager telecomManager = getTelecommService();
898 boolean hungUp = false;
899 if (telecomManager != null) {
900 if (telecomManager.isRinging()) {
901 // Pressing Power while there's a ringing incoming
902 // call should silence the ringer.
903 telecomManager.silenceRinger();
904 } else if ((mIncallPowerBehavior
905 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
906 && telecomManager.isInCall() && interactive) {
907 // Otherwise, if "Power button ends call" is enabled,
908 // the Power button will hang up any current active call.
909 hungUp = telecomManager.endCall();
910 }
911 }
912
913 // If the power key has still not yet been handled, then detect short
914 // press, long press, or multi press and decide what to do.
915 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
916 || mScreenshotChordVolumeUpKeyTriggered;
917 if (!mPowerKeyHandled) {
918 if (interactive) {
919 // When interactive, we're already awake.
920 // Wait for a long press or for the button to be released to decide what to do.
921 if (hasLongPressOnPowerBehavior()) {
922 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
923 msg.setAsynchronous(true);
924 mHandler.sendMessageDelayed(msg,
925 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
926 }
927 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800928 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800929
Bryce Leed3b28402015-03-09 15:49:13 +0000930 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
931 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
932 msg.setAsynchronous(true);
933 mHandler.sendMessageDelayed(msg,
934 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800935 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000936 } else {
937 final int maxCount = getMaxMultiPressPowerCount();
938
939 if (maxCount <= 1) {
940 mPowerKeyHandled = true;
941 } else {
942 mBeganFromNonInteractive = true;
943 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700944 }
945 }
Jeff Brown4d396052010-10-29 21:50:21 -0700946 }
947 }
948
Jeff Brown13f00f02014-10-31 14:45:50 -0700949 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
950 final boolean handled = canceled || mPowerKeyHandled;
951 mScreenshotChordPowerKeyTriggered = false;
952 cancelPendingScreenshotChordAction();
953 cancelPendingPowerKeyAction();
954
955 if (!handled) {
956 // Figure out how to handle the key now that it has been released.
957 mPowerKeyPressCounter += 1;
958
959 final int maxCount = getMaxMultiPressPowerCount();
960 final long eventTime = event.getDownTime();
961 if (mPowerKeyPressCounter < maxCount) {
962 // This could be a multi-press. Wait a little bit longer to confirm.
963 // Continue holding the wake lock.
964 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
965 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
966 msg.setAsynchronous(true);
967 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
968 return;
969 }
970
971 // No other actions. Handle it immediately.
972 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700973 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700974
975 // Done. Reset our state.
976 finishPowerKeyPress();
977 }
978
979 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800980 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700981 mPowerKeyPressCounter = 0;
982 if (mPowerKeyWakeLock.isHeld()) {
983 mPowerKeyWakeLock.release();
984 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700985 }
986
987 private void cancelPendingPowerKeyAction() {
988 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700989 mPowerKeyHandled = true;
990 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700991 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700992 }
993
994 private void powerPress(long eventTime, boolean interactive, int count) {
995 if (mScreenOnEarly && !mScreenOnFully) {
996 Slog.i(TAG, "Suppressed redundant power key press while "
997 + "already in the process of turning the screen on.");
998 return;
Jeff Brownff204712011-10-25 21:27:54 -0700999 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001000
1001 if (count == 2) {
1002 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1003 } else if (count == 3) {
1004 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001005 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001006 switch (mShortPressOnPowerBehavior) {
1007 case SHORT_PRESS_POWER_NOTHING:
1008 break;
1009 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1010 mPowerManager.goToSleep(eventTime,
1011 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1012 break;
1013 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1014 mPowerManager.goToSleep(eventTime,
1015 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1016 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1017 break;
1018 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1019 mPowerManager.goToSleep(eventTime,
1020 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1021 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1022 launchHomeFromHotKey();
1023 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001024 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001025 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001026 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001027 }
1028 }
1029 }
1030
1031 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1032 switch (behavior) {
1033 case MULTI_PRESS_POWER_NOTHING:
1034 break;
1035 case MULTI_PRESS_POWER_THEATER_MODE:
1036 if (isTheaterModeEnabled()) {
1037 Slog.i(TAG, "Toggling theater mode off.");
1038 Settings.Global.putInt(mContext.getContentResolver(),
1039 Settings.Global.THEATER_MODE_ON, 0);
1040 if (!interactive) {
1041 wakeUpFromPowerKey(eventTime);
1042 }
1043 } else {
1044 Slog.i(TAG, "Toggling theater mode on.");
1045 Settings.Global.putInt(mContext.getContentResolver(),
1046 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001047
1048 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001049 mPowerManager.goToSleep(eventTime,
1050 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1051 }
1052 }
1053 break;
1054 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001055 Slog.i(TAG, "Starting brightness boost.");
1056 if (!interactive) {
1057 wakeUpFromPowerKey(eventTime);
1058 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001059 mPowerManager.boostScreenBrightness(eventTime);
1060 break;
1061 }
1062 }
1063
1064 private int getMaxMultiPressPowerCount() {
1065 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1066 return 3;
1067 }
1068 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1069 return 2;
1070 }
1071 return 1;
1072 }
1073
1074 private void powerLongPress() {
1075 final int behavior = getResolvedLongPressOnPowerBehavior();
1076 switch (behavior) {
1077 case LONG_PRESS_POWER_NOTHING:
1078 break;
1079 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1080 mPowerKeyHandled = true;
1081 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1082 performAuditoryFeedbackForAccessibilityIfNeed();
1083 }
1084 showGlobalActionsInternal();
1085 break;
1086 case LONG_PRESS_POWER_SHUT_OFF:
1087 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1088 mPowerKeyHandled = true;
1089 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1090 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1091 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1092 break;
1093 }
1094 }
1095
Nick Vaccarob593a812015-05-15 11:23:05 -07001096 private void sleepPress(long eventTime) {
1097 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1098 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1099 }
1100 }
1101
1102 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001103 switch (mShortPressOnSleepBehavior) {
1104 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001105 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001106 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1107 mPowerManager.goToSleep(eventTime,
1108 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001109 break;
1110 }
1111 }
1112
Jeff Brown13f00f02014-10-31 14:45:50 -07001113 private int getResolvedLongPressOnPowerBehavior() {
1114 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1115 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1116 }
1117 return mLongPressOnPowerBehavior;
1118 }
1119
1120 private boolean hasLongPressOnPowerBehavior() {
1121 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001122 }
1123
1124 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001125 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001126 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1127 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001128 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001129 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1130 && now <= mScreenshotChordPowerKeyTime
1131 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1132 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001133 cancelPendingPowerKeyAction();
1134
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001135 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001136 }
1137 }
1138 }
1139
Winson Chung1cea2f32012-10-08 20:42:01 -07001140 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001141 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001142 // Double the time it takes to take a screenshot from the keyguard
1143 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001144 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001145 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001146 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001147 }
1148
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001149 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001150 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001151 }
1152
Jeff Brown13f00f02014-10-31 14:45:50 -07001153 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001154 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001155 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001156 mEndCallKeyHandled = true;
1157 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1158 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001159 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001160 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001161 }
1162 };
1163
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001164 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001165 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001166 public void run() {
1167 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001168 }
1169 };
1170
Alan Viverettee34560b22014-07-10 14:50:06 -07001171 @Override
1172 public void showGlobalActions() {
1173 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1174 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1175 }
1176
1177 void showGlobalActionsInternal() {
1178 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001179 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001180 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001181 }
Jim Millerab954542014-10-10 18:21:49 -07001182 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001183 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1184 if (keyguardShowing) {
1185 // since it took two seconds of long press to bring this up,
1186 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001187 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001188 }
1189 }
1190
1191 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001192 return Settings.Global.getInt(
1193 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001194 }
1195
Maurice Lam99c6e072014-04-28 18:24:28 -07001196 boolean isUserSetupComplete() {
1197 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1198 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1199 }
1200
Jeff Brown13f00f02014-10-31 14:45:50 -07001201 private void handleShortPressOnHome() {
1202 // If there's a dream running then use home to escape the dream
1203 // but don't actually go home.
1204 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1205 mDreamManagerInternal.stopDream(false /*immediate*/);
1206 return;
1207 }
1208
1209 // Go home!
1210 launchHomeFromHotKey();
1211 }
1212
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001213 private void handleLongPressOnHome(int deviceId) {
Joe Onorato46b0d682010-11-22 17:37:27 -08001214 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001215 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001216 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001217
Jeff Browncaca8812013-05-09 13:34:33 -07001218 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1219 toggleRecentApps();
1220 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001221 launchAssistAction(null, deviceId);
Jim Millere6ad1a82010-08-20 19:25:39 -07001222 }
1223 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001224 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001225
Jeff Browncaca8812013-05-09 13:34:33 -07001226 private void handleDoubleTapOnHome() {
1227 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1228 mHomeConsumed = true;
1229 toggleRecentApps();
1230 }
1231 }
1232
1233 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1234 @Override
1235 public void run() {
1236 if (mHomeDoubleTapPending) {
1237 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001238 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001239 }
1240 }
1241 };
1242
Mark Renoufc1256912015-03-11 14:38:23 -04001243 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001244 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001245 }
1246
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001247 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001248 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001249 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001250 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001251 mContext = context;
1252 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001253 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001254 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001255 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001256 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Mark Renoufc1256912015-03-11 14:38:23 -04001257
1258 // Init display burn-in protection
1259 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1260 com.android.internal.R.bool.config_enableBurnInProtection);
1261 // Allow a system property to override this. Used by developer settings.
1262 boolean burnInProtectionDevMode =
1263 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1264 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1265 final int minHorizontal;
1266 final int maxHorizontal;
1267 final int minVertical;
1268 final int maxVertical;
1269 final int maxRadius;
1270 if (burnInProtectionDevMode) {
1271 minHorizontal = -8;
1272 maxHorizontal = 8;
1273 minVertical = -8;
1274 maxVertical = -4;
1275 maxRadius = (isRoundWindow()) ? 6 : -1;
1276 } else {
1277 Resources resources = context.getResources();
1278 minHorizontal = resources.getInteger(
1279 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1280 maxHorizontal = resources.getInteger(
1281 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1282 minVertical = resources.getInteger(
1283 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1284 maxVertical = resources.getInteger(
1285 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1286 maxRadius = resources.getInteger(
1287 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1288 }
1289 mBurnInProtectionHelper = new BurnInProtectionHelper(
1290 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001291 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001292
Jeff Brown70825162012-03-28 17:27:48 -07001293 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001294 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001295 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001296 try {
1297 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1298 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001299 mSettingsObserver = new SettingsObserver(mHandler);
1300 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001301 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001302 mUiMode = context.getResources().getInteger(
1303 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001304 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1305 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1306 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1307 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001308 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1309 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1310 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1311 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1312 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1313 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1314 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1315 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001316
Jeff Brown96307042012-07-27 15:51:34 -07001317 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1318 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001319 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001320 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1321 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001322 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001323 mSupportAutoRotation = mContext.getResources().getBoolean(
1324 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001325 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001326 com.android.internal.R.integer.config_lidOpenRotation);
1327 mCarDockRotation = readRotation(
1328 com.android.internal.R.integer.config_carDockRotation);
1329 mDeskDockRotation = readRotation(
1330 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001331 mUndockedHdmiRotation = readRotation(
1332 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001333 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1334 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1335 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1336 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001337 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1338 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1339 mLidNavigationAccessibility = mContext.getResources().getInteger(
1340 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001341 mLidControlsSleep = mContext.getResources().getBoolean(
1342 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001343 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1344 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001345
1346 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1347 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1348 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1349 || mContext.getResources().getBoolean(
1350 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1351 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1352 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001353 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1354 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001355 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1356 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1357 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1358 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1359 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1360 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1361
Bryce Lee55e846d2014-11-04 12:43:44 -08001362 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1363 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1364
Bryce Leed3b28402015-03-09 15:49:13 +00001365 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1366 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1367
Jeff Brown13f00f02014-10-31 14:45:50 -07001368 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1369 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1370 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1371 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1372 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1373 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1374 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1375 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001376 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1377 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001378
John Spurlock61560172015-02-06 19:46:04 -05001379 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001380
Jeff Brownf71343d2013-05-31 17:59:11 -07001381 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001382
Svetoslav8e3feb12014-02-24 13:46:47 -08001383 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1384 Context.ACCESSIBILITY_SERVICE);
1385
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001386 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001387 IntentFilter filter = new IntentFilter();
1388 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1389 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1390 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1391 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001392 filter.addAction(Intent.ACTION_DOCK_EVENT);
1393 Intent intent = context.registerReceiver(mDockReceiver, filter);
1394 if (intent != null) {
1395 // Retrieve current sticky dock event broadcast.
1396 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1397 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1398 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001399
Jeff Brown6aaf2952012-10-05 16:01:08 -07001400 // register for dream-related broadcasts
1401 filter = new IntentFilter();
1402 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1403 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1404 context.registerReceiver(mDreamReceiver, filter);
1405
Christopher Tate5e08af02012-09-21 17:17:22 -07001406 // register for multiuser-relevant broadcasts
1407 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1408 context.registerReceiver(mMultiuserReceiver, filter);
1409
John Spurlock57306e62013-04-22 09:48:49 -04001410 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001411 mSystemGestures = new SystemGesturesPointerEventListener(context,
1412 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001413 @Override
1414 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001415 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001416 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001417 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001418 }
1419 @Override
1420 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001421 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001422 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001423 }
1424 }
1425 @Override
1426 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001427 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001428 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001429 }
1430 }
1431 @Override
1432 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001433 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001434 }
Adrian Roos3595be42015-03-05 16:31:15 +01001435 @Override
1436 public void onDown() {
1437 mOrientationListener.onTouchStart();
1438 }
1439 @Override
1440 public void onUpOrCancel() {
1441 mOrientationListener.onTouchEnd();
1442 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001443 });
John Spurlockf1a36642013-10-12 17:50:42 -04001444 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001445 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001446
Jeff Brownc2346132012-04-13 01:55:38 -07001447 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001448 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1449 com.android.internal.R.array.config_longPressVibePattern);
1450 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1451 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001452 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1453 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001454 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1455 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001456 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1457 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001458 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1459 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1460 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1461 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001462 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1463 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001464
Christopher Tatee90585f2012-03-05 18:56:25 -08001465 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1466 com.android.internal.R.bool.config_enableScreenshotChord);
1467
Justin Kohd378ad72013-04-01 12:18:26 -07001468 mGlobalKeyManager = new GlobalKeyManager(mContext);
1469
Joe Onoratoea495d42011-04-06 11:41:11 -07001470 // Controls rotation and the like.
1471 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001472
1473 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001474 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001475 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1476 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001477 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001478
1479 mWindowManagerInternal.registerAppTransitionListener(
1480 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001481 }
1482
Jeff Brownf71343d2013-05-31 17:59:11 -07001483 /**
1484 * Read values from config.xml that may be overridden depending on
1485 * the configuration of the device.
1486 * eg. Disable long press on home goes to recents on sw600dp.
1487 */
1488 private void readConfigurationDependentBehaviors() {
1489 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1490 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1491 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1492 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1493 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1494 }
1495
1496 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1497 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1498 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1499 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1500 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1501 }
1502 }
1503
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001504 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001505 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001506 // This method might be called before the policy has been fully initialized
1507 // or for other displays we don't care about.
1508 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1509 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001510 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001511 mDisplay = display;
1512
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001513 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001514 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001515 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001516 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001517 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001518 mLandscapeRotation = Surface.ROTATION_0;
1519 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001520 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001521 mPortraitRotation = Surface.ROTATION_90;
1522 mUpsideDownRotation = Surface.ROTATION_270;
1523 } else {
1524 mPortraitRotation = Surface.ROTATION_270;
1525 mUpsideDownRotation = Surface.ROTATION_90;
1526 }
1527 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001528 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001529 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001530 mPortraitRotation = Surface.ROTATION_0;
1531 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001532 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001533 mLandscapeRotation = Surface.ROTATION_270;
1534 mSeascapeRotation = Surface.ROTATION_90;
1535 } else {
1536 mLandscapeRotation = Surface.ROTATION_90;
1537 mSeascapeRotation = Surface.ROTATION_270;
1538 }
1539 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001540
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001541 mStatusBarHeight =
1542 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001543
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001544 // Height of the navigation bar when presented horizontally at bottom
1545 mNavigationBarHeightForRotation[mPortraitRotation] =
1546 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001547 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001548 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001549 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1550 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001551
1552 // Width of the navigation bar when presented vertically along one side
1553 mNavigationBarWidthForRotation[mPortraitRotation] =
1554 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1555 mNavigationBarWidthForRotation[mLandscapeRotation] =
1556 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001557 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001558
1559 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001560 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001561 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001562
Devin Kimd7b12b42014-05-05 14:34:58 -07001563 // Allow the navigation bar to move on non-square small devices (phones).
1564 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001565
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001566 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001567 // Allow a system property to override this. Used by the emulator.
1568 // See also hasNavigationBar().
1569 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1570 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001571 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001572 } else if ("0".equals(navBarOverride)) {
1573 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001574 }
1575
Jeff Brown27f1d672012-10-17 18:32:34 -07001576 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1577 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001578 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001579 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001580 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001581 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001582 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001583 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001584
Chong Zhangae6119ff2014-11-11 18:54:39 -08001585 // For demo purposes, allow the rotation of the remote display to be controlled.
1586 // By default, remote display locks rotation to landscape.
1587 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1588 mDemoRotation = mPortraitRotation;
1589 } else {
1590 mDemoRotation = mLandscapeRotation;
1591 }
1592 mDemoRotationLock = SystemProperties.getBoolean(
1593 "persist.demo.rotationlock", false);
1594
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001595 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1596 // http://developer.android.com/guide/practices/screens_support.html#range
1597 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1598 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1599 // For debug purposes the next line turns this feature off with:
1600 // $ adb shell setprop config.override_forced_orient true
1601 // $ adb shell wm size reset
1602 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1603 }
1604
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001605 /**
1606 * @return whether the navigation bar can be hidden, e.g. the device has a
1607 * navigation bar and touch exploration is not enabled
1608 */
1609 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001610 return mHasNavigationBar
1611 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001612 }
1613
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001614 @Override
1615 public boolean isDefaultOrientationForced() {
1616 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001617 }
1618
Dianne Hackbornc652de82013-02-15 16:32:56 -08001619 @Override
1620 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1621 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1622 mOverscanLeft = left;
1623 mOverscanTop = top;
1624 mOverscanRight = right;
1625 mOverscanBottom = bottom;
1626 }
1627 }
1628
Dianne Hackbornc777e072010-02-12 13:07:59 -08001629 public void updateSettings() {
1630 ContentResolver resolver = mContext.getContentResolver();
1631 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001632 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001633 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001634 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001635 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1636 UserHandle.USER_CURRENT);
1637 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001638 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001639 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1640 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001641
Jeff Browna20dda42014-05-27 20:57:24 -07001642 // Configure wake gesture.
1643 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1644 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1645 UserHandle.USER_CURRENT) != 0;
1646 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1647 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1648 updateWakeGestureListenerLp();
1649 }
1650
Jeff Brown207673cd2012-06-05 17:47:11 -07001651 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001652 int userRotation = Settings.System.getIntForUser(resolver,
1653 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1654 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001655 if (mUserRotation != userRotation) {
1656 mUserRotation = userRotation;
1657 updateRotation = true;
1658 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001659 int userRotationMode = Settings.System.getIntForUser(resolver,
1660 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001661 WindowManagerPolicy.USER_ROTATION_FREE :
1662 WindowManagerPolicy.USER_ROTATION_LOCKED;
1663 if (mUserRotationMode != userRotationMode) {
1664 mUserRotationMode = userRotationMode;
1665 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001666 updateOrientationListenerLp();
1667 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001668
Dianne Hackbornc777e072010-02-12 13:07:59 -08001669 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001670 int pointerLocation = Settings.System.getIntForUser(resolver,
1671 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001672 if (mPointerLocationMode != pointerLocation) {
1673 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001674 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1675 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001676 }
1677 }
1678 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001679 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1680 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1681 String imId = Settings.Secure.getStringForUser(resolver,
1682 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001683 boolean hasSoftInput = imId != null && imId.length() > 0;
1684 if (mHasSoftInput != hasSoftInput) {
1685 mHasSoftInput = hasSoftInput;
1686 updateRotation = true;
1687 }
John Spurlockf1a36642013-10-12 17:50:42 -04001688 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001689 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001690 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001691 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001692 }
1693 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001694 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001695 }
Jeff Brown70825162012-03-28 17:27:48 -07001696 }
1697
Jeff Browna20dda42014-05-27 20:57:24 -07001698 private void updateWakeGestureListenerLp() {
1699 if (shouldEnableWakeGestureLp()) {
1700 mWakeGestureListener.requestWakeUpTrigger();
1701 } else {
1702 mWakeGestureListener.cancelWakeUpTrigger();
1703 }
1704 }
1705
1706 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001707 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001708 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1709 && mWakeGestureListener.isSupported();
1710 }
1711
Jeff Brown70825162012-03-28 17:27:48 -07001712 private void enablePointerLocation() {
1713 if (mPointerLocationView == null) {
1714 mPointerLocationView = new PointerLocationView(mContext);
1715 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001716 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1717 WindowManager.LayoutParams.MATCH_PARENT,
1718 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001719 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001720 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1721 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1722 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1723 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001724 if (ActivityManager.isHighEndGfx()) {
1725 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1726 lp.privateFlags |=
1727 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1728 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001729 lp.format = PixelFormat.TRANSLUCENT;
1730 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001731 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001732 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001733 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001734 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001735 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001736 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001737 }
Jeff Brown70825162012-03-28 17:27:48 -07001738
1739 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001740 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001741 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1742 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001743 wm.removeView(mPointerLocationView);
1744 mPointerLocationView = null;
1745 }
1746 }
1747
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001748 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001749 try {
1750 int rotation = mContext.getResources().getInteger(resID);
1751 switch (rotation) {
1752 case 0:
1753 return Surface.ROTATION_0;
1754 case 90:
1755 return Surface.ROTATION_90;
1756 case 180:
1757 return Surface.ROTATION_180;
1758 case 270:
1759 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001760 }
1761 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001762 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001763 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001764 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001765 }
1766
1767 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001768 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001769 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001770 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001771
1772 outAppOp[0] = AppOpsManager.OP_NONE;
1773
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001774 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1775 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1776 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1777 return WindowManagerGlobal.ADD_INVALID_TYPE;
1778 }
1779
1780 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1781 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001782 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001783 }
1784 String permission = null;
1785 switch (type) {
1786 case TYPE_TOAST:
1787 // XXX right now the app process has complete control over
1788 // this... should introduce a token to let the system
1789 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001790 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001791 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001792 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001793 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001794 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001795 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001796 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001797 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001798 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001799 break;
1800 case TYPE_PHONE:
1801 case TYPE_PRIORITY_PHONE:
1802 case TYPE_SYSTEM_ALERT:
1803 case TYPE_SYSTEM_ERROR:
1804 case TYPE_SYSTEM_OVERLAY:
1805 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001806 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001807 break;
1808 default:
1809 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1810 }
1811 if (permission != null) {
1812 if (mContext.checkCallingOrSelfPermission(permission)
1813 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001814 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001815 }
1816 }
Jeff Brown98365d72012-08-19 20:30:52 -07001817 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001818 }
Craig Mautner88400d32012-09-30 12:35:45 -07001819
1820 @Override
1821 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1822
1823 // If this switch statement is modified, modify the comment in the declarations of
1824 // the type in {@link WindowManager.LayoutParams} as well.
1825 switch (attrs.type) {
1826 default:
1827 // These are the windows that by default are shown only to the user that created
1828 // them. If this needs to be overridden, set
1829 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1830 // {@link WindowManager.LayoutParams}. Note that permission
1831 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1832 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1833 return true;
1834 }
1835 break;
1836
1837 // These are the windows that by default are shown to all users. However, to
1838 // protect against spoofing, check permissions below.
1839 case TYPE_APPLICATION_STARTING:
1840 case TYPE_BOOT_PROGRESS:
1841 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07001842 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001843 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001844 case TYPE_KEYGUARD_DIALOG:
1845 case TYPE_MAGNIFICATION_OVERLAY:
1846 case TYPE_NAVIGATION_BAR:
1847 case TYPE_NAVIGATION_BAR_PANEL:
1848 case TYPE_PHONE:
1849 case TYPE_POINTER:
1850 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001851 case TYPE_SEARCH_BAR:
1852 case TYPE_STATUS_BAR:
1853 case TYPE_STATUS_BAR_PANEL:
1854 case TYPE_STATUS_BAR_SUB_PANEL:
1855 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001856 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001857 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001858 break;
1859 }
1860
1861 // Check if third party app has set window to system window type.
1862 return mContext.checkCallingOrSelfPermission(
1863 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1864 != PackageManager.PERMISSION_GRANTED;
1865 }
1866
Craig Mautner967212c2013-04-13 21:10:58 -07001867 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001868 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1869 switch (attrs.type) {
1870 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001871 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001872 // These types of windows can't receive input events.
1873 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1874 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001875 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001876 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001877 case TYPE_STATUS_BAR:
1878
1879 // If the Keyguard is in a hidden state (occluded by another window), we force to
1880 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1881 // the keyguard as occluded wouldn't set these flags again.
1882 // See {@link #processKeyguardSetHiddenResultLw}.
1883 if (mKeyguardHidden) {
1884 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1885 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1886 }
1887 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001888 }
Adrian Roos38502112014-04-09 21:04:11 +02001889
1890 if (attrs.type != TYPE_STATUS_BAR) {
1891 // The status bar is the only window allowed to exhibit keyguard behavior.
1892 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1893 }
Adrian Roosea562512014-05-05 13:33:03 +02001894
1895 if (ActivityManager.isHighEndGfx()
1896 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001897 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001898 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1899 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001900 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001901
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001902 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001903 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001904 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001905
Michael Wright3818c922014-09-02 13:59:07 -07001906 private void readCameraLensCoverState() {
1907 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1908 }
1909
Jeff Browndaa37532012-05-01 15:54:03 -07001910 private boolean isHidden(int accessibilityMode) {
1911 switch (accessibilityMode) {
1912 case 1:
1913 return mLidState == LID_CLOSED;
1914 case 2:
1915 return mLidState == LID_OPEN;
1916 default:
1917 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001918 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001919 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001920
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001921 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001922 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001923 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1924 int navigationPresence) {
1925 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1926
Jeff Brownf71343d2013-05-31 17:59:11 -07001927 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001928 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001929 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001930
Jeff Browndaa37532012-05-01 15:54:03 -07001931 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1932 || (keyboardPresence == PRESENCE_INTERNAL
1933 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001934 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001935 if (!mHasSoftInput) {
1936 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1937 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001938 }
1939
Jeff Browndaa37532012-05-01 15:54:03 -07001940 if (config.navigation == Configuration.NAVIGATION_NONAV
1941 || (navigationPresence == PRESENCE_INTERNAL
1942 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001943 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001944 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001945 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001946
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001947 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001948 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001949 public int windowTypeToLayerLw(int type) {
1950 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001951 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001952 }
1953 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001954 case TYPE_PRIVATE_PRESENTATION:
1955 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001956 case TYPE_WALLPAPER:
1957 // wallpaper is at the bottom, though the window manager may move it.
1958 return 2;
1959 case TYPE_PHONE:
1960 return 3;
1961 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07001962 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001963 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001964 case TYPE_VOICE_INTERACTION:
1965 // voice interaction layer is almost immediately above apps.
1966 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07001967 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001968 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07001969 case TYPE_SYSTEM_DIALOG:
1970 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001971 case TYPE_TOAST:
1972 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07001973 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001974 case TYPE_PRIORITY_PHONE:
1975 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07001976 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001977 case TYPE_DREAM:
1978 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07001979 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001980 case TYPE_SYSTEM_ALERT:
1981 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07001982 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001983 case TYPE_INPUT_METHOD:
1984 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07001985 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001986 case TYPE_INPUT_METHOD_DIALOG:
1987 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07001988 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08001989 case TYPE_KEYGUARD_SCRIM:
1990 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001991 return 14;
Selim Cinekf83e8242015-05-19 18:08:14 -07001992 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001993 return 15;
Selim Cinekf83e8242015-05-19 18:08:14 -07001994 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001995 return 16;
Selim Cinekf83e8242015-05-19 18:08:14 -07001996 case TYPE_STATUS_BAR_PANEL:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001997 return 17;
Selim Cinekf83e8242015-05-19 18:08:14 -07001998 case TYPE_KEYGUARD_DIALOG:
1999 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002000 case TYPE_VOLUME_OVERLAY:
2001 // the on-screen volume indicator and controller shown when the user
2002 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07002003 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002004 case TYPE_SYSTEM_OVERLAY:
2005 // the on-screen volume indicator and controller shown when the user
2006 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07002007 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002008 case TYPE_NAVIGATION_BAR:
2009 // the navigation bar, if available, shows atop most things
Selim Cinekf83e8242015-05-19 18:08:14 -07002010 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002011 case TYPE_NAVIGATION_BAR_PANEL:
2012 // some panels (e.g. search) need to show on top of the navigation bar
Selim Cinekf83e8242015-05-19 18:08:14 -07002013 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002014 case TYPE_SYSTEM_ERROR:
2015 // system-level error dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002016 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002017 case TYPE_MAGNIFICATION_OVERLAY:
2018 // used to highlight the magnified portion of a display
Selim Cinekf83e8242015-05-19 18:08:14 -07002019 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002020 case TYPE_DISPLAY_OVERLAY:
2021 // used to simulate secondary display devices
Selim Cinekf83e8242015-05-19 18:08:14 -07002022 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002023 case TYPE_DRAG:
2024 // the drag layer: input for drag-and-drop is associated with this window,
2025 // which sits above all other focusable windows
Selim Cinekf83e8242015-05-19 18:08:14 -07002026 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002027 case TYPE_ACCESSIBILITY_OVERLAY:
2028 // overlay put by accessibility services to intercept user interaction
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002029 return 27;
Selim Cinekf83e8242015-05-19 18:08:14 -07002030 case TYPE_SECURE_SYSTEM_OVERLAY:
Svetoslav3a5c7212014-10-14 09:54:26 -07002031 return 28;
Selim Cinekf83e8242015-05-19 18:08:14 -07002032 case TYPE_BOOT_PROGRESS:
2033 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002034 case TYPE_POINTER:
2035 // the (mouse) pointer layer
Svetoslav3a5c7212014-10-14 09:54:26 -07002036 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002037 }
2038 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002039 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002040 }
2041
2042 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002043 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002044 public int subWindowTypeToLayerLw(int type) {
2045 switch (type) {
2046 case TYPE_APPLICATION_PANEL:
2047 case TYPE_APPLICATION_ATTACHED_DIALOG:
2048 return APPLICATION_PANEL_SUBLAYER;
2049 case TYPE_APPLICATION_MEDIA:
2050 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002051 case TYPE_APPLICATION_MEDIA_OVERLAY:
2052 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002053 case TYPE_APPLICATION_SUB_PANEL:
2054 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002055 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2056 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002057 }
2058 Log.e(TAG, "Unknown sub-window type: " + type);
2059 return 0;
2060 }
2061
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002062 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002063 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002064 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002065 }
2066
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002067 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002068 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002069 if (mHasNavigationBar) {
2070 // For a basic navigation bar, when we are in landscape mode we place
2071 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002072 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2073 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002074 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002075 }
2076 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002077 }
2078
Jose Lima9546b202014-07-02 17:21:51 -07002079 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002080 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002081 if (mHasNavigationBar) {
2082 // For a basic navigation bar, when we are in portrait mode we place
2083 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002084 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2085 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002086 }
2087 }
2088 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002089 }
2090
Jose Lima9546b202014-07-02 17:21:51 -07002091 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002092 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2093 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002094 }
2095
Jose Lima9546b202014-07-02 17:21:51 -07002096 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002097 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002098 // There is a separate status bar at the top of the display. We don't count that as part
2099 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002100 // we do want to exclude it since applications can't generally use that part
2101 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002102 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002103 }
2104
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002105 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002106 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2107 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002108 (isKeyguardHostWindow(attrs) &&
2109 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002110 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002111 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002112
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002113 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002114 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2115 return attrs.type == TYPE_STATUS_BAR;
2116 }
2117
2118 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002119 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002120 switch (attrs.type) {
2121 case TYPE_STATUS_BAR:
2122 case TYPE_NAVIGATION_BAR:
2123 case TYPE_WALLPAPER:
2124 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002125 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002126 return false;
2127 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002128 // Hide only windows below the keyguard host window.
2129 return windowTypeToLayerLw(win.getBaseType())
2130 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002131 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002132 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002133
Craig Mautner7d7808f2014-09-11 18:02:38 -07002134 @Override
2135 public WindowState getWinShowWhenLockedLw() {
2136 return mWinShowWhenLocked;
2137 }
2138
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002139 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002140 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002141 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2142 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002143 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002144 if (!SHOW_STARTING_ANIMATIONS) {
2145 return null;
2146 }
2147 if (packageName == null) {
2148 return null;
2149 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002150
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002151 WindowManager wm = null;
2152 View view = null;
2153
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002154 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002155 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002156 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2157 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2158 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002159 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002160 try {
2161 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002162 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002163 } catch (PackageManager.NameNotFoundException e) {
2164 // Ignore
2165 }
2166 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002167
Jorim Jaggia16cc152015-06-01 16:55:05 -07002168 PhoneWindow win = new PhoneWindow(context);
2169 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002170 final TypedArray ta = win.getWindowStyle();
2171 if (ta.getBoolean(
2172 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2173 || ta.getBoolean(
2174 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002175 return null;
2176 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002177
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002178 Resources r = context.getResources();
2179 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002180
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002181 win.setType(
2182 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002183
2184 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2185 // Assumes it's safe to show starting windows of launched apps while
2186 // the keyguard is being hidden. This is okay because starting windows never show
2187 // secret information.
2188 if (mKeyguardHidden) {
2189 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2190 }
2191 }
2192
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002193 // Force the window flags: this is a fake window, so it is not really
2194 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2195 // flag because we do know that the next window will take input
2196 // focus, so we want to get the IME window up on top of us right away.
2197 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002198 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002199 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2200 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2201 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002202 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002203 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2204 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2205 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002206
Adam Powell04fe6eb2013-05-31 14:39:48 -07002207 win.setDefaultIcon(icon);
2208 win.setDefaultLogo(logo);
2209
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002210 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002211 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002212
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002213 final WindowManager.LayoutParams params = win.getAttributes();
2214 params.token = appToken;
2215 params.packageName = packageName;
2216 params.windowAnimations = win.getWindowStyle().getResourceId(
2217 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002218 params.privateFlags |=
2219 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002220 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002221
2222 if (!compatInfo.supportsScreen()) {
2223 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2224 }
2225
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002226 params.setTitle("Starting " + packageName);
2227
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002228 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2229 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002230
2231 if (win.isFloating()) {
2232 // Whoops, there is no way to display an animation/preview
2233 // of such a thing! After all that work... let's skip it.
2234 // (Note that we must do this here because it is in
2235 // getDecorView() where the theme is evaluated... maybe
2236 // we should peek the floating attribute from the theme
2237 // earlier.)
2238 return null;
2239 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002240
Craig Mautner6fbda632012-07-03 09:26:39 -07002241 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002242 TAG, "Adding starting window for " + packageName
2243 + " / " + appToken + ": "
2244 + (view.getParent() != null ? view : null));
2245
2246 wm.addView(view, params);
2247
2248 // Only return the view if it was successfully added to the
2249 // window manager... which we can tell by it having a parent.
2250 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002251 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002252 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002253 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2254 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002255 } catch (RuntimeException e) {
2256 // don't crash if something else bad happens, for example a
2257 // failure loading resources because we are loading from an app
2258 // on external storage that has been unmounted.
2259 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002260 } finally {
2261 if (view != null && view.getParent() == null) {
2262 Log.w(TAG, "view not successfully added to wm, removing view");
2263 wm.removeViewImmediate(view);
2264 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002265 }
2266
2267 return null;
2268 }
2269
2270 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002271 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002272 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002273 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2274 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002275
2276 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002277 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002278 wm.removeView(window);
2279 }
2280 }
2281
2282 /**
2283 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002284 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002285 * Currently enforces that three window types are singletons:
2286 * <ul>
2287 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002288 * <li>KEYGUARD_TYPE</li>
2289 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002290 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002291 * @param win The window to be added
2292 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002293 *
Jeff Brown98365d72012-08-19 20:30:52 -07002294 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2295 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002296 */
Jose Lima9546b202014-07-02 17:21:51 -07002297 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002298 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2299 switch (attrs.type) {
2300 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002301 mContext.enforceCallingOrSelfPermission(
2302 android.Manifest.permission.STATUS_BAR_SERVICE,
2303 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002304 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002305 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002306 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002307 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002308 }
2309 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002310 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002311 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002312 case TYPE_NAVIGATION_BAR:
2313 mContext.enforceCallingOrSelfPermission(
2314 android.Manifest.permission.STATUS_BAR_SERVICE,
2315 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002316 if (mNavigationBar != null) {
2317 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002318 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002319 }
2320 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002321 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002322 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002323 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002324 break;
Jim Millere898ac52012-04-06 17:10:57 -07002325 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002326 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002327 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002328 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002329 mContext.enforceCallingOrSelfPermission(
2330 android.Manifest.permission.STATUS_BAR_SERVICE,
2331 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002332 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002333 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002334 if (mKeyguardScrim != null) {
2335 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2336 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002337 mKeyguardScrim = win;
2338 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002339 }
Jeff Brown98365d72012-08-19 20:30:52 -07002340 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002341 }
2342
2343 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002344 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002345 public void removeWindowLw(WindowState win) {
2346 if (mStatusBar == win) {
2347 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002348 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002349 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002350 } else if (mKeyguardScrim == win) {
2351 Log.v(TAG, "Removing keyguard scrim");
2352 mKeyguardScrim = null;
2353 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002354 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002355 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002356 }
2357 }
2358
2359 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002360
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002361 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002362 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002363 public int selectAnimationLw(WindowState win, int transit) {
2364 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2365 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002366 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002367 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002368 if (transit == TRANSIT_EXIT
2369 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002370 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002371 } else if (transit == TRANSIT_ENTER
2372 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002373 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002374 }
2375 } else if (win == mNavigationBar) {
2376 // This can be on either the bottom or the right.
2377 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002378 if (transit == TRANSIT_EXIT
2379 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002380 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002381 } else if (transit == TRANSIT_ENTER
2382 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002383 return R.anim.dock_bottom_enter;
2384 }
2385 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002386 if (transit == TRANSIT_EXIT
2387 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002388 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002389 } else if (transit == TRANSIT_ENTER
2390 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002391 return R.anim.dock_right_enter;
2392 }
2393 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002394 }
2395
2396 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002397 if (win.hasAppShownWindows()) {
2398 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2399 return com.android.internal.R.anim.app_starting_exit;
2400 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002401 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002402 && transit == TRANSIT_ENTER) {
2403 // Special case: we are animating in a dream, while the keyguard
2404 // is shown. We don't want an animation on the dream, because
2405 // we need it shown immediately with the keyguard animating away
2406 // to reveal it.
2407 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002408 }
2409
2410 return 0;
2411 }
2412
Craig Mautner3c174372013-02-21 17:54:37 -08002413 @Override
2414 public void selectRotationAnimationLw(int anim[]) {
2415 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2416 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2417 + (mTopFullscreenOpaqueWindowState == null ?
2418 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2419 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2420 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2421 case ROTATION_ANIMATION_CROSSFADE:
2422 anim[0] = R.anim.rotation_animation_xfade_exit;
2423 anim[1] = R.anim.rotation_animation_enter;
2424 break;
2425 case ROTATION_ANIMATION_JUMPCUT:
2426 anim[0] = R.anim.rotation_animation_jump_exit;
2427 anim[1] = R.anim.rotation_animation_enter;
2428 break;
2429 case ROTATION_ANIMATION_ROTATE:
2430 default:
2431 anim[0] = anim[1] = 0;
2432 break;
2433 }
2434 } else {
2435 anim[0] = anim[1] = 0;
2436 }
2437 }
2438
2439 @Override
2440 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2441 boolean forceDefault) {
2442 switch (exitAnimId) {
2443 case R.anim.rotation_animation_xfade_exit:
2444 case R.anim.rotation_animation_jump_exit:
2445 // These are the only cases that matter.
2446 if (forceDefault) {
2447 return false;
2448 }
2449 int anim[] = new int[2];
2450 selectRotationAnimationLw(anim);
2451 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2452 default:
2453 return true;
2454 }
2455 }
2456
2457 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002458 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2459 boolean goingToNotificationShade) {
2460 if (goingToNotificationShade) {
2461 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002462 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002463
2464 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2465 R.anim.lock_screen_behind_enter_wallpaper :
2466 R.anim.lock_screen_behind_enter);
2467
2468 // TODO: Use XML interpolators when we have log interpolators available in XML.
2469 final List<Animation> animations = set.getAnimations();
2470 for (int i = animations.size() - 1; i >= 0; --i) {
2471 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2472 }
2473
2474 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002475 }
2476
2477
2478 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002479 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2480 if (goingToNotificationShade) {
2481 return null;
2482 } else {
2483 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2484 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002485 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002486
2487 private static void awakenDreams() {
2488 IDreamManager dreamManager = getDreamManager();
2489 if (dreamManager != null) {
2490 try {
2491 dreamManager.awaken();
2492 } catch (RemoteException e) {
2493 // fine, stay asleep then
2494 }
2495 }
2496 }
2497
2498 static IDreamManager getDreamManager() {
2499 return IDreamManager.Stub.asInterface(
2500 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2501 }
2502
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002503 TelecomManager getTelecommService() {
2504 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002505 }
2506
Jeff Brown4d396052010-10-29 21:50:21 -07002507 static IAudioService getAudioService() {
2508 IAudioService audioService = IAudioService.Stub.asInterface(
2509 ServiceManager.checkService(Context.AUDIO_SERVICE));
2510 if (audioService == null) {
2511 Log.w(TAG, "Unable to find IAudioService interface.");
2512 }
2513 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002514 }
2515
2516 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002517 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002518 }
2519
2520 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2521 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2522 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2523 };
2524
2525 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002526 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002527 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002528 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002529 final int keyCode = event.getKeyCode();
2530 final int repeatCount = event.getRepeatCount();
2531 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002532 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002533 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2534 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002535
Jeff Brown40013652012-05-16 21:22:36 -07002536 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002537 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002538 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2539 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002540 }
2541
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002542 // If we think we might have a volume down & power key chord on the way
2543 // but we're not sure, then tell the dispatcher to wait a little while and
2544 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002545 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002546 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002547 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002548 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2549 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002550 if (now < timeoutTime) {
2551 return timeoutTime - now;
2552 }
2553 }
2554 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002555 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002556 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002557 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002558 }
2559 return -1;
2560 }
2561 }
2562
Michael Wright6a62e552014-06-03 19:19:48 -07002563 // Cancel any pending meta actions if we see any other keys being pressed between the down
2564 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002565 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002566 mPendingMetaAction = false;
2567 }
2568
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002569 // First we always handle the home key here, so applications
2570 // can never break it, although if keyguard is on, we do let
2571 // it handle it, because that gives us the correct 5 second
2572 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002573 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002574
Jeff Brown49ed71d2010-12-06 17:13:33 -08002575 // If we have released the home key, and didn't do anything else
2576 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002577 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002578 cancelPreloadRecentApps();
2579
Jeff Brown49ed71d2010-12-06 17:13:33 -08002580 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002581 if (mHomeConsumed) {
2582 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002583 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002584 }
Jeff Browncaca8812013-05-09 13:34:33 -07002585
2586 if (canceled) {
2587 Log.i(TAG, "Ignoring HOME; event canceled.");
2588 return -1;
2589 }
2590
Yorke Lee4f803242014-12-15 23:22:06 +00002591 // If an incoming call is ringing, HOME is totally disabled.
2592 // (The user is already on the InCallUI at this point,
2593 // and his ONLY options are to answer or reject the call.)
2594 TelecomManager telecomManager = getTelecommService();
2595 if (telecomManager != null && telecomManager.isRinging()) {
2596 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2597 return -1;
2598 }
2599
Jeff Browncaca8812013-05-09 13:34:33 -07002600 // Delay handling home if a double-tap is possible.
2601 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2602 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2603 mHomeDoubleTapPending = true;
2604 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2605 ViewConfiguration.getDoubleTapTimeout());
2606 return -1;
2607 }
2608
Jeff Brown13f00f02014-10-31 14:45:50 -07002609 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002610 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002611 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002612
2613 // If a system window has focus, then it doesn't make sense
2614 // right now to interact with applications.
2615 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2616 if (attrs != null) {
2617 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002618 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2619 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2620 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002621 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002622 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002623 }
2624 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2625 for (int i=0; i<typeCount; i++) {
2626 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2627 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002628 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002629 }
2630 }
2631 }
Jeff Browncaca8812013-05-09 13:34:33 -07002632
2633 // Remember that home is pressed and handle special actions.
2634 if (repeatCount == 0) {
2635 mHomePressed = true;
2636 if (mHomeDoubleTapPending) {
2637 mHomeDoubleTapPending = false;
2638 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2639 handleDoubleTapOnHome();
2640 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2641 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2642 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002643 }
Jeff Browncaca8812013-05-09 13:34:33 -07002644 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2645 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002646 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002647 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002648 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002649 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002650 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002651 // Hijack modified menu keys for debugging features
2652 final int chordBug = KeyEvent.META_SHIFT_ON;
2653
2654 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002655 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002656 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002657 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2658 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002659 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002660 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002661 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002662 Intent service = new Intent();
2663 service.setClassName(mContext, "com.android.server.LoadAverageService");
2664 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002665 boolean shown = Settings.Global.getInt(
2666 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002667 if (!shown) {
2668 mContext.startService(service);
2669 } else {
2670 mContext.stopService(service);
2671 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002672 Settings.Global.putInt(
2673 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002674 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002675 }
2676 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002677 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002678 if (down) {
2679 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002680 mSearchKeyShortcutPending = true;
2681 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002682 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002683 } else {
2684 mSearchKeyShortcutPending = false;
2685 if (mConsumeSearchKeyUp) {
2686 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002687 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002688 }
2689 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002690 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002691 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002692 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002693 if (down && repeatCount == 0) {
2694 preloadRecentApps();
2695 } else if (!down) {
2696 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002697 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002698 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002699 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002700 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2701 if (down) {
2702 IStatusBarService service = getStatusBarService();
2703 if (service != null) {
2704 try {
2705 service.expandNotificationsPanel();
2706 } catch (RemoteException e) {
2707 // do nothing.
2708 }
2709 }
2710 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002711 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2712 if (down) {
2713 if (repeatCount == 0) {
2714 mAssistKeyLongPressed = false;
2715 } else if (repeatCount == 1) {
2716 mAssistKeyLongPressed = true;
2717 if (!keyguardOn) {
2718 launchAssistLongPressAction();
2719 }
2720 }
2721 } else {
2722 if (mAssistKeyLongPressed) {
2723 mAssistKeyLongPressed = false;
2724 } else {
2725 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002726 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002727 }
2728 }
2729 }
2730 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002731 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2732 if (!down) {
2733 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002734 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002735 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2736 } else {
2737 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002738 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002739 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002740 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002741 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002742 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2743 if (down && repeatCount == 0) {
2744 mHandler.post(mScreenshotRunnable);
2745 }
2746 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002747 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2748 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2749 if (down) {
2750 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2751
2752 // Disable autobrightness if it's on
2753 int auto = Settings.System.getIntForUser(
2754 mContext.getContentResolver(),
2755 Settings.System.SCREEN_BRIGHTNESS_MODE,
2756 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2757 UserHandle.USER_CURRENT_OR_SELF);
2758 if (auto != 0) {
2759 Settings.System.putIntForUser(mContext.getContentResolver(),
2760 Settings.System.SCREEN_BRIGHTNESS_MODE,
2761 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2762 UserHandle.USER_CURRENT_OR_SELF);
2763 }
2764
2765 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2766 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2767 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2768 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2769 Settings.System.SCREEN_BRIGHTNESS,
2770 mPowerManager.getDefaultScreenBrightnessSetting(),
2771 UserHandle.USER_CURRENT_OR_SELF);
2772 brightness += step;
2773 // Make sure we don't go beyond the limits.
2774 brightness = Math.min(max, brightness);
2775 brightness = Math.max(min, brightness);
2776
2777 Settings.System.putIntForUser(mContext.getContentResolver(),
2778 Settings.System.SCREEN_BRIGHTNESS, brightness,
2779 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002780 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002781 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002782 }
2783 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002784 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002785 if (down) {
2786 mPendingMetaAction = true;
2787 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002788 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07002789 }
2790 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002791 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002792
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002793 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002794 // Any printing key that is chorded with Search should be consumed
2795 // even if no shortcut was invoked. This prevents text from being
2796 // inadvertently inserted when using a keyboard that has built-in macro
2797 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002798 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002799 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2800 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002801 mConsumeSearchKeyUp = true;
2802 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002803 if (down && repeatCount == 0 && !keyguardOn) {
2804 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2805 if (shortcutIntent != null) {
2806 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002807 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002808 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002809 } catch (ActivityNotFoundException ex) {
2810 Slog.w(TAG, "Dropping shortcut key combination because "
2811 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002812 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002813 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002814 } else {
2815 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002816 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002817 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002818 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002819 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002820 }
2821 }
2822
Jeff Brown68b909d2011-12-07 16:36:01 -08002823 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002824 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002825 && (metaState & KeyEvent.META_META_ON) != 0) {
2826 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002827 if (kcm.isPrintingKey(keyCode)) {
2828 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2829 metaState & ~(KeyEvent.META_META_ON
2830 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2831 if (shortcutIntent != null) {
2832 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2833 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002834 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002835 } catch (ActivityNotFoundException ex) {
2836 Slog.w(TAG, "Dropping shortcut key combination because "
2837 + "the activity to which it is registered was not found: "
2838 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2839 }
2840 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002841 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002842 }
2843 }
2844
Jeff Brown6651a632011-11-28 12:59:11 -08002845 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002846 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002847 String category = sApplicationLaunchKeyCategories.get(keyCode);
2848 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002849 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002850 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2851 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002852 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002853 } catch (ActivityNotFoundException ex) {
2854 Slog.w(TAG, "Dropping application launch key because "
2855 + "the activity to which it is registered was not found: "
2856 + "keyCode=" + keyCode + ", category=" + category, ex);
2857 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002858 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002859 }
2860 }
2861
Michael Wright61c46752014-08-21 16:57:33 -07002862 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002863 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002864 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002865 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002866 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002867 mRecentAppsHeldModifiers = shiftlessModifiers;
2868 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002869 return -1;
2870 }
2871 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002872 } else if (!down && mRecentAppsHeldModifiers != 0
2873 && (metaState & mRecentAppsHeldModifiers) == 0) {
2874 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002875 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002876 }
2877
Jeff Browncf39bdf2012-05-18 14:41:19 -07002878 // Handle keyboard language switching.
2879 if (down && repeatCount == 0
2880 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2881 || (keyCode == KeyEvent.KEYCODE_SPACE
2882 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2883 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2884 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2885 return -1;
2886 }
2887 if (mLanguageSwitchKeyPressed && !down
2888 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2889 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2890 mLanguageSwitchKeyPressed = false;
2891 return -1;
2892 }
2893
Jeff Brown13f00f02014-10-31 14:45:50 -07002894 if (isValidGlobalKey(keyCode)
2895 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002896 return -1;
2897 }
2898
Michael Wright6a62e552014-06-03 19:19:48 -07002899 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002900 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002901 return -1;
2902 }
2903
Jeff Brown68b909d2011-12-07 16:36:01 -08002904 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002905 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002906 }
2907
Jeff Brown3915bb82010-11-05 15:02:16 -07002908 /** {@inheritDoc} */
2909 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002910 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002911 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002912 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002913 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2914 + ", flags=" + event.getFlags()
2915 + ", keyCode=" + event.getKeyCode()
2916 + ", scanCode=" + event.getScanCode()
2917 + ", metaState=" + event.getMetaState()
2918 + ", repeatCount=" + event.getRepeatCount()
2919 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002920 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002921
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002922 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002923 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2924 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002925 final int keyCode = event.getKeyCode();
2926 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002927 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2928 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002929
Jeff Brown54875002011-04-06 15:33:01 -07002930 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002931 final FallbackAction fallbackAction;
2932 if (initialDown) {
2933 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2934 } else {
2935 fallbackAction = mFallbackActions.get(keyCode);
2936 }
2937
2938 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002939 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002940 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2941 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002942 }
2943
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002944 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2945 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002946 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002947 event.getAction(), fallbackAction.keyCode,
2948 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002949 event.getDeviceId(), event.getScanCode(),
2950 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002951
2952 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2953 fallbackEvent.recycle();
2954 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002955 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002956
2957 if (initialDown) {
2958 mFallbackActions.put(keyCode, fallbackAction);
2959 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2960 mFallbackActions.remove(keyCode);
2961 fallbackAction.recycle();
2962 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002963 }
2964 }
2965
Jeff Brown40013652012-05-16 21:22:36 -07002966 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002967 if (fallbackEvent == null) {
2968 Slog.d(TAG, "No fallback.");
2969 } else {
2970 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2971 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002972 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002973 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002974 }
2975
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002976 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002977 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002978 if ((actions & ACTION_PASS_TO_USER) != 0) {
2979 long delayMillis = interceptKeyBeforeDispatching(
2980 win, fallbackEvent, policyFlags);
2981 if (delayMillis == 0) {
2982 return true;
2983 }
2984 }
2985 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002986 }
2987
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002988 private void launchAssistLongPressAction() {
2989 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2990 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2991
2992 // launch the search activity
2993 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2994 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2995 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002996 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002997 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002998 SearchManager searchManager = getSearchManager();
2999 if (searchManager != null) {
3000 searchManager.stopSearch();
3001 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003002 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003003 } catch (ActivityNotFoundException e) {
3004 Slog.w(TAG, "No activity to handle assist long press action.", e);
3005 }
3006 }
3007
3008 private void launchAssistAction() {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003009 launchAssistAction(null, Integer.MIN_VALUE);
Michael Wright8ab940a2014-09-01 11:01:27 -07003010 }
3011
3012 private void launchAssistAction(String hint) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003013 launchAssistAction(hint, Integer.MIN_VALUE);
3014 }
3015
3016 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003017 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003018 Bundle args = null;
3019 if (deviceId > Integer.MIN_VALUE) {
3020 args = new Bundle();
3021 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003022 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003023 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3024 .launchAssistAction(hint, UserHandle.myUserId(), args);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003025 }
3026
Bart Sears8b1c27c2015-03-18 23:51:02 +00003027 private void startActivityAsUser(Intent intent, UserHandle handle) {
3028 if (isUserSetupComplete()) {
3029 mContext.startActivityAsUser(intent, handle);
3030 } else {
3031 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3032 }
3033 }
3034
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003035 private SearchManager getSearchManager() {
3036 if (mSearchManager == null) {
3037 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3038 }
3039 return mSearchManager;
3040 }
3041
Jeff Browncaca8812013-05-09 13:34:33 -07003042 private void preloadRecentApps() {
3043 mPreloadedRecentApps = true;
3044 try {
3045 IStatusBarService statusbar = getStatusBarService();
3046 if (statusbar != null) {
3047 statusbar.preloadRecentApps();
3048 }
3049 } catch (RemoteException e) {
3050 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3051 // re-acquire status bar service next time it is needed.
3052 mStatusBarService = null;
3053 }
3054 }
3055
3056 private void cancelPreloadRecentApps() {
3057 if (mPreloadedRecentApps) {
3058 mPreloadedRecentApps = false;
3059 try {
3060 IStatusBarService statusbar = getStatusBarService();
3061 if (statusbar != null) {
3062 statusbar.cancelPreloadRecentApps();
3063 }
3064 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003065 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003066 // re-acquire status bar service next time it is needed.
3067 mStatusBarService = null;
3068 }
3069 }
3070 }
3071
3072 private void toggleRecentApps() {
3073 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003074 try {
3075 IStatusBarService statusbar = getStatusBarService();
3076 if (statusbar != null) {
3077 statusbar.toggleRecentApps();
3078 }
3079 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003080 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3081 // re-acquire status bar service next time it is needed.
3082 mStatusBarService = null;
3083 }
3084 }
3085
Craig Mautner84984fa2014-06-19 11:19:20 -07003086 @Override
3087 public void showRecentApps() {
3088 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3089 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3090 }
3091
Winson Chung1e8d71b2014-05-16 17:05:22 -07003092 private void showRecentApps(boolean triggeredFromAltTab) {
3093 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3094 try {
3095 IStatusBarService statusbar = getStatusBarService();
3096 if (statusbar != null) {
3097 statusbar.showRecentApps(triggeredFromAltTab);
3098 }
3099 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003100 Slog.e(TAG, "RemoteException when showing recent apps", e);
3101 // re-acquire status bar service next time it is needed.
3102 mStatusBarService = null;
3103 }
3104 }
3105
Winson Chungcdcd4872014-08-05 18:00:13 -07003106 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003107 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3108 try {
3109 IStatusBarService statusbar = getStatusBarService();
3110 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003111 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003112 }
3113 } catch (RemoteException e) {
3114 Slog.e(TAG, "RemoteException when closing recent apps", e);
3115 // re-acquire status bar service next time it is needed.
3116 mStatusBarService = null;
3117 }
3118 }
3119
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003120 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003121 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003122 }
3123
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003124 /**
3125 * A home key -> launch home action was detected. Take the appropriate action
3126 * given the situation with the keyguard.
3127 */
Bryce Lee662ed802015-04-10 20:11:39 +00003128 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3129 if (respectKeyguard) {
3130 if (isKeyguardShowingAndNotOccluded()) {
3131 // don't launch home if keyguard showing
3132 return;
3133 }
3134
3135 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3136 // when in keyguard restricted mode, must first verify unlock
3137 // before launching home
3138 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3139 @Override
3140 public void onKeyguardExitResult(boolean success) {
3141 if (success) {
3142 try {
3143 ActivityManagerNative.getDefault().stopAppSwitches();
3144 } catch (RemoteException e) {
3145 }
3146 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3147 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003148 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003149 }
Bryce Lee662ed802015-04-10 20:11:39 +00003150 });
3151 return;
3152 }
3153 }
3154
3155 // no keyguard stuff to worry about, just launch home!
3156 try {
3157 ActivityManagerNative.getDefault().stopAppSwitches();
3158 } catch (RemoteException e) {
3159 }
3160 if (mRecentsVisible) {
3161 // Hide Recents and notify it to launch Home
3162 if (awakenFromDreams) {
3163 awakenDreams();
3164 }
3165 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3166 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003167 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003168 // Otherwise, just launch Home
3169 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3170 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003171 }
3172 }
3173
John Spurlock04db1762013-05-13 12:46:41 -04003174 private final Runnable mClearHideNavigationFlag = new Runnable() {
3175 @Override
3176 public void run() {
3177 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3178 // Clear flags.
3179 mForceClearedSystemUiFlags &=
3180 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3181 }
3182 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003183 }
3184 };
3185
3186 /**
3187 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3188 * to determine when the nav bar should be shown and prevent applications from
3189 * receiving those touches.
3190 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003191 final class HideNavInputEventReceiver extends InputEventReceiver {
3192 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3193 super(inputChannel, looper);
3194 }
3195
Dianne Hackborndf89e652011-10-06 22:35:11 -07003196 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003197 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003198 boolean handled = false;
3199 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003200 if (event instanceof MotionEvent
3201 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3202 final MotionEvent motionEvent = (MotionEvent)event;
3203 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003204 // When the user taps down, we re-show the nav bar.
3205 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003206 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003207 // Any user activity always causes us to show the
3208 // navigation controls, if they had been hidden.
3209 // We also clear the low profile and only content
3210 // flags so that tapping on the screen will atomically
3211 // restore all currently hidden screen decorations.
3212 int newVal = mResettingSystemUiFlags |
3213 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3214 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3215 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003216 if (mResettingSystemUiFlags != newVal) {
3217 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003218 changed = true;
3219 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003220 // We don't allow the system's nav bar to be hidden
3221 // again for 1 second, to prevent applications from
3222 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003223 newVal = mForceClearedSystemUiFlags |
3224 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003225 if (mForceClearedSystemUiFlags != newVal) {
3226 mForceClearedSystemUiFlags = newVal;
3227 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003228 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003229 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003230 }
3231 if (changed) {
3232 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3233 }
3234 }
3235 }
3236 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003237 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003238 }
3239 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003240 }
3241 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3242 new InputEventReceiver.Factory() {
3243 @Override
3244 public InputEventReceiver createInputEventReceiver(
3245 InputChannel inputChannel, Looper looper) {
3246 return new HideNavInputEventReceiver(inputChannel, looper);
3247 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003248 };
3249
3250 @Override
3251 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003252 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3253 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003254 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003255
Dianne Hackborndf89e652011-10-06 22:35:11 -07003256 // Reset any bits in mForceClearingStatusBarVisibility that
3257 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003258 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003259 // Clear any bits in the new visibility that are currently being
3260 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003261 return visibility & ~mResettingSystemUiFlags
3262 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003263 }
3264
Craig Mautner69b08182012-09-05 13:07:13 -07003265 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003266 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3267 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003268 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003269 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3270 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003271
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003272 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003273 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003274 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003275 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003276 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003277 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3278 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3279 } else {
3280 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3281 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3282 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003283 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3284 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003285 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003286 availRight - mStableFullscreenRight,
3287 availBottom - mStableFullscreenBottom);
3288 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003289 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003290 availRight - mStableRight, availBottom - mStableBottom);
3291 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003292 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003293 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003294 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003295 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003296 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003297 availRight - mCurRight, availBottom - mCurBottom);
3298 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003299 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003300 availRight - mCurRight, availBottom - mCurBottom);
3301 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003302
3303 outStableInsets.set(mStableLeft, mStableTop,
3304 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003305 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003306 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003307 outContentInsets.setEmpty();
3308 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003309 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003310
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003311 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003312 @Override
3313 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3314 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003315 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3316 if (isDefaultDisplay) {
3317 switch (displayRotation) {
3318 case Surface.ROTATION_90:
3319 overscanLeft = mOverscanTop;
3320 overscanTop = mOverscanRight;
3321 overscanRight = mOverscanBottom;
3322 overscanBottom = mOverscanLeft;
3323 break;
3324 case Surface.ROTATION_180:
3325 overscanLeft = mOverscanRight;
3326 overscanTop = mOverscanBottom;
3327 overscanRight = mOverscanLeft;
3328 overscanBottom = mOverscanTop;
3329 break;
3330 case Surface.ROTATION_270:
3331 overscanLeft = mOverscanBottom;
3332 overscanTop = mOverscanLeft;
3333 overscanRight = mOverscanTop;
3334 overscanBottom = mOverscanRight;
3335 break;
3336 default:
3337 overscanLeft = mOverscanLeft;
3338 overscanTop = mOverscanTop;
3339 overscanRight = mOverscanRight;
3340 overscanBottom = mOverscanBottom;
3341 break;
3342 }
3343 } else {
3344 overscanLeft = 0;
3345 overscanTop = 0;
3346 overscanRight = 0;
3347 overscanBottom = 0;
3348 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003349 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3350 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3351 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3352 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003353 mSystemLeft = 0;
3354 mSystemTop = 0;
3355 mSystemRight = displayWidth;
3356 mSystemBottom = displayHeight;
3357 mUnrestrictedScreenLeft = overscanLeft;
3358 mUnrestrictedScreenTop = overscanTop;
3359 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3360 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3361 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3362 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003363 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3364 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003365 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003366 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003367 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003368 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003369 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003370 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003371 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003372 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003373 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003374 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003375
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003376 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3377 final Rect pf = mTmpParentFrame;
3378 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003379 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003380 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003381 final Rect dcf = mTmpDecorFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003382 final Rect osf = mTmpOutsetFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003383 pf.left = df.left = of.left = vf.left = mDockLeft;
3384 pf.top = df.top = of.top = vf.top = mDockTop;
3385 pf.right = df.right = of.right = vf.right = mDockRight;
3386 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003387 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003388
Craig Mautner69b08182012-09-05 13:07:13 -07003389 if (isDefaultDisplay) {
3390 // For purposes of putting out fake window up to steal focus, we will
3391 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003392 final int sysui = mLastSystemUiFlags;
3393 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003394 boolean navTranslucent = (sysui
3395 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003396 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3397 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3398 boolean navAllowedHidden = immersive || immersiveSticky;
3399 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003400 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3401 if (!isKeyguardShowing) {
3402 navTranslucent &= areTranslucentBarsAllowed();
3403 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003404
Craig Mautner69b08182012-09-05 13:07:13 -07003405 // When the navigation bar isn't visible, we put up a fake
3406 // input window to catch all touch events. This way we can
3407 // detect when the user presses anywhere to bring back the nav
3408 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003409 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003410 if (mInputConsumer != null) {
3411 mInputConsumer.dismiss();
3412 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003413 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003414 } else if (mInputConsumer == null) {
3415 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3416 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003417 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003418
Craig Mautner69b08182012-09-05 13:07:13 -07003419 // For purposes of positioning and showing the nav bar, if we have
3420 // decided that it can't be hidden (because of the screen aspect ratio),
3421 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003422 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003423
John Spurlockad3e6cb2013-04-30 08:47:43 -04003424 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003425 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003426 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003427 // Force the navigation bar to its appropriate place and
3428 // size. We need to do this directly, instead of relying on
3429 // it to bubble up from the nav bar, because this needs to
3430 // change atomically with screen rotations.
3431 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3432 if (mNavigationBarOnBottom) {
3433 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003434 int top = displayHeight - overscanBottom
3435 - mNavigationBarHeightForRotation[displayRotation];
3436 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003437 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003438 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003439 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003440 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003441 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003442 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003443 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3444 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003445 } else {
3446 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003447 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003448 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003449 if (navVisible && !navTranslucent && !navAllowedHidden
3450 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003451 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003452 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003453 // and not in the process of animating on or off, then
3454 // we can tell the app that it is covered by it.
3455 mSystemBottom = mTmpNavigationFrame.top;
3456 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003457 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003458 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003459 int left = displayWidth - overscanRight
3460 - mNavigationBarWidthForRotation[displayRotation];
3461 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003462 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003463 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003464 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003465 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003466 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003467 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003468 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3469 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003470 } else {
3471 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003472 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003473 }
John Spurlockbd957402013-10-03 11:38:39 -04003474 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3475 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003476 // If the nav bar is currently requested to be visible,
3477 // and not in the process of animating on or off, then
3478 // we can tell the app that it is covered by it.
3479 mSystemRight = mTmpNavigationFrame.left;
3480 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003481 }
Craig Mautner69b08182012-09-05 13:07:13 -07003482 // Make sure the content and current rectangles are updated to
3483 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003484 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3485 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3486 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3487 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003488 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3489 // And compute the final frame.
3490 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003491 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003492 mTmpNavigationFrame, mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003493 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003494 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003495 updateSysUiVisibility = true;
3496 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003497 }
Craig Mautnereda67292013-04-28 13:50:14 -07003498 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003499 mDockLeft, mDockTop, mDockRight, mDockBottom));
3500
3501 // decide where the status bar goes ahead of time
3502 if (mStatusBar != null) {
3503 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003504 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3505 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3506 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3507 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3508 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003509 vf.left = mStableLeft;
3510 vf.top = mStableTop;
3511 vf.right = mStableRight;
3512 vf.bottom = mStableBottom;
3513
3514 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3515
3516 // Let the status bar determine its size.
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003517 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3518 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3519 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
Craig Mautner69b08182012-09-05 13:07:13 -07003520
3521 // For layout, the status bar is always at the top with our fixed height.
3522 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3523
John Spurlocke1f366f2013-08-05 12:22:40 -04003524 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003525 boolean statusBarTranslucent = (sysui
3526 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003527 if (!isKeyguardShowing) {
3528 statusBarTranslucent &= areTranslucentBarsAllowed();
3529 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003530
Craig Mautner69b08182012-09-05 13:07:13 -07003531 // If the status bar is hidden, we don't want to cause
3532 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003533 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003534 // Status bar may go away, so the screen area it occupies
3535 // is available to apps but just covering them when the
3536 // status bar is visible.
3537 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3538
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003539 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3540 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3541 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3542 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003543
Craig Mautnereda67292013-04-28 13:50:14 -07003544 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003545 String.format(
3546 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3547 mDockLeft, mDockTop, mDockRight, mDockBottom,
3548 mContentLeft, mContentTop, mContentRight, mContentBottom,
3549 mCurLeft, mCurTop, mCurRight, mCurBottom));
3550 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003551 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003552 && !statusBarTransient && !statusBarTranslucent
3553 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003554 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003555 // and not in the process of animating on or off, then
3556 // we can tell the app that it is covered by it.
3557 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3558 }
John Spurlock27735a42013-08-14 17:57:38 -04003559 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003560 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003561 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003562 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003563 if (updateSysUiVisibility) {
3564 updateSystemUiVisibilityLw();
3565 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003566 }
3567 }
3568
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003569 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003570 @Override
John Spurlock46646232013-09-30 22:32:42 -04003571 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003572 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3573 return mStatusBar.getSurfaceLayer();
3574 }
3575
3576 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3577 return mNavigationBar.getSurfaceLayer();
3578 }
3579
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003580 return 0;
3581 }
3582
Craig Mautner967212c2013-04-13 21:10:58 -07003583 @Override
3584 public void getContentRectLw(Rect r) {
3585 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3586 }
3587
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003588 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3589 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003590 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3591 // Here's a special case: if this attached window is a panel that is
3592 // above the dock window, and the window it is attached to is below
3593 // the dock window, then the frames we computed for the window it is
3594 // attached to can not be used because the dock is effectively part
3595 // of the underlying window and the attached window is floating on top
3596 // of the whole thing. So, we ignore the attached window and explicitly
3597 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003598 df.left = of.left = cf.left = vf.left = mDockLeft;
3599 df.top = of.top = cf.top = vf.top = mDockTop;
3600 df.right = of.right = cf.right = vf.right = mDockRight;
3601 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003602 } else {
3603 // The effective display frame of the attached window depends on
3604 // whether it is taking care of insetting its content. If not,
3605 // we need to use the parent's content frame so that the entire
3606 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003607 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003608 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003609 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003610 // Set the content frame of the attached window to the parent's decor frame
3611 // (same as content frame when IME isn't present) if specifically requested by
3612 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3613 // Otherwise, use the overscan frame.
3614 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3615 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003616 } else {
3617 // If the window is resizing, then we want to base the content
3618 // frame on our attached content frame to resize... however,
3619 // things can be tricky if the attached window is NOT in resize
3620 // mode, in which case its content frame will be larger.
3621 // Ungh. So to deal with that, make sure the content frame
3622 // we end up using is not covering the IM dock.
3623 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003624 if (attached.isVoiceInteraction()) {
3625 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3626 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3627 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3628 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3629 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003630 if (cf.left < mContentLeft) cf.left = mContentLeft;
3631 if (cf.top < mContentTop) cf.top = mContentTop;
3632 if (cf.right > mContentRight) cf.right = mContentRight;
3633 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3634 }
3635 }
3636 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003637 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003638 vf.set(attached.getVisibleFrameLw());
3639 }
3640 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3641 // window should be positioned relative to its parent or the entire
3642 // screen.
3643 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3644 ? attached.getFrameLw() : df);
3645 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003646
3647 private void applyStableConstraints(int sysui, int fl, Rect r) {
3648 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3649 // If app is requesting a stable layout, don't let the
3650 // content insets go below the stable values.
3651 if ((fl & FLAG_FULLSCREEN) != 0) {
3652 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3653 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3654 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3655 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3656 } else {
3657 if (r.left < mStableLeft) r.left = mStableLeft;
3658 if (r.top < mStableTop) r.top = mStableTop;
3659 if (r.right > mStableRight) r.right = mStableRight;
3660 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3661 }
3662 }
3663 }
3664
Jorim Jaggiaa806142015-05-20 18:04:16 -07003665 private boolean canReceiveInput(WindowState win) {
3666 boolean notFocusable =
3667 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
3668 boolean altFocusableIm =
3669 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
3670 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
3671 return !notFocusableForIm;
3672 }
3673
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003674 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003675 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003676 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07003677 // We've already done the navigation bar and status bar. If the status bar can receive
3678 // input, we need to layout it again to accomodate for the IME window.
3679 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003680 return;
3681 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07003682 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07003683 final boolean isDefaultDisplay = win.isDefaultDisplay();
3684 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003685 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3686 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003687 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003688 offsetInputMethodWindowLw(mLastInputMethodWindow);
3689 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003690
John Spurlockc6d1c602014-01-17 15:22:06 -05003691 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003692 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003693 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003694
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003695 final Rect pf = mTmpParentFrame;
3696 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003697 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003698 final Rect cf = mTmpContentFrame;
3699 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003700 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003701 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003702 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04003703 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003704
3705 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003706 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003707
Craig Mautnerf683b562012-10-02 11:10:57 -07003708 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3709
Adrian Roosfa104232014-06-20 16:10:14 -07003710 if (isDefaultDisplay) {
3711 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3712 } else {
3713 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3714 }
3715
Craig Mautner69b08182012-09-05 13:07:13 -07003716 if (!isDefaultDisplay) {
3717 if (attached != null) {
3718 // If this window is attached to another, our display
3719 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003720 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003721 } else {
3722 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003723 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3724 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3725 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003726 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003727 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003728 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003729 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003730 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003731 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3732 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3733 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003734 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003735 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003736 // ...with content insets above the nav bar
3737 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003738 // IM dock windows always go to the bottom of the screen.
3739 attrs.gravity = Gravity.BOTTOM;
3740 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003741 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003742 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003743 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003744 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3745 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003746 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003747 // Note: In Phone landscape mode, the button bar should also be excluded.
3748 cf.right = vf.right = mStableRight;
3749 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003750 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07003751 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02003752 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3753 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3754 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3755 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3756 cf.left = vf.left = mStableLeft;
3757 cf.top = vf.top = mStableTop;
3758 cf.right = vf.right = mStableRight;
3759 vf.bottom = mStableBottom;
3760 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003761 } else {
John Spurlock46646232013-09-30 22:32:42 -04003762
3763 // Default policy decor for the default display
3764 dcf.left = mSystemLeft;
3765 dcf.top = mSystemTop;
3766 dcf.right = mSystemRight;
3767 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003768 final boolean inheritTranslucentDecor = (attrs.privateFlags
3769 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003770 final boolean isAppWindow =
3771 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3772 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3773 final boolean topAtRest =
3774 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3775 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003776 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3777 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003778 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3779 && (fl & WindowManager.LayoutParams.
3780 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003781 // Ensure policy decor includes status bar
3782 dcf.top = mStableTop;
3783 }
John Spurlockbd957402013-10-03 11:38:39 -04003784 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003785 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3786 && (fl & WindowManager.LayoutParams.
3787 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003788 // Ensure policy decor includes navigation bar
3789 dcf.bottom = mStableBottom;
3790 dcf.right = mStableRight;
3791 }
3792 }
3793
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003794 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3795 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003796 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003797 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003798 // This is the case for a normal activity window: we want it
3799 // to cover all of the screen space, and it can take care of
3800 // moving its contents to account for screen decorations that
3801 // intrude into that space.
3802 if (attached != null) {
3803 // If this window is attached to another, our display
3804 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003805 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003806 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003807 if (attrs.type == TYPE_STATUS_BAR_PANEL
3808 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003809 // Status bar panels are the only windows who can go on top of
3810 // the status bar. They are protected by the STATUS_BAR_SERVICE
3811 // permission, so they have the same privileges as the status
3812 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003813 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003814 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003815
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003816 pf.left = df.left = of.left = hasNavBar
3817 ? mDockLeft : mUnrestrictedScreenLeft;
3818 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3819 pf.right = df.right = of.right = hasNavBar
3820 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3821 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3822 pf.bottom = df.bottom = of.bottom = hasNavBar
3823 ? mRestrictedScreenTop+mRestrictedScreenHeight
3824 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003825
Craig Mautnereda67292013-04-28 13:50:14 -07003826 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003827 "Laying out status bar window: (%d,%d - %d,%d)",
3828 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003829 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003830 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3831 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3832 // Asking to layout into the overscan region, so give it that pure
3833 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003834 pf.left = df.left = of.left = mOverscanScreenLeft;
3835 pf.top = df.top = of.top = mOverscanScreenTop;
3836 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3837 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3838 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003839 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003840 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003841 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3842 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003843 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003844 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003845 // only do this for application windows to ensure no window that
3846 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003847 pf.left = df.left = mOverscanScreenLeft;
3848 pf.top = df.top = mOverscanScreenTop;
3849 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3850 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003851 // We need to tell the app about where the frame inside the overscan
3852 // is, so it can inset its content by that amount -- it didn't ask
3853 // to actually extend itself into the overscan region.
3854 of.left = mUnrestrictedScreenLeft;
3855 of.top = mUnrestrictedScreenTop;
3856 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3857 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003858 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003859 pf.left = df.left = mRestrictedOverscanScreenLeft;
3860 pf.top = df.top = mRestrictedOverscanScreenTop;
3861 pf.right = df.right = mRestrictedOverscanScreenLeft
3862 + mRestrictedOverscanScreenWidth;
3863 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3864 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003865 // We need to tell the app about where the frame inside the overscan
3866 // is, so it can inset its content by that amount -- it didn't ask
3867 // to actually extend itself into the overscan region.
3868 of.left = mUnrestrictedScreenLeft;
3869 of.top = mUnrestrictedScreenTop;
3870 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3871 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003872 }
Craig Mautner69b08182012-09-05 13:07:13 -07003873
John Spurlock46646232013-09-30 22:32:42 -04003874 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003875 if (win.isVoiceInteraction()) {
3876 cf.left = mVoiceContentLeft;
3877 cf.top = mVoiceContentTop;
3878 cf.right = mVoiceContentRight;
3879 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003880 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003881 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3882 cf.left = mDockLeft;
3883 cf.top = mDockTop;
3884 cf.right = mDockRight;
3885 cf.bottom = mDockBottom;
3886 } else {
3887 cf.left = mContentLeft;
3888 cf.top = mContentTop;
3889 cf.right = mContentRight;
3890 cf.bottom = mContentBottom;
3891 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003892 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003893 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003894 // Full screen windows are always given a layout that is as if the
3895 // status bar and other transient decors are gone. This is to avoid
3896 // bad states when moving from a window that is not hding the
3897 // status bar to one that is.
3898 cf.left = mRestrictedScreenLeft;
3899 cf.top = mRestrictedScreenTop;
3900 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3901 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003902 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003903 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003904 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3905 vf.left = mCurLeft;
3906 vf.top = mCurTop;
3907 vf.right = mCurRight;
3908 vf.bottom = mCurBottom;
3909 } else {
3910 vf.set(cf);
3911 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003912 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003913 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3914 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3915 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003916 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3917 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003918 // A window that has requested to fill the entire screen just
3919 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003920 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04003921 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
3922 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003923 pf.left = df.left = of.left = cf.left = hasNavBar
3924 ? mDockLeft : mUnrestrictedScreenLeft;
3925 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3926 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003927 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003928 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003929 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003930 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003931 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003932 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003933 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3934 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003935 } else if (attrs.type == TYPE_NAVIGATION_BAR
3936 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003937 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003938 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3939 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3940 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3941 + mUnrestrictedScreenWidth;
3942 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3943 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003944 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003945 "Laying out navigation bar window: (%d,%d - %d,%d)",
3946 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003947 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3948 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003949 && ((fl & FLAG_FULLSCREEN) != 0)) {
3950 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003951 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3952 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3953 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3954 + mOverscanScreenWidth;
3955 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3956 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003957 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003958 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003959 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3960 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3961 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3962 + mOverscanScreenWidth;
3963 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3964 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003965 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003966 // The wallpaper also has Real Ultimate Power, but we want to tell
3967 // it about the overscan area.
3968 pf.left = df.left = mOverscanScreenLeft;
3969 pf.top = df.top = mOverscanScreenTop;
3970 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3971 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3972 of.left = cf.left = mUnrestrictedScreenLeft;
3973 of.top = cf.top = mUnrestrictedScreenTop;
3974 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3975 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003976 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003977 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3978 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3979 // Asking to layout into the overscan region, so give it that pure
3980 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003981 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3982 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3983 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003984 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003985 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003986 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003987 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003988 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003989 && (attrs.type == TYPE_STATUS_BAR
3990 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07003991 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04003992 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3993 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003994 // Asking for layout as if the nav bar is hidden, lets the
3995 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003996 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003997 // can be above the nav bar can do this.
3998 // XXX This assumes that an app asking for this will also
3999 // ask for layout in only content. We can't currently figure out
4000 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004001 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4002 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4003 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4004 + mUnrestrictedScreenWidth;
4005 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4006 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004007 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004008 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4009 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4010 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4011 + mRestrictedScreenWidth;
4012 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4013 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004014 }
Craig Mautner69b08182012-09-05 13:07:13 -07004015
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004016 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004017
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004018 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4019 vf.left = mCurLeft;
4020 vf.top = mCurTop;
4021 vf.right = mCurRight;
4022 vf.bottom = mCurBottom;
4023 } else {
4024 vf.set(cf);
4025 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004026 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004027 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4028 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004029 // A child window should be placed inside of the same visible
4030 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004031 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004032 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004033 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4034 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004035 // Otherwise, a normal window must be placed inside the content
4036 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004037 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4038 // Status bar panels and the volume dialog are the only windows who can go on
4039 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004040 // permission, so they have the same privileges as the status
4041 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004042 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4043 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4044 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4045 + mRestrictedScreenWidth;
4046 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4047 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004048 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004049 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004050 pf.left = df.left = of.left = cf.left = mStableLeft;
4051 pf.top = df.top = of.top = cf.top = mStableTop;
4052 pf.right = df.right = of.right = cf.right = mStableRight;
4053 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004054 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004055 pf.left = mContentLeft;
4056 pf.top = mContentTop;
4057 pf.right = mContentRight;
4058 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004059 if (win.isVoiceInteraction()) {
4060 df.left = of.left = cf.left = mVoiceContentLeft;
4061 df.top = of.top = cf.top = mVoiceContentTop;
4062 df.right = of.right = cf.right = mVoiceContentRight;
4063 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4064 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004065 df.left = of.left = cf.left = mDockLeft;
4066 df.top = of.top = cf.top = mDockTop;
4067 df.right = of.right = cf.right = mDockRight;
4068 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004069 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004070 df.left = of.left = cf.left = mContentLeft;
4071 df.top = of.top = cf.top = mContentTop;
4072 df.right = of.right = cf.right = mContentRight;
4073 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004074 }
4075 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4076 vf.left = mCurLeft;
4077 vf.top = mCurTop;
4078 vf.right = mCurRight;
4079 vf.bottom = mCurBottom;
4080 } else {
4081 vf.set(cf);
4082 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004083 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004084 }
4085 }
Craig Mautner69b08182012-09-05 13:07:13 -07004086
Craig Mautnerb816bed2013-07-23 10:26:17 -07004087 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4088 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004089 df.left = df.top = -10000;
4090 df.right = df.bottom = 10000;
4091 if (attrs.type != TYPE_WALLPAPER) {
4092 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4093 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4094 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004095 }
4096
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004097 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4098 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004099 // We only want to apply outsets to certain types of windows. For example, we never want to
4100 // apply the outsets to floating dialogs, because they wouldn't make sense there.
4101 final boolean useOutsets = attrs.type == TYPE_WALLPAPER
4102 || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
4103 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
4104 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004105 osf = mTmpOutsetFrame;
4106 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4107 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4108 if (outset > 0) {
4109 int rotation = Surface.ROTATION_0;
4110 try {
4111 rotation = mWindowManager.getRotation();
4112 } catch (RemoteException e) {
4113 }
4114 if (rotation == Surface.ROTATION_0) {
4115 osf.bottom += outset;
4116 } else if (rotation == Surface.ROTATION_90) {
4117 osf.right += outset;
4118 } else if (rotation == Surface.ROTATION_180) {
4119 osf.top -= outset;
4120 } else if (rotation == Surface.ROTATION_270) {
4121 osf.left -= outset;
4122 }
4123 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4124 + " with rotation " + rotation + ", result: " + osf);
4125 }
4126 }
4127
Craig Mautnereda67292013-04-28 13:50:14 -07004128 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004129 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004130 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004131 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004132 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004133 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004134 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004135 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004136 + " sf=" + sf.toShortString()
4137 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004138
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004139 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004140
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004141 // Dock windows carve out the bottom of the screen, so normal windows
4142 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004143 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4144 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004145 setLastInputMethodWindowLw(null, null);
4146 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004147 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004148 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4149 && !win.getGivenInsetsPendingLw()) {
4150 offsetVoiceInputWindowLw(win);
4151 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004152 }
4153
satok1bc0a492012-04-25 22:47:12 +09004154 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004155 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004156 top += win.getGivenContentInsetsLw().top;
4157 if (mContentBottom > top) {
4158 mContentBottom = top;
4159 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004160 if (mVoiceContentBottom > top) {
4161 mVoiceContentBottom = top;
4162 }
satok1bc0a492012-04-25 22:47:12 +09004163 top = win.getVisibleFrameLw().top;
4164 top += win.getGivenVisibleInsetsLw().top;
4165 if (mCurBottom > top) {
4166 mCurBottom = top;
4167 }
Craig Mautnereda67292013-04-28 13:50:14 -07004168 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004169 + mDockBottom + " mContentBottom="
4170 + mContentBottom + " mCurBottom=" + mCurBottom);
4171 }
4172
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004173 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004174 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004175 top += win.getGivenContentInsetsLw().top;
4176 if (mVoiceContentBottom > top) {
4177 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004178 }
4179 }
4180
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004181 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004182 @Override
4183 public void finishLayoutLw() {
4184 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004185 }
4186
4187 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004188 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004189 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004190 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004191 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004192 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004193 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004194 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004195 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004196 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004197 mForcingShowNavBar = false;
4198 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004199
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004200 mHideLockScreen = false;
4201 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004202 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004203 mShowingLockscreen = false;
4204 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004205 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004206 mKeyguardSecure = isKeyguardSecure();
4207 mKeyguardSecureIncludingHidden = mKeyguardSecure
4208 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004209 }
4210
4211 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004212 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004213 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004214 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4215 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004216 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004217 if (mTopFullscreenOpaqueWindowState == null
4218 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4219 mForcingShowNavBar = true;
4220 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004221 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004222 if (attrs.type == TYPE_STATUS_BAR) {
4223 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4224 mForceStatusBarFromKeyguard = true;
4225 }
4226 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4227 mForceStatusBarTransparent = true;
4228 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004229 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004230
4231 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4232 && attrs.type < FIRST_SYSTEM_WINDOW;
4233 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4234 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4235
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004236 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004237 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004238 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004239 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004240 mForceStatusBarFromKeyguard = true;
4241 } else {
4242 mForceStatusBar = true;
4243 }
4244 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004245 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004246 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004247 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004248 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004249 // If the lockscreen was showing when the dream started then wait
4250 // for the dream to draw before hiding the lockscreen.
4251 if (!mDreamingLockscreen
4252 || (win.isVisibleLw() && win.hasDrawnLw())) {
4253 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004254 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004255 }
4256 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004257
Craig Mautnerab55e522014-03-03 13:26:03 -08004258 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004259 final IApplicationToken appToken = win.getAppToken();
4260 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004261 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004262 mAppsToBeHidden.remove(appToken);
4263 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004264 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004265 if (dismissKeyguard && !mKeyguardSecure) {
4266 mAppsThatDismissKeyguard.add(appToken);
4267 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004268 mWinShowWhenLocked = win;
4269 mHideLockScreen = true;
4270 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004271 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004272 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004273 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004274 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004275 mAppsToBeHidden.add(appToken);
4276 } else {
4277 mAppsToBeHidden.remove(appToken);
4278 }
4279 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004280 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004281 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004282 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004283 if (attrs.x == 0 && attrs.y == 0
4284 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4285 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4286 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4287 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004288 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4289 mTopFullscreenOpaqueOrDimmingWindowState = win;
4290 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004291 if (!mAppsThatDismissKeyguard.isEmpty() &&
4292 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4293 if (DEBUG_LAYOUT) Slog.v(TAG,
4294 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004295 mDismissKeyguard = (mWinDismissingKeyguard == win
4296 && mSecureDismissingKeyguard == mKeyguardSecure)
4297 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004298 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004299 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004300 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004301 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4302 if (DEBUG_LAYOUT) Slog.v(TAG,
4303 "Setting mHideLockScreen to true by win " + win);
4304 mHideLockScreen = true;
4305 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004306 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004307 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004308 mAllowLockscreenWhenOn = true;
4309 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004310 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004311
4312 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004313 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4314 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004315 win.hideLw(false);
4316 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004317 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004318 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4319 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4320 // that is being hidden in an animation - keep the
4321 // keyguard hidden until the new window shows up and
4322 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004323 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004324 mHideLockScreen = true;
4325 mWinShowWhenLocked = win;
4326 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004327 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004328 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4329 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4330 && win.isDimming()) {
4331 mTopFullscreenOpaqueOrDimmingWindowState = win;
4332 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004333 }
4334
4335 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004336 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004337 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004338 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4339 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4340 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004341 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4342 // fullscreen window.
4343 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4344 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4345 mTopFullscreenOpaqueWindowState.hideLw(false);
4346 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4347 }
4348
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004349 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004350 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004351
4352 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4353 ? mTopFullscreenOpaqueWindowState.getAttrs()
4354 : null;
4355
Jeff Brownc8018eb2012-10-29 21:33:27 -07004356 // If we are not currently showing a dream then remember the current
4357 // lockscreen state. We will use this to determine whether the dream
4358 // started while the lockscreen was showing and remember this state
4359 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004360 if (!mShowingDream) {
4361 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004362 if (mDreamingSleepTokenNeeded) {
4363 mDreamingSleepTokenNeeded = false;
4364 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4365 }
4366 } else {
4367 if (!mDreamingSleepTokenNeeded) {
4368 mDreamingSleepTokenNeeded = true;
4369 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4370 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004371 }
4372
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004373 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004374 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004375 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004376 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004377 boolean shouldBeTransparent = mForceStatusBarTransparent
4378 && !mForceStatusBar
4379 && !mForceStatusBarFromKeyguard;
4380 if (!shouldBeTransparent) {
4381 mStatusBarController.setShowTransparent(false /* transparent */);
4382 } else if (!mStatusBar.isVisibleLw()) {
4383 mStatusBarController.setShowTransparent(true /* transparent */);
4384 }
4385 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004386 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004387 if (mStatusBarController.setBarShowingLw(true)) {
4388 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4389 }
Craig Mautner81defc72013-10-29 11:10:42 -07004390 // Maintain fullscreen layout until incoming animation is complete.
4391 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004392 // Transient status bar on the lockscreen is not allowed
4393 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4394 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4395 mLastSystemUiFlags, mLastSystemUiFlags);
4396 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004397 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004398 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004399 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004400 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004401 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004402 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004403 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004404 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004405 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004406 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004407 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004408 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004409 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4410 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004411 if (mStatusBarController.isTransientShowing()) {
4412 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004413 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4414 }
4415 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004416 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004417 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004418 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004419 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004420 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004421 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004422 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004423 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004424 if (mStatusBarController.setBarShowingLw(true)) {
4425 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4426 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004427 }
4428 }
4429 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004430
Craig Mautner81defc72013-10-29 11:10:42 -07004431 if (mTopIsFullscreen != topIsFullscreen) {
4432 if (!topIsFullscreen) {
4433 // Force another layout when status bar becomes fully shown.
4434 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4435 }
4436 mTopIsFullscreen = topIsFullscreen;
4437 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004438
Craig Mautner39834192012-09-02 07:47:24 -07004439 // Hide the key guard if a visible window explicitly specifies that it wants to be
4440 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004441 if (mKeyguardDelegate != null && mStatusBar != null) {
4442 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4443 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004444 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004445 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004446 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004447 changes |= FINISH_LAYOUT_REDO_LAYOUT
4448 | FINISH_LAYOUT_REDO_CONFIG
4449 | FINISH_LAYOUT_REDO_WALLPAPER;
4450 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004451 if (mKeyguardDelegate.isShowing()) {
4452 mHandler.post(new Runnable() {
4453 @Override
4454 public void run() {
4455 mKeyguardDelegate.keyguardDone(false, false);
4456 }
4457 });
4458 }
4459 } else if (mHideLockScreen) {
4460 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004461 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004462 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004463 changes |= FINISH_LAYOUT_REDO_LAYOUT
4464 | FINISH_LAYOUT_REDO_CONFIG
4465 | FINISH_LAYOUT_REDO_WALLPAPER;
4466 }
4467 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004468 mKeyguardHidden = false;
4469 if (setKeyguardOccludedLw(false)) {
4470 changes |= FINISH_LAYOUT_REDO_LAYOUT
4471 | FINISH_LAYOUT_REDO_CONFIG
4472 | FINISH_LAYOUT_REDO_WALLPAPER;
4473 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004474 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4475 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004476 mHandler.post(new Runnable() {
4477 @Override
4478 public void run() {
4479 mKeyguardDelegate.dismiss();
4480 }
4481 });
4482 }
4483 } else {
4484 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004485 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004486 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004487 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004488 changes |= FINISH_LAYOUT_REDO_LAYOUT
4489 | FINISH_LAYOUT_REDO_CONFIG
4490 | FINISH_LAYOUT_REDO_WALLPAPER;
4491 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004492 }
4493 }
Joe Onorato664644d2011-01-23 17:53:23 -08004494
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004495 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004496 // If the navigation bar has been hidden or shown, we need to do another
4497 // layout pass to update that window.
4498 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4499 }
Joe Onorato664644d2011-01-23 17:53:23 -08004500
Mike Lockwood28569302010-01-28 11:54:40 -05004501 // update since mAllowLockscreenWhenOn might have changed
4502 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004503 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004504 }
4505
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004506 /**
Jim Millerab954542014-10-10 18:21:49 -07004507 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004508 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004509 * @return Whether the flags have changed and we have to redo the layout.
4510 */
Jim Millerab954542014-10-10 18:21:49 -07004511 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4512 boolean wasOccluded = mKeyguardOccluded;
4513 boolean showing = mKeyguardDelegate.isShowing();
4514 if (wasOccluded && !isOccluded && showing) {
4515 mKeyguardOccluded = false;
4516 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004517 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4518 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4519 return true;
Jim Millerab954542014-10-10 18:21:49 -07004520 } else if (!wasOccluded && isOccluded && showing) {
4521 mKeyguardOccluded = true;
4522 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004523 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4524 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4525 return true;
4526 } else {
4527 return false;
4528 }
4529 }
4530
4531 private boolean isStatusBarKeyguard() {
4532 return mStatusBar != null
4533 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4534 }
4535
Jose Lima9546b202014-07-02 17:21:51 -07004536 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004537 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004538 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004539 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004540 return false;
4541 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004542 return true;
4543 }
4544
Jose Lima9546b202014-07-02 17:21:51 -07004545 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004546 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004547 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004548 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004549 // If the navigation bar has been hidden or shown, we need to do another
4550 // layout pass to update that window.
4551 return FINISH_LAYOUT_REDO_LAYOUT;
4552 }
4553 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004554 }
4555
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004556 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004557 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004558 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4559 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004560 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4561 if (newLidState == mLidState) {
4562 return;
4563 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004564
Jeff Brownc458ce92012-04-30 14:58:40 -07004565 mLidState = newLidState;
4566 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004567 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004568
4569 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004570 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004571 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004572 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004573 }
4574 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004575
Michael Wright3818c922014-09-02 13:59:07 -07004576 @Override
4577 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4578 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4579 if (mCameraLensCoverState == lensCoverState) {
4580 return;
4581 }
4582 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4583 lensCoverState == CAMERA_LENS_UNCOVERED) {
4584 Intent intent;
4585 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4586 mKeyguardDelegate.isShowing();
4587 if (keyguardActive) {
4588 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4589 } else {
4590 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4591 }
Bryce Lee584a4452014-10-21 15:55:55 -07004592 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004593 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004594 }
4595 mCameraLensCoverState = lensCoverState;
4596 }
4597
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004598 void setHdmiPlugged(boolean plugged) {
4599 if (mHdmiPlugged != plugged) {
4600 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004601 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004602 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004603 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004604 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004605 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004606 }
4607 }
4608
Joe Onoratoea495d42011-04-06 11:41:11 -07004609 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004610 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004611 // watch for HDMI plug messages if the hdmi switch exists
4612 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4613 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4614
Joe Onoratoea495d42011-04-06 11:41:11 -07004615 final String filename = "/sys/class/switch/hdmi/state";
4616 FileReader reader = null;
4617 try {
4618 reader = new FileReader(filename);
4619 char[] buf = new char[15];
4620 int n = reader.read(buf);
4621 if (n > 1) {
4622 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4623 }
4624 } catch (IOException ex) {
4625 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4626 } catch (NumberFormatException ex) {
4627 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4628 } finally {
4629 if (reader != null) {
4630 try {
4631 reader.close();
4632 } catch (IOException ex) {
4633 }
Joe Onoratodc100302011-01-11 17:07:41 -08004634 }
4635 }
4636 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004637 // This dance forces the code in setHdmiPlugged to run.
4638 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4639 mHdmiPlugged = !plugged;
4640 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004641 }
4642
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004643 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004644 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004645
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004646 final Runnable mScreenshotTimeout = new Runnable() {
4647 @Override public void run() {
4648 synchronized (mScreenshotLock) {
4649 if (mScreenshotConnection != null) {
4650 mContext.unbindService(mScreenshotConnection);
4651 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004652 }
Winson Chung9112ec32011-06-27 13:15:32 -07004653 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004654 }
4655 };
4656
4657 // Assume this is called from the Handler thread.
4658 private void takeScreenshot() {
4659 synchronized (mScreenshotLock) {
4660 if (mScreenshotConnection != null) {
4661 return;
4662 }
4663 ComponentName cn = new ComponentName("com.android.systemui",
4664 "com.android.systemui.screenshot.TakeScreenshotService");
4665 Intent intent = new Intent();
4666 intent.setComponent(cn);
4667 ServiceConnection conn = new ServiceConnection() {
4668 @Override
4669 public void onServiceConnected(ComponentName name, IBinder service) {
4670 synchronized (mScreenshotLock) {
4671 if (mScreenshotConnection != this) {
4672 return;
4673 }
4674 Messenger messenger = new Messenger(service);
4675 Message msg = Message.obtain(null, 1);
4676 final ServiceConnection myConn = this;
4677 Handler h = new Handler(mHandler.getLooper()) {
4678 @Override
4679 public void handleMessage(Message msg) {
4680 synchronized (mScreenshotLock) {
4681 if (mScreenshotConnection == myConn) {
4682 mContext.unbindService(mScreenshotConnection);
4683 mScreenshotConnection = null;
4684 mHandler.removeCallbacks(mScreenshotTimeout);
4685 }
4686 }
4687 }
4688 };
4689 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004690 msg.arg1 = msg.arg2 = 0;
4691 if (mStatusBar != null && mStatusBar.isVisibleLw())
4692 msg.arg1 = 1;
4693 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4694 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004695 try {
4696 messenger.send(msg);
4697 } catch (RemoteException e) {
4698 }
4699 }
4700 }
4701 @Override
4702 public void onServiceDisconnected(ComponentName name) {}
4703 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004704 if (mContext.bindServiceAsUser(
4705 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004706 mScreenshotConnection = conn;
4707 mHandler.postDelayed(mScreenshotTimeout, 10000);
4708 }
4709 }
Winson Chung9112ec32011-06-27 13:15:32 -07004710 }
4711
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004712 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004713 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004714 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004715 if (!mSystemBooted) {
4716 // If we have not yet booted, don't let key events do anything.
4717 return 0;
4718 }
4719
Jeff Brown037c33e2014-04-09 00:31:55 -07004720 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004721 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4722 final boolean canceled = event.isCanceled();
4723 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004724
Jeff Brown3122e442010-10-11 23:32:49 -07004725 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004726
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004727 // If screen is off then we treat the case where the keyguard is open but hidden
4728 // the same as if it were open and in front.
4729 // This will prevent any keys other than the power button from waking the screen
4730 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004731 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004732 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004733 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004734 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004735
Jeff Brown40013652012-05-16 21:22:36 -07004736 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004737 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004738 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004739 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004740 }
4741
Jeff Brown037c33e2014-04-09 00:31:55 -07004742 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004743 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004744 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4745 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004746 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004747 // When the device is interactive or the key is injected pass the
4748 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004749 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004750 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004751 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4752 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4753 // to the application but preserve its wake key status to make sure we still move
4754 // from dozing to fully interactive if we would normally go from off to fully
4755 // interactive.
4756 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004757 } else {
4758 // When the screen is off and the key is not injected, determine whether
4759 // to wake the device but don't pass the key to the application.
4760 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004761 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4762 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004763 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004764 }
4765
Justin Kohd378ad72013-04-01 12:18:26 -07004766 // If the key would be handled globally, just return the result, don't worry about special
4767 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004768 if (isValidGlobalKey(keyCode)
4769 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004770 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004771 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004772 }
Justin Kohd378ad72013-04-01 12:18:26 -07004773 return result;
4774 }
4775
Jeff Brownbae8e772014-06-12 19:59:45 -07004776 boolean useHapticFeedback = down
4777 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4778 && event.getRepeatCount() == 0;
4779
Jeff Brown4d396052010-10-29 21:50:21 -07004780 // Handle special keys.
4781 switch (keyCode) {
4782 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004783 case KeyEvent.KEYCODE_VOLUME_UP:
4784 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004785 if (mUseTvRouting) {
4786 // On TVs volume keys never go to the foreground app
4787 result &= ~ACTION_PASS_TO_USER;
4788 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004789 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4790 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004791 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004792 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004793 mScreenshotChordVolumeDownKeyTriggered = true;
4794 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4795 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004796 cancelPendingPowerKeyAction();
4797 interceptScreenshotChord();
4798 }
4799 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004800 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004801 cancelPendingScreenshotChordAction();
4802 }
4803 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4804 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004805 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004806 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004807 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004808 cancelPendingPowerKeyAction();
4809 cancelPendingScreenshotChordAction();
4810 }
4811 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004812 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004813 cancelPendingScreenshotChordAction();
4814 }
4815 }
Jeff Brown4d396052010-10-29 21:50:21 -07004816 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004817 TelecomManager telecomManager = getTelecommService();
4818 if (telecomManager != null) {
4819 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004820 // If an incoming call is ringing, either VOLUME key means
4821 // "silence ringer". We handle these keys here, rather than
4822 // in the InCallScreen, to make sure we'll respond to them
4823 // even if the InCallScreen hasn't come to the foreground yet.
4824 // Look for the DOWN event here, to agree with the "fallback"
4825 // behavior in the InCallScreen.
4826 Log.i(TAG, "interceptKeyBeforeQueueing:"
4827 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004828
Santos Cordon6848f722014-05-21 15:22:12 -07004829 // Silence the ringer. (It's safe to call this
4830 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004831 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004832
Santos Cordon6848f722014-05-21 15:22:12 -07004833 // And *don't* pass this key thru to the current activity
4834 // (which is probably the InCallScreen.)
4835 result &= ~ACTION_PASS_TO_USER;
4836 break;
4837 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004838 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004839 && (result & ACTION_PASS_TO_USER) == 0) {
4840 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004841 // the application, just pass it to the session service.
4842
4843 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004844 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004845 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004846 }
4847 }
4848
RoboErik430fc482014-06-12 15:49:20 -07004849 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004850 if (mUseTvRouting) {
4851 dispatchDirectAudioEvent(event);
4852 } else {
4853 // If we aren't passing to the user and no one else
4854 // handled it send it to the session manager to
4855 // figure out.
4856 MediaSessionLegacyHelper.getHelper(mContext)
4857 .sendVolumeKeyEvent(event, true);
4858 }
Jeff Brown4d396052010-10-29 21:50:21 -07004859 break;
4860 }
4861 }
4862 break;
4863 }
4864
4865 case KeyEvent.KEYCODE_ENDCALL: {
4866 result &= ~ACTION_PASS_TO_USER;
4867 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004868 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004869 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004870 if (telecomManager != null) {
4871 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004872 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004873 if (interactive && !hungUp) {
4874 mEndCallKeyHandled = false;
4875 mHandler.postDelayed(mEndCallLongPress,
4876 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4877 } else {
4878 mEndCallKeyHandled = true;
4879 }
Jeff Brown4d396052010-10-29 21:50:21 -07004880 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004881 if (!mEndCallKeyHandled) {
4882 mHandler.removeCallbacks(mEndCallLongPress);
4883 if (!canceled) {
4884 if ((mEndcallBehavior
4885 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4886 if (goHome()) {
4887 break;
4888 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004889 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004890 if ((mEndcallBehavior
4891 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4892 mPowerManager.goToSleep(event.getEventTime(),
4893 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4894 isWakeKey = false;
4895 }
Jeff Brown4d396052010-10-29 21:50:21 -07004896 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004897 }
Jeff Brown4d396052010-10-29 21:50:21 -07004898 }
4899 break;
4900 }
4901
4902 case KeyEvent.KEYCODE_POWER: {
4903 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004904 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004905 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004906 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004907 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004908 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004909 }
4910 break;
4911 }
4912
Jeff Brown6212a492014-03-07 13:58:47 -08004913 case KeyEvent.KEYCODE_SLEEP: {
4914 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004915 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004916 if (!mPowerManager.isInteractive()) {
4917 useHapticFeedback = false; // suppress feedback if already non-interactive
4918 }
Nick Vaccarob593a812015-05-15 11:23:05 -07004919 if (down) {
4920 sleepPress(event.getEventTime());
4921 } else {
4922 sleepRelease(event.getEventTime());
4923 }
Jeff Brown6212a492014-03-07 13:58:47 -08004924 break;
4925 }
4926
4927 case KeyEvent.KEYCODE_WAKEUP: {
4928 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004929 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004930 break;
4931 }
4932
Jeff Brown4d396052010-10-29 21:50:21 -07004933 case KeyEvent.KEYCODE_MEDIA_PLAY:
4934 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4935 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004936 case KeyEvent.KEYCODE_HEADSETHOOK:
4937 case KeyEvent.KEYCODE_MUTE:
4938 case KeyEvent.KEYCODE_MEDIA_STOP:
4939 case KeyEvent.KEYCODE_MEDIA_NEXT:
4940 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4941 case KeyEvent.KEYCODE_MEDIA_REWIND:
4942 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004943 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4944 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004945 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4946 // If the global session is active pass all media keys to it
4947 // instead of the active window.
4948 result &= ~ACTION_PASS_TO_USER;
4949 }
Jeff Brown4d396052010-10-29 21:50:21 -07004950 if ((result & ACTION_PASS_TO_USER) == 0) {
4951 // Only do this if we would otherwise not pass it to the user. In that
4952 // case, the PhoneWindow class will do the same thing, except it will
4953 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004954 // Note that we need to make a copy of the key event here because the
4955 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004956 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004957 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4958 new KeyEvent(event));
4959 msg.setAsynchronous(true);
4960 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004961 }
4962 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004963 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004964
Jeff Brown4d396052010-10-29 21:50:21 -07004965 case KeyEvent.KEYCODE_CALL: {
4966 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004967 TelecomManager telecomManager = getTelecommService();
4968 if (telecomManager != null) {
4969 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004970 Log.i(TAG, "interceptKeyBeforeQueueing:"
4971 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004972 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004973
Santos Cordon6848f722014-05-21 15:22:12 -07004974 // And *don't* pass this key thru to the current activity
4975 // (which is presumably the InCallScreen.)
4976 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004977 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004978 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004979 }
Jeff Brown4d396052010-10-29 21:50:21 -07004980 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004981 }
Michael Wright869a67c2014-08-26 19:33:06 -07004982 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4983 // Only do this if we would otherwise not pass it to the user. In that case,
4984 // interceptKeyBeforeDispatching would apply a similar but different policy in
4985 // order to invoke voice assist actions. Note that we need to make a copy of the
4986 // key event here because the original key event will be recycled when we return.
4987 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4988 mBroadcastWakeLock.acquire();
4989 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4990 keyguardActive ? 1 : 0, 0);
4991 msg.setAsynchronous(true);
4992 msg.sendToTarget();
4993 }
4994 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004995 }
Jeff Brown26875502014-01-30 21:47:47 -08004996
Jeff Brownbae8e772014-06-12 19:59:45 -07004997 if (useHapticFeedback) {
4998 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4999 }
5000
Jeff Brown26875502014-01-30 21:47:47 -08005001 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005002 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08005003 }
Bryce Lee584a4452014-10-21 15:55:55 -07005004
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005005 return result;
5006 }
5007
Jeff Brown1c2e4942012-11-06 16:32:01 -08005008 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005009 * Returns true if the key can have global actions attached to it.
5010 * We reserve all power management keys for the system since they require
5011 * very careful handling.
5012 */
5013 private static boolean isValidGlobalKey(int keyCode) {
5014 switch (keyCode) {
5015 case KeyEvent.KEYCODE_POWER:
5016 case KeyEvent.KEYCODE_WAKEUP:
5017 case KeyEvent.KEYCODE_SLEEP:
5018 return false;
5019 default:
5020 return true;
5021 }
5022 }
5023
5024 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005025 * When the screen is off we ignore some keys that might otherwise typically
5026 * be considered wake keys. We filter them out here.
5027 *
5028 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5029 * is always considered a wake key.
5030 */
5031 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5032 switch (keyCode) {
5033 // ignore volume keys unless docked
5034 case KeyEvent.KEYCODE_VOLUME_UP:
5035 case KeyEvent.KEYCODE_VOLUME_DOWN:
5036 case KeyEvent.KEYCODE_VOLUME_MUTE:
5037 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5038
5039 // ignore media and camera keys
5040 case KeyEvent.KEYCODE_MUTE:
5041 case KeyEvent.KEYCODE_HEADSETHOOK:
5042 case KeyEvent.KEYCODE_MEDIA_PLAY:
5043 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5044 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5045 case KeyEvent.KEYCODE_MEDIA_STOP:
5046 case KeyEvent.KEYCODE_MEDIA_NEXT:
5047 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5048 case KeyEvent.KEYCODE_MEDIA_REWIND:
5049 case KeyEvent.KEYCODE_MEDIA_RECORD:
5050 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005051 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005052 case KeyEvent.KEYCODE_CAMERA:
5053 return false;
5054 }
5055 return true;
5056 }
5057
5058
Jeff Brown56194eb2011-03-02 19:23:13 -08005059 /** {@inheritDoc} */
5060 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005061 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5062 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08005063 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
5064 return 0;
5065 }
Michael Wright70af00a2014-09-03 19:30:20 -07005066 }
Bryce Lee5c138322014-11-03 08:26:09 -08005067
Michael Wright70af00a2014-09-03 19:30:20 -07005068 if (shouldDispatchInputWhenNonInteractive()) {
5069 return ACTION_PASS_TO_USER;
5070 }
Bryce Lee5c138322014-11-03 08:26:09 -08005071
Bryce Lee812d7022014-11-10 13:33:28 -08005072 // If we have not passed the action up and we are in theater mode without dreaming,
5073 // there will be no dream to intercept the touch and wake into ambient. The device should
5074 // wake up in this case.
5075 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
5076 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
5077 }
5078
Jeff Brown037c33e2014-04-09 00:31:55 -07005079 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005080 }
5081
Michael Wright70af00a2014-09-03 19:30:20 -07005082 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08005083 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07005084 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5085 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005086 return true;
5087 }
5088
5089 // Send events to a dozing dream even if the screen is off since the dream
5090 // is in control of the state of the screen.
5091 IDreamManager dreamManager = getDreamManager();
5092
5093 try {
5094 if (dreamManager != null && dreamManager.isDreaming()) {
5095 return true;
5096 }
5097 } catch (RemoteException e) {
5098 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5099 }
5100
5101 // Otherwise, consume events since the user can't see what is being
5102 // interacted with.
5103 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005104 }
5105
RoboErik001c59c2015-01-26 15:53:51 -08005106 private void dispatchDirectAudioEvent(KeyEvent event) {
5107 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5108 return;
5109 }
5110 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005111 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5112 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005113 String pkgName = mContext.getOpPackageName();
5114 switch (keyCode) {
5115 case KeyEvent.KEYCODE_VOLUME_UP:
5116 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005117 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005118 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005119 } catch (RemoteException e) {
5120 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5121 }
5122 break;
5123 case KeyEvent.KEYCODE_VOLUME_DOWN:
5124 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005125 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005126 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005127 } catch (RemoteException e) {
5128 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5129 }
5130 break;
5131 case KeyEvent.KEYCODE_VOLUME_MUTE:
5132 try {
5133 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005134 getAudioService().adjustSuggestedStreamVolume(
5135 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005136 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005137 }
5138 } catch (RemoteException e) {
5139 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5140 }
5141 break;
5142 }
5143 }
5144
Jeff Brown40013652012-05-16 21:22:36 -07005145 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5146 if (DEBUG_INPUT) {
5147 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005148 }
5149
Jeff Brown40013652012-05-16 21:22:36 -07005150 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5151 if (DEBUG_INPUT) {
5152 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5153 }
5154
5155 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5156 mHavePendingMediaKeyRepeatWithWakeLock = false;
5157 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5158 }
5159
5160 dispatchMediaKeyWithWakeLockToAudioService(event);
5161
5162 if (event.getAction() == KeyEvent.ACTION_DOWN
5163 && event.getRepeatCount() == 0) {
5164 mHavePendingMediaKeyRepeatWithWakeLock = true;
5165
5166 Message msg = mHandler.obtainMessage(
5167 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5168 msg.setAsynchronous(true);
5169 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5170 } else {
5171 mBroadcastWakeLock.release();
5172 }
5173 }
5174
5175 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5176 mHavePendingMediaKeyRepeatWithWakeLock = false;
5177
5178 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5179 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5180 if (DEBUG_INPUT) {
5181 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5182 }
5183
5184 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5185 mBroadcastWakeLock.release();
5186 }
5187
5188 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5189 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005190 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005191 }
5192 }
5193
Michael Wright869a67c2014-08-26 19:33:06 -07005194 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
5195 Intent voiceIntent =
5196 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5197 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005198 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005199 mBroadcastWakeLock.release();
5200 }
5201
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005202 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005203 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005204 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005205 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5206 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5207 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005208 } else {
5209 try {
5210 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5211 ServiceManager.getService(Context.UI_MODE_SERVICE));
5212 mUiMode = uiModeService.getCurrentModeType();
5213 } catch (RemoteException e) {
5214 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005215 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005216 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005217 synchronized (mLock) {
5218 updateOrientationListenerLp();
5219 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005220 }
5221 };
5222
Jeff Brown6aaf2952012-10-05 16:01:08 -07005223 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5224 @Override
5225 public void onReceive(Context context, Intent intent) {
5226 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005227 if (mKeyguardDelegate != null) {
5228 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005229 }
5230 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005231 if (mKeyguardDelegate != null) {
5232 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005233 }
5234 }
5235 }
5236 };
5237
Christopher Tate5e08af02012-09-21 17:17:22 -07005238 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5239 @Override
5240 public void onReceive(Context context, Intent intent) {
5241 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5242 // tickle the settings observer: this first ensures that we're
5243 // observing the relevant settings for the newly-active user,
5244 // and then updates our own bookkeeping based on the now-
5245 // current user.
5246 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005247
5248 // force a re-application of focused window sysui visibility.
5249 // the window may never have been shown for this user
5250 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005251 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005252 mLastSystemUiFlags = 0;
5253 updateSystemUiVisibilityLw();
5254 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005255 }
5256 }
5257 };
5258
Adrian Roosddc8b272015-05-21 16:28:27 -07005259 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005260 @Override
5261 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005262 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5263 if (!isUserSetupComplete()) {
5264 // Swipe-up for navigation bar is disabled during setup
5265 return;
5266 }
5267 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5268 mNavigationBarController.showTransient();
5269 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005270 }
5271 };
5272
John Spurlocke1f366f2013-08-05 12:22:40 -04005273 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005274 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005275 if (!isUserSetupComplete()) {
5276 // Swipe-up for navigation bar is disabled during setup
5277 return;
5278 }
John Spurlock27735a42013-08-14 17:57:38 -04005279 boolean sb = mStatusBarController.checkShowTransientBarLw();
5280 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005281 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005282 // Don't show status bar when swiping on already visible navigation bar
5283 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005284 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005285 return;
5286 }
John Spurlock27735a42013-08-14 17:57:38 -04005287 if (sb) mStatusBarController.showTransient();
5288 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005289 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005290 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005291 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005292 }
5293 }
5294
Jeff Brown3ee549c2014-09-22 20:14:39 -07005295 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005296 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005297 public void startedGoingToSleep(int why) {
5298 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005299 if (mKeyguardDelegate != null) {
5300 mKeyguardDelegate.onStartedGoingToSleep(why);
5301 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005302 }
5303
5304 // Called on the PowerManager's Notifier thread.
5305 @Override
5306 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005307 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005308 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005309
5310 // We must get this work done here because the power manager will drop
5311 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005312 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005313 mAwake = false;
5314 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005315 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005316 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005317 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005318 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005319 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005320 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005321 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005322 }
5323
Jeff Brown3ee549c2014-09-22 20:14:39 -07005324 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005325 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005326 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005327 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005328 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005329
Jeff Brown3ee549c2014-09-22 20:14:39 -07005330 // Since goToSleep performs these functions synchronously, we must
5331 // do the same here. We cannot post this work to a handler because
5332 // that might cause it to become reordered with respect to what
5333 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005334 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005335 mAwake = true;
5336 mKeyguardDrawComplete = false;
5337 if (mKeyguardDelegate != null) {
5338 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5339 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5340 }
5341
Jeff Browna20dda42014-05-27 20:57:24 -07005342 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005343 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005344 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005345 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005346
Jim Miller5ecd8112013-01-09 18:50:26 -08005347 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005348 mKeyguardDelegate.onStartedWakingUp(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005349 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005350 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005351 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005352 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005353 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005354 }
5355
Jeff Brown416c49c2015-05-26 19:50:18 -07005356 // Called on the PowerManager's Notifier thread.
5357 @Override
5358 public void finishedWakingUp() {
5359 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5360 }
5361
5362 private void wakeUpFromPowerKey(long eventTime) {
5363 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5364 }
5365
5366 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
5367 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
5368 return false;
5369 }
5370
5371 mPowerManager.wakeUp(wakeTime);
5372 return true;
5373 }
5374
Jeff Brown36c4db82014-09-19 12:05:31 -07005375 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005376 synchronized (mLock) {
5377 if (!mAwake || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005378 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005379 }
5380
Jeff Brown36c4db82014-09-19 12:05:31 -07005381 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005382 if (mKeyguardDelegate != null) {
5383 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5384 }
5385 }
5386
5387 finishScreenTurningOn();
5388 }
5389
5390 // Called on the DisplayManager's DisplayPowerController thread.
5391 @Override
5392 public void screenTurnedOff() {
5393 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5394
Jeff Brown48d1b142015-06-10 16:36:03 -07005395 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005396 synchronized (mLock) {
5397 mScreenOnEarly = false;
5398 mScreenOnFully = false;
5399 mWindowManagerDrawComplete = false;
5400 mScreenOnListener = null;
5401 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005402 }
5403 }
5404
Jeff Brown3ee549c2014-09-22 20:14:39 -07005405 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005406 @Override
5407 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005408 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005409
Jeff Brown48d1b142015-06-10 16:36:03 -07005410 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005411 synchronized (mLock) {
5412 mScreenOnEarly = true;
5413 mScreenOnFully = false;
5414 mWindowManagerDrawComplete = false;
5415 mScreenOnListener = screenOnListener;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005416 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005417
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005418 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5419 WAITING_FOR_DRAWN_TIMEOUT);
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005420 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
5421 // as well as enabling the orientation change logic/sensor.
Jeff Brown36c4db82014-09-19 12:05:31 -07005422 }
5423
Jeff Brown36c4db82014-09-19 12:05:31 -07005424 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005425 synchronized (mLock) {
5426 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005427 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005428 }
5429
Jeff Brown36c4db82014-09-19 12:05:31 -07005430 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005431 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005432
5433 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005434 }
5435
Craig Mautner8a0da012014-05-31 15:13:37 -07005436 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005437 synchronized (mLock) {
5438 // We have just finished drawing screen content. Since the orientation listener
5439 // gets only installed when all windows are drawn, we try to install it again.
5440 updateOrientationListenerLp();
5441 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005442 final ScreenOnListener listener;
5443 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005444 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005445 if (DEBUG_WAKEUP) Slog.d(TAG,
5446 "finishScreenTurningOn: mAwake=" + mAwake
5447 + ", mScreenOnEarly=" + mScreenOnEarly
5448 + ", mScreenOnFully=" + mScreenOnFully
5449 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5450 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5451
5452 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5453 || (mAwake && !mKeyguardDrawComplete)) {
5454 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005455 }
5456
Jeff Brown3ee549c2014-09-22 20:14:39 -07005457 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5458 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005459 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005460 mScreenOnFully = true;
5461
5462 // Remember the first time we draw the keyguard so we know when we're done with
5463 // the main part of booting and can enable the screen and hide boot messages.
5464 if (!mKeyguardDrawnOnce && mAwake) {
5465 mKeyguardDrawnOnce = true;
5466 enableScreen = true;
5467 if (mBootMessageNeedsHiding) {
5468 mBootMessageNeedsHiding = false;
5469 hideBootMessages();
5470 }
5471 } else {
5472 enableScreen = false;
5473 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005474 }
5475
Jeff Brown3ee549c2014-09-22 20:14:39 -07005476 if (listener != null) {
5477 listener.onScreenOn();
5478 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005479
Jeff Brown3ee549c2014-09-22 20:14:39 -07005480 if (enableScreen) {
5481 try {
5482 mWindowManager.enableScreenIfNeeded();
5483 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005484 }
Craig Mautnera631d492014-08-05 15:16:01 -07005485 }
5486 }
5487
5488 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005489 synchronized (mLock) {
5490 if (!mKeyguardDrawnOnce) {
5491 mBootMessageNeedsHiding = true;
5492 return; // keyguard hasn't drawn the first time yet, not done booting
5493 }
Craig Mautnera631d492014-08-05 15:16:01 -07005494 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005495
5496 if (mBootMsgDialog != null) {
5497 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5498 mBootMsgDialog.dismiss();
5499 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005500 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005501 }
5502
5503 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005504 public boolean isScreenOn() {
5505 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005506 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005507
Dianne Hackborn08743722009-12-21 12:16:51 -08005508 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005509 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005510 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005511 if (mKeyguardDelegate != null) {
5512 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005513 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005514 }
5515
5516 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005517 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005518 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005519 if (mKeyguardDelegate != null) {
5520 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005521 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005522 }
5523
Jim Millerab954542014-10-10 18:21:49 -07005524 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005525 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005526 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005527 }
5528
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005529 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005530 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005531 public boolean isKeyguardLocked() {
5532 return keyguardOn();
5533 }
5534
5535 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005536 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005537 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005538 if (mKeyguardDelegate == null) return false;
5539 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005540 }
5541
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005542 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005543 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07005544 public boolean isKeyguardShowingOrOccluded() {
5545 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
5546 }
5547
5548 /** {@inheritDoc} */
5549 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005550 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005551 if (mKeyguardDelegate == null) return false;
5552 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005553 }
5554
Jose Lima9546b202014-07-02 17:21:51 -07005555 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005556 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005557 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005558 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005559 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005560 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005561 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005562 // ask the keyguard to prompt the user to authenticate if necessary
5563 mKeyguardDelegate.dismiss();
5564 }
5565 });
5566 }
5567 }
5568
5569 public void notifyActivityDrawnForKeyguardLw() {
5570 if (mKeyguardDelegate != null) {
5571 mHandler.post(new Runnable() {
5572 @Override
5573 public void run() {
5574 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005575 }
5576 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005577 }
5578 }
5579
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005580 @Override
5581 public boolean isKeyguardDrawnLw() {
5582 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005583 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005584 }
5585 }
5586
Jorim Jaggi0d674622014-05-21 01:34:15 +02005587 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005588 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005589 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005590 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005591 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005592 }
5593 }
5594
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005595 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005596 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005597 }
5598
5599 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005600 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005601 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005602
Jeff Brown01a98dd2011-09-20 15:08:29 -07005603 @Override
5604 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005605 if (false) {
5606 Slog.v(TAG, "rotationForOrientationLw(orient="
5607 + orientation + ", last=" + lastRotation
5608 + "); user=" + mUserRotation + " "
5609 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5610 ? "USER_ROTATION_LOCKED" : "")
5611 );
5612 }
5613
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005614 if (mForceDefaultOrientation) {
5615 return Surface.ROTATION_0;
5616 }
5617
The Android Open Source Project0727d222009-03-11 12:11:58 -07005618 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005619 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5620 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005621 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005622 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005623
Jeff Browndec6cf42011-11-15 14:08:20 -08005624 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005625 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005626 // Ignore sensor when lid switch is open and rotation is forced.
5627 preferredRotation = mLidOpenRotation;
5628 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005629 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005630 // Ignore sensor when in car dock unless explicitly enabled.
5631 // This case can override the behavior of NOSENSOR, and can also
5632 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005633 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005634 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005635 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5636 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5637 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005638 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005639 // Ignore sensor when in desk dock unless explicitly enabled.
5640 // This case can override the behavior of NOSENSOR, and can also
5641 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005642 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005643 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005644 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5645 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005646 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005647 preferredRotation = mDemoHdmiRotation;
5648 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5649 && mUndockedHdmiRotation >= 0) {
5650 // Ignore sensor when plugged into HDMI and an undocked orientation has
5651 // been specified in the configuration (only for legacy devices without
5652 // full multi-display support).
5653 // Note that the dock orientation overrides the HDMI orientation.
5654 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005655 } else if (mDemoRotationLock) {
5656 // Ignore sensor when demo rotation lock is enabled.
5657 // Note that the dock orientation and HDMI rotation lock override this.
5658 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005659 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5660 // Application just wants to remain locked in the last rotation.
5661 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005662 } else if (!mSupportAutoRotation) {
5663 // If we don't support auto-rotation then bail out here and ignore
5664 // the sensor and any rotation lock settings.
5665 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005666 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005667 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005668 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5669 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5670 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5671 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005672 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5673 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5674 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5675 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5676 // Otherwise, use sensor only if requested by the application or enabled
5677 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005678 if (mAllowAllRotations < 0) {
5679 // Can't read this during init() because the context doesn't
5680 // have display metrics at that time so we cannot determine
5681 // tablet vs. phone then.
5682 mAllowAllRotations = mContext.getResources().getBoolean(
5683 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5684 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005685 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005686 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005687 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5688 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005689 preferredRotation = sensorRotation;
5690 } else {
5691 preferredRotation = lastRotation;
5692 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005693 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5694 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5695 // Apply rotation lock. Does not apply to NOSENSOR.
5696 // The idea is that the user rotation expresses a weak preference for the direction
5697 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5698 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005699 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005700 } else {
5701 // No overriding preference.
5702 // We will do exactly what the application asked us to do.
5703 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005704 }
5705
Dianne Hackborne5439f22010-10-02 16:53:50 -07005706 switch (orientation) {
5707 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005708 // Return portrait unless overridden.
5709 if (isAnyPortrait(preferredRotation)) {
5710 return preferredRotation;
5711 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005712 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005713
Jeff Brown01a98dd2011-09-20 15:08:29 -07005714 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005715 // Return landscape unless overridden.
5716 if (isLandscapeOrSeascape(preferredRotation)) {
5717 return preferredRotation;
5718 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005719 return mLandscapeRotation;
5720
5721 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005722 // Return reverse portrait unless overridden.
5723 if (isAnyPortrait(preferredRotation)) {
5724 return preferredRotation;
5725 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005726 return mUpsideDownRotation;
5727
5728 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005729 // Return seascape unless overridden.
5730 if (isLandscapeOrSeascape(preferredRotation)) {
5731 return preferredRotation;
5732 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005733 return mSeascapeRotation;
5734
5735 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005736 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005737 // Return either landscape rotation.
5738 if (isLandscapeOrSeascape(preferredRotation)) {
5739 return preferredRotation;
5740 }
5741 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005742 return lastRotation;
5743 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005744 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005745
Jeff Brown01a98dd2011-09-20 15:08:29 -07005746 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005747 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005748 // Return either portrait rotation.
5749 if (isAnyPortrait(preferredRotation)) {
5750 return preferredRotation;
5751 }
5752 if (isAnyPortrait(lastRotation)) {
5753 return lastRotation;
5754 }
5755 return mPortraitRotation;
5756
5757 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005758 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5759 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005760 if (preferredRotation >= 0) {
5761 return preferredRotation;
5762 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005763 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005764 }
5765 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005766 }
5767
Jeff Brown01a98dd2011-09-20 15:08:29 -07005768 @Override
5769 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5770 switch (orientation) {
5771 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5772 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5773 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5774 return isAnyPortrait(rotation);
5775
5776 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5777 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5778 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5779 return isLandscapeOrSeascape(rotation);
5780
5781 default:
5782 return true;
5783 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005784 }
5785
Jeff Brownc0347aa2011-09-23 17:26:09 -07005786 @Override
5787 public void setRotationLw(int rotation) {
5788 mOrientationListener.setCurrentRotation(rotation);
5789 }
5790
Jeff Brown01a98dd2011-09-20 15:08:29 -07005791 private boolean isLandscapeOrSeascape(int rotation) {
5792 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005793 }
5794
Jeff Brown01a98dd2011-09-20 15:08:29 -07005795 private boolean isAnyPortrait(int rotation) {
5796 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005797 }
5798
Jose Lima9546b202014-07-02 17:21:51 -07005799 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005800 public int getUserRotationMode() {
5801 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005802 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5803 WindowManagerPolicy.USER_ROTATION_FREE :
5804 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005805 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005806
5807 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005808 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005809 public void setUserRotationMode(int mode, int rot) {
5810 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005811
5812 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005813 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005814 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005815 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005816 rot,
5817 UserHandle.USER_CURRENT);
5818 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005819 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005820 0,
5821 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005822 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005823 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005824 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005825 1,
5826 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005827 }
5828 }
5829
Jose Lima9546b202014-07-02 17:21:51 -07005830 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005831 public void setSafeMode(boolean safeMode) {
5832 mSafeMode = safeMode;
5833 performHapticFeedbackLw(null, safeMode
5834 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5835 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005836 }
Craig Mautnereda67292013-04-28 13:50:14 -07005837
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005838 static long[] getLongIntArray(Resources r, int resid) {
5839 int[] ar = r.getIntArray(resid);
5840 if (ar == null) {
5841 return null;
5842 }
5843 long[] out = new long[ar.length];
5844 for (int i=0; i<ar.length; i++) {
5845 out[i] = ar[i];
5846 }
5847 return out;
5848 }
Craig Mautnereda67292013-04-28 13:50:14 -07005849
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005850 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005851 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005852 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005853 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005854 mKeyguardDelegate.onSystemReady();
5855
Michael Wright3818c922014-09-02 13:59:07 -07005856 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005857 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005858 synchronized (mLock) {
5859 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005860 mSystemReady = true;
5861 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005862 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005863 public void run() {
5864 updateSettings();
5865 }
5866 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005867 }
5868 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005869
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005870 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005871 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005872 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005873 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005874 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005875 mKeyguardDelegate.onBootCompleted();
5876 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005877 synchronized (mLock) {
5878 mSystemBooted = true;
5879 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005880 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005881 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005882 }
5883
Dianne Hackborn661cd522011-08-22 00:26:20 -07005884 ProgressDialog mBootMsgDialog = null;
5885
5886 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005887 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005888 public void showBootMessage(final CharSequence msg, final boolean always) {
5889 mHandler.post(new Runnable() {
5890 @Override public void run() {
5891 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005892 int theme;
5893 if (mContext.getPackageManager().hasSystemFeature(
5894 PackageManager.FEATURE_WATCH)) {
5895 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5896 } else if (mContext.getPackageManager().hasSystemFeature(
5897 PackageManager.FEATURE_TELEVISION)) {
5898 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5899 } else {
5900 theme = 0;
5901 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005902
5903 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005904 // This dialog will consume all events coming in to
5905 // it, to avoid it trying to do things too early in boot.
5906 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5907 return true;
5908 }
5909 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5910 return true;
5911 }
5912 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5913 return true;
5914 }
5915 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5916 return true;
5917 }
5918 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5919 return true;
5920 }
5921 @Override public boolean dispatchPopulateAccessibilityEvent(
5922 AccessibilityEvent event) {
5923 return true;
5924 }
5925 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005926 if (mContext.getPackageManager().isUpgrade()) {
5927 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5928 } else {
5929 mBootMsgDialog.setTitle(R.string.android_start_title);
5930 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005931 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5932 mBootMsgDialog.setIndeterminate(true);
5933 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005934 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005935 mBootMsgDialog.getWindow().addFlags(
5936 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5937 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5938 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005939 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5940 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5941 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005942 mBootMsgDialog.setCancelable(false);
5943 mBootMsgDialog.show();
5944 }
5945 mBootMsgDialog.setMessage(msg);
5946 }
5947 });
5948 }
5949
5950 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005951 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005952 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005953 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005954 }
5955
Mike Lockwood28569302010-01-28 11:54:40 -05005956 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005957 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005958 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005959 // ***************************************
5960 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5961 // ***************************************
5962 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5963 // WITH ITS LOCKS HELD.
5964 //
5965 // This code must be VERY careful about the locks
5966 // it acquires.
5967 // In fact, the current code acquires way too many,
5968 // and probably has lurking deadlocks.
5969
Mike Lockwood28569302010-01-28 11:54:40 -05005970 synchronized (mScreenLockTimeout) {
5971 if (mLockScreenTimerActive) {
5972 // reset the timer
5973 mHandler.removeCallbacks(mScreenLockTimeout);
5974 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5975 }
5976 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005977 }
5978
Adam Cohenf7522022012-10-03 20:03:18 -07005979 class ScreenLockTimeout implements Runnable {
5980 Bundle options;
5981
5982 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005983 public void run() {
5984 synchronized (this) {
5985 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005986 if (mKeyguardDelegate != null) {
5987 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005988 }
Mike Lockwood28569302010-01-28 11:54:40 -05005989 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005990 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005991 }
5992 }
Mike Lockwood28569302010-01-28 11:54:40 -05005993
Adam Cohenf7522022012-10-03 20:03:18 -07005994 public void setLockOptions(Bundle options) {
5995 this.options = options;
5996 }
5997 }
5998
5999 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6000
Jose Lima9546b202014-07-02 17:21:51 -07006001 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006002 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006003 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6004 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006005 if (options != null) {
6006 // In case multiple calls are made to lockNow, we don't wipe out the options
6007 // until the runnable actually executes.
6008 mScreenLockTimeout.setLockOptions(options);
6009 }
Jim Miller93c518e2012-01-17 15:55:31 -08006010 mHandler.post(mScreenLockTimeout);
6011 }
6012
Mike Lockwood28569302010-01-28 11:54:40 -05006013 private void updateLockScreenTimeout() {
6014 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006015 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006016 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006017 if (mLockScreenTimerActive != enable) {
6018 if (enable) {
6019 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
6020 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6021 } else {
6022 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6023 mHandler.removeCallbacks(mScreenLockTimeout);
6024 }
6025 mLockScreenTimerActive = enable;
6026 }
6027 }
6028 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006029
Jeff Brown061ea992015-04-17 19:55:47 -07006030 private void updateDreamingSleepToken(boolean acquire) {
6031 if (acquire) {
6032 if (mDreamingSleepToken == null) {
6033 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6034 }
6035 } else {
6036 if (mDreamingSleepToken != null) {
6037 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006038 mDreamingSleepToken = null;
6039 }
6040 }
6041 }
6042
6043 private void updateScreenOffSleepToken(boolean acquire) {
6044 if (acquire) {
6045 if (mScreenOffSleepToken == null) {
6046 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6047 }
6048 } else {
6049 if (mScreenOffSleepToken != null) {
6050 mScreenOffSleepToken.release();
6051 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006052 }
6053 }
6054 }
6055
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006056 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006057 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006058 public void enableScreenAfterBoot() {
6059 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006060 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006061 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006062 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006063
Jeff Brownc458ce92012-04-30 14:58:40 -07006064 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006065 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006066 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006067 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006068 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07006069 }
Jeff Browna20dda42014-05-27 20:57:24 -07006070
6071 synchronized (mLock) {
6072 updateWakeGestureListenerLp();
6073 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006074 }
6075
Jeff Brown4f5fa282014-06-12 19:19:15 -07006076 void updateUiMode() {
6077 if (mUiModeManager == null) {
6078 mUiModeManager = IUiModeManager.Stub.asInterface(
6079 ServiceManager.getService(Context.UI_MODE_SERVICE));
6080 }
6081 try {
6082 mUiMode = mUiModeManager.getCurrentModeType();
6083 } catch (RemoteException e) {
6084 }
6085 }
6086
Jeff Brown01a98dd2011-09-20 15:08:29 -07006087 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006088 try {
6089 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006090 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6091 } catch (RemoteException e) {
6092 // Ignore
6093 }
6094 }
6095
6096 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6097 try {
6098 //set orientation on WindowManager
6099 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006100 } catch (RemoteException e) {
6101 // Ignore
6102 }
6103 }
6104
Daniel Sandler6396c722013-04-16 20:19:09 -04006105 /**
6106 * Return an Intent to launch the currently active dock app as home. Returns
6107 * null if the standard home should be launched, which is the case if any of the following is
6108 * true:
6109 * <ul>
6110 * <li>The device is not in either car mode or desk mode
6111 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
6112 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6113 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6114 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6115 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006116 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006117 */
6118 Intent createHomeDockIntent() {
6119 Intent intent = null;
6120
6121 // What home does is based on the mode, not the dock state. That
6122 // is, when in car mode you should be taken to car home regardless
6123 // of whether we are actually in a car dock.
6124 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6125 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
6126 intent = mCarDockIntent;
6127 }
6128 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6129 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6130 intent = mDeskDockIntent;
6131 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006132 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6133 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6134 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6135 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6136 // Always launch dock home from home when watch is docked, if it exists.
6137 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006138 }
6139
6140 if (intent == null) {
6141 return null;
6142 }
6143
6144 ActivityInfo ai = null;
6145 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6146 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006147 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006148 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006149 if (info != null) {
6150 ai = info.activityInfo;
6151 }
6152 if (ai != null
6153 && ai.metaData != null
6154 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6155 intent = new Intent(intent);
6156 intent.setClassName(ai.packageName, ai.name);
6157 return intent;
6158 }
6159
6160 return null;
6161 }
6162
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006163 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6164 if (awakenFromDreams) {
6165 awakenDreams();
6166 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006167
6168 Intent dock = createHomeDockIntent();
6169 if (dock != null) {
6170 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006171 if (fromHomeKey) {
6172 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6173 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006174 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006175 return;
6176 } catch (ActivityNotFoundException e) {
6177 }
6178 }
6179
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006180 Intent intent;
6181
6182 if (fromHomeKey) {
6183 intent = new Intent(mHomeIntent);
6184 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6185 } else {
6186 intent = mHomeIntent;
6187 }
6188
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006189 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006190 }
Craig Mautnereda67292013-04-28 13:50:14 -07006191
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006192 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006193 * goes to the home screen
6194 * @return whether it did anything
6195 */
6196 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006197 if (!isUserSetupComplete()) {
6198 Slog.i(TAG, "Not going home because user setup is in progress.");
6199 return false;
6200 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006201 if (false) {
6202 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006203 try {
6204 ActivityManagerNative.getDefault().stopAppSwitches();
6205 } catch (RemoteException e) {
6206 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006207 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006208 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006209 } else {
6210 // This code brings home to the front or, if it is already
6211 // at the front, puts the device to sleep.
6212 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006213 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6214 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6215 Log.d(TAG, "UTS-TEST-MODE");
6216 } else {
6217 ActivityManagerNative.getDefault().stopAppSwitches();
6218 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006219 Intent dock = createHomeDockIntent();
6220 if (dock != null) {
6221 int result = ActivityManagerNative.getDefault()
6222 .startActivityAsUser(null, null, dock,
6223 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6224 null, null, 0,
6225 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006226 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006227 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6228 return false;
6229 }
6230 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006231 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006232 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006233 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006234 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006235 null, null, 0,
6236 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006237 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006238 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006239 return false;
6240 }
6241 } catch (RemoteException ex) {
6242 // bummer, the activity manager, which is in this process, is dead
6243 }
6244 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006245 return true;
6246 }
Craig Mautnereda67292013-04-28 13:50:14 -07006247
6248 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006249 public void setCurrentOrientationLw(int newOrientation) {
6250 synchronized (mLock) {
6251 if (newOrientation != mCurrentAppOrientation) {
6252 mCurrentAppOrientation = newOrientation;
6253 updateOrientationListenerLp();
6254 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006255 }
6256 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006257
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006258 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6259 if (!isGlobalAccessibilityGestureEnabled()) {
6260 return;
6261 }
6262 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6263 Context.AUDIO_SERVICE);
6264 if (audioManager.isSilentMode()) {
6265 return;
6266 }
6267 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6268 Settings.System.DEFAULT_NOTIFICATION_URI);
6269 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6270 ringTone.play();
6271 }
Craig Mautnereda67292013-04-28 13:50:14 -07006272
Bryce Lee584a4452014-10-21 15:55:55 -07006273 private boolean isTheaterModeEnabled() {
6274 return Settings.Global.getInt(mContext.getContentResolver(),
6275 Settings.Global.THEATER_MODE_ON, 0) == 1;
6276 }
6277
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006278 private boolean isGlobalAccessibilityGestureEnabled() {
6279 return Settings.Global.getInt(mContext.getContentResolver(),
6280 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6281 }
6282
Craig Mautnereda67292013-04-28 13:50:14 -07006283 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006284 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006285 if (!mVibrator.hasVibrator()) {
6286 return false;
6287 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006288 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6289 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006290 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006291 return false;
6292 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006293 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006294 switch (effectId) {
6295 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006296 pattern = mLongPressVibePattern;
6297 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006298 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006299 pattern = mVirtualKeyVibePattern;
6300 break;
6301 case HapticFeedbackConstants.KEYBOARD_TAP:
6302 pattern = mKeyboardTapVibePattern;
6303 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006304 case HapticFeedbackConstants.CLOCK_TICK:
6305 pattern = mClockTickVibePattern;
6306 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006307 case HapticFeedbackConstants.CALENDAR_DATE:
6308 pattern = mCalendarDateVibePattern;
6309 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006310 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006311 pattern = mSafeModeDisabledVibePattern;
6312 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006313 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006314 pattern = mSafeModeEnabledVibePattern;
6315 break;
Mady Mellore8608912015-06-05 09:02:55 -07006316 case HapticFeedbackConstants.CONTEXT_CLICK:
6317 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006318 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006319 default:
6320 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006321 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006322 int owningUid;
6323 String owningPackage;
6324 if (win != null) {
6325 owningUid = win.getOwningUid();
6326 owningPackage = win.getOwningPackage();
6327 } else {
6328 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006329 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006330 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006331 if (pattern.length == 1) {
6332 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006333 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006334 } else {
6335 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006336 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006337 }
6338 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006339 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006340
6341 @Override
6342 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006343 }
6344
Jeff Brownc38c9be2012-10-04 13:16:19 -07006345 @Override
6346 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006347 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006348 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006349 }
6350 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006351
Dianne Hackborndf89e652011-10-06 22:35:11 -07006352 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006353 // If there is no window focused, there will be nobody to handle the events
6354 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006355 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6356 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006357 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006358 return 0;
6359 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006360 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006361 // We are updating at a point where the keyguard has gotten
6362 // focus, but we were last in a state where the top window is
6363 // hiding it. This is probably because the keyguard as been
6364 // shown while the top window was displayed, so we want to ignore
6365 // it here because this is just a very transient change and it
6366 // will quickly lose focus once it correctly gets hidden.
6367 return 0;
6368 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006369
John Spurlock1db8b682014-02-18 11:18:59 -05006370 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006371 & ~mResettingSystemUiFlags
6372 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006373 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006374 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006375 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006376 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006377 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006378 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006379 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006380 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006381 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006382 return 0;
6383 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006384 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006385 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006386 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006387 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006388 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006389 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006390 try {
6391 IStatusBarService statusbar = getStatusBarService();
6392 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006393 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006394 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006395 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006396 } catch (RemoteException e) {
6397 // re-acquire status bar service next time it is needed.
6398 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006399 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006400 }
6401 });
6402 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006403 }
6404
Adrian Rooscd3884d2015-02-18 17:25:23 +01006405 private int updateLightStatusBarLw(int vis) {
6406 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6407 ? mStatusBar
6408 : mTopFullscreenOpaqueOrDimmingWindowState;
6409
6410 if (statusColorWin != null) {
6411 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6412 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6413 // its light flag.
6414 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6415 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6416 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6417 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6418 // Otherwise if it's dimming, clear the light flag.
6419 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6420 }
6421 }
6422 return vis;
6423 }
6424
John Spurlock79da8332013-09-20 12:04:47 -04006425 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006426 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006427 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6428 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006429 : mTopFullscreenOpaqueWindowState;
6430 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6431 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6432
John Spurlock27735a42013-08-14 17:57:38 -04006433 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006434 int type = win.getAttrs().type;
6435 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006436 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006437 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6438 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006439 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006440 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6441 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006442 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006443 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6444 }
John Spurlockbd957402013-10-03 11:38:39 -04006445 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006446 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006447
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006448 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006449 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6450 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006451 }
6452
John Spurlock27735a42013-08-14 17:57:38 -04006453 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006454 boolean immersiveSticky =
6455 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006456 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006457 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006458 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006459 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6460 boolean hideStatusBarSysui =
6461 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006462 boolean hideNavBarSysui =
6463 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006464
John Spurlock27735a42013-08-14 17:57:38 -04006465 boolean transientStatusBarAllowed =
6466 mStatusBar != null && (
6467 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006468 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006469 || statusBarHasFocus);
6470
John Spurlockf1a36642013-10-12 17:50:42 -04006471 boolean transientNavBarAllowed =
6472 mNavigationBar != null &&
6473 hideNavBarSysui && immersiveSticky;
6474
Adrian Roosddc8b272015-05-21 16:28:27 -07006475 final long now = SystemClock.uptimeMillis();
6476 final boolean pendingPanic = mPendingPanicGestureUptime != 0
6477 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
6478 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
6479 // The user performed the panic gesture recently, we're about to hide the bars,
6480 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
6481 mPendingPanicGestureUptime = 0;
6482 mStatusBarController.showTransient();
6483 mNavigationBarController.showTransient();
6484 }
6485
John Spurlockf25706f2013-11-07 18:02:43 -05006486 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006487 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006488 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006489 && !transientNavBarAllowed;
6490 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006491 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006492 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006493 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006494 }
John Spurlock27735a42013-08-14 17:57:38 -04006495
Selim Cinekf98702e2015-05-20 22:48:40 -07006496 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
6497 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
6498 final boolean navAllowedHidden = immersive || immersiveSticky;
6499
Selim Cinekd6623612015-05-22 18:56:22 -07006500 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
6501 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07006502 // We can't hide the navbar from this window otherwise the input consumer would not get
6503 // the input events.
6504 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
6505 }
6506
John Spurlock27735a42013-08-14 17:57:38 -04006507 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6508
6509 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006510 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6511 boolean newImmersiveMode = isImmersiveMode(vis);
6512 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006513 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006514 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6515 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006516 }
John Spurlock27735a42013-08-14 17:57:38 -04006517
John Spurlockf1a36642013-10-12 17:50:42 -04006518 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6519
John Spurlocke1f366f2013-08-05 12:22:40 -04006520 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006521 }
6522
John Spurlockf1a36642013-10-12 17:50:42 -04006523 private void clearClearableFlagsLw() {
6524 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6525 if (newVal != mResettingSystemUiFlags) {
6526 mResettingSystemUiFlags = newVal;
6527 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6528 }
6529 }
6530
6531 private boolean isImmersiveMode(int vis) {
6532 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006533 return mNavigationBar != null
6534 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006535 && (vis & flags) != 0
6536 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006537 }
6538
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006539 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006540 * @return whether the navigation or status bar can be made translucent
6541 *
6542 * This should return true unless touch exploration is not enabled or
6543 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006544 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006545 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006546 return mTranslucentDecorEnabled
6547 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006548 }
6549
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006550 // Use this instead of checking config_showNavigationBar so that it can be consistently
6551 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006552 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006553 public boolean hasNavigationBar() {
6554 return mHasNavigationBar;
6555 }
6556
satok1bc0a492012-04-25 22:47:12 +09006557 @Override
6558 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6559 mLastInputMethodWindow = ime;
6560 mLastInputMethodTargetWindow = target;
6561 }
6562
Craig Mautnerf1b67412012-09-19 13:18:29 -07006563 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006564 public int getInputMethodWindowVisibleHeightLw() {
6565 return mDockBottom - mCurBottom;
6566 }
6567
6568 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006569 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006570 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006571 if (mKeyguardDelegate != null) {
6572 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006573 }
John Spurlock13451a22012-09-28 14:40:41 -04006574 if (mStatusBarService != null) {
6575 try {
6576 mStatusBarService.setCurrentUser(newUserId);
6577 } catch (RemoteException e) {
6578 // oh well
6579 }
6580 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006581 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006582 }
6583
6584 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006585 public boolean canMagnifyWindow(int windowType) {
6586 switch (windowType) {
6587 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6588 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6589 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6590 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6591 return false;
6592 }
6593 }
6594 return true;
6595 }
6596
6597 @Override
6598 public boolean isTopLevelWindow(int windowType) {
6599 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6600 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6601 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6602 }
6603 return true;
6604 }
6605
Jim Miller4eeb4f62012-11-08 00:04:29 -08006606 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006607 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006608 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006609 pw.print(" mSystemReady="); pw.print(mSystemReady);
6610 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006611 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006612 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006613 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006614 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006615 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6616 || mForceClearedSystemUiFlags != 0) {
6617 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6618 pw.print(Integer.toHexString(mLastSystemUiFlags));
6619 pw.print(" mResettingSystemUiFlags=0x");
6620 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6621 pw.print(" mForceClearedSystemUiFlags=0x");
6622 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006623 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006624 if (mLastFocusNeedsMenu) {
6625 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6626 pw.println(mLastFocusNeedsMenu);
6627 }
Jeff Browna20dda42014-05-27 20:57:24 -07006628 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6629 pw.println(mWakeGestureEnabledSetting);
6630
Jeff Brownbcdfc622014-03-06 19:13:04 -08006631 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006632 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6633 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006634 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6635 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6636 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6637 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006638 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006639 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006640 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6641 pw.print(mCarDockEnablesAccelerometer);
6642 pw.print(" mDeskDockEnablesAccelerometer=");
6643 pw.println(mDeskDockEnablesAccelerometer);
6644 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6645 pw.print(mLidKeyboardAccessibility);
6646 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006647 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006648 pw.print(prefix);
6649 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6650 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006651 pw.print(prefix);
6652 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6653 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006654 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006655 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6656 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6657 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6658 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6659 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6660 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6661 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006662 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6663 pw.print(","); pw.print(mOverscanScreenTop);
6664 pw.print(") "); pw.print(mOverscanScreenWidth);
6665 pw.print("x"); pw.println(mOverscanScreenHeight);
6666 if (mOverscanLeft != 0 || mOverscanTop != 0
6667 || mOverscanRight != 0 || mOverscanBottom != 0) {
6668 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6669 pw.print(" top="); pw.print(mOverscanTop);
6670 pw.print(" right="); pw.print(mOverscanRight);
6671 pw.print(" bottom="); pw.println(mOverscanBottom);
6672 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006673 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6674 pw.print(mRestrictedOverscanScreenLeft);
6675 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6676 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6677 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006678 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6679 pw.print(","); pw.print(mUnrestrictedScreenTop);
6680 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6681 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6682 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6683 pw.print(","); pw.print(mRestrictedScreenTop);
6684 pw.print(") "); pw.print(mRestrictedScreenWidth);
6685 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006686 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6687 pw.print(","); pw.print(mStableFullscreenTop);
6688 pw.print(")-("); pw.print(mStableFullscreenRight);
6689 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006690 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6691 pw.print(","); pw.print(mStableTop);
6692 pw.print(")-("); pw.print(mStableRight);
6693 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006694 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6695 pw.print(","); pw.print(mSystemTop);
6696 pw.print(")-("); pw.print(mSystemRight);
6697 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006698 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6699 pw.print(","); pw.print(mCurTop);
6700 pw.print(")-("); pw.print(mCurRight);
6701 pw.print(","); pw.print(mCurBottom); pw.println(")");
6702 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6703 pw.print(","); pw.print(mContentTop);
6704 pw.print(")-("); pw.print(mContentRight);
6705 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006706 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6707 pw.print(","); pw.print(mVoiceContentTop);
6708 pw.print(")-("); pw.print(mVoiceContentRight);
6709 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006710 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6711 pw.print(","); pw.print(mDockTop);
6712 pw.print(")-("); pw.print(mDockRight);
6713 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006714 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6715 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006716 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6717 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006718 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6719 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006720 if (mLastInputMethodWindow != null) {
6721 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6722 pw.println(mLastInputMethodWindow);
6723 }
6724 if (mLastInputMethodTargetWindow != null) {
6725 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6726 pw.println(mLastInputMethodTargetWindow);
6727 }
6728 if (mStatusBar != null) {
6729 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006730 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6731 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006732 }
6733 if (mNavigationBar != null) {
6734 pw.print(prefix); pw.print("mNavigationBar=");
6735 pw.println(mNavigationBar);
6736 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006737 if (mFocusedWindow != null) {
6738 pw.print(prefix); pw.print("mFocusedWindow=");
6739 pw.println(mFocusedWindow);
6740 }
6741 if (mFocusedApp != null) {
6742 pw.print(prefix); pw.print("mFocusedApp=");
6743 pw.println(mFocusedApp);
6744 }
6745 if (mWinDismissingKeyguard != null) {
6746 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6747 pw.println(mWinDismissingKeyguard);
6748 }
6749 if (mTopFullscreenOpaqueWindowState != null) {
6750 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6751 pw.println(mTopFullscreenOpaqueWindowState);
6752 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006753 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6754 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6755 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6756 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006757 if (mForcingShowNavBar) {
6758 pw.print(prefix); pw.print("mForcingShowNavBar=");
6759 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6760 pw.println(mForcingShowNavBarLayer);
6761 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006762 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006763 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006764 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6765 pw.print(" mForceStatusBarFromKeyguard=");
6766 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006767 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006768 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006769 pw.print(" mHomePressed="); pw.println(mHomePressed);
6770 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6771 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6772 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6773 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6774 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6775 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6776 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6777 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6778 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6779 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006780 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6781 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6782 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006783
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006784 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006785 mStatusBarController.dump(pw, prefix);
6786 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006787 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006788
Jeff Browna20dda42014-05-27 20:57:24 -07006789 if (mWakeGestureListener != null) {
6790 mWakeGestureListener.dump(pw, prefix);
6791 }
Jeff Brown600f0032014-05-22 17:06:00 -07006792 if (mOrientationListener != null) {
6793 mOrientationListener.dump(pw, prefix);
6794 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006795 if (mBurnInProtectionHelper != null) {
6796 mBurnInProtectionHelper.dump(prefix, pw);
6797 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006798 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006799}