blob: 936840ae5a1b444cf816763f0614c7f8cb0ab8f1 [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
Jeff Brown37df39a92015-02-25 15:42:31 -08002 * Copyright (C) 2006 The Android Open Source Project
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jorim Jaggib10e33f2015-02-04 21:57:40 +010017package com.android.server.policy;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080018
Dianne Hackborna4972e92012-03-14 10:38:05 -070019import android.app.ActivityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080020import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080021import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040022import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070023import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070024import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040025import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080026import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070027import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080028import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040029import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080030import android.content.ContentResolver;
31import android.content.Context;
32import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070033import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070034import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080035import android.content.pm.ActivityInfo;
36import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040037import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070038import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080039import android.content.res.Configuration;
40import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070041import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080042import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080043import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080044import android.graphics.Rect;
John Spurlock7b414672014-07-18 13:02:39 -040045import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080046import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050047import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080048import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070049import android.media.Ringtone;
50import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070051import android.media.session.MediaSessionLegacyHelper;
Mark Renoufc1256912015-03-11 14:38:23 -040052import android.os.Build;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070053import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080054import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070055import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080056import android.os.Handler;
57import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080058import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070059import android.os.Message;
60import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080061import android.os.PowerManager;
62import android.os.RemoteException;
63import android.os.ServiceManager;
64import android.os.SystemClock;
65import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080066import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070067import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080068import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070069import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080070import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070071import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040072import android.service.dreams.DreamService;
73import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070074import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070075import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070076import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080077import android.util.EventLog;
78import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070079import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080080import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070081import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080082import android.view.Gravity;
83import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080084import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080085import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070086import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070087import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080088import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080089import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080090import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080091import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080092import android.view.KeyEvent;
93import android.view.MotionEvent;
Jorim Jaggib10e33f2015-02-04 21:57:40 +010094import android.view.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080095import android.view.Surface;
96import android.view.View;
97import android.view.ViewConfiguration;
Mark Renoufc1256912015-03-11 14:38:23 -040098import android.view.ViewRootImpl;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080099import android.view.Window;
100import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800101import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700102import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800103import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800104import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800105import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800106import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200107import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800108import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800109import com.android.internal.R;
Craig Mautnerae446592012-12-06 19:05:05 -0800110import com.android.internal.statusbar.IStatusBarService;
Craig Mautnerae446592012-12-06 19:05:05 -0800111import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700112import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100113import com.android.server.policy.keyguard.KeyguardServiceDelegate;
114import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800115
116import java.io.File;
117import java.io.FileReader;
118import java.io.IOException;
119import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700120import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800121import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800122
Dianne Hackbornc652de82013-02-15 16:32:56 -0800123import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700124import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
125import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
126import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700127import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
128import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
129import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800130
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800131/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700132 * WindowManagerPolicy implementation for the Android phone UI. This
133 * introduces a new method suffix, Lp, for an internal lock of the
134 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400135 * can be acquired with either the Lw and Li lock held, so has the restrictions
The Android Open Source Project0727d222009-03-11 12:11:58 -0700136 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800137 */
138public class PhoneWindowManager implements WindowManagerPolicy {
139 static final String TAG = "WindowManager";
140 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700141 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700142 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700143 static final boolean DEBUG_KEYGUARD = false;
144 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700145 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700146 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800147 static final boolean SHOW_STARTING_ANIMATIONS = true;
148 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400149
Daniel Sandler6396c722013-04-16 20:19:09 -0400150 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
151 // No longer recommended for desk docks; still useful in car docks.
152 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
153 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
154
Jeff Brown6d8fd272014-05-20 21:24:38 -0700155 static final int SHORT_PRESS_POWER_NOTHING = 0;
156 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
157 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
158 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800159 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700160
Joe Onoratod208e702010-10-08 16:22:43 -0400161 static final int LONG_PRESS_POWER_NOTHING = 0;
162 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
163 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700164 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700165
Jeff Brown13f00f02014-10-31 14:45:50 -0700166 static final int MULTI_PRESS_POWER_NOTHING = 0;
167 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
168 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
169
Michael Jurka3b1fc472011-06-13 10:54:40 -0700170 // These need to match the documentation/constant in
171 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800172 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800173 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700174 static final int LONG_PRESS_HOME_ASSIST = 2;
175
176 static final int DOUBLE_TAP_HOME_NOTHING = 0;
177 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800178
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000179 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
180 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
181
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700182 static final int APPLICATION_MEDIA_SUBLAYER = -2;
183 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800184 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800185 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700186
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800187 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
188 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
189 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500190 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700191 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800192
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700193 /**
194 * These are the system UI flags that, when changing, can cause the layout
195 * of the screen to change.
196 */
197 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400198 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400199 | View.SYSTEM_UI_FLAG_FULLSCREEN
200 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200201 | View.NAVIGATION_BAR_TRANSLUCENT
202 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700203
John Spurlock7b414672014-07-18 13:02:39 -0400204 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
205 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
206 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
207 .build();
208
Jim Miller5ecd8112013-01-09 18:50:26 -0800209 /**
210 * Keyguard stuff
211 */
212 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100213 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700214 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800215
Jeff Brown6651a632011-11-28 12:59:11 -0800216 /* Table of Application Launch keys. Maps from key codes to intent categories.
217 *
218 * These are special keys that are used to launch particular kinds of applications,
219 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
220 * usage page. We don't support quite that many yet...
221 */
222 static SparseArray<String> sApplicationLaunchKeyCategories;
223 static {
224 sApplicationLaunchKeyCategories = new SparseArray<String>();
225 sApplicationLaunchKeyCategories.append(
226 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
227 sApplicationLaunchKeyCategories.append(
228 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
229 sApplicationLaunchKeyCategories.append(
230 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
231 sApplicationLaunchKeyCategories.append(
232 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
233 sApplicationLaunchKeyCategories.append(
234 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
235 sApplicationLaunchKeyCategories.append(
236 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
237 }
238
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700239 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
240 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
241
Dianne Hackborndf89e652011-10-06 22:35:11 -0700242 /**
243 * Lock protecting internal state. Must not call out into window
244 * manager with lock held. (This lock will be acquired in places
245 * where the window manager is calling in with its own lock held.)
246 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800247 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700248
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800249 Context mContext;
250 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700251 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700252 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700253 PowerManager mPowerManager;
Jose Lima9546b202014-07-02 17:21:51 -0700254 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400255 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700256 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700257 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800258 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700259 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800260 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000261 BurnInProtectionHelper mBurnInProtectionHelper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800262
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700263 // Vibrator pattern for haptic feedback of a long press.
264 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700265
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700266 // Vibrator pattern for haptic feedback of virtual key press.
267 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700268
Amith Yamasanic33cb712010-02-10 15:21:49 -0800269 // Vibrator pattern for a short vibration.
270 long[] mKeyboardTapVibePattern;
271
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700272 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
273 long[] mClockTickVibePattern;
274
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700275 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
276 long[] mCalendarDateVibePattern;
277
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700278 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
279 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700280
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700281 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
282 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700283
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800284 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
285 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400286
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800287 boolean mSafeMode;
288 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700289 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400290 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400291 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700292 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400293 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
294 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
295 int[] mNavigationBarHeightForRotation = new int[4];
296 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400297
Craig Mautnera631d492014-08-05 15:16:01 -0700298 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800299 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700300 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700301 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700302 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700303 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
304 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
305 }
306 };
307 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
308 @Override
309 public void onShown(IBinder windowToken) {
310 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
311 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
312 }
313 };
314
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800315 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800316 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900317 WindowState mLastInputMethodWindow = null;
318 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800319
Jeff Brown13f00f02014-10-31 14:45:50 -0700320 // FIXME This state is shared between the input reader and handler thread.
321 // Technically it's broken and buggy but it has been like this for many years
322 // and we have not yet seen any problems. Someday we'll rewrite this logic
323 // so that only one thread is involved in handling input policy. Unfortunately
324 // it's on a critical path for power management so we can't just post the work to the
325 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
326 // to hold wakelocks during dispatch and eliminating the critical path.
327 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800328 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700329 volatile int mPowerKeyPressCounter;
330 volatile boolean mEndCallKeyHandled;
331
Winson Chungd42a6cf2014-06-03 16:24:04 -0700332 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700333 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700334 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800335
Jeff Brown2e7760e2012-04-11 15:14:55 -0700336 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700337 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700338 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800339
Dianne Hackbornc777e072010-02-12 13:07:59 -0800340 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700341 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800342 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700343 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400344 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700345 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700346 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400347 int mCarDockRotation;
348 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700349 int mUndockedHdmiRotation;
350 int mDemoHdmiRotation;
351 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800352 int mDemoRotation;
353 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400354
Jeff Browna20dda42014-05-27 20:57:24 -0700355 boolean mWakeGestureEnabledSetting;
356 MyWakeGestureListener mWakeGestureListener;
357
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700358 // Default display does not rotate, apps that require non-default orientation will have to
359 // have the orientation emulated.
360 private boolean mForceDefaultOrientation = false;
361
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400362 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
363 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700364 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400365
Jeff Brownbcdfc622014-03-06 19:13:04 -0800366 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700367 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400368 boolean mCarDockEnablesAccelerometer;
369 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700370 int mLidKeyboardAccessibility;
371 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700372 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700373 int mShortPressOnPowerBehavior;
374 int mLongPressOnPowerBehavior;
375 int mDoublePressOnPowerBehavior;
376 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000377 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700378 boolean mAwake;
379 boolean mScreenOnEarly;
380 boolean mScreenOnFully;
381 ScreenOnListener mScreenOnListener;
382 boolean mKeyguardDrawComplete;
383 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800384 boolean mOrientationSensorEnabled = false;
385 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800386 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400387 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800388 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700389
Jeff Brown70825162012-03-28 17:27:48 -0700390 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800391
392 // The last window we were told about in focusChanged.
393 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800394 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800395
Jeff Brown70825162012-03-28 17:27:48 -0700396 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800397
Dianne Hackbornc652de82013-02-15 16:32:56 -0800398 // The current size of the screen; really; extends into the overscan area of
399 // the screen and doesn't account for any system elements like the status bar.
400 int mOverscanScreenLeft, mOverscanScreenTop;
401 int mOverscanScreenWidth, mOverscanScreenHeight;
402 // The current visible size of the screen; really; (ir)regardless of whether the status
403 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800404 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
405 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800406 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
407 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
408 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700409 // The current size of the screen; these may be different than (0,0)-(dw,dh)
410 // if the status bar can't be hidden; in that case it effectively carves out
411 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800412 int mRestrictedScreenLeft, mRestrictedScreenTop;
413 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700414 // During layout, the current screen borders accounting for any currently
415 // visible system UI elements.
416 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700417 // For applications requesting stable content insets, these are them.
418 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700419 // For applications requesting stable content insets but have also set the
420 // fullscreen window flag, these are the stable dimensions without the status bar.
421 int mStableFullscreenLeft, mStableFullscreenTop;
422 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800423 // During layout, the current screen borders with all outer decoration
424 // (status bar, input method dock) accounted for.
425 int mCurLeft, mCurTop, mCurRight, mCurBottom;
426 // During layout, the frame in which content should be displayed
427 // to the user, accounting for all screen decoration except for any
428 // space they deem as available for other content. This is usually
429 // the same as mCur*, but may be larger if the screen decor has supplied
430 // content insets.
431 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700432 // During layout, the frame in which voice content should be displayed
433 // to the user, accounting for all screen decoration except for any
434 // space they deem as available for other content.
435 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800436 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800437 // windows are placed.
438 int mDockLeft, mDockTop, mDockRight, mDockBottom;
439 // During layout, the layer at which the doc window is placed.
440 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700441 // During layout, this is the layer of the status bar.
442 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700443 int mLastSystemUiFlags;
444 // Bits that we are in the process of clearing, so we want to prevent
445 // them from being set by applications until everything has been updated
446 // to have them clear.
447 int mResettingSystemUiFlags = 0;
448 // Bits that we are currently always keeping cleared.
449 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800450 // What we last reported to system UI about whether the compatibility
451 // menu needs to be displayed.
452 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700453
454 FakeWindow mHideNavFakeWindow = null;
455
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800456 static final Rect mTmpParentFrame = new Rect();
457 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800458 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800459 static final Rect mTmpContentFrame = new Rect();
460 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400461 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700462 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700463 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700464
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800465 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100466 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700467 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200468 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400469 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800470 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700471 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700472 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800473 boolean mForcingShowNavBar;
474 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700475
476 // States of keyguard dismiss.
477 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
478 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
479 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
480 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
481
482 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
483 * be done once per window. */
484 private WindowState mWinDismissingKeyguard;
485
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700486 /** The window that is currently showing "over" the keyguard. If there is an app window
487 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
488 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
489 * the wallpaper. */
490 private WindowState mWinShowWhenLocked;
491
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700492 boolean mShowingLockscreen;
493 boolean mShowingDream;
494 boolean mDreamingLockscreen;
Jim Millerab954542014-10-10 18:21:49 -0700495 boolean mKeyguardSecure;
496 boolean mKeyguardSecureIncludingHidden;
497 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800498 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700499 boolean mHomeConsumed;
500 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800501 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700502 Intent mCarDockIntent;
503 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700504 boolean mSearchKeyShortcutPending;
505 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700506 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700507 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800508
Mike Lockwood28569302010-01-28 11:54:40 -0500509 // support for activating the lock screen while the screen is on
510 boolean mAllowLockscreenWhenOn;
511 int mLockScreenTimeout;
512 boolean mLockScreenTimerActive;
513
David Brownbaf8d092010-03-08 21:52:59 -0800514 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800515 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800516
517 // Behavior of POWER button while in-call and screen on.
518 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
519 int mIncallPowerBehavior;
520
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700521 Display mDisplay;
522
Dianne Hackborn9d132642011-04-21 17:26:39 -0700523 int mLandscapeRotation = 0; // default landscape rotation
524 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
525 int mPortraitRotation = 0; // default portrait rotation
526 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700527
Dianne Hackbornc652de82013-02-15 16:32:56 -0800528 int mOverscanLeft = 0;
529 int mOverscanTop = 0;
530 int mOverscanRight = 0;
531 int mOverscanBottom = 0;
532
Joe Onorato46b0d682010-11-22 17:37:27 -0800533 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700534 private int mLongPressOnHomeBehavior;
535
536 // What we do when the user double-taps on home
537 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800538
Bryce Lee584a4452014-10-21 15:55:55 -0700539 // Allowed theater mode wake actions
540 private boolean mAllowTheaterModeWakeFromKey;
541 private boolean mAllowTheaterModeWakeFromPowerKey;
542 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800543 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700544 private boolean mAllowTheaterModeWakeFromCameraLens;
545 private boolean mAllowTheaterModeWakeFromLidSwitch;
546 private boolean mAllowTheaterModeWakeFromWakeGesture;
547
Bryce Leed3b28402015-03-09 15:49:13 +0000548 // Whether to support long press from power button in non-interactive mode
549 private boolean mSupportLongPressPowerWhenNonInteractive;
550
Bryce Lee55e846d2014-11-04 12:43:44 -0800551 // Whether to go to sleep entering theater mode from power button
552 private boolean mGoToSleepOnButtonPressTheaterMode;
553
Winson Chung9112ec32011-06-27 13:15:32 -0700554 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700555 // Time to volume and power must be pressed within this interval of each other.
556 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700557 // Increase the chord delay when taking a screenshot from the keyguard
558 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800559 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700560 private boolean mScreenshotChordVolumeDownKeyTriggered;
561 private long mScreenshotChordVolumeDownKeyTime;
562 private boolean mScreenshotChordVolumeDownKeyConsumed;
563 private boolean mScreenshotChordVolumeUpKeyTriggered;
564 private boolean mScreenshotChordPowerKeyTriggered;
565 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700566
Michael Wrightb854e242013-02-05 17:54:02 -0800567 /* The number of steps between min and max brightness */
568 private static final int BRIGHTNESS_STEPS = 10;
569
Christopher Tate5e08af02012-09-21 17:17:22 -0700570 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800571 ShortcutManager mShortcutManager;
572 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700573 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700574 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800575
Craig Mautnerd625ab22013-09-06 13:40:31 -0700576 private int mCurrentUserId;
577
Justin Kohd378ad72013-04-01 12:18:26 -0700578 // Maps global key codes to the components that will handle them.
579 private GlobalKeyManager mGlobalKeyManager;
580
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700581 // Fallback actions by key code.
582 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
583 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800584
Jorim Jaggi76a16232014-08-08 17:00:47 +0200585 private final LogDecelerateInterpolator mLogDecelerateInterpolator
586 = new LogDecelerateInterpolator(100, 0);
587
Jeff Brown70825162012-03-28 17:27:48 -0700588 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
589 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700590 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
591 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700592 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
593 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
594 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700595 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700596 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700597 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700598 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700599 private static final int MSG_POWER_DELAYED_PRESS = 13;
600 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown70825162012-03-28 17:27:48 -0700601
602 private class PolicyHandler extends Handler {
603 @Override
604 public void handleMessage(Message msg) {
605 switch (msg.what) {
606 case MSG_ENABLE_POINTER_LOCATION:
607 enablePointerLocation();
608 break;
609 case MSG_DISABLE_POINTER_LOCATION:
610 disablePointerLocation();
611 break;
Jeff Brown40013652012-05-16 21:22:36 -0700612 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
613 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
614 break;
615 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
616 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
617 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700618 case MSG_DISPATCH_SHOW_RECENTS:
619 showRecentApps(false);
620 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700621 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
622 showGlobalActionsInternal();
623 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700624 case MSG_KEYGUARD_DRAWN_COMPLETE:
625 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700626 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700627 break;
628 case MSG_KEYGUARD_DRAWN_TIMEOUT:
629 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700630 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700631 break;
632 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
633 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700634 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700635 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700636 case MSG_HIDE_BOOT_MESSAGE:
637 handleHideBootMessage();
638 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700639 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
640 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
641 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700642 case MSG_POWER_DELAYED_PRESS:
643 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
644 finishPowerKeyPress();
645 break;
646 case MSG_POWER_LONG_PRESS:
647 powerLongPress();
648 break;
Jeff Brown70825162012-03-28 17:27:48 -0700649 }
650 }
651 }
652
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800653 private UEventObserver mHDMIObserver = new UEventObserver() {
654 @Override
655 public void onUEvent(UEventObserver.UEvent event) {
656 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
657 }
658 };
659
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800660 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800661 SettingsObserver(Handler handler) {
662 super(handler);
663 }
David Brownbaf8d092010-03-08 21:52:59 -0800664
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800665 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700666 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800667 ContentResolver resolver = mContext.getContentResolver();
668 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700669 Settings.System.END_BUTTON_BEHAVIOR), false, this,
670 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800671 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700672 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
673 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700674 resolver.registerContentObserver(Settings.Secure.getUriFor(
675 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
676 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800677 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700678 Settings.System.ACCELEROMETER_ROTATION), false, this,
679 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500680 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700681 Settings.System.USER_ROTATION), false, this,
682 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400683 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700684 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
685 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800686 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700687 Settings.System.POINTER_LOCATION), false, this,
688 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800689 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700690 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
691 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500692 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400693 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700694 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500695 resolver.registerContentObserver(Settings.Global.getUriFor(
696 Settings.Global.POLICY_CONTROL), false, this,
697 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800698 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800699 }
700
701 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800702 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700703 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800704 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800705 }
Craig Mautner967212c2013-04-13 21:10:58 -0700706
Jeff Browna20dda42014-05-27 20:57:24 -0700707 class MyWakeGestureListener extends WakeGestureListener {
708 MyWakeGestureListener(Context context, Handler handler) {
709 super(context, handler);
710 }
711
712 @Override
713 public void onWakeUp() {
714 synchronized (mLock) {
715 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700716 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700717 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700718 }
719 }
720 }
721 }
722
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800723 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800724 MyOrientationListener(Context context, Handler handler) {
725 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800726 }
Craig Mautner967212c2013-04-13 21:10:58 -0700727
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800728 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700729 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700730 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700731 updateRotation(false);
732 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800733 }
734 MyOrientationListener mOrientationListener;
735
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100736 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400737
John Spurlock27735a42013-08-14 17:57:38 -0400738 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400739 View.NAVIGATION_BAR_TRANSIENT,
740 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400741 View.NAVIGATION_BAR_TRANSLUCENT,
742 StatusBarManager.WINDOW_NAVIGATION_BAR,
743 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400744
John Spurlockf1a36642013-10-12 17:50:42 -0400745 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400746
Craig Mautner037aa8d2013-06-07 10:35:44 -0700747 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400748
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700749 IStatusBarService getStatusBarService() {
750 synchronized (mServiceAquireLock) {
751 if (mStatusBarService == null) {
752 mStatusBarService = IStatusBarService.Stub.asInterface(
753 ServiceManager.getService("statusbar"));
754 }
755 return mStatusBarService;
756 }
757 }
758
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700759 /*
760 * We always let the sensor be switched on by default except when
761 * the user has explicitly disabled sensor based rotation or when the
762 * screen is switched off.
763 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700764 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800765 if (mSupportAutoRotation) {
766 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
767 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
768 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
769 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
770 // If the application has explicitly requested to follow the
771 // orientation, then we need to turn the sensor on.
772 return true;
773 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800774 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700775 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800776 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
777 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
778 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400779 // enable accelerometer if we are docked in a dock that enables accelerometer
780 // orientation management,
781 return true;
782 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700783 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800784 // If the setting for using the sensor by default is enabled, then
785 // we will always leave it on. Note that the user could go to
786 // a window that forces an orientation that does not use the
787 // sensor and in theory we could turn it off... however, when next
788 // turning it on we won't have a good value for the current
789 // orientation for a little bit, which can cause orientation
790 // changes to lag, so we'd like to keep it always on. (It will
791 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700792 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800793 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800794 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800795 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700796
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800797 /*
798 * Various use cases for invoking this function
799 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700800 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800801 * if not already enabled
802 * screen turned on and current app does not have sensor orientation, disable listeners if
803 * already enabled
804 * screen turning on and current app has sensor based orientation, enable listeners if needed
805 * screen turning on and current app has nosensor based orientation, do nothing
806 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700807 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800808 if (!mOrientationListener.canDetectOrientation()) {
809 // If sensor is turned off or nonexistent for some reason
810 return;
811 }
812 //Could have been invoked due to screen turning on or off or
813 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700814 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
815 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
816 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800817 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700818 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700819 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800820 disable = false;
821 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700822 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800823 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700824 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800825 mOrientationSensorEnabled = true;
826 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700827 }
828 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800829 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700830 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800831 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700832 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800833 mOrientationSensorEnabled = false;
834 }
835 }
836
Jeff Brown13f00f02014-10-31 14:45:50 -0700837 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
838 // Hold a wake lock until the power key is released.
839 if (!mPowerKeyWakeLock.isHeld()) {
840 mPowerKeyWakeLock.acquire();
841 }
842
843 // Cancel multi-press detection timeout.
844 if (mPowerKeyPressCounter != 0) {
845 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
846 }
847
848 // Detect user pressing the power button in panic when an application has
849 // taken over the whole screen.
850 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800851 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700852 if (panic) {
853 mHandler.post(mRequestTransientNav);
854 }
855
856 // Latch power key state to detect screenshot chord.
857 if (interactive && !mScreenshotChordPowerKeyTriggered
858 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
859 mScreenshotChordPowerKeyTriggered = true;
860 mScreenshotChordPowerKeyTime = event.getDownTime();
861 interceptScreenshotChord();
862 }
863
864 // Stop ringing or end call if configured to do so when power is pressed.
865 TelecomManager telecomManager = getTelecommService();
866 boolean hungUp = false;
867 if (telecomManager != null) {
868 if (telecomManager.isRinging()) {
869 // Pressing Power while there's a ringing incoming
870 // call should silence the ringer.
871 telecomManager.silenceRinger();
872 } else if ((mIncallPowerBehavior
873 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
874 && telecomManager.isInCall() && interactive) {
875 // Otherwise, if "Power button ends call" is enabled,
876 // the Power button will hang up any current active call.
877 hungUp = telecomManager.endCall();
878 }
879 }
880
881 // If the power key has still not yet been handled, then detect short
882 // press, long press, or multi press and decide what to do.
883 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
884 || mScreenshotChordVolumeUpKeyTriggered;
885 if (!mPowerKeyHandled) {
886 if (interactive) {
887 // When interactive, we're already awake.
888 // Wait for a long press or for the button to be released to decide what to do.
889 if (hasLongPressOnPowerBehavior()) {
890 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
891 msg.setAsynchronous(true);
892 mHandler.sendMessageDelayed(msg,
893 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
894 }
895 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800896 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800897
Bryce Leed3b28402015-03-09 15:49:13 +0000898 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
899 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
900 msg.setAsynchronous(true);
901 mHandler.sendMessageDelayed(msg,
902 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800903 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000904 } else {
905 final int maxCount = getMaxMultiPressPowerCount();
906
907 if (maxCount <= 1) {
908 mPowerKeyHandled = true;
909 } else {
910 mBeganFromNonInteractive = true;
911 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700912 }
913 }
Jeff Brown4d396052010-10-29 21:50:21 -0700914 }
915 }
916
Jeff Brown13f00f02014-10-31 14:45:50 -0700917 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
918 final boolean handled = canceled || mPowerKeyHandled;
919 mScreenshotChordPowerKeyTriggered = false;
920 cancelPendingScreenshotChordAction();
921 cancelPendingPowerKeyAction();
922
923 if (!handled) {
924 // Figure out how to handle the key now that it has been released.
925 mPowerKeyPressCounter += 1;
926
927 final int maxCount = getMaxMultiPressPowerCount();
928 final long eventTime = event.getDownTime();
929 if (mPowerKeyPressCounter < maxCount) {
930 // This could be a multi-press. Wait a little bit longer to confirm.
931 // Continue holding the wake lock.
932 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
933 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
934 msg.setAsynchronous(true);
935 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
936 return;
937 }
938
939 // No other actions. Handle it immediately.
940 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700941 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700942
943 // Done. Reset our state.
944 finishPowerKeyPress();
945 }
946
947 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800948 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700949 mPowerKeyPressCounter = 0;
950 if (mPowerKeyWakeLock.isHeld()) {
951 mPowerKeyWakeLock.release();
952 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700953 }
954
955 private void cancelPendingPowerKeyAction() {
956 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700957 mPowerKeyHandled = true;
958 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700959 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700960 }
961
962 private void powerPress(long eventTime, boolean interactive, int count) {
963 if (mScreenOnEarly && !mScreenOnFully) {
964 Slog.i(TAG, "Suppressed redundant power key press while "
965 + "already in the process of turning the screen on.");
966 return;
Jeff Brownff204712011-10-25 21:27:54 -0700967 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700968
969 if (count == 2) {
970 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
971 } else if (count == 3) {
972 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -0800973 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700974 switch (mShortPressOnPowerBehavior) {
975 case SHORT_PRESS_POWER_NOTHING:
976 break;
977 case SHORT_PRESS_POWER_GO_TO_SLEEP:
978 mPowerManager.goToSleep(eventTime,
979 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
980 break;
981 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
982 mPowerManager.goToSleep(eventTime,
983 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
984 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
985 break;
986 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
987 mPowerManager.goToSleep(eventTime,
988 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
989 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
990 launchHomeFromHotKey();
991 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800992 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +0000993 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800994 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700995 }
996 }
997 }
998
999 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1000 switch (behavior) {
1001 case MULTI_PRESS_POWER_NOTHING:
1002 break;
1003 case MULTI_PRESS_POWER_THEATER_MODE:
1004 if (isTheaterModeEnabled()) {
1005 Slog.i(TAG, "Toggling theater mode off.");
1006 Settings.Global.putInt(mContext.getContentResolver(),
1007 Settings.Global.THEATER_MODE_ON, 0);
1008 if (!interactive) {
1009 wakeUpFromPowerKey(eventTime);
1010 }
1011 } else {
1012 Slog.i(TAG, "Toggling theater mode on.");
1013 Settings.Global.putInt(mContext.getContentResolver(),
1014 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001015
1016 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001017 mPowerManager.goToSleep(eventTime,
1018 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1019 }
1020 }
1021 break;
1022 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001023 Slog.i(TAG, "Starting brightness boost.");
1024 if (!interactive) {
1025 wakeUpFromPowerKey(eventTime);
1026 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001027 mPowerManager.boostScreenBrightness(eventTime);
1028 break;
1029 }
1030 }
1031
1032 private int getMaxMultiPressPowerCount() {
1033 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1034 return 3;
1035 }
1036 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1037 return 2;
1038 }
1039 return 1;
1040 }
1041
1042 private void powerLongPress() {
1043 final int behavior = getResolvedLongPressOnPowerBehavior();
1044 switch (behavior) {
1045 case LONG_PRESS_POWER_NOTHING:
1046 break;
1047 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1048 mPowerKeyHandled = true;
1049 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1050 performAuditoryFeedbackForAccessibilityIfNeed();
1051 }
1052 showGlobalActionsInternal();
1053 break;
1054 case LONG_PRESS_POWER_SHUT_OFF:
1055 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1056 mPowerKeyHandled = true;
1057 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1058 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1059 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1060 break;
1061 }
1062 }
1063
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001064 private void sleepPress(KeyEvent event) {
1065 switch (mShortPressOnSleepBehavior) {
1066 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
1067 mPowerManager.goToSleep(event.getEventTime(),
1068 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1069 break;
1070 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001071 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001072 mPowerManager.goToSleep(event.getEventTime(),
1073 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1074 break;
1075 }
1076 }
1077
Jeff Brown13f00f02014-10-31 14:45:50 -07001078 private int getResolvedLongPressOnPowerBehavior() {
1079 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1080 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1081 }
1082 return mLongPressOnPowerBehavior;
1083 }
1084
1085 private boolean hasLongPressOnPowerBehavior() {
1086 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001087 }
1088
1089 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001090 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001091 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1092 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001093 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001094 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1095 && now <= mScreenshotChordPowerKeyTime
1096 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1097 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001098 cancelPendingPowerKeyAction();
1099
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001100 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001101 }
1102 }
1103 }
1104
Winson Chung1cea2f32012-10-08 20:42:01 -07001105 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001106 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001107 // Double the time it takes to take a screenshot from the keyguard
1108 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001109 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001110 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001111 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001112 }
1113
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001114 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001115 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001116 }
1117
Jeff Brown13f00f02014-10-31 14:45:50 -07001118 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001119 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001120 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001121 mEndCallKeyHandled = true;
1122 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1123 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001124 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001125 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001126 }
1127 };
1128
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001129 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001130 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001131 public void run() {
1132 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001133 }
1134 };
1135
Alan Viverettee34560b22014-07-10 14:50:06 -07001136 @Override
1137 public void showGlobalActions() {
1138 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1139 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1140 }
1141
1142 void showGlobalActionsInternal() {
1143 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001144 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001145 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001146 }
Jim Millerab954542014-10-10 18:21:49 -07001147 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001148 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1149 if (keyguardShowing) {
1150 // since it took two seconds of long press to bring this up,
1151 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001152 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001153 }
1154 }
1155
1156 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001157 return Settings.Global.getInt(
1158 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001159 }
1160
Maurice Lam99c6e072014-04-28 18:24:28 -07001161 boolean isUserSetupComplete() {
1162 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1163 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1164 }
1165
Jeff Brown13f00f02014-10-31 14:45:50 -07001166 private void handleShortPressOnHome() {
1167 // If there's a dream running then use home to escape the dream
1168 // but don't actually go home.
1169 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1170 mDreamManagerInternal.stopDream(false /*immediate*/);
1171 return;
1172 }
1173
1174 // Go home!
1175 launchHomeFromHotKey();
1176 }
1177
Patrick Dubroyece94522011-02-23 18:35:01 -08001178 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -08001179 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001180 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001181 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001182
Jeff Browncaca8812013-05-09 13:34:33 -07001183 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1184 toggleRecentApps();
1185 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1186 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -07001187 }
1188 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001189 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001190
Jeff Browncaca8812013-05-09 13:34:33 -07001191 private void handleDoubleTapOnHome() {
1192 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1193 mHomeConsumed = true;
1194 toggleRecentApps();
1195 }
1196 }
1197
1198 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1199 @Override
1200 public void run() {
1201 if (mHomeDoubleTapPending) {
1202 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001203 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001204 }
1205 }
1206 };
1207
Mark Renoufc1256912015-03-11 14:38:23 -04001208 private boolean isRoundWindow() {
1209 return mContext.getResources().getBoolean(com.android.internal.R.bool.config_windowIsRound)
1210 || (Build.HARDWARE.contains("goldfish")
1211 && SystemProperties.getBoolean(ViewRootImpl.PROPERTY_EMULATOR_CIRCULAR, false));
1212 }
1213
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001214 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001215 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001216 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001217 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001218 mContext = context;
1219 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001220 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001221 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001222 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Mark Renoufc1256912015-03-11 14:38:23 -04001223
1224 // Init display burn-in protection
1225 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1226 com.android.internal.R.bool.config_enableBurnInProtection);
1227 // Allow a system property to override this. Used by developer settings.
1228 boolean burnInProtectionDevMode =
1229 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1230 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1231 final int minHorizontal;
1232 final int maxHorizontal;
1233 final int minVertical;
1234 final int maxVertical;
1235 final int maxRadius;
1236 if (burnInProtectionDevMode) {
1237 minHorizontal = -8;
1238 maxHorizontal = 8;
1239 minVertical = -8;
1240 maxVertical = -4;
1241 maxRadius = (isRoundWindow()) ? 6 : -1;
1242 } else {
1243 Resources resources = context.getResources();
1244 minHorizontal = resources.getInteger(
1245 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1246 maxHorizontal = resources.getInteger(
1247 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1248 minVertical = resources.getInteger(
1249 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1250 maxVertical = resources.getInteger(
1251 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1252 maxRadius = resources.getInteger(
1253 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1254 }
1255 mBurnInProtectionHelper = new BurnInProtectionHelper(
1256 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001257 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001258
Jeff Brown70825162012-03-28 17:27:48 -07001259 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001260 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001261 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001262 try {
1263 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1264 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001265 mSettingsObserver = new SettingsObserver(mHandler);
1266 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001267 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001268 mUiMode = context.getResources().getInteger(
1269 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001270 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1271 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1272 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1273 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001274 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1275 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1276 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1277 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1278 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1279 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1280 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1281 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001282
Jeff Brown96307042012-07-27 15:51:34 -07001283 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1284 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001285 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001286 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1287 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001288 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001289 mSupportAutoRotation = mContext.getResources().getBoolean(
1290 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001291 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001292 com.android.internal.R.integer.config_lidOpenRotation);
1293 mCarDockRotation = readRotation(
1294 com.android.internal.R.integer.config_carDockRotation);
1295 mDeskDockRotation = readRotation(
1296 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001297 mUndockedHdmiRotation = readRotation(
1298 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001299 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1300 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1301 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1302 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001303 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1304 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1305 mLidNavigationAccessibility = mContext.getResources().getInteger(
1306 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001307 mLidControlsSleep = mContext.getResources().getBoolean(
1308 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001309 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1310 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001311
1312 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1313 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1314 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1315 || mContext.getResources().getBoolean(
1316 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1317 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1318 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001319 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1320 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001321 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1322 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1323 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1324 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1325 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1326 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1327
Bryce Lee55e846d2014-11-04 12:43:44 -08001328 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1329 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1330
Bryce Leed3b28402015-03-09 15:49:13 +00001331 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1332 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1333
Jeff Brown13f00f02014-10-31 14:45:50 -07001334 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1335 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1336 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1337 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1338 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1339 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1340 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1341 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001342 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1343 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001344
John Spurlock61560172015-02-06 19:46:04 -05001345 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001346
Jeff Brownf71343d2013-05-31 17:59:11 -07001347 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001348
Svetoslav8e3feb12014-02-24 13:46:47 -08001349 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1350 Context.ACCESSIBILITY_SERVICE);
1351
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001352 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001353 IntentFilter filter = new IntentFilter();
1354 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1355 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1356 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1357 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001358 filter.addAction(Intent.ACTION_DOCK_EVENT);
1359 Intent intent = context.registerReceiver(mDockReceiver, filter);
1360 if (intent != null) {
1361 // Retrieve current sticky dock event broadcast.
1362 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1363 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1364 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001365
Jeff Brown6aaf2952012-10-05 16:01:08 -07001366 // register for dream-related broadcasts
1367 filter = new IntentFilter();
1368 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1369 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1370 context.registerReceiver(mDreamReceiver, filter);
1371
Christopher Tate5e08af02012-09-21 17:17:22 -07001372 // register for multiuser-relevant broadcasts
1373 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1374 context.registerReceiver(mMultiuserReceiver, filter);
1375
John Spurlock57306e62013-04-22 09:48:49 -04001376 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001377 mSystemGestures = new SystemGesturesPointerEventListener(context,
1378 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001379 @Override
1380 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001381 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001382 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001383 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001384 }
1385 @Override
1386 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001387 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001388 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001389 }
1390 }
1391 @Override
1392 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001393 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001394 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001395 }
1396 }
1397 @Override
1398 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001399 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001400 }
Adrian Roos3595be42015-03-05 16:31:15 +01001401 @Override
1402 public void onDown() {
1403 mOrientationListener.onTouchStart();
1404 }
1405 @Override
1406 public void onUpOrCancel() {
1407 mOrientationListener.onTouchEnd();
1408 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001409 });
John Spurlockf1a36642013-10-12 17:50:42 -04001410 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001411 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001412
Jeff Brownc2346132012-04-13 01:55:38 -07001413 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001414 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1415 com.android.internal.R.array.config_longPressVibePattern);
1416 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1417 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001418 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1419 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001420 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1421 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001422 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1423 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001424 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1425 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1426 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1427 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001428
Christopher Tatee90585f2012-03-05 18:56:25 -08001429 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1430 com.android.internal.R.bool.config_enableScreenshotChord);
1431
Justin Kohd378ad72013-04-01 12:18:26 -07001432 mGlobalKeyManager = new GlobalKeyManager(mContext);
1433
Joe Onoratoea495d42011-04-06 11:41:11 -07001434 // Controls rotation and the like.
1435 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001436
1437 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001438 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001439 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001440 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001441
1442 mWindowManagerInternal.registerAppTransitionListener(
1443 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001444 }
1445
Jeff Brownf71343d2013-05-31 17:59:11 -07001446 /**
1447 * Read values from config.xml that may be overridden depending on
1448 * the configuration of the device.
1449 * eg. Disable long press on home goes to recents on sw600dp.
1450 */
1451 private void readConfigurationDependentBehaviors() {
1452 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1453 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1454 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1455 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1456 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1457 }
1458
1459 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1460 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1461 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1462 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1463 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1464 }
1465 }
1466
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001467 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001468 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001469 // This method might be called before the policy has been fully initialized
1470 // or for other displays we don't care about.
1471 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1472 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001473 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001474 mDisplay = display;
1475
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001476 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001477 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001478 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001479 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001480 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001481 mLandscapeRotation = Surface.ROTATION_0;
1482 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001483 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001484 mPortraitRotation = Surface.ROTATION_90;
1485 mUpsideDownRotation = Surface.ROTATION_270;
1486 } else {
1487 mPortraitRotation = Surface.ROTATION_270;
1488 mUpsideDownRotation = Surface.ROTATION_90;
1489 }
1490 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001491 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001492 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001493 mPortraitRotation = Surface.ROTATION_0;
1494 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001495 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001496 mLandscapeRotation = Surface.ROTATION_270;
1497 mSeascapeRotation = Surface.ROTATION_90;
1498 } else {
1499 mLandscapeRotation = Surface.ROTATION_90;
1500 mSeascapeRotation = Surface.ROTATION_270;
1501 }
1502 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001503
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001504 mStatusBarHeight =
1505 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001506
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001507 // Height of the navigation bar when presented horizontally at bottom
1508 mNavigationBarHeightForRotation[mPortraitRotation] =
1509 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001510 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001511 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001512 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1513 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001514
1515 // Width of the navigation bar when presented vertically along one side
1516 mNavigationBarWidthForRotation[mPortraitRotation] =
1517 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1518 mNavigationBarWidthForRotation[mLandscapeRotation] =
1519 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001520 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001521
1522 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001523 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001524 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001525
Devin Kimd7b12b42014-05-05 14:34:58 -07001526 // Allow the navigation bar to move on non-square small devices (phones).
1527 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001528
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001529 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001530 // Allow a system property to override this. Used by the emulator.
1531 // See also hasNavigationBar().
1532 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1533 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001534 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001535 } else if ("0".equals(navBarOverride)) {
1536 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001537 }
1538
Jeff Brown27f1d672012-10-17 18:32:34 -07001539 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1540 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001541 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001542 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001543 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001544 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001545 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001546 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001547
Chong Zhangae6119ff2014-11-11 18:54:39 -08001548 // For demo purposes, allow the rotation of the remote display to be controlled.
1549 // By default, remote display locks rotation to landscape.
1550 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1551 mDemoRotation = mPortraitRotation;
1552 } else {
1553 mDemoRotation = mLandscapeRotation;
1554 }
1555 mDemoRotationLock = SystemProperties.getBoolean(
1556 "persist.demo.rotationlock", false);
1557
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001558 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1559 // http://developer.android.com/guide/practices/screens_support.html#range
1560 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1561 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1562 // For debug purposes the next line turns this feature off with:
1563 // $ adb shell setprop config.override_forced_orient true
1564 // $ adb shell wm size reset
1565 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1566 }
1567
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001568 /**
1569 * @return whether the navigation bar can be hidden, e.g. the device has a
1570 * navigation bar and touch exploration is not enabled
1571 */
1572 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001573 return mHasNavigationBar
1574 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001575 }
1576
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001577 @Override
1578 public boolean isDefaultOrientationForced() {
1579 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001580 }
1581
Dianne Hackbornc652de82013-02-15 16:32:56 -08001582 @Override
1583 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1584 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1585 mOverscanLeft = left;
1586 mOverscanTop = top;
1587 mOverscanRight = right;
1588 mOverscanBottom = bottom;
1589 }
1590 }
1591
Dianne Hackbornc777e072010-02-12 13:07:59 -08001592 public void updateSettings() {
1593 ContentResolver resolver = mContext.getContentResolver();
1594 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001595 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001596 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001597 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001598 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1599 UserHandle.USER_CURRENT);
1600 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001601 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001602 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1603 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001604
Jeff Browna20dda42014-05-27 20:57:24 -07001605 // Configure wake gesture.
1606 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1607 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1608 UserHandle.USER_CURRENT) != 0;
1609 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1610 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1611 updateWakeGestureListenerLp();
1612 }
1613
Jeff Brown207673cd2012-06-05 17:47:11 -07001614 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001615 int userRotation = Settings.System.getIntForUser(resolver,
1616 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1617 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001618 if (mUserRotation != userRotation) {
1619 mUserRotation = userRotation;
1620 updateRotation = true;
1621 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001622 int userRotationMode = Settings.System.getIntForUser(resolver,
1623 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001624 WindowManagerPolicy.USER_ROTATION_FREE :
1625 WindowManagerPolicy.USER_ROTATION_LOCKED;
1626 if (mUserRotationMode != userRotationMode) {
1627 mUserRotationMode = userRotationMode;
1628 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001629 updateOrientationListenerLp();
1630 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001631
Dianne Hackbornc777e072010-02-12 13:07:59 -08001632 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001633 int pointerLocation = Settings.System.getIntForUser(resolver,
1634 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001635 if (mPointerLocationMode != pointerLocation) {
1636 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001637 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1638 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001639 }
1640 }
1641 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001642 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1643 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1644 String imId = Settings.Secure.getStringForUser(resolver,
1645 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001646 boolean hasSoftInput = imId != null && imId.length() > 0;
1647 if (mHasSoftInput != hasSoftInput) {
1648 mHasSoftInput = hasSoftInput;
1649 updateRotation = true;
1650 }
John Spurlockf1a36642013-10-12 17:50:42 -04001651 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001652 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001653 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001654 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001655 }
1656 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001657 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001658 }
Jeff Brown70825162012-03-28 17:27:48 -07001659 }
1660
Jeff Browna20dda42014-05-27 20:57:24 -07001661 private void updateWakeGestureListenerLp() {
1662 if (shouldEnableWakeGestureLp()) {
1663 mWakeGestureListener.requestWakeUpTrigger();
1664 } else {
1665 mWakeGestureListener.cancelWakeUpTrigger();
1666 }
1667 }
1668
1669 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001670 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001671 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1672 && mWakeGestureListener.isSupported();
1673 }
1674
Jeff Brown70825162012-03-28 17:27:48 -07001675 private void enablePointerLocation() {
1676 if (mPointerLocationView == null) {
1677 mPointerLocationView = new PointerLocationView(mContext);
1678 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001679 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1680 WindowManager.LayoutParams.MATCH_PARENT,
1681 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001682 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001683 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1684 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1685 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1686 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001687 if (ActivityManager.isHighEndGfx()) {
1688 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1689 lp.privateFlags |=
1690 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1691 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001692 lp.format = PixelFormat.TRANSLUCENT;
1693 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001694 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001695 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001696 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001697 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001698 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001699 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001700 }
Jeff Brown70825162012-03-28 17:27:48 -07001701
1702 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001703 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001704 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1705 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001706 wm.removeView(mPointerLocationView);
1707 mPointerLocationView = null;
1708 }
1709 }
1710
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001711 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001712 try {
1713 int rotation = mContext.getResources().getInteger(resID);
1714 switch (rotation) {
1715 case 0:
1716 return Surface.ROTATION_0;
1717 case 90:
1718 return Surface.ROTATION_90;
1719 case 180:
1720 return Surface.ROTATION_180;
1721 case 270:
1722 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001723 }
1724 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001725 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001726 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001727 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001728 }
1729
1730 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001731 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001732 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001733 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001734
1735 outAppOp[0] = AppOpsManager.OP_NONE;
1736
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001737 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1738 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1739 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1740 return WindowManagerGlobal.ADD_INVALID_TYPE;
1741 }
1742
1743 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1744 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001745 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001746 }
1747 String permission = null;
1748 switch (type) {
1749 case TYPE_TOAST:
1750 // XXX right now the app process has complete control over
1751 // this... should introduce a token to let the system
1752 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001753 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001754 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001755 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001756 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001757 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001758 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001759 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001760 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001761 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001762 break;
1763 case TYPE_PHONE:
1764 case TYPE_PRIORITY_PHONE:
1765 case TYPE_SYSTEM_ALERT:
1766 case TYPE_SYSTEM_ERROR:
1767 case TYPE_SYSTEM_OVERLAY:
1768 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001769 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001770 break;
1771 default:
1772 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1773 }
1774 if (permission != null) {
1775 if (mContext.checkCallingOrSelfPermission(permission)
1776 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001777 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001778 }
1779 }
Jeff Brown98365d72012-08-19 20:30:52 -07001780 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001781 }
Craig Mautner88400d32012-09-30 12:35:45 -07001782
1783 @Override
1784 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1785
1786 // If this switch statement is modified, modify the comment in the declarations of
1787 // the type in {@link WindowManager.LayoutParams} as well.
1788 switch (attrs.type) {
1789 default:
1790 // These are the windows that by default are shown only to the user that created
1791 // them. If this needs to be overridden, set
1792 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1793 // {@link WindowManager.LayoutParams}. Note that permission
1794 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1795 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1796 return true;
1797 }
1798 break;
1799
1800 // These are the windows that by default are shown to all users. However, to
1801 // protect against spoofing, check permissions below.
1802 case TYPE_APPLICATION_STARTING:
1803 case TYPE_BOOT_PROGRESS:
1804 case TYPE_DISPLAY_OVERLAY:
1805 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001806 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001807 case TYPE_KEYGUARD_DIALOG:
1808 case TYPE_MAGNIFICATION_OVERLAY:
1809 case TYPE_NAVIGATION_BAR:
1810 case TYPE_NAVIGATION_BAR_PANEL:
1811 case TYPE_PHONE:
1812 case TYPE_POINTER:
1813 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001814 case TYPE_SEARCH_BAR:
1815 case TYPE_STATUS_BAR:
1816 case TYPE_STATUS_BAR_PANEL:
1817 case TYPE_STATUS_BAR_SUB_PANEL:
1818 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001819 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001820 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001821 break;
1822 }
1823
1824 // Check if third party app has set window to system window type.
1825 return mContext.checkCallingOrSelfPermission(
1826 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1827 != PackageManager.PERMISSION_GRANTED;
1828 }
1829
Craig Mautner967212c2013-04-13 21:10:58 -07001830 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001831 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1832 switch (attrs.type) {
1833 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001834 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001835 // These types of windows can't receive input events.
1836 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1837 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001838 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001839 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001840 case TYPE_STATUS_BAR:
1841
1842 // If the Keyguard is in a hidden state (occluded by another window), we force to
1843 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1844 // the keyguard as occluded wouldn't set these flags again.
1845 // See {@link #processKeyguardSetHiddenResultLw}.
1846 if (mKeyguardHidden) {
1847 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1848 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1849 }
1850 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001851 }
Adrian Roos38502112014-04-09 21:04:11 +02001852
1853 if (attrs.type != TYPE_STATUS_BAR) {
1854 // The status bar is the only window allowed to exhibit keyguard behavior.
1855 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1856 }
Adrian Roosea562512014-05-05 13:33:03 +02001857
1858 if (ActivityManager.isHighEndGfx()
1859 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001860 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001861 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1862 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001863 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001864
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001865 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001866 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001867 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001868
Michael Wright3818c922014-09-02 13:59:07 -07001869 private void readCameraLensCoverState() {
1870 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1871 }
1872
Jeff Browndaa37532012-05-01 15:54:03 -07001873 private boolean isHidden(int accessibilityMode) {
1874 switch (accessibilityMode) {
1875 case 1:
1876 return mLidState == LID_CLOSED;
1877 case 2:
1878 return mLidState == LID_OPEN;
1879 default:
1880 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001881 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001882 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001883
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001884 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001885 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001886 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1887 int navigationPresence) {
1888 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1889
Jeff Brownf71343d2013-05-31 17:59:11 -07001890 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001891 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001892 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001893
Jeff Browndaa37532012-05-01 15:54:03 -07001894 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1895 || (keyboardPresence == PRESENCE_INTERNAL
1896 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001897 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001898 if (!mHasSoftInput) {
1899 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1900 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001901 }
1902
Jeff Browndaa37532012-05-01 15:54:03 -07001903 if (config.navigation == Configuration.NAVIGATION_NONAV
1904 || (navigationPresence == PRESENCE_INTERNAL
1905 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001906 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001907 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001908 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001909
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001910 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001911 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001912 public int windowTypeToLayerLw(int type) {
1913 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001914 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001915 }
1916 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001917 case TYPE_PRIVATE_PRESENTATION:
1918 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001919 case TYPE_WALLPAPER:
1920 // wallpaper is at the bottom, though the window manager may move it.
1921 return 2;
1922 case TYPE_PHONE:
1923 return 3;
1924 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07001925 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001926 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001927 case TYPE_VOICE_INTERACTION:
1928 // voice interaction layer is almost immediately above apps.
1929 return 5;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001930 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001931 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001932 case TYPE_TOAST:
1933 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001934 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001935 case TYPE_PRIORITY_PHONE:
1936 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001937 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001938 case TYPE_DREAM:
1939 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001940 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001941 case TYPE_SYSTEM_ALERT:
1942 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001943 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001944 case TYPE_INPUT_METHOD:
1945 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001946 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001947 case TYPE_INPUT_METHOD_DIALOG:
1948 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001949 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001950 case TYPE_KEYGUARD_SCRIM:
1951 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001952 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001953 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001954 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001955 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001956 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001957 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001958 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001959 case TYPE_KEYGUARD_DIALOG:
1960 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001961 case TYPE_VOLUME_OVERLAY:
1962 // the on-screen volume indicator and controller shown when the user
1963 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001964 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001965 case TYPE_SYSTEM_OVERLAY:
1966 // the on-screen volume indicator and controller shown when the user
1967 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001968 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001969 case TYPE_NAVIGATION_BAR:
1970 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001971 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001972 case TYPE_NAVIGATION_BAR_PANEL:
1973 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001974 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001975 case TYPE_SYSTEM_ERROR:
1976 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001977 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001978 case TYPE_MAGNIFICATION_OVERLAY:
1979 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001980 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001981 case TYPE_DISPLAY_OVERLAY:
1982 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001983 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001984 case TYPE_DRAG:
1985 // the drag layer: input for drag-and-drop is associated with this window,
1986 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001987 return 25;
Svetoslav3a5c7212014-10-14 09:54:26 -07001988 case TYPE_ACCESSIBILITY_OVERLAY:
1989 // overlay put by accessibility services to intercept user interaction
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001990 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07001991 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001992 return 27;
Svetoslav3a5c7212014-10-14 09:54:26 -07001993 case TYPE_BOOT_PROGRESS:
1994 return 28;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001995 case TYPE_POINTER:
1996 // the (mouse) pointer layer
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001997 return 29;
Svetoslav3a5c7212014-10-14 09:54:26 -07001998 case TYPE_HIDDEN_NAV_CONSUMER:
1999 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002000 }
2001 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002002 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002003 }
2004
2005 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002006 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002007 public int subWindowTypeToLayerLw(int type) {
2008 switch (type) {
2009 case TYPE_APPLICATION_PANEL:
2010 case TYPE_APPLICATION_ATTACHED_DIALOG:
2011 return APPLICATION_PANEL_SUBLAYER;
2012 case TYPE_APPLICATION_MEDIA:
2013 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002014 case TYPE_APPLICATION_MEDIA_OVERLAY:
2015 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002016 case TYPE_APPLICATION_SUB_PANEL:
2017 return APPLICATION_SUB_PANEL_SUBLAYER;
2018 }
2019 Log.e(TAG, "Unknown sub-window type: " + type);
2020 return 0;
2021 }
2022
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002023 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002024 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002025 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002026 }
2027
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002028 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002029 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002030 if (mHasNavigationBar) {
2031 // For a basic navigation bar, when we are in landscape mode we place
2032 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002033 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2034 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002035 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002036 }
2037 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002038 }
2039
Jose Lima9546b202014-07-02 17:21:51 -07002040 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002041 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002042 if (mHasNavigationBar) {
2043 // For a basic navigation bar, when we are in portrait mode we place
2044 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002045 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2046 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002047 }
2048 }
2049 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002050 }
2051
Jose Lima9546b202014-07-02 17:21:51 -07002052 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002053 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2054 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002055 }
2056
Jose Lima9546b202014-07-02 17:21:51 -07002057 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002058 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002059 // There is a separate status bar at the top of the display. We don't count that as part
2060 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002061 // we do want to exclude it since applications can't generally use that part
2062 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002063 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002064 }
2065
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002066 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002067 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2068 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002069 (isKeyguardHostWindow(attrs) &&
2070 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002071 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002072 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002073
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002074 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002075 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2076 return attrs.type == TYPE_STATUS_BAR;
2077 }
2078
2079 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002080 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002081 switch (attrs.type) {
2082 case TYPE_STATUS_BAR:
2083 case TYPE_NAVIGATION_BAR:
2084 case TYPE_WALLPAPER:
2085 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002086 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002087 return false;
2088 default:
2089 return true;
2090 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002091 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002092
Craig Mautner7d7808f2014-09-11 18:02:38 -07002093 @Override
2094 public WindowState getWinShowWhenLockedLw() {
2095 return mWinShowWhenLocked;
2096 }
2097
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002098 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002099 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002100 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2101 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002102 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002103 if (!SHOW_STARTING_ANIMATIONS) {
2104 return null;
2105 }
2106 if (packageName == null) {
2107 return null;
2108 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002109
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002110 WindowManager wm = null;
2111 View view = null;
2112
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002113 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002114 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002115 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2116 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2117 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002118 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002119 try {
2120 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002121 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002122 } catch (PackageManager.NameNotFoundException e) {
2123 // Ignore
2124 }
2125 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002126
Jorim Jaggib10e33f2015-02-04 21:57:40 +01002127 Window win = new PhoneWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002128 final TypedArray ta = win.getWindowStyle();
2129 if (ta.getBoolean(
2130 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2131 || ta.getBoolean(
2132 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002133 return null;
2134 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002135
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002136 Resources r = context.getResources();
2137 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002138
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002139 win.setType(
2140 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
2141 // Force the window flags: this is a fake window, so it is not really
2142 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2143 // flag because we do know that the next window will take input
2144 // focus, so we want to get the IME window up on top of us right away.
2145 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002146 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002147 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2148 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2149 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002150 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002151 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2152 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2153 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002154
Adam Powell04fe6eb2013-05-31 14:39:48 -07002155 win.setDefaultIcon(icon);
2156 win.setDefaultLogo(logo);
2157
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002158 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002159 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002160
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002161 final WindowManager.LayoutParams params = win.getAttributes();
2162 params.token = appToken;
2163 params.packageName = packageName;
2164 params.windowAnimations = win.getWindowStyle().getResourceId(
2165 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002166 params.privateFlags |=
2167 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002168 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002169
2170 if (!compatInfo.supportsScreen()) {
2171 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2172 }
2173
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002174 params.setTitle("Starting " + packageName);
2175
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002176 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2177 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002178
2179 if (win.isFloating()) {
2180 // Whoops, there is no way to display an animation/preview
2181 // of such a thing! After all that work... let's skip it.
2182 // (Note that we must do this here because it is in
2183 // getDecorView() where the theme is evaluated... maybe
2184 // we should peek the floating attribute from the theme
2185 // earlier.)
2186 return null;
2187 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002188
Craig Mautner6fbda632012-07-03 09:26:39 -07002189 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002190 TAG, "Adding starting window for " + packageName
2191 + " / " + appToken + ": "
2192 + (view.getParent() != null ? view : null));
2193
2194 wm.addView(view, params);
2195
2196 // Only return the view if it was successfully added to the
2197 // window manager... which we can tell by it having a parent.
2198 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002199 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002200 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002201 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2202 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002203 } catch (RuntimeException e) {
2204 // don't crash if something else bad happens, for example a
2205 // failure loading resources because we are loading from an app
2206 // on external storage that has been unmounted.
2207 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002208 } finally {
2209 if (view != null && view.getParent() == null) {
2210 Log.w(TAG, "view not successfully added to wm, removing view");
2211 wm.removeViewImmediate(view);
2212 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002213 }
2214
2215 return null;
2216 }
2217
2218 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002219 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002220 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002221 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2222 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002223
2224 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002225 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002226 wm.removeView(window);
2227 }
2228 }
2229
2230 /**
2231 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002232 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002233 * Currently enforces that three window types are singletons:
2234 * <ul>
2235 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002236 * <li>KEYGUARD_TYPE</li>
2237 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002238 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002239 * @param win The window to be added
2240 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002241 *
Jeff Brown98365d72012-08-19 20:30:52 -07002242 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2243 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002244 */
Jose Lima9546b202014-07-02 17:21:51 -07002245 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002246 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2247 switch (attrs.type) {
2248 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002249 mContext.enforceCallingOrSelfPermission(
2250 android.Manifest.permission.STATUS_BAR_SERVICE,
2251 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002252 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002253 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002254 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002255 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002256 }
2257 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002258 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002259 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002260 case TYPE_NAVIGATION_BAR:
2261 mContext.enforceCallingOrSelfPermission(
2262 android.Manifest.permission.STATUS_BAR_SERVICE,
2263 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002264 if (mNavigationBar != null) {
2265 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002266 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002267 }
2268 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002269 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002270 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002271 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002272 break;
Jim Millere898ac52012-04-06 17:10:57 -07002273 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002274 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002275 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002276 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002277 mContext.enforceCallingOrSelfPermission(
2278 android.Manifest.permission.STATUS_BAR_SERVICE,
2279 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002280 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002281 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002282 if (mKeyguardScrim != null) {
2283 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2284 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002285 mKeyguardScrim = win;
2286 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002287 }
Jeff Brown98365d72012-08-19 20:30:52 -07002288 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002289 }
2290
2291 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002292 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002293 public void removeWindowLw(WindowState win) {
2294 if (mStatusBar == win) {
2295 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002296 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002297 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002298 } else if (mKeyguardScrim == win) {
2299 Log.v(TAG, "Removing keyguard scrim");
2300 mKeyguardScrim = null;
2301 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002302 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002303 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002304 }
2305 }
2306
2307 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002308
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002309 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002310 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002311 public int selectAnimationLw(WindowState win, int transit) {
2312 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2313 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002314 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002315 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002316 if (transit == TRANSIT_EXIT
2317 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002318 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002319 } else if (transit == TRANSIT_ENTER
2320 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002321 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002322 }
2323 } else if (win == mNavigationBar) {
2324 // This can be on either the bottom or the right.
2325 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002326 if (transit == TRANSIT_EXIT
2327 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002328 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002329 } else if (transit == TRANSIT_ENTER
2330 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002331 return R.anim.dock_bottom_enter;
2332 }
2333 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002334 if (transit == TRANSIT_EXIT
2335 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002336 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002337 } else if (transit == TRANSIT_ENTER
2338 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002339 return R.anim.dock_right_enter;
2340 }
2341 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002342 }
2343
2344 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002345 if (win.hasAppShownWindows()) {
2346 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2347 return com.android.internal.R.anim.app_starting_exit;
2348 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002349 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002350 && transit == TRANSIT_ENTER) {
2351 // Special case: we are animating in a dream, while the keyguard
2352 // is shown. We don't want an animation on the dream, because
2353 // we need it shown immediately with the keyguard animating away
2354 // to reveal it.
2355 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002356 }
2357
2358 return 0;
2359 }
2360
Craig Mautner3c174372013-02-21 17:54:37 -08002361 @Override
2362 public void selectRotationAnimationLw(int anim[]) {
2363 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2364 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2365 + (mTopFullscreenOpaqueWindowState == null ?
2366 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2367 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2368 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2369 case ROTATION_ANIMATION_CROSSFADE:
2370 anim[0] = R.anim.rotation_animation_xfade_exit;
2371 anim[1] = R.anim.rotation_animation_enter;
2372 break;
2373 case ROTATION_ANIMATION_JUMPCUT:
2374 anim[0] = R.anim.rotation_animation_jump_exit;
2375 anim[1] = R.anim.rotation_animation_enter;
2376 break;
2377 case ROTATION_ANIMATION_ROTATE:
2378 default:
2379 anim[0] = anim[1] = 0;
2380 break;
2381 }
2382 } else {
2383 anim[0] = anim[1] = 0;
2384 }
2385 }
2386
2387 @Override
2388 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2389 boolean forceDefault) {
2390 switch (exitAnimId) {
2391 case R.anim.rotation_animation_xfade_exit:
2392 case R.anim.rotation_animation_jump_exit:
2393 // These are the only cases that matter.
2394 if (forceDefault) {
2395 return false;
2396 }
2397 int anim[] = new int[2];
2398 selectRotationAnimationLw(anim);
2399 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2400 default:
2401 return true;
2402 }
2403 }
2404
2405 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002406 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2407 boolean goingToNotificationShade) {
2408 if (goingToNotificationShade) {
2409 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002410 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002411
2412 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2413 R.anim.lock_screen_behind_enter_wallpaper :
2414 R.anim.lock_screen_behind_enter);
2415
2416 // TODO: Use XML interpolators when we have log interpolators available in XML.
2417 final List<Animation> animations = set.getAnimations();
2418 for (int i = animations.size() - 1; i >= 0; --i) {
2419 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2420 }
2421
2422 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002423 }
2424
2425
2426 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002427 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2428 if (goingToNotificationShade) {
2429 return null;
2430 } else {
2431 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2432 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002433 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002434
2435 private static void awakenDreams() {
2436 IDreamManager dreamManager = getDreamManager();
2437 if (dreamManager != null) {
2438 try {
2439 dreamManager.awaken();
2440 } catch (RemoteException e) {
2441 // fine, stay asleep then
2442 }
2443 }
2444 }
2445
2446 static IDreamManager getDreamManager() {
2447 return IDreamManager.Stub.asInterface(
2448 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2449 }
2450
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002451 TelecomManager getTelecommService() {
2452 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002453 }
2454
Jeff Brown4d396052010-10-29 21:50:21 -07002455 static IAudioService getAudioService() {
2456 IAudioService audioService = IAudioService.Stub.asInterface(
2457 ServiceManager.checkService(Context.AUDIO_SERVICE));
2458 if (audioService == null) {
2459 Log.w(TAG, "Unable to find IAudioService interface.");
2460 }
2461 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002462 }
2463
2464 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002465 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002466 }
2467
2468 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2469 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2470 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2471 };
2472
2473 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002474 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002475 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002476 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002477 final int keyCode = event.getKeyCode();
2478 final int repeatCount = event.getRepeatCount();
2479 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002480 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002481 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2482 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002483
Jeff Brown40013652012-05-16 21:22:36 -07002484 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002485 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002486 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2487 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002488 }
2489
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002490 // If we think we might have a volume down & power key chord on the way
2491 // but we're not sure, then tell the dispatcher to wait a little while and
2492 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002493 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002494 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002495 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002496 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2497 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002498 if (now < timeoutTime) {
2499 return timeoutTime - now;
2500 }
2501 }
2502 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002503 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002504 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002505 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002506 }
2507 return -1;
2508 }
2509 }
2510
Michael Wright6a62e552014-06-03 19:19:48 -07002511 // Cancel any pending meta actions if we see any other keys being pressed between the down
2512 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002513 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002514 mPendingMetaAction = false;
2515 }
2516
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002517 // First we always handle the home key here, so applications
2518 // can never break it, although if keyguard is on, we do let
2519 // it handle it, because that gives us the correct 5 second
2520 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002521 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002522
Jeff Brown49ed71d2010-12-06 17:13:33 -08002523 // If we have released the home key, and didn't do anything else
2524 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002525 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002526 cancelPreloadRecentApps();
2527
Jeff Brown49ed71d2010-12-06 17:13:33 -08002528 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002529 if (mHomeConsumed) {
2530 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002531 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002532 }
Jeff Browncaca8812013-05-09 13:34:33 -07002533
2534 if (canceled) {
2535 Log.i(TAG, "Ignoring HOME; event canceled.");
2536 return -1;
2537 }
2538
Yorke Lee4f803242014-12-15 23:22:06 +00002539 // If an incoming call is ringing, HOME is totally disabled.
2540 // (The user is already on the InCallUI at this point,
2541 // and his ONLY options are to answer or reject the call.)
2542 TelecomManager telecomManager = getTelecommService();
2543 if (telecomManager != null && telecomManager.isRinging()) {
2544 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2545 return -1;
2546 }
2547
Jeff Browncaca8812013-05-09 13:34:33 -07002548 // Delay handling home if a double-tap is possible.
2549 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2550 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2551 mHomeDoubleTapPending = true;
2552 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2553 ViewConfiguration.getDoubleTapTimeout());
2554 return -1;
2555 }
2556
Jeff Brown13f00f02014-10-31 14:45:50 -07002557 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002558 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002559 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002560
2561 // If a system window has focus, then it doesn't make sense
2562 // right now to interact with applications.
2563 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2564 if (attrs != null) {
2565 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002566 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2567 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2568 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002569 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002570 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002571 }
2572 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2573 for (int i=0; i<typeCount; i++) {
2574 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2575 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002576 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002577 }
2578 }
2579 }
Jeff Browncaca8812013-05-09 13:34:33 -07002580
2581 // Remember that home is pressed and handle special actions.
2582 if (repeatCount == 0) {
2583 mHomePressed = true;
2584 if (mHomeDoubleTapPending) {
2585 mHomeDoubleTapPending = false;
2586 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2587 handleDoubleTapOnHome();
2588 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2589 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2590 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002591 }
Jeff Browncaca8812013-05-09 13:34:33 -07002592 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2593 if (!keyguardOn) {
2594 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002595 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002596 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002597 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002598 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002599 // Hijack modified menu keys for debugging features
2600 final int chordBug = KeyEvent.META_SHIFT_ON;
2601
2602 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002603 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002604 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002605 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2606 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002607 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002608 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002609 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002610 Intent service = new Intent();
2611 service.setClassName(mContext, "com.android.server.LoadAverageService");
2612 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002613 boolean shown = Settings.Global.getInt(
2614 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002615 if (!shown) {
2616 mContext.startService(service);
2617 } else {
2618 mContext.stopService(service);
2619 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002620 Settings.Global.putInt(
2621 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002622 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002623 }
2624 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002625 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002626 if (down) {
2627 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002628 mSearchKeyShortcutPending = true;
2629 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002630 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002631 } else {
2632 mSearchKeyShortcutPending = false;
2633 if (mConsumeSearchKeyUp) {
2634 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002635 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002636 }
2637 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002638 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002639 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002640 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002641 if (down && repeatCount == 0) {
2642 preloadRecentApps();
2643 } else if (!down) {
2644 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002645 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002646 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002647 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002648 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2649 if (down) {
2650 if (repeatCount == 0) {
2651 mAssistKeyLongPressed = false;
2652 } else if (repeatCount == 1) {
2653 mAssistKeyLongPressed = true;
2654 if (!keyguardOn) {
2655 launchAssistLongPressAction();
2656 }
2657 }
2658 } else {
2659 if (mAssistKeyLongPressed) {
2660 mAssistKeyLongPressed = false;
2661 } else {
2662 if (!keyguardOn) {
2663 launchAssistAction();
2664 }
2665 }
2666 }
2667 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002668 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2669 if (!down) {
2670 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002671 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002672 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2673 } else {
2674 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002675 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002676 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002677 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002678 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002679 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2680 if (down && repeatCount == 0) {
2681 mHandler.post(mScreenshotRunnable);
2682 }
2683 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002684 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2685 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2686 if (down) {
2687 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2688
2689 // Disable autobrightness if it's on
2690 int auto = Settings.System.getIntForUser(
2691 mContext.getContentResolver(),
2692 Settings.System.SCREEN_BRIGHTNESS_MODE,
2693 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2694 UserHandle.USER_CURRENT_OR_SELF);
2695 if (auto != 0) {
2696 Settings.System.putIntForUser(mContext.getContentResolver(),
2697 Settings.System.SCREEN_BRIGHTNESS_MODE,
2698 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2699 UserHandle.USER_CURRENT_OR_SELF);
2700 }
2701
2702 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2703 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2704 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2705 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2706 Settings.System.SCREEN_BRIGHTNESS,
2707 mPowerManager.getDefaultScreenBrightnessSetting(),
2708 UserHandle.USER_CURRENT_OR_SELF);
2709 brightness += step;
2710 // Make sure we don't go beyond the limits.
2711 brightness = Math.min(max, brightness);
2712 brightness = Math.max(min, brightness);
2713
2714 Settings.System.putIntForUser(mContext.getContentResolver(),
2715 Settings.System.SCREEN_BRIGHTNESS, brightness,
2716 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002717 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002718 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002719 }
2720 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002721 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002722 if (down) {
2723 mPendingMetaAction = true;
2724 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002725 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002726 }
2727 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002728 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002729
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002730 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002731 // Any printing key that is chorded with Search should be consumed
2732 // even if no shortcut was invoked. This prevents text from being
2733 // inadvertently inserted when using a keyboard that has built-in macro
2734 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002735 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002736 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2737 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002738 mConsumeSearchKeyUp = true;
2739 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002740 if (down && repeatCount == 0 && !keyguardOn) {
2741 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2742 if (shortcutIntent != null) {
2743 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002744 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002745 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002746 } catch (ActivityNotFoundException ex) {
2747 Slog.w(TAG, "Dropping shortcut key combination because "
2748 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002749 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002750 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002751 } else {
2752 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002753 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002754 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002755 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002756 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002757 }
2758 }
2759
Jeff Brown68b909d2011-12-07 16:36:01 -08002760 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002761 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002762 && (metaState & KeyEvent.META_META_ON) != 0) {
2763 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002764 if (kcm.isPrintingKey(keyCode)) {
2765 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2766 metaState & ~(KeyEvent.META_META_ON
2767 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2768 if (shortcutIntent != null) {
2769 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2770 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002771 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002772 } catch (ActivityNotFoundException ex) {
2773 Slog.w(TAG, "Dropping shortcut key combination because "
2774 + "the activity to which it is registered was not found: "
2775 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2776 }
2777 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002778 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002779 }
2780 }
2781
Jeff Brown6651a632011-11-28 12:59:11 -08002782 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002783 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002784 String category = sApplicationLaunchKeyCategories.get(keyCode);
2785 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002786 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002787 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2788 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002789 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002790 } catch (ActivityNotFoundException ex) {
2791 Slog.w(TAG, "Dropping application launch key because "
2792 + "the activity to which it is registered was not found: "
2793 + "keyCode=" + keyCode + ", category=" + category, ex);
2794 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002795 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002796 }
2797 }
2798
Michael Wright61c46752014-08-21 16:57:33 -07002799 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002800 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002801 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002802 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002803 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002804 mRecentAppsHeldModifiers = shiftlessModifiers;
2805 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002806 return -1;
2807 }
2808 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002809 } else if (!down && mRecentAppsHeldModifiers != 0
2810 && (metaState & mRecentAppsHeldModifiers) == 0) {
2811 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002812 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002813 }
2814
Jeff Browncf39bdf2012-05-18 14:41:19 -07002815 // Handle keyboard language switching.
2816 if (down && repeatCount == 0
2817 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2818 || (keyCode == KeyEvent.KEYCODE_SPACE
2819 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2820 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2821 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2822 return -1;
2823 }
2824 if (mLanguageSwitchKeyPressed && !down
2825 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2826 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2827 mLanguageSwitchKeyPressed = false;
2828 return -1;
2829 }
2830
Jeff Brown13f00f02014-10-31 14:45:50 -07002831 if (isValidGlobalKey(keyCode)
2832 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002833 return -1;
2834 }
2835
Michael Wright6a62e552014-06-03 19:19:48 -07002836 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002837 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002838 return -1;
2839 }
2840
Jeff Brown68b909d2011-12-07 16:36:01 -08002841 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002842 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002843 }
2844
Jeff Brown3915bb82010-11-05 15:02:16 -07002845 /** {@inheritDoc} */
2846 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002847 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002848 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002849 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002850 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2851 + ", flags=" + event.getFlags()
2852 + ", keyCode=" + event.getKeyCode()
2853 + ", scanCode=" + event.getScanCode()
2854 + ", metaState=" + event.getMetaState()
2855 + ", repeatCount=" + event.getRepeatCount()
2856 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002857 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002858
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002859 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002860 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2861 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002862 final int keyCode = event.getKeyCode();
2863 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002864 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2865 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002866
Jeff Brown54875002011-04-06 15:33:01 -07002867 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002868 final FallbackAction fallbackAction;
2869 if (initialDown) {
2870 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2871 } else {
2872 fallbackAction = mFallbackActions.get(keyCode);
2873 }
2874
2875 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002876 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002877 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2878 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002879 }
2880
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002881 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2882 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002883 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002884 event.getAction(), fallbackAction.keyCode,
2885 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002886 event.getDeviceId(), event.getScanCode(),
2887 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002888
2889 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2890 fallbackEvent.recycle();
2891 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002892 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002893
2894 if (initialDown) {
2895 mFallbackActions.put(keyCode, fallbackAction);
2896 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2897 mFallbackActions.remove(keyCode);
2898 fallbackAction.recycle();
2899 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002900 }
2901 }
2902
Jeff Brown40013652012-05-16 21:22:36 -07002903 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002904 if (fallbackEvent == null) {
2905 Slog.d(TAG, "No fallback.");
2906 } else {
2907 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2908 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002909 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002910 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002911 }
2912
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002913 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002914 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002915 if ((actions & ACTION_PASS_TO_USER) != 0) {
2916 long delayMillis = interceptKeyBeforeDispatching(
2917 win, fallbackEvent, policyFlags);
2918 if (delayMillis == 0) {
2919 return true;
2920 }
2921 }
2922 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002923 }
2924
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002925 private void launchAssistLongPressAction() {
2926 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2927 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2928
2929 // launch the search activity
2930 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2931 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2932 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002933 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002934 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002935 SearchManager searchManager = getSearchManager();
2936 if (searchManager != null) {
2937 searchManager.stopSearch();
2938 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002939 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002940 } catch (ActivityNotFoundException e) {
2941 Slog.w(TAG, "No activity to handle assist long press action.", e);
2942 }
2943 }
2944
2945 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002946 launchAssistAction(null);
2947 }
2948
2949 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002950 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002951 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002952 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002953 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002954 if (hint != null) {
2955 intent.putExtra(hint, true);
2956 }
Jim Miller45308b12012-06-18 19:23:39 -07002957 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2958 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2959 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2960 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002961 startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002962 } catch (ActivityNotFoundException e) {
2963 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002964 }
2965 }
2966 }
2967
Bart Sears8b1c27c2015-03-18 23:51:02 +00002968 private void startActivityAsUser(Intent intent, UserHandle handle) {
2969 if (isUserSetupComplete()) {
2970 mContext.startActivityAsUser(intent, handle);
2971 } else {
2972 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
2973 }
2974 }
2975
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002976 private SearchManager getSearchManager() {
2977 if (mSearchManager == null) {
2978 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2979 }
2980 return mSearchManager;
2981 }
2982
Jeff Browncaca8812013-05-09 13:34:33 -07002983 private void preloadRecentApps() {
2984 mPreloadedRecentApps = true;
2985 try {
2986 IStatusBarService statusbar = getStatusBarService();
2987 if (statusbar != null) {
2988 statusbar.preloadRecentApps();
2989 }
2990 } catch (RemoteException e) {
2991 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2992 // re-acquire status bar service next time it is needed.
2993 mStatusBarService = null;
2994 }
2995 }
2996
2997 private void cancelPreloadRecentApps() {
2998 if (mPreloadedRecentApps) {
2999 mPreloadedRecentApps = false;
3000 try {
3001 IStatusBarService statusbar = getStatusBarService();
3002 if (statusbar != null) {
3003 statusbar.cancelPreloadRecentApps();
3004 }
3005 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003006 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003007 // re-acquire status bar service next time it is needed.
3008 mStatusBarService = null;
3009 }
3010 }
3011 }
3012
3013 private void toggleRecentApps() {
3014 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003015 try {
3016 IStatusBarService statusbar = getStatusBarService();
3017 if (statusbar != null) {
3018 statusbar.toggleRecentApps();
3019 }
3020 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003021 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3022 // re-acquire status bar service next time it is needed.
3023 mStatusBarService = null;
3024 }
3025 }
3026
Craig Mautner84984fa2014-06-19 11:19:20 -07003027 @Override
3028 public void showRecentApps() {
3029 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3030 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3031 }
3032
Winson Chung1e8d71b2014-05-16 17:05:22 -07003033 private void showRecentApps(boolean triggeredFromAltTab) {
3034 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3035 try {
3036 IStatusBarService statusbar = getStatusBarService();
3037 if (statusbar != null) {
3038 statusbar.showRecentApps(triggeredFromAltTab);
3039 }
3040 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003041 Slog.e(TAG, "RemoteException when showing recent apps", e);
3042 // re-acquire status bar service next time it is needed.
3043 mStatusBarService = null;
3044 }
3045 }
3046
Winson Chungcdcd4872014-08-05 18:00:13 -07003047 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003048 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3049 try {
3050 IStatusBarService statusbar = getStatusBarService();
3051 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003052 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003053 }
3054 } catch (RemoteException e) {
3055 Slog.e(TAG, "RemoteException when closing recent apps", e);
3056 // re-acquire status bar service next time it is needed.
3057 mStatusBarService = null;
3058 }
3059 }
3060
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003061 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003062 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003063 }
3064
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003065 /**
3066 * A home key -> launch home action was detected. Take the appropriate action
3067 * given the situation with the keyguard.
3068 */
Bryce Lee662ed802015-04-10 20:11:39 +00003069 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3070 if (respectKeyguard) {
3071 if (isKeyguardShowingAndNotOccluded()) {
3072 // don't launch home if keyguard showing
3073 return;
3074 }
3075
3076 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3077 // when in keyguard restricted mode, must first verify unlock
3078 // before launching home
3079 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3080 @Override
3081 public void onKeyguardExitResult(boolean success) {
3082 if (success) {
3083 try {
3084 ActivityManagerNative.getDefault().stopAppSwitches();
3085 } catch (RemoteException e) {
3086 }
3087 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3088 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003089 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003090 }
Bryce Lee662ed802015-04-10 20:11:39 +00003091 });
3092 return;
3093 }
3094 }
3095
3096 // no keyguard stuff to worry about, just launch home!
3097 try {
3098 ActivityManagerNative.getDefault().stopAppSwitches();
3099 } catch (RemoteException e) {
3100 }
3101 if (mRecentsVisible) {
3102 // Hide Recents and notify it to launch Home
3103 if (awakenFromDreams) {
3104 awakenDreams();
3105 }
3106 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3107 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003108 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003109 // Otherwise, just launch Home
3110 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3111 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003112 }
3113 }
3114
John Spurlock04db1762013-05-13 12:46:41 -04003115 private final Runnable mClearHideNavigationFlag = new Runnable() {
3116 @Override
3117 public void run() {
3118 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3119 // Clear flags.
3120 mForceClearedSystemUiFlags &=
3121 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3122 }
3123 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003124 }
3125 };
3126
3127 /**
3128 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3129 * to determine when the nav bar should be shown and prevent applications from
3130 * receiving those touches.
3131 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003132 final class HideNavInputEventReceiver extends InputEventReceiver {
3133 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3134 super(inputChannel, looper);
3135 }
3136
Dianne Hackborndf89e652011-10-06 22:35:11 -07003137 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003138 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003139 boolean handled = false;
3140 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003141 if (event instanceof MotionEvent
3142 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3143 final MotionEvent motionEvent = (MotionEvent)event;
3144 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003145 // When the user taps down, we re-show the nav bar.
3146 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003147 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003148 // Any user activity always causes us to show the
3149 // navigation controls, if they had been hidden.
3150 // We also clear the low profile and only content
3151 // flags so that tapping on the screen will atomically
3152 // restore all currently hidden screen decorations.
3153 int newVal = mResettingSystemUiFlags |
3154 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3155 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3156 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003157 if (mResettingSystemUiFlags != newVal) {
3158 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003159 changed = true;
3160 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003161 // We don't allow the system's nav bar to be hidden
3162 // again for 1 second, to prevent applications from
3163 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003164 newVal = mForceClearedSystemUiFlags |
3165 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003166 if (mForceClearedSystemUiFlags != newVal) {
3167 mForceClearedSystemUiFlags = newVal;
3168 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003169 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003170 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003171 }
3172 if (changed) {
3173 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3174 }
3175 }
3176 }
3177 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003178 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003179 }
3180 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003181 }
3182 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3183 new InputEventReceiver.Factory() {
3184 @Override
3185 public InputEventReceiver createInputEventReceiver(
3186 InputChannel inputChannel, Looper looper) {
3187 return new HideNavInputEventReceiver(inputChannel, looper);
3188 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003189 };
3190
3191 @Override
3192 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003193 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3194 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003195 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003196
Dianne Hackborndf89e652011-10-06 22:35:11 -07003197 // Reset any bits in mForceClearingStatusBarVisibility that
3198 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003199 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003200 // Clear any bits in the new visibility that are currently being
3201 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003202 return visibility & ~mResettingSystemUiFlags
3203 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003204 }
3205
Craig Mautner69b08182012-09-05 13:07:13 -07003206 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003207 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3208 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003209 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003210 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3211 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003212
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003213 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003214 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003215 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003216 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003217 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003218 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3219 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3220 } else {
3221 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3222 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3223 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003224 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3225 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003226 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003227 availRight - mStableFullscreenRight,
3228 availBottom - mStableFullscreenBottom);
3229 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003230 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003231 availRight - mStableRight, availBottom - mStableBottom);
3232 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003233 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003234 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003235 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003236 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003237 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003238 availRight - mCurRight, availBottom - mCurBottom);
3239 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003240 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003241 availRight - mCurRight, availBottom - mCurBottom);
3242 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003243
3244 outStableInsets.set(mStableLeft, mStableTop,
3245 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003246 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003247 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003248 outContentInsets.setEmpty();
3249 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003250 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003251
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003252 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003253 @Override
3254 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3255 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003256 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3257 if (isDefaultDisplay) {
3258 switch (displayRotation) {
3259 case Surface.ROTATION_90:
3260 overscanLeft = mOverscanTop;
3261 overscanTop = mOverscanRight;
3262 overscanRight = mOverscanBottom;
3263 overscanBottom = mOverscanLeft;
3264 break;
3265 case Surface.ROTATION_180:
3266 overscanLeft = mOverscanRight;
3267 overscanTop = mOverscanBottom;
3268 overscanRight = mOverscanLeft;
3269 overscanBottom = mOverscanTop;
3270 break;
3271 case Surface.ROTATION_270:
3272 overscanLeft = mOverscanBottom;
3273 overscanTop = mOverscanLeft;
3274 overscanRight = mOverscanTop;
3275 overscanBottom = mOverscanRight;
3276 break;
3277 default:
3278 overscanLeft = mOverscanLeft;
3279 overscanTop = mOverscanTop;
3280 overscanRight = mOverscanRight;
3281 overscanBottom = mOverscanBottom;
3282 break;
3283 }
3284 } else {
3285 overscanLeft = 0;
3286 overscanTop = 0;
3287 overscanRight = 0;
3288 overscanBottom = 0;
3289 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003290 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3291 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3292 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3293 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003294 mSystemLeft = 0;
3295 mSystemTop = 0;
3296 mSystemRight = displayWidth;
3297 mSystemBottom = displayHeight;
3298 mUnrestrictedScreenLeft = overscanLeft;
3299 mUnrestrictedScreenTop = overscanTop;
3300 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3301 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3302 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3303 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003304 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3305 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003306 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003307 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003308 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003309 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003310 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003311 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003312 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003313 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003314 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003315 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003316
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003317 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3318 final Rect pf = mTmpParentFrame;
3319 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003320 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003321 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003322 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003323 pf.left = df.left = of.left = vf.left = mDockLeft;
3324 pf.top = df.top = of.top = vf.top = mDockTop;
3325 pf.right = df.right = of.right = vf.right = mDockRight;
3326 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003327 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003328
Craig Mautner69b08182012-09-05 13:07:13 -07003329 if (isDefaultDisplay) {
3330 // For purposes of putting out fake window up to steal focus, we will
3331 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003332 final int sysui = mLastSystemUiFlags;
3333 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003334 boolean navTranslucent = (sysui
3335 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003336 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3337 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3338 boolean navAllowedHidden = immersive || immersiveSticky;
3339 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003340 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3341 if (!isKeyguardShowing) {
3342 navTranslucent &= areTranslucentBarsAllowed();
3343 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003344
Craig Mautner69b08182012-09-05 13:07:13 -07003345 // When the navigation bar isn't visible, we put up a fake
3346 // input window to catch all touch events. This way we can
3347 // detect when the user presses anywhere to bring back the nav
3348 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003349 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07003350 if (mHideNavFakeWindow != null) {
3351 mHideNavFakeWindow.dismiss();
3352 mHideNavFakeWindow = null;
3353 }
3354 } else if (mHideNavFakeWindow == null) {
3355 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
3356 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07003357 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07003358 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003359 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003360
Craig Mautner69b08182012-09-05 13:07:13 -07003361 // For purposes of positioning and showing the nav bar, if we have
3362 // decided that it can't be hidden (because of the screen aspect ratio),
3363 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003364 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003365
John Spurlockad3e6cb2013-04-30 08:47:43 -04003366 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003367 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003368 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003369 // Force the navigation bar to its appropriate place and
3370 // size. We need to do this directly, instead of relying on
3371 // it to bubble up from the nav bar, because this needs to
3372 // change atomically with screen rotations.
3373 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3374 if (mNavigationBarOnBottom) {
3375 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003376 int top = displayHeight - overscanBottom
3377 - mNavigationBarHeightForRotation[displayRotation];
3378 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003379 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003380 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003381 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003382 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003383 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003384 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003385 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3386 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003387 } else {
3388 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003389 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003390 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003391 if (navVisible && !navTranslucent && !navAllowedHidden
3392 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003393 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003394 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003395 // and not in the process of animating on or off, then
3396 // we can tell the app that it is covered by it.
3397 mSystemBottom = mTmpNavigationFrame.top;
3398 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003399 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003400 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003401 int left = displayWidth - overscanRight
3402 - mNavigationBarWidthForRotation[displayRotation];
3403 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003404 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003405 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003406 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003407 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003408 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003409 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003410 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3411 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003412 } else {
3413 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003414 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003415 }
John Spurlockbd957402013-10-03 11:38:39 -04003416 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3417 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003418 // If the nav bar is currently requested to be visible,
3419 // and not in the process of animating on or off, then
3420 // we can tell the app that it is covered by it.
3421 mSystemRight = mTmpNavigationFrame.left;
3422 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003423 }
Craig Mautner69b08182012-09-05 13:07:13 -07003424 // Make sure the content and current rectangles are updated to
3425 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003426 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3427 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3428 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3429 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003430 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3431 // And compute the final frame.
3432 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003433 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3434 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003435 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003436 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003437 updateSysUiVisibility = true;
3438 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003439 }
Craig Mautnereda67292013-04-28 13:50:14 -07003440 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003441 mDockLeft, mDockTop, mDockRight, mDockBottom));
3442
3443 // decide where the status bar goes ahead of time
3444 if (mStatusBar != null) {
3445 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003446 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3447 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3448 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3449 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3450 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003451 vf.left = mStableLeft;
3452 vf.top = mStableTop;
3453 vf.right = mStableRight;
3454 vf.bottom = mStableBottom;
3455
3456 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3457
3458 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003459 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003460
3461 // For layout, the status bar is always at the top with our fixed height.
3462 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3463
John Spurlocke1f366f2013-08-05 12:22:40 -04003464 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003465 boolean statusBarTranslucent = (sysui
3466 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003467 if (!isKeyguardShowing) {
3468 statusBarTranslucent &= areTranslucentBarsAllowed();
3469 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003470
Craig Mautner69b08182012-09-05 13:07:13 -07003471 // If the status bar is hidden, we don't want to cause
3472 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003473 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003474 // Status bar may go away, so the screen area it occupies
3475 // is available to apps but just covering them when the
3476 // status bar is visible.
3477 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3478
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003479 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3480 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3481 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3482 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003483
Craig Mautnereda67292013-04-28 13:50:14 -07003484 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003485 String.format(
3486 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3487 mDockLeft, mDockTop, mDockRight, mDockBottom,
3488 mContentLeft, mContentTop, mContentRight, mContentBottom,
3489 mCurLeft, mCurTop, mCurRight, mCurBottom));
3490 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003491 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003492 && !statusBarTransient && !statusBarTranslucent
3493 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003494 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003495 // and not in the process of animating on or off, then
3496 // we can tell the app that it is covered by it.
3497 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3498 }
John Spurlock27735a42013-08-14 17:57:38 -04003499 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003500 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003501 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003502 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003503 if (updateSysUiVisibility) {
3504 updateSystemUiVisibilityLw();
3505 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003506 }
3507 }
3508
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003509 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003510 @Override
John Spurlock46646232013-09-30 22:32:42 -04003511 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003512 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3513 return mStatusBar.getSurfaceLayer();
3514 }
3515
3516 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3517 return mNavigationBar.getSurfaceLayer();
3518 }
3519
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003520 return 0;
3521 }
3522
Craig Mautner967212c2013-04-13 21:10:58 -07003523 @Override
3524 public void getContentRectLw(Rect r) {
3525 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3526 }
3527
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003528 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3529 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003530 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3531 // Here's a special case: if this attached window is a panel that is
3532 // above the dock window, and the window it is attached to is below
3533 // the dock window, then the frames we computed for the window it is
3534 // attached to can not be used because the dock is effectively part
3535 // of the underlying window and the attached window is floating on top
3536 // of the whole thing. So, we ignore the attached window and explicitly
3537 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003538 df.left = of.left = cf.left = vf.left = mDockLeft;
3539 df.top = of.top = cf.top = vf.top = mDockTop;
3540 df.right = of.right = cf.right = vf.right = mDockRight;
3541 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003542 } else {
3543 // The effective display frame of the attached window depends on
3544 // whether it is taking care of insetting its content. If not,
3545 // we need to use the parent's content frame so that the entire
3546 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003547 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003548 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003549 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003550 // Set the content frame of the attached window to the parent's decor frame
3551 // (same as content frame when IME isn't present) if specifically requested by
3552 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3553 // Otherwise, use the overscan frame.
3554 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3555 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003556 } else {
3557 // If the window is resizing, then we want to base the content
3558 // frame on our attached content frame to resize... however,
3559 // things can be tricky if the attached window is NOT in resize
3560 // mode, in which case its content frame will be larger.
3561 // Ungh. So to deal with that, make sure the content frame
3562 // we end up using is not covering the IM dock.
3563 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003564 if (attached.isVoiceInteraction()) {
3565 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3566 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3567 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3568 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3569 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003570 if (cf.left < mContentLeft) cf.left = mContentLeft;
3571 if (cf.top < mContentTop) cf.top = mContentTop;
3572 if (cf.right > mContentRight) cf.right = mContentRight;
3573 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3574 }
3575 }
3576 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003577 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003578 vf.set(attached.getVisibleFrameLw());
3579 }
3580 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3581 // window should be positioned relative to its parent or the entire
3582 // screen.
3583 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3584 ? attached.getFrameLw() : df);
3585 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003586
3587 private void applyStableConstraints(int sysui, int fl, Rect r) {
3588 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3589 // If app is requesting a stable layout, don't let the
3590 // content insets go below the stable values.
3591 if ((fl & FLAG_FULLSCREEN) != 0) {
3592 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3593 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3594 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3595 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3596 } else {
3597 if (r.left < mStableLeft) r.left = mStableLeft;
3598 if (r.top < mStableTop) r.top = mStableTop;
3599 if (r.right > mStableRight) r.right = mStableRight;
3600 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3601 }
3602 }
3603 }
3604
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003605 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003606 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003607 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003608 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003609 final WindowManager.LayoutParams attrs = win.getAttrs();
3610 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3611 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003612 return;
3613 }
Craig Mautner69b08182012-09-05 13:07:13 -07003614 final boolean isDefaultDisplay = win.isDefaultDisplay();
3615 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003616 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3617 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003618 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003619 offsetInputMethodWindowLw(mLastInputMethodWindow);
3620 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003621
John Spurlockc6d1c602014-01-17 15:22:06 -05003622 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003623 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003624 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003625
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003626 final Rect pf = mTmpParentFrame;
3627 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003628 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003629 final Rect cf = mTmpContentFrame;
3630 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003631 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003632 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003633 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003634
3635 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003636 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003637
Craig Mautnerf683b562012-10-02 11:10:57 -07003638 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3639
Adrian Roosfa104232014-06-20 16:10:14 -07003640 if (isDefaultDisplay) {
3641 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3642 } else {
3643 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3644 }
3645
Craig Mautner69b08182012-09-05 13:07:13 -07003646 if (!isDefaultDisplay) {
3647 if (attached != null) {
3648 // If this window is attached to another, our display
3649 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003650 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003651 } else {
3652 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003653 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3654 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3655 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003656 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003657 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003658 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003659 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003660 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003661 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3662 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3663 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003664 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003665 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003666 // ...with content insets above the nav bar
3667 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003668 // IM dock windows always go to the bottom of the screen.
3669 attrs.gravity = Gravity.BOTTOM;
3670 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003671 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
3672 pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft;
3673 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3674 pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft
3675 + mUnrestrictedScreenWidth;
3676 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3677 + mUnrestrictedScreenHeight;
3678 cf.bottom = vf.bottom = mStableBottom;
3679 cf.top = vf.top = mStableTop;
Jorim Jaggie0700182014-08-21 01:12:37 +02003680 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3681 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3682 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3683 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3684 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3685 cf.left = vf.left = mStableLeft;
3686 cf.top = vf.top = mStableTop;
3687 cf.right = vf.right = mStableRight;
3688 vf.bottom = mStableBottom;
3689 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003690 } else {
John Spurlock46646232013-09-30 22:32:42 -04003691
3692 // Default policy decor for the default display
3693 dcf.left = mSystemLeft;
3694 dcf.top = mSystemTop;
3695 dcf.right = mSystemRight;
3696 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003697 final boolean inheritTranslucentDecor = (attrs.privateFlags
3698 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003699 final boolean isAppWindow =
3700 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3701 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3702 final boolean topAtRest =
3703 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3704 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003705 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3706 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003707 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3708 && (fl & WindowManager.LayoutParams.
3709 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003710 // Ensure policy decor includes status bar
3711 dcf.top = mStableTop;
3712 }
John Spurlockbd957402013-10-03 11:38:39 -04003713 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003714 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3715 && (fl & WindowManager.LayoutParams.
3716 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003717 // Ensure policy decor includes navigation bar
3718 dcf.bottom = mStableBottom;
3719 dcf.right = mStableRight;
3720 }
3721 }
3722
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003723 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3724 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003725 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003726 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003727 // This is the case for a normal activity window: we want it
3728 // to cover all of the screen space, and it can take care of
3729 // moving its contents to account for screen decorations that
3730 // intrude into that space.
3731 if (attached != null) {
3732 // If this window is attached to another, our display
3733 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003734 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003735 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003736 if (attrs.type == TYPE_STATUS_BAR_PANEL
3737 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003738 // Status bar panels are the only windows who can go on top of
3739 // the status bar. They are protected by the STATUS_BAR_SERVICE
3740 // permission, so they have the same privileges as the status
3741 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003742 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003743 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003744
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003745 pf.left = df.left = of.left = hasNavBar
3746 ? mDockLeft : mUnrestrictedScreenLeft;
3747 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3748 pf.right = df.right = of.right = hasNavBar
3749 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3750 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3751 pf.bottom = df.bottom = of.bottom = hasNavBar
3752 ? mRestrictedScreenTop+mRestrictedScreenHeight
3753 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003754
Craig Mautnereda67292013-04-28 13:50:14 -07003755 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003756 "Laying out status bar window: (%d,%d - %d,%d)",
3757 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003758 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003759 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3760 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3761 // Asking to layout into the overscan region, so give it that pure
3762 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003763 pf.left = df.left = of.left = mOverscanScreenLeft;
3764 pf.top = df.top = of.top = mOverscanScreenTop;
3765 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3766 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3767 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003768 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003769 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003770 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3771 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003772 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003773 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003774 // only do this for application windows to ensure no window that
3775 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003776 pf.left = df.left = mOverscanScreenLeft;
3777 pf.top = df.top = mOverscanScreenTop;
3778 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3779 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003780 // We need to tell the app about where the frame inside the overscan
3781 // is, so it can inset its content by that amount -- it didn't ask
3782 // to actually extend itself into the overscan region.
3783 of.left = mUnrestrictedScreenLeft;
3784 of.top = mUnrestrictedScreenTop;
3785 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3786 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003787 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003788 pf.left = df.left = mRestrictedOverscanScreenLeft;
3789 pf.top = df.top = mRestrictedOverscanScreenTop;
3790 pf.right = df.right = mRestrictedOverscanScreenLeft
3791 + mRestrictedOverscanScreenWidth;
3792 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3793 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003794 // We need to tell the app about where the frame inside the overscan
3795 // is, so it can inset its content by that amount -- it didn't ask
3796 // to actually extend itself into the overscan region.
3797 of.left = mUnrestrictedScreenLeft;
3798 of.top = mUnrestrictedScreenTop;
3799 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3800 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003801 }
Craig Mautner69b08182012-09-05 13:07:13 -07003802
John Spurlock46646232013-09-30 22:32:42 -04003803 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003804 if (win.isVoiceInteraction()) {
3805 cf.left = mVoiceContentLeft;
3806 cf.top = mVoiceContentTop;
3807 cf.right = mVoiceContentRight;
3808 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003809 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003810 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3811 cf.left = mDockLeft;
3812 cf.top = mDockTop;
3813 cf.right = mDockRight;
3814 cf.bottom = mDockBottom;
3815 } else {
3816 cf.left = mContentLeft;
3817 cf.top = mContentTop;
3818 cf.right = mContentRight;
3819 cf.bottom = mContentBottom;
3820 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003821 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003822 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003823 // Full screen windows are always given a layout that is as if the
3824 // status bar and other transient decors are gone. This is to avoid
3825 // bad states when moving from a window that is not hding the
3826 // status bar to one that is.
3827 cf.left = mRestrictedScreenLeft;
3828 cf.top = mRestrictedScreenTop;
3829 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3830 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003831 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003832 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003833 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3834 vf.left = mCurLeft;
3835 vf.top = mCurTop;
3836 vf.right = mCurRight;
3837 vf.bottom = mCurBottom;
3838 } else {
3839 vf.set(cf);
3840 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003841 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003842 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3843 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3844 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003845 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3846 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003847 // A window that has requested to fill the entire screen just
3848 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003849 if (attrs.type == TYPE_STATUS_BAR_PANEL
3850 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003851 pf.left = df.left = of.left = cf.left = hasNavBar
3852 ? mDockLeft : mUnrestrictedScreenLeft;
3853 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3854 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003855 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003856 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003857 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003858 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003859 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003860 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003861 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3862 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003863 } else if (attrs.type == TYPE_NAVIGATION_BAR
3864 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003865 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003866 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3867 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3868 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3869 + mUnrestrictedScreenWidth;
3870 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3871 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003872 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003873 "Laying out navigation bar window: (%d,%d - %d,%d)",
3874 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003875 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3876 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003877 && ((fl & FLAG_FULLSCREEN) != 0)) {
3878 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003879 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3880 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3881 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3882 + mOverscanScreenWidth;
3883 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3884 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003885 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003886 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003887 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3888 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3889 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3890 + mOverscanScreenWidth;
3891 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3892 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003893 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003894 // The wallpaper also has Real Ultimate Power, but we want to tell
3895 // it about the overscan area.
3896 pf.left = df.left = mOverscanScreenLeft;
3897 pf.top = df.top = mOverscanScreenTop;
3898 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3899 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3900 of.left = cf.left = mUnrestrictedScreenLeft;
3901 of.top = cf.top = mUnrestrictedScreenTop;
3902 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3903 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003904 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003905 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3906 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3907 // Asking to layout into the overscan region, so give it that pure
3908 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003909 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3910 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3911 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003912 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003913 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003914 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003915 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003916 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003917 && (attrs.type == TYPE_STATUS_BAR
3918 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07003919 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04003920 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3921 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003922 // Asking for layout as if the nav bar is hidden, lets the
3923 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003924 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003925 // can be above the nav bar can do this.
3926 // XXX This assumes that an app asking for this will also
3927 // ask for layout in only content. We can't currently figure out
3928 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003929 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3930 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3931 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3932 + mUnrestrictedScreenWidth;
3933 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3934 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003935 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003936 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3937 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3938 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3939 + mRestrictedScreenWidth;
3940 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3941 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003942 }
Craig Mautner69b08182012-09-05 13:07:13 -07003943
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003944 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003945
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003946 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3947 vf.left = mCurLeft;
3948 vf.top = mCurTop;
3949 vf.right = mCurRight;
3950 vf.bottom = mCurBottom;
3951 } else {
3952 vf.set(cf);
3953 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003954 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003955 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3956 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003957 // A child window should be placed inside of the same visible
3958 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003959 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003960 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003961 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3962 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003963 // Otherwise, a normal window must be placed inside the content
3964 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003965 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3966 // Status bar panels are the only windows who can go on top of
3967 // the status bar. They are protected by the STATUS_BAR_SERVICE
3968 // permission, so they have the same privileges as the status
3969 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003970 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3971 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3972 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3973 + mRestrictedScreenWidth;
3974 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3975 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003976 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3977 || attrs.type == TYPE_VOLUME_OVERLAY) {
3978 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003979 pf.left = df.left = of.left = cf.left = mStableLeft;
3980 pf.top = df.top = of.top = cf.top = mStableTop;
3981 pf.right = df.right = of.right = cf.right = mStableRight;
3982 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003983 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003984 pf.left = mContentLeft;
3985 pf.top = mContentTop;
3986 pf.right = mContentRight;
3987 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003988 if (win.isVoiceInteraction()) {
3989 df.left = of.left = cf.left = mVoiceContentLeft;
3990 df.top = of.top = cf.top = mVoiceContentTop;
3991 df.right = of.right = cf.right = mVoiceContentRight;
3992 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3993 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003994 df.left = of.left = cf.left = mDockLeft;
3995 df.top = of.top = cf.top = mDockTop;
3996 df.right = of.right = cf.right = mDockRight;
3997 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003998 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003999 df.left = of.left = cf.left = mContentLeft;
4000 df.top = of.top = cf.top = mContentTop;
4001 df.right = of.right = cf.right = mContentRight;
4002 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004003 }
4004 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4005 vf.left = mCurLeft;
4006 vf.top = mCurTop;
4007 vf.right = mCurRight;
4008 vf.bottom = mCurBottom;
4009 } else {
4010 vf.set(cf);
4011 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004012 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004013 }
4014 }
Craig Mautner69b08182012-09-05 13:07:13 -07004015
Craig Mautnerb816bed2013-07-23 10:26:17 -07004016 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4017 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004018 df.left = df.top = -10000;
4019 df.right = df.bottom = 10000;
4020 if (attrs.type != TYPE_WALLPAPER) {
4021 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4022 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4023 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004024 }
4025
Craig Mautnereda67292013-04-28 13:50:14 -07004026 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004027 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004028 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004029 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004030 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004031 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004032 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004033 + " dcf=" + dcf.toShortString()
4034 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07004035
Adrian Roosfa104232014-06-20 16:10:14 -07004036 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07004037
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004038 // Dock windows carve out the bottom of the screen, so normal windows
4039 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004040 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4041 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004042 setLastInputMethodWindowLw(null, null);
4043 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004044 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004045 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4046 && !win.getGivenInsetsPendingLw()) {
4047 offsetVoiceInputWindowLw(win);
4048 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004049 }
4050
satok1bc0a492012-04-25 22:47:12 +09004051 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004052 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004053 top += win.getGivenContentInsetsLw().top;
4054 if (mContentBottom > top) {
4055 mContentBottom = top;
4056 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004057 if (mVoiceContentBottom > top) {
4058 mVoiceContentBottom = top;
4059 }
satok1bc0a492012-04-25 22:47:12 +09004060 top = win.getVisibleFrameLw().top;
4061 top += win.getGivenVisibleInsetsLw().top;
4062 if (mCurBottom > top) {
4063 mCurBottom = top;
4064 }
Craig Mautnereda67292013-04-28 13:50:14 -07004065 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004066 + mDockBottom + " mContentBottom="
4067 + mContentBottom + " mCurBottom=" + mCurBottom);
4068 }
4069
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004070 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004071 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004072 top += win.getGivenContentInsetsLw().top;
4073 if (mVoiceContentBottom > top) {
4074 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004075 }
4076 }
4077
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004078 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004079 @Override
4080 public void finishLayoutLw() {
4081 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004082 }
4083
4084 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004085 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004086 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004087 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004088 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004089 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004090 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004091 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004092 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004093 mForcingShowNavBar = false;
4094 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004095
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004096 mHideLockScreen = false;
4097 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004098 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004099 mShowingLockscreen = false;
4100 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004101 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004102 mKeyguardSecure = isKeyguardSecure();
4103 mKeyguardSecureIncludingHidden = mKeyguardSecure
4104 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004105 }
4106
4107 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004108 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004109 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004110 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4111 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004112 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004113 if (mTopFullscreenOpaqueWindowState == null
4114 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4115 mForcingShowNavBar = true;
4116 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004117 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004118 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004119 mForceStatusBarFromKeyguard = true;
4120 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004121 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004122 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004123 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004124 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004125 mForceStatusBarFromKeyguard = true;
4126 } else {
4127 mForceStatusBar = true;
4128 }
4129 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004130 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004131 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004132 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004133 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Craig Mautner7d7808f2014-09-11 18:02:38 -07004134 && attrs.type < FIRST_SYSTEM_WINDOW;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004135 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004136 // If the lockscreen was showing when the dream started then wait
4137 // for the dream to draw before hiding the lockscreen.
4138 if (!mDreamingLockscreen
4139 || (win.isVisibleLw() && win.hasDrawnLw())) {
4140 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004141 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004142 }
4143 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004144
Craig Mautner00156ec2014-03-06 22:29:02 -08004145 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07004146 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerab55e522014-03-03 13:26:03 -08004147 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004148 final IApplicationToken appToken = win.getAppToken();
4149 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004150 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004151 mAppsToBeHidden.remove(appToken);
4152 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004153 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004154 if (dismissKeyguard && !mKeyguardSecure) {
4155 mAppsThatDismissKeyguard.add(appToken);
4156 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004157 mWinShowWhenLocked = win;
4158 mHideLockScreen = true;
4159 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004160 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004161 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004162 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004163 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004164 mAppsToBeHidden.add(appToken);
4165 } else {
4166 mAppsToBeHidden.remove(appToken);
4167 }
4168 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004169 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004170 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004171 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004172 if (attrs.x == 0 && attrs.y == 0
4173 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4174 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4175 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4176 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004177 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4178 mTopFullscreenOpaqueOrDimmingWindowState = win;
4179 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004180 if (!mAppsThatDismissKeyguard.isEmpty() &&
4181 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4182 if (DEBUG_LAYOUT) Slog.v(TAG,
4183 "Setting mDismissKeyguard true by win " + win);
4184 mDismissKeyguard = mWinDismissingKeyguard == win ?
4185 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
4186 mWinDismissingKeyguard = win;
Jim Millerab954542014-10-10 18:21:49 -07004187 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004188 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4189 if (DEBUG_LAYOUT) Slog.v(TAG,
4190 "Setting mHideLockScreen to true by win " + win);
4191 mHideLockScreen = true;
4192 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004193 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004194 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004195 mAllowLockscreenWhenOn = true;
4196 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004197 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004198
4199 if (mWinShowWhenLocked != null &&
4200 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
4201 win.hideLw(false);
4202 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004203 }
4204 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004205 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4206 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4207 && win.isDimming()) {
4208 mTopFullscreenOpaqueOrDimmingWindowState = win;
4209 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004210 }
4211
4212 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004213 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004214 public int finishPostLayoutPolicyLw() {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004215 if (mWinShowWhenLocked != null &&
4216 mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) {
4217 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4218 // fullscreen window.
4219 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4220 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4221 mTopFullscreenOpaqueWindowState.hideLw(false);
4222 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4223 }
4224
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004225 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004226 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004227
4228 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4229 ? mTopFullscreenOpaqueWindowState.getAttrs()
4230 : null;
4231
Jeff Brownc8018eb2012-10-29 21:33:27 -07004232 // If we are not currently showing a dream then remember the current
4233 // lockscreen state. We will use this to determine whether the dream
4234 // started while the lockscreen was showing and remember this state
4235 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004236 if (!mShowingDream) {
4237 mDreamingLockscreen = mShowingLockscreen;
4238 }
4239
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004240 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004241 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004242 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004243 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004244 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07004245 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004246 if (mStatusBarController.setBarShowingLw(true)) {
4247 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4248 }
Craig Mautner81defc72013-10-29 11:10:42 -07004249 // Maintain fullscreen layout until incoming animation is complete.
4250 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004251 // Transient status bar on the lockscreen is not allowed
4252 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4253 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4254 mLastSystemUiFlags, mLastSystemUiFlags);
4255 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004256 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004257 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004258 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004259 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004260 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004261 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004262 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004263 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004264 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004265 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004266 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004267 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004268 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4269 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004270 if (mStatusBarController.isTransientShowing()) {
4271 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004272 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4273 }
4274 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004275 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004276 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004277 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004278 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004279 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004280 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004281 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004282 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004283 if (mStatusBarController.setBarShowingLw(true)) {
4284 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4285 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004286 }
4287 }
4288 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004289
Craig Mautner81defc72013-10-29 11:10:42 -07004290 if (mTopIsFullscreen != topIsFullscreen) {
4291 if (!topIsFullscreen) {
4292 // Force another layout when status bar becomes fully shown.
4293 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4294 }
4295 mTopIsFullscreen = topIsFullscreen;
4296 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004297
Craig Mautner39834192012-09-02 07:47:24 -07004298 // Hide the key guard if a visible window explicitly specifies that it wants to be
4299 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004300 if (mKeyguardDelegate != null && mStatusBar != null) {
4301 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4302 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004303 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004304 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004305 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004306 changes |= FINISH_LAYOUT_REDO_LAYOUT
4307 | FINISH_LAYOUT_REDO_CONFIG
4308 | FINISH_LAYOUT_REDO_WALLPAPER;
4309 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004310 if (mKeyguardDelegate.isShowing()) {
4311 mHandler.post(new Runnable() {
4312 @Override
4313 public void run() {
4314 mKeyguardDelegate.keyguardDone(false, false);
4315 }
4316 });
4317 }
4318 } else if (mHideLockScreen) {
4319 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004320 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004321 changes |= FINISH_LAYOUT_REDO_LAYOUT
4322 | FINISH_LAYOUT_REDO_CONFIG
4323 | FINISH_LAYOUT_REDO_WALLPAPER;
4324 }
4325 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
4326 // This is the case of keyguard isSecure() and not mHideLockScreen.
4327 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4328 // Only launch the next keyguard unlock window once per window.
4329 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004330 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004331 changes |= FINISH_LAYOUT_REDO_LAYOUT
4332 | FINISH_LAYOUT_REDO_CONFIG
4333 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004334 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004335 mHandler.post(new Runnable() {
4336 @Override
4337 public void run() {
4338 mKeyguardDelegate.dismiss();
4339 }
4340 });
4341 }
4342 } else {
4343 mWinDismissingKeyguard = null;
4344 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004345 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004346 changes |= FINISH_LAYOUT_REDO_LAYOUT
4347 | FINISH_LAYOUT_REDO_CONFIG
4348 | FINISH_LAYOUT_REDO_WALLPAPER;
4349 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004350 }
4351 }
Joe Onorato664644d2011-01-23 17:53:23 -08004352
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004353 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004354 // If the navigation bar has been hidden or shown, we need to do another
4355 // layout pass to update that window.
4356 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4357 }
Joe Onorato664644d2011-01-23 17:53:23 -08004358
Mike Lockwood28569302010-01-28 11:54:40 -05004359 // update since mAllowLockscreenWhenOn might have changed
4360 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004361 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004362 }
4363
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004364 /**
Jim Millerab954542014-10-10 18:21:49 -07004365 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004366 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004367 * @return Whether the flags have changed and we have to redo the layout.
4368 */
Jim Millerab954542014-10-10 18:21:49 -07004369 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4370 boolean wasOccluded = mKeyguardOccluded;
4371 boolean showing = mKeyguardDelegate.isShowing();
4372 if (wasOccluded && !isOccluded && showing) {
4373 mKeyguardOccluded = false;
4374 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004375 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4376 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4377 return true;
Jim Millerab954542014-10-10 18:21:49 -07004378 } else if (!wasOccluded && isOccluded && showing) {
4379 mKeyguardOccluded = true;
4380 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004381 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4382 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4383 return true;
4384 } else {
4385 return false;
4386 }
4387 }
4388
4389 private boolean isStatusBarKeyguard() {
4390 return mStatusBar != null
4391 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4392 }
4393
Jose Lima9546b202014-07-02 17:21:51 -07004394 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004395 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004396 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004397 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004398 return false;
4399 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004400 return true;
4401 }
4402
Jose Lima9546b202014-07-02 17:21:51 -07004403 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004404 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004405 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004406 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004407 // If the navigation bar has been hidden or shown, we need to do another
4408 // layout pass to update that window.
4409 return FINISH_LAYOUT_REDO_LAYOUT;
4410 }
4411 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004412 }
4413
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004414 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004415 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004416 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4417 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004418 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4419 if (newLidState == mLidState) {
4420 return;
4421 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004422
Jeff Brownc458ce92012-04-30 14:58:40 -07004423 mLidState = newLidState;
4424 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004425 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004426
4427 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004428 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004429 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004430 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004431 }
4432 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004433
Michael Wright3818c922014-09-02 13:59:07 -07004434 @Override
4435 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4436 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4437 if (mCameraLensCoverState == lensCoverState) {
4438 return;
4439 }
4440 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4441 lensCoverState == CAMERA_LENS_UNCOVERED) {
4442 Intent intent;
4443 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4444 mKeyguardDelegate.isShowing();
4445 if (keyguardActive) {
4446 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4447 } else {
4448 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4449 }
Bryce Lee584a4452014-10-21 15:55:55 -07004450 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004451 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004452 }
4453 mCameraLensCoverState = lensCoverState;
4454 }
4455
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004456 void setHdmiPlugged(boolean plugged) {
4457 if (mHdmiPlugged != plugged) {
4458 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004459 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004460 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004461 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004462 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004463 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004464 }
4465 }
4466
Joe Onoratoea495d42011-04-06 11:41:11 -07004467 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004468 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004469 // watch for HDMI plug messages if the hdmi switch exists
4470 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4471 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4472
Joe Onoratoea495d42011-04-06 11:41:11 -07004473 final String filename = "/sys/class/switch/hdmi/state";
4474 FileReader reader = null;
4475 try {
4476 reader = new FileReader(filename);
4477 char[] buf = new char[15];
4478 int n = reader.read(buf);
4479 if (n > 1) {
4480 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4481 }
4482 } catch (IOException ex) {
4483 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4484 } catch (NumberFormatException ex) {
4485 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4486 } finally {
4487 if (reader != null) {
4488 try {
4489 reader.close();
4490 } catch (IOException ex) {
4491 }
Joe Onoratodc100302011-01-11 17:07:41 -08004492 }
4493 }
4494 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004495 // This dance forces the code in setHdmiPlugged to run.
4496 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4497 mHdmiPlugged = !plugged;
4498 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004499 }
4500
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004501 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004502 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004503
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004504 final Runnable mScreenshotTimeout = new Runnable() {
4505 @Override public void run() {
4506 synchronized (mScreenshotLock) {
4507 if (mScreenshotConnection != null) {
4508 mContext.unbindService(mScreenshotConnection);
4509 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004510 }
Winson Chung9112ec32011-06-27 13:15:32 -07004511 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004512 }
4513 };
4514
4515 // Assume this is called from the Handler thread.
4516 private void takeScreenshot() {
4517 synchronized (mScreenshotLock) {
4518 if (mScreenshotConnection != null) {
4519 return;
4520 }
4521 ComponentName cn = new ComponentName("com.android.systemui",
4522 "com.android.systemui.screenshot.TakeScreenshotService");
4523 Intent intent = new Intent();
4524 intent.setComponent(cn);
4525 ServiceConnection conn = new ServiceConnection() {
4526 @Override
4527 public void onServiceConnected(ComponentName name, IBinder service) {
4528 synchronized (mScreenshotLock) {
4529 if (mScreenshotConnection != this) {
4530 return;
4531 }
4532 Messenger messenger = new Messenger(service);
4533 Message msg = Message.obtain(null, 1);
4534 final ServiceConnection myConn = this;
4535 Handler h = new Handler(mHandler.getLooper()) {
4536 @Override
4537 public void handleMessage(Message msg) {
4538 synchronized (mScreenshotLock) {
4539 if (mScreenshotConnection == myConn) {
4540 mContext.unbindService(mScreenshotConnection);
4541 mScreenshotConnection = null;
4542 mHandler.removeCallbacks(mScreenshotTimeout);
4543 }
4544 }
4545 }
4546 };
4547 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004548 msg.arg1 = msg.arg2 = 0;
4549 if (mStatusBar != null && mStatusBar.isVisibleLw())
4550 msg.arg1 = 1;
4551 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4552 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004553 try {
4554 messenger.send(msg);
4555 } catch (RemoteException e) {
4556 }
4557 }
4558 }
4559 @Override
4560 public void onServiceDisconnected(ComponentName name) {}
4561 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004562 if (mContext.bindServiceAsUser(
4563 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004564 mScreenshotConnection = conn;
4565 mHandler.postDelayed(mScreenshotTimeout, 10000);
4566 }
4567 }
Winson Chung9112ec32011-06-27 13:15:32 -07004568 }
4569
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004570 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004571 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004572 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004573 if (!mSystemBooted) {
4574 // If we have not yet booted, don't let key events do anything.
4575 return 0;
4576 }
4577
Jeff Brown037c33e2014-04-09 00:31:55 -07004578 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004579 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4580 final boolean canceled = event.isCanceled();
4581 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004582
Jeff Brown3122e442010-10-11 23:32:49 -07004583 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004584
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004585 // If screen is off then we treat the case where the keyguard is open but hidden
4586 // the same as if it were open and in front.
4587 // This will prevent any keys other than the power button from waking the screen
4588 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004589 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004590 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004591 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004592 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004593
Jeff Brown40013652012-05-16 21:22:36 -07004594 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004595 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004596 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004597 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004598 }
4599
Jeff Brown037c33e2014-04-09 00:31:55 -07004600 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004601 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004602 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4603 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004604 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004605 // When the device is interactive or the key is injected pass the
4606 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004607 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004608 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004609 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4610 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4611 // to the application but preserve its wake key status to make sure we still move
4612 // from dozing to fully interactive if we would normally go from off to fully
4613 // interactive.
4614 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004615 } else {
4616 // When the screen is off and the key is not injected, determine whether
4617 // to wake the device but don't pass the key to the application.
4618 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004619 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4620 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004621 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004622 }
4623
Justin Kohd378ad72013-04-01 12:18:26 -07004624 // If the key would be handled globally, just return the result, don't worry about special
4625 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004626 if (isValidGlobalKey(keyCode)
4627 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004628 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004629 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004630 }
Justin Kohd378ad72013-04-01 12:18:26 -07004631 return result;
4632 }
4633
Jeff Brownbae8e772014-06-12 19:59:45 -07004634 boolean useHapticFeedback = down
4635 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4636 && event.getRepeatCount() == 0;
4637
Jeff Brown4d396052010-10-29 21:50:21 -07004638 // Handle special keys.
4639 switch (keyCode) {
4640 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004641 case KeyEvent.KEYCODE_VOLUME_UP:
4642 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004643 if (mUseTvRouting) {
4644 // On TVs volume keys never go to the foreground app
4645 result &= ~ACTION_PASS_TO_USER;
4646 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004647 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4648 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004649 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004650 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004651 mScreenshotChordVolumeDownKeyTriggered = true;
4652 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4653 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004654 cancelPendingPowerKeyAction();
4655 interceptScreenshotChord();
4656 }
4657 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004658 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004659 cancelPendingScreenshotChordAction();
4660 }
4661 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4662 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004663 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004664 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004665 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004666 cancelPendingPowerKeyAction();
4667 cancelPendingScreenshotChordAction();
4668 }
4669 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004670 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004671 cancelPendingScreenshotChordAction();
4672 }
4673 }
Jeff Brown4d396052010-10-29 21:50:21 -07004674 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004675 TelecomManager telecomManager = getTelecommService();
4676 if (telecomManager != null) {
4677 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004678 // If an incoming call is ringing, either VOLUME key means
4679 // "silence ringer". We handle these keys here, rather than
4680 // in the InCallScreen, to make sure we'll respond to them
4681 // even if the InCallScreen hasn't come to the foreground yet.
4682 // Look for the DOWN event here, to agree with the "fallback"
4683 // behavior in the InCallScreen.
4684 Log.i(TAG, "interceptKeyBeforeQueueing:"
4685 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004686
Santos Cordon6848f722014-05-21 15:22:12 -07004687 // Silence the ringer. (It's safe to call this
4688 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004689 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004690
Santos Cordon6848f722014-05-21 15:22:12 -07004691 // And *don't* pass this key thru to the current activity
4692 // (which is probably the InCallScreen.)
4693 result &= ~ACTION_PASS_TO_USER;
4694 break;
4695 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004696 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004697 && (result & ACTION_PASS_TO_USER) == 0) {
4698 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004699 // the application, just pass it to the session service.
4700
4701 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004702 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004703 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004704 }
4705 }
4706
RoboErik430fc482014-06-12 15:49:20 -07004707 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004708 if (mUseTvRouting) {
4709 dispatchDirectAudioEvent(event);
4710 } else {
4711 // If we aren't passing to the user and no one else
4712 // handled it send it to the session manager to
4713 // figure out.
4714 MediaSessionLegacyHelper.getHelper(mContext)
4715 .sendVolumeKeyEvent(event, true);
4716 }
Jeff Brown4d396052010-10-29 21:50:21 -07004717 break;
4718 }
4719 }
4720 break;
4721 }
4722
4723 case KeyEvent.KEYCODE_ENDCALL: {
4724 result &= ~ACTION_PASS_TO_USER;
4725 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004726 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004727 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004728 if (telecomManager != null) {
4729 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004730 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004731 if (interactive && !hungUp) {
4732 mEndCallKeyHandled = false;
4733 mHandler.postDelayed(mEndCallLongPress,
4734 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4735 } else {
4736 mEndCallKeyHandled = true;
4737 }
Jeff Brown4d396052010-10-29 21:50:21 -07004738 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004739 if (!mEndCallKeyHandled) {
4740 mHandler.removeCallbacks(mEndCallLongPress);
4741 if (!canceled) {
4742 if ((mEndcallBehavior
4743 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4744 if (goHome()) {
4745 break;
4746 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004747 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004748 if ((mEndcallBehavior
4749 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4750 mPowerManager.goToSleep(event.getEventTime(),
4751 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4752 isWakeKey = false;
4753 }
Jeff Brown4d396052010-10-29 21:50:21 -07004754 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004755 }
Jeff Brown4d396052010-10-29 21:50:21 -07004756 }
4757 break;
4758 }
4759
4760 case KeyEvent.KEYCODE_POWER: {
4761 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004762 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004763 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004764 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004765 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004766 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004767 }
4768 break;
4769 }
4770
Jeff Brown6212a492014-03-07 13:58:47 -08004771 case KeyEvent.KEYCODE_SLEEP: {
4772 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004773 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004774 if (!mPowerManager.isInteractive()) {
4775 useHapticFeedback = false; // suppress feedback if already non-interactive
4776 }
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004777 sleepPress(event);
Jeff Brown6212a492014-03-07 13:58:47 -08004778 break;
4779 }
4780
4781 case KeyEvent.KEYCODE_WAKEUP: {
4782 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004783 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004784 break;
4785 }
4786
Jeff Brown4d396052010-10-29 21:50:21 -07004787 case KeyEvent.KEYCODE_MEDIA_PLAY:
4788 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4789 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004790 case KeyEvent.KEYCODE_HEADSETHOOK:
4791 case KeyEvent.KEYCODE_MUTE:
4792 case KeyEvent.KEYCODE_MEDIA_STOP:
4793 case KeyEvent.KEYCODE_MEDIA_NEXT:
4794 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4795 case KeyEvent.KEYCODE_MEDIA_REWIND:
4796 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004797 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4798 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004799 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4800 // If the global session is active pass all media keys to it
4801 // instead of the active window.
4802 result &= ~ACTION_PASS_TO_USER;
4803 }
Jeff Brown4d396052010-10-29 21:50:21 -07004804 if ((result & ACTION_PASS_TO_USER) == 0) {
4805 // Only do this if we would otherwise not pass it to the user. In that
4806 // case, the PhoneWindow class will do the same thing, except it will
4807 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004808 // Note that we need to make a copy of the key event here because the
4809 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004810 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004811 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4812 new KeyEvent(event));
4813 msg.setAsynchronous(true);
4814 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004815 }
4816 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004817 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004818
Jeff Brown4d396052010-10-29 21:50:21 -07004819 case KeyEvent.KEYCODE_CALL: {
4820 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004821 TelecomManager telecomManager = getTelecommService();
4822 if (telecomManager != null) {
4823 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004824 Log.i(TAG, "interceptKeyBeforeQueueing:"
4825 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004826 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004827
Santos Cordon6848f722014-05-21 15:22:12 -07004828 // And *don't* pass this key thru to the current activity
4829 // (which is presumably the InCallScreen.)
4830 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004831 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004832 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004833 }
Jeff Brown4d396052010-10-29 21:50:21 -07004834 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004835 }
Michael Wright869a67c2014-08-26 19:33:06 -07004836 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4837 // Only do this if we would otherwise not pass it to the user. In that case,
4838 // interceptKeyBeforeDispatching would apply a similar but different policy in
4839 // order to invoke voice assist actions. Note that we need to make a copy of the
4840 // key event here because the original key event will be recycled when we return.
4841 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4842 mBroadcastWakeLock.acquire();
4843 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4844 keyguardActive ? 1 : 0, 0);
4845 msg.setAsynchronous(true);
4846 msg.sendToTarget();
4847 }
4848 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004849 }
Jeff Brown26875502014-01-30 21:47:47 -08004850
Jeff Brownbae8e772014-06-12 19:59:45 -07004851 if (useHapticFeedback) {
4852 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4853 }
4854
Jeff Brown26875502014-01-30 21:47:47 -08004855 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004856 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004857 }
Bryce Lee584a4452014-10-21 15:55:55 -07004858
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004859 return result;
4860 }
4861
Jeff Brown1c2e4942012-11-06 16:32:01 -08004862 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004863 * Returns true if the key can have global actions attached to it.
4864 * We reserve all power management keys for the system since they require
4865 * very careful handling.
4866 */
4867 private static boolean isValidGlobalKey(int keyCode) {
4868 switch (keyCode) {
4869 case KeyEvent.KEYCODE_POWER:
4870 case KeyEvent.KEYCODE_WAKEUP:
4871 case KeyEvent.KEYCODE_SLEEP:
4872 return false;
4873 default:
4874 return true;
4875 }
4876 }
4877
4878 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08004879 * When the screen is off we ignore some keys that might otherwise typically
4880 * be considered wake keys. We filter them out here.
4881 *
4882 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4883 * is always considered a wake key.
4884 */
4885 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4886 switch (keyCode) {
4887 // ignore volume keys unless docked
4888 case KeyEvent.KEYCODE_VOLUME_UP:
4889 case KeyEvent.KEYCODE_VOLUME_DOWN:
4890 case KeyEvent.KEYCODE_VOLUME_MUTE:
4891 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4892
4893 // ignore media and camera keys
4894 case KeyEvent.KEYCODE_MUTE:
4895 case KeyEvent.KEYCODE_HEADSETHOOK:
4896 case KeyEvent.KEYCODE_MEDIA_PLAY:
4897 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4898 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4899 case KeyEvent.KEYCODE_MEDIA_STOP:
4900 case KeyEvent.KEYCODE_MEDIA_NEXT:
4901 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4902 case KeyEvent.KEYCODE_MEDIA_REWIND:
4903 case KeyEvent.KEYCODE_MEDIA_RECORD:
4904 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004905 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004906 case KeyEvent.KEYCODE_CAMERA:
4907 return false;
4908 }
4909 return true;
4910 }
4911
4912
Jeff Brown56194eb2011-03-02 19:23:13 -08004913 /** {@inheritDoc} */
4914 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004915 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4916 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08004917 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
4918 return 0;
4919 }
Michael Wright70af00a2014-09-03 19:30:20 -07004920 }
Bryce Lee5c138322014-11-03 08:26:09 -08004921
Michael Wright70af00a2014-09-03 19:30:20 -07004922 if (shouldDispatchInputWhenNonInteractive()) {
4923 return ACTION_PASS_TO_USER;
4924 }
Bryce Lee5c138322014-11-03 08:26:09 -08004925
Bryce Lee812d7022014-11-10 13:33:28 -08004926 // If we have not passed the action up and we are in theater mode without dreaming,
4927 // there will be no dream to intercept the touch and wake into ambient. The device should
4928 // wake up in this case.
4929 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
4930 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
4931 }
4932
Jeff Brown037c33e2014-04-09 00:31:55 -07004933 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004934 }
4935
Michael Wright70af00a2014-09-03 19:30:20 -07004936 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08004937 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07004938 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
4939 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08004940 return true;
4941 }
4942
4943 // Send events to a dozing dream even if the screen is off since the dream
4944 // is in control of the state of the screen.
4945 IDreamManager dreamManager = getDreamManager();
4946
4947 try {
4948 if (dreamManager != null && dreamManager.isDreaming()) {
4949 return true;
4950 }
4951 } catch (RemoteException e) {
4952 Slog.e(TAG, "RemoteException when checking if dreaming", e);
4953 }
4954
4955 // Otherwise, consume events since the user can't see what is being
4956 // interacted with.
4957 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07004958 }
4959
RoboErik001c59c2015-01-26 15:53:51 -08004960 private void dispatchDirectAudioEvent(KeyEvent event) {
4961 if (event.getAction() != KeyEvent.ACTION_DOWN) {
4962 return;
4963 }
4964 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04004965 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
4966 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08004967 String pkgName = mContext.getOpPackageName();
4968 switch (keyCode) {
4969 case KeyEvent.KEYCODE_VOLUME_UP:
4970 try {
John Spurlockee5ad722015-03-03 16:17:21 -05004971 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04004972 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08004973 } catch (RemoteException e) {
4974 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
4975 }
4976 break;
4977 case KeyEvent.KEYCODE_VOLUME_DOWN:
4978 try {
John Spurlockee5ad722015-03-03 16:17:21 -05004979 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04004980 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08004981 } catch (RemoteException e) {
4982 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
4983 }
4984 break;
4985 case KeyEvent.KEYCODE_VOLUME_MUTE:
4986 try {
4987 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05004988 getAudioService().adjustSuggestedStreamVolume(
4989 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04004990 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08004991 }
4992 } catch (RemoteException e) {
4993 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
4994 }
4995 break;
4996 }
4997 }
4998
Jeff Brown40013652012-05-16 21:22:36 -07004999 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5000 if (DEBUG_INPUT) {
5001 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005002 }
5003
Jeff Brown40013652012-05-16 21:22:36 -07005004 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5005 if (DEBUG_INPUT) {
5006 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5007 }
5008
5009 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5010 mHavePendingMediaKeyRepeatWithWakeLock = false;
5011 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5012 }
5013
5014 dispatchMediaKeyWithWakeLockToAudioService(event);
5015
5016 if (event.getAction() == KeyEvent.ACTION_DOWN
5017 && event.getRepeatCount() == 0) {
5018 mHavePendingMediaKeyRepeatWithWakeLock = true;
5019
5020 Message msg = mHandler.obtainMessage(
5021 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5022 msg.setAsynchronous(true);
5023 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5024 } else {
5025 mBroadcastWakeLock.release();
5026 }
5027 }
5028
5029 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5030 mHavePendingMediaKeyRepeatWithWakeLock = false;
5031
5032 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5033 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5034 if (DEBUG_INPUT) {
5035 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5036 }
5037
5038 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5039 mBroadcastWakeLock.release();
5040 }
5041
5042 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5043 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005044 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005045 }
5046 }
5047
Michael Wright869a67c2014-08-26 19:33:06 -07005048 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
5049 Intent voiceIntent =
5050 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5051 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005052 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005053 mBroadcastWakeLock.release();
5054 }
5055
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005056 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005057 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005058 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005059 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5060 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5061 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005062 } else {
5063 try {
5064 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5065 ServiceManager.getService(Context.UI_MODE_SERVICE));
5066 mUiMode = uiModeService.getCurrentModeType();
5067 } catch (RemoteException e) {
5068 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005069 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005070 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005071 synchronized (mLock) {
5072 updateOrientationListenerLp();
5073 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005074 }
5075 };
5076
Jeff Brown6aaf2952012-10-05 16:01:08 -07005077 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5078 @Override
5079 public void onReceive(Context context, Intent intent) {
5080 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005081 if (mKeyguardDelegate != null) {
5082 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005083 }
5084 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005085 if (mKeyguardDelegate != null) {
5086 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005087 }
5088 }
5089 }
5090 };
5091
Christopher Tate5e08af02012-09-21 17:17:22 -07005092 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5093 @Override
5094 public void onReceive(Context context, Intent intent) {
5095 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5096 // tickle the settings observer: this first ensures that we're
5097 // observing the relevant settings for the newly-active user,
5098 // and then updates our own bookkeeping based on the now-
5099 // current user.
5100 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005101
5102 // force a re-application of focused window sysui visibility.
5103 // the window may never have been shown for this user
5104 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005105 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005106 mLastSystemUiFlags = 0;
5107 updateSystemUiVisibilityLw();
5108 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005109 }
5110 }
5111 };
5112
John Spurlockd9b70bd2014-02-06 17:02:44 -05005113 private final Runnable mRequestTransientNav = new Runnable() {
5114 @Override
5115 public void run() {
5116 requestTransientBars(mNavigationBar);
5117 }
5118 };
5119
John Spurlocke1f366f2013-08-05 12:22:40 -04005120 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005121 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005122 if (!isUserSetupComplete()) {
5123 // Swipe-up for navigation bar is disabled during setup
5124 return;
5125 }
John Spurlock27735a42013-08-14 17:57:38 -04005126 boolean sb = mStatusBarController.checkShowTransientBarLw();
5127 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005128 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005129 // Don't show status bar when swiping on already visible navigation bar
5130 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005131 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005132 return;
5133 }
John Spurlock27735a42013-08-14 17:57:38 -04005134 if (sb) mStatusBarController.showTransient();
5135 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005136 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005137 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005138 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005139 }
5140 }
5141
Jeff Brown3ee549c2014-09-22 20:14:39 -07005142 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005143 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07005144 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005145 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07005146 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005147
5148 // We must get this work done here because the power manager will drop
5149 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005150 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005151 mAwake = false;
5152 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005153 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005154 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005155 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005156 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005157
5158 if (mKeyguardDelegate != null) {
5159 mKeyguardDelegate.onScreenTurnedOff(why);
5160 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005161 }
5162
Jeff Brown13f00f02014-10-31 14:45:50 -07005163 private void wakeUpFromPowerKey(long eventTime) {
5164 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5165 }
5166
Bryce Lee5c138322014-11-03 08:26:09 -08005167 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Lee584a4452014-10-21 15:55:55 -07005168 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005169 return false;
Bryce Lee584a4452014-10-21 15:55:55 -07005170 }
5171
5172 mPowerManager.wakeUp(wakeTime);
Bryce Lee5c138322014-11-03 08:26:09 -08005173 return true;
Bryce Lee584a4452014-10-21 15:55:55 -07005174 }
5175
Jeff Brown3ee549c2014-09-22 20:14:39 -07005176 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005177 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07005178 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005179 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07005180 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005181
Jeff Brown3ee549c2014-09-22 20:14:39 -07005182 // Since goToSleep performs these functions synchronously, we must
5183 // do the same here. We cannot post this work to a handler because
5184 // that might cause it to become reordered with respect to what
5185 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005186 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005187 mAwake = true;
5188 mKeyguardDrawComplete = false;
5189 if (mKeyguardDelegate != null) {
5190 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5191 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5192 }
5193
Jeff Browna20dda42014-05-27 20:57:24 -07005194 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005195 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005196 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005197 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005198
Jim Miller5ecd8112013-01-09 18:50:26 -08005199 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07005200 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005201 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005202 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005203 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005204 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005205 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005206 }
5207
Jeff Brown36c4db82014-09-19 12:05:31 -07005208 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005209 synchronized (mLock) {
5210 if (!mAwake || mKeyguardDrawComplete) {
5211 return; // spurious
5212 }
5213
Jeff Brown36c4db82014-09-19 12:05:31 -07005214 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005215 if (mKeyguardDelegate != null) {
5216 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5217 }
5218 }
5219
5220 finishScreenTurningOn();
5221 }
5222
5223 // Called on the DisplayManager's DisplayPowerController thread.
5224 @Override
5225 public void screenTurnedOff() {
5226 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5227
5228 synchronized (mLock) {
5229 mScreenOnEarly = false;
5230 mScreenOnFully = false;
5231 mWindowManagerDrawComplete = false;
5232 mScreenOnListener = null;
5233 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005234 }
5235 }
5236
Jeff Brown3ee549c2014-09-22 20:14:39 -07005237 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005238 @Override
5239 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005240 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005241
Jeff Brown3ee549c2014-09-22 20:14:39 -07005242 synchronized (mLock) {
5243 mScreenOnEarly = true;
5244 mScreenOnFully = false;
5245 mWindowManagerDrawComplete = false;
5246 mScreenOnListener = screenOnListener;
5247 updateOrientationListenerLp();
5248 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005249
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005250 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5251 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005252 // ... eventually calls finishWindowsDrawn
5253 }
5254
Jeff Brown36c4db82014-09-19 12:05:31 -07005255 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005256 synchronized (mLock) {
5257 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5258 return; // spurious
5259 }
5260
Jeff Brown36c4db82014-09-19 12:05:31 -07005261 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005262 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005263
5264 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005265 }
5266
Craig Mautner8a0da012014-05-31 15:13:37 -07005267 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005268 final ScreenOnListener listener;
5269 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005270 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005271 if (DEBUG_WAKEUP) Slog.d(TAG,
5272 "finishScreenTurningOn: mAwake=" + mAwake
5273 + ", mScreenOnEarly=" + mScreenOnEarly
5274 + ", mScreenOnFully=" + mScreenOnFully
5275 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5276 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5277
5278 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5279 || (mAwake && !mKeyguardDrawComplete)) {
5280 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005281 }
5282
Jeff Brown3ee549c2014-09-22 20:14:39 -07005283 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5284 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005285 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005286 mScreenOnFully = true;
5287
5288 // Remember the first time we draw the keyguard so we know when we're done with
5289 // the main part of booting and can enable the screen and hide boot messages.
5290 if (!mKeyguardDrawnOnce && mAwake) {
5291 mKeyguardDrawnOnce = true;
5292 enableScreen = true;
5293 if (mBootMessageNeedsHiding) {
5294 mBootMessageNeedsHiding = false;
5295 hideBootMessages();
5296 }
5297 } else {
5298 enableScreen = false;
5299 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005300 }
5301
Jeff Brown3ee549c2014-09-22 20:14:39 -07005302 if (listener != null) {
5303 listener.onScreenOn();
5304 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005305
Jeff Brown3ee549c2014-09-22 20:14:39 -07005306 if (enableScreen) {
5307 try {
5308 mWindowManager.enableScreenIfNeeded();
5309 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005310 }
Craig Mautnera631d492014-08-05 15:16:01 -07005311 }
5312 }
5313
5314 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005315 synchronized (mLock) {
5316 if (!mKeyguardDrawnOnce) {
5317 mBootMessageNeedsHiding = true;
5318 return; // keyguard hasn't drawn the first time yet, not done booting
5319 }
Craig Mautnera631d492014-08-05 15:16:01 -07005320 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005321
5322 if (mBootMsgDialog != null) {
5323 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5324 mBootMsgDialog.dismiss();
5325 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005326 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005327 }
5328
5329 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005330 public boolean isScreenOn() {
5331 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005332 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005333
Dianne Hackborn08743722009-12-21 12:16:51 -08005334 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005335 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005336 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005337 if (mKeyguardDelegate != null) {
5338 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005339 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005340 }
5341
5342 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005343 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005344 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005345 if (mKeyguardDelegate != null) {
5346 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005347 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005348 }
5349
Jim Millerab954542014-10-10 18:21:49 -07005350 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005351 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005352 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005353 }
5354
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005355 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005356 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005357 public boolean isKeyguardLocked() {
5358 return keyguardOn();
5359 }
5360
5361 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005362 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005363 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005364 if (mKeyguardDelegate == null) return false;
5365 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005366 }
5367
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005368 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005369 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005370 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005371 if (mKeyguardDelegate == null) return false;
5372 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005373 }
5374
Jose Lima9546b202014-07-02 17:21:51 -07005375 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005376 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005377 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005378 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005379 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005380 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005381 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005382 // ask the keyguard to prompt the user to authenticate if necessary
5383 mKeyguardDelegate.dismiss();
5384 }
5385 });
5386 }
5387 }
5388
5389 public void notifyActivityDrawnForKeyguardLw() {
5390 if (mKeyguardDelegate != null) {
5391 mHandler.post(new Runnable() {
5392 @Override
5393 public void run() {
5394 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005395 }
5396 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005397 }
5398 }
5399
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005400 @Override
5401 public boolean isKeyguardDrawnLw() {
5402 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005403 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005404 }
5405 }
5406
Jorim Jaggi0d674622014-05-21 01:34:15 +02005407 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005408 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005409 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005410 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005411 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005412 }
5413 }
5414
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005415 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005416 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005417 }
5418
5419 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005420 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005421 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005422
Jeff Brown01a98dd2011-09-20 15:08:29 -07005423 @Override
5424 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005425 if (false) {
5426 Slog.v(TAG, "rotationForOrientationLw(orient="
5427 + orientation + ", last=" + lastRotation
5428 + "); user=" + mUserRotation + " "
5429 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5430 ? "USER_ROTATION_LOCKED" : "")
5431 );
5432 }
5433
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005434 if (mForceDefaultOrientation) {
5435 return Surface.ROTATION_0;
5436 }
5437
The Android Open Source Project0727d222009-03-11 12:11:58 -07005438 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005439 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5440 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005441 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005442 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005443
Jeff Browndec6cf42011-11-15 14:08:20 -08005444 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005445 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005446 // Ignore sensor when lid switch is open and rotation is forced.
5447 preferredRotation = mLidOpenRotation;
5448 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005449 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005450 // Ignore sensor when in car dock unless explicitly enabled.
5451 // This case can override the behavior of NOSENSOR, and can also
5452 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005453 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005454 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005455 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5456 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5457 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005458 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005459 // Ignore sensor when in desk dock unless explicitly enabled.
5460 // This case can override the behavior of NOSENSOR, and can also
5461 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005462 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005463 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005464 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5465 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005466 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005467 preferredRotation = mDemoHdmiRotation;
5468 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5469 && mUndockedHdmiRotation >= 0) {
5470 // Ignore sensor when plugged into HDMI and an undocked orientation has
5471 // been specified in the configuration (only for legacy devices without
5472 // full multi-display support).
5473 // Note that the dock orientation overrides the HDMI orientation.
5474 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005475 } else if (mDemoRotationLock) {
5476 // Ignore sensor when demo rotation lock is enabled.
5477 // Note that the dock orientation and HDMI rotation lock override this.
5478 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005479 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5480 // Application just wants to remain locked in the last rotation.
5481 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005482 } else if (!mSupportAutoRotation) {
5483 // If we don't support auto-rotation then bail out here and ignore
5484 // the sensor and any rotation lock settings.
5485 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005486 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005487 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005488 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5489 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5490 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5491 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005492 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5493 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5494 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5495 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5496 // Otherwise, use sensor only if requested by the application or enabled
5497 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005498 if (mAllowAllRotations < 0) {
5499 // Can't read this during init() because the context doesn't
5500 // have display metrics at that time so we cannot determine
5501 // tablet vs. phone then.
5502 mAllowAllRotations = mContext.getResources().getBoolean(
5503 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5504 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005505 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005506 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005507 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5508 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005509 preferredRotation = sensorRotation;
5510 } else {
5511 preferredRotation = lastRotation;
5512 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005513 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5514 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5515 // Apply rotation lock. Does not apply to NOSENSOR.
5516 // The idea is that the user rotation expresses a weak preference for the direction
5517 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5518 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005519 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005520 } else {
5521 // No overriding preference.
5522 // We will do exactly what the application asked us to do.
5523 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005524 }
5525
Dianne Hackborne5439f22010-10-02 16:53:50 -07005526 switch (orientation) {
5527 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005528 // Return portrait unless overridden.
5529 if (isAnyPortrait(preferredRotation)) {
5530 return preferredRotation;
5531 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005532 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005533
Jeff Brown01a98dd2011-09-20 15:08:29 -07005534 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005535 // Return landscape unless overridden.
5536 if (isLandscapeOrSeascape(preferredRotation)) {
5537 return preferredRotation;
5538 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005539 return mLandscapeRotation;
5540
5541 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005542 // Return reverse portrait unless overridden.
5543 if (isAnyPortrait(preferredRotation)) {
5544 return preferredRotation;
5545 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005546 return mUpsideDownRotation;
5547
5548 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005549 // Return seascape unless overridden.
5550 if (isLandscapeOrSeascape(preferredRotation)) {
5551 return preferredRotation;
5552 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005553 return mSeascapeRotation;
5554
5555 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005556 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005557 // Return either landscape rotation.
5558 if (isLandscapeOrSeascape(preferredRotation)) {
5559 return preferredRotation;
5560 }
5561 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005562 return lastRotation;
5563 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005564 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005565
Jeff Brown01a98dd2011-09-20 15:08:29 -07005566 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005567 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005568 // Return either portrait rotation.
5569 if (isAnyPortrait(preferredRotation)) {
5570 return preferredRotation;
5571 }
5572 if (isAnyPortrait(lastRotation)) {
5573 return lastRotation;
5574 }
5575 return mPortraitRotation;
5576
5577 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005578 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5579 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005580 if (preferredRotation >= 0) {
5581 return preferredRotation;
5582 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005583 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005584 }
5585 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005586 }
5587
Jeff Brown01a98dd2011-09-20 15:08:29 -07005588 @Override
5589 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5590 switch (orientation) {
5591 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5592 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5593 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5594 return isAnyPortrait(rotation);
5595
5596 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5597 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5598 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5599 return isLandscapeOrSeascape(rotation);
5600
5601 default:
5602 return true;
5603 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005604 }
5605
Jeff Brownc0347aa2011-09-23 17:26:09 -07005606 @Override
5607 public void setRotationLw(int rotation) {
5608 mOrientationListener.setCurrentRotation(rotation);
5609 }
5610
Jeff Brown01a98dd2011-09-20 15:08:29 -07005611 private boolean isLandscapeOrSeascape(int rotation) {
5612 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005613 }
5614
Jeff Brown01a98dd2011-09-20 15:08:29 -07005615 private boolean isAnyPortrait(int rotation) {
5616 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005617 }
5618
Jose Lima9546b202014-07-02 17:21:51 -07005619 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005620 public int getUserRotationMode() {
5621 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005622 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5623 WindowManagerPolicy.USER_ROTATION_FREE :
5624 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005625 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005626
5627 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005628 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005629 public void setUserRotationMode(int mode, int rot) {
5630 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005631
5632 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005633 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005634 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005635 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005636 rot,
5637 UserHandle.USER_CURRENT);
5638 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005639 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005640 0,
5641 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005642 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005643 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005644 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005645 1,
5646 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005647 }
5648 }
5649
Jose Lima9546b202014-07-02 17:21:51 -07005650 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005651 public void setSafeMode(boolean safeMode) {
5652 mSafeMode = safeMode;
5653 performHapticFeedbackLw(null, safeMode
5654 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5655 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005656 }
Craig Mautnereda67292013-04-28 13:50:14 -07005657
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005658 static long[] getLongIntArray(Resources r, int resid) {
5659 int[] ar = r.getIntArray(resid);
5660 if (ar == null) {
5661 return null;
5662 }
5663 long[] out = new long[ar.length];
5664 for (int i=0; i<ar.length; i++) {
5665 out[i] = ar[i];
5666 }
5667 return out;
5668 }
Craig Mautnereda67292013-04-28 13:50:14 -07005669
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005670 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005671 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005672 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005673 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005674 mKeyguardDelegate.onSystemReady();
5675
Michael Wright3818c922014-09-02 13:59:07 -07005676 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005677 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005678 synchronized (mLock) {
5679 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005680 mSystemReady = true;
5681 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005682 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005683 public void run() {
5684 updateSettings();
5685 }
5686 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005687 }
5688 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005689
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005690 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005691 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005692 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005693 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005694 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005695 mKeyguardDelegate.onBootCompleted();
5696 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005697 synchronized (mLock) {
5698 mSystemBooted = true;
5699 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005700 wakingUp();
5701 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005702 }
5703
Dianne Hackborn661cd522011-08-22 00:26:20 -07005704 ProgressDialog mBootMsgDialog = null;
5705
5706 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005707 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005708 public void showBootMessage(final CharSequence msg, final boolean always) {
5709 mHandler.post(new Runnable() {
5710 @Override public void run() {
5711 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005712 int theme;
5713 if (mContext.getPackageManager().hasSystemFeature(
5714 PackageManager.FEATURE_WATCH)) {
5715 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5716 } else if (mContext.getPackageManager().hasSystemFeature(
5717 PackageManager.FEATURE_TELEVISION)) {
5718 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5719 } else {
5720 theme = 0;
5721 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005722
5723 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005724 // This dialog will consume all events coming in to
5725 // it, to avoid it trying to do things too early in boot.
5726 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5727 return true;
5728 }
5729 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5730 return true;
5731 }
5732 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5733 return true;
5734 }
5735 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5736 return true;
5737 }
5738 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5739 return true;
5740 }
5741 @Override public boolean dispatchPopulateAccessibilityEvent(
5742 AccessibilityEvent event) {
5743 return true;
5744 }
5745 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005746 if (mContext.getPackageManager().isUpgrade()) {
5747 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5748 } else {
5749 mBootMsgDialog.setTitle(R.string.android_start_title);
5750 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005751 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5752 mBootMsgDialog.setIndeterminate(true);
5753 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005754 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005755 mBootMsgDialog.getWindow().addFlags(
5756 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5757 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5758 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005759 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5760 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5761 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005762 mBootMsgDialog.setCancelable(false);
5763 mBootMsgDialog.show();
5764 }
5765 mBootMsgDialog.setMessage(msg);
5766 }
5767 });
5768 }
5769
5770 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005771 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005772 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005773 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005774 }
5775
Mike Lockwood28569302010-01-28 11:54:40 -05005776 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005777 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005778 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005779 // ***************************************
5780 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5781 // ***************************************
5782 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5783 // WITH ITS LOCKS HELD.
5784 //
5785 // This code must be VERY careful about the locks
5786 // it acquires.
5787 // In fact, the current code acquires way too many,
5788 // and probably has lurking deadlocks.
5789
Mike Lockwood28569302010-01-28 11:54:40 -05005790 synchronized (mScreenLockTimeout) {
5791 if (mLockScreenTimerActive) {
5792 // reset the timer
5793 mHandler.removeCallbacks(mScreenLockTimeout);
5794 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5795 }
5796 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005797 }
5798
Adam Cohenf7522022012-10-03 20:03:18 -07005799 class ScreenLockTimeout implements Runnable {
5800 Bundle options;
5801
5802 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005803 public void run() {
5804 synchronized (this) {
5805 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005806 if (mKeyguardDelegate != null) {
5807 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005808 }
Mike Lockwood28569302010-01-28 11:54:40 -05005809 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005810 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005811 }
5812 }
Mike Lockwood28569302010-01-28 11:54:40 -05005813
Adam Cohenf7522022012-10-03 20:03:18 -07005814 public void setLockOptions(Bundle options) {
5815 this.options = options;
5816 }
5817 }
5818
5819 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5820
Jose Lima9546b202014-07-02 17:21:51 -07005821 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005822 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005823 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5824 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005825 if (options != null) {
5826 // In case multiple calls are made to lockNow, we don't wipe out the options
5827 // until the runnable actually executes.
5828 mScreenLockTimeout.setLockOptions(options);
5829 }
Jim Miller93c518e2012-01-17 15:55:31 -08005830 mHandler.post(mScreenLockTimeout);
5831 }
5832
Mike Lockwood28569302010-01-28 11:54:40 -05005833 private void updateLockScreenTimeout() {
5834 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005835 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005836 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005837 if (mLockScreenTimerActive != enable) {
5838 if (enable) {
5839 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5840 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5841 } else {
5842 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5843 mHandler.removeCallbacks(mScreenLockTimeout);
5844 }
5845 mLockScreenTimerActive = enable;
5846 }
5847 }
5848 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005849
5850 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005851 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005852 public void enableScreenAfterBoot() {
5853 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005854 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005855 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005856 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005857
Jeff Brownc458ce92012-04-30 14:58:40 -07005858 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005859 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005860 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005861 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005862 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005863 }
Jeff Browna20dda42014-05-27 20:57:24 -07005864
5865 synchronized (mLock) {
5866 updateWakeGestureListenerLp();
5867 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005868 }
5869
Jeff Brown4f5fa282014-06-12 19:19:15 -07005870 void updateUiMode() {
5871 if (mUiModeManager == null) {
5872 mUiModeManager = IUiModeManager.Stub.asInterface(
5873 ServiceManager.getService(Context.UI_MODE_SERVICE));
5874 }
5875 try {
5876 mUiMode = mUiModeManager.getCurrentModeType();
5877 } catch (RemoteException e) {
5878 }
5879 }
5880
Jeff Brown01a98dd2011-09-20 15:08:29 -07005881 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005882 try {
5883 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005884 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5885 } catch (RemoteException e) {
5886 // Ignore
5887 }
5888 }
5889
5890 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5891 try {
5892 //set orientation on WindowManager
5893 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005894 } catch (RemoteException e) {
5895 // Ignore
5896 }
5897 }
5898
Daniel Sandler6396c722013-04-16 20:19:09 -04005899 /**
5900 * Return an Intent to launch the currently active dock app as home. Returns
5901 * null if the standard home should be launched, which is the case if any of the following is
5902 * true:
5903 * <ul>
5904 * <li>The device is not in either car mode or desk mode
5905 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5906 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5907 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5908 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5909 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005910 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005911 */
5912 Intent createHomeDockIntent() {
5913 Intent intent = null;
5914
5915 // What home does is based on the mode, not the dock state. That
5916 // is, when in car mode you should be taken to car home regardless
5917 // of whether we are actually in a car dock.
5918 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5919 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5920 intent = mCarDockIntent;
5921 }
5922 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5923 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5924 intent = mDeskDockIntent;
5925 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005926 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5927 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5928 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5929 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5930 // Always launch dock home from home when watch is docked, if it exists.
5931 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005932 }
5933
5934 if (intent == null) {
5935 return null;
5936 }
5937
5938 ActivityInfo ai = null;
5939 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5940 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005941 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005942 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005943 if (info != null) {
5944 ai = info.activityInfo;
5945 }
5946 if (ai != null
5947 && ai.metaData != null
5948 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5949 intent = new Intent(intent);
5950 intent.setClassName(ai.packageName, ai.name);
5951 return intent;
5952 }
5953
5954 return null;
5955 }
5956
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005957 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
5958 if (awakenFromDreams) {
5959 awakenDreams();
5960 }
Daniel Sandler6396c722013-04-16 20:19:09 -04005961
5962 Intent dock = createHomeDockIntent();
5963 if (dock != null) {
5964 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005965 if (fromHomeKey) {
5966 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5967 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00005968 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04005969 return;
5970 } catch (ActivityNotFoundException e) {
5971 }
5972 }
5973
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005974 Intent intent;
5975
5976 if (fromHomeKey) {
5977 intent = new Intent(mHomeIntent);
5978 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5979 } else {
5980 intent = mHomeIntent;
5981 }
5982
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00005983 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005984 }
Craig Mautnereda67292013-04-28 13:50:14 -07005985
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005986 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005987 * goes to the home screen
5988 * @return whether it did anything
5989 */
5990 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00005991 if (!isUserSetupComplete()) {
5992 Slog.i(TAG, "Not going home because user setup is in progress.");
5993 return false;
5994 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005995 if (false) {
5996 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005997 try {
5998 ActivityManagerNative.getDefault().stopAppSwitches();
5999 } catch (RemoteException e) {
6000 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006001 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006002 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006003 } else {
6004 // This code brings home to the front or, if it is already
6005 // at the front, puts the device to sleep.
6006 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006007 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6008 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6009 Log.d(TAG, "UTS-TEST-MODE");
6010 } else {
6011 ActivityManagerNative.getDefault().stopAppSwitches();
6012 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006013 Intent dock = createHomeDockIntent();
6014 if (dock != null) {
6015 int result = ActivityManagerNative.getDefault()
6016 .startActivityAsUser(null, null, dock,
6017 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6018 null, null, 0,
6019 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006020 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006021 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6022 return false;
6023 }
6024 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006025 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006026 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006027 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006028 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006029 null, null, 0,
6030 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006031 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006032 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006033 return false;
6034 }
6035 } catch (RemoteException ex) {
6036 // bummer, the activity manager, which is in this process, is dead
6037 }
6038 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006039 return true;
6040 }
Craig Mautnereda67292013-04-28 13:50:14 -07006041
6042 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006043 public void setCurrentOrientationLw(int newOrientation) {
6044 synchronized (mLock) {
6045 if (newOrientation != mCurrentAppOrientation) {
6046 mCurrentAppOrientation = newOrientation;
6047 updateOrientationListenerLp();
6048 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006049 }
6050 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006051
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006052 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6053 if (!isGlobalAccessibilityGestureEnabled()) {
6054 return;
6055 }
6056 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6057 Context.AUDIO_SERVICE);
6058 if (audioManager.isSilentMode()) {
6059 return;
6060 }
6061 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6062 Settings.System.DEFAULT_NOTIFICATION_URI);
6063 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6064 ringTone.play();
6065 }
Craig Mautnereda67292013-04-28 13:50:14 -07006066
Bryce Lee584a4452014-10-21 15:55:55 -07006067 private boolean isTheaterModeEnabled() {
6068 return Settings.Global.getInt(mContext.getContentResolver(),
6069 Settings.Global.THEATER_MODE_ON, 0) == 1;
6070 }
6071
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006072 private boolean isGlobalAccessibilityGestureEnabled() {
6073 return Settings.Global.getInt(mContext.getContentResolver(),
6074 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6075 }
6076
Craig Mautnereda67292013-04-28 13:50:14 -07006077 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006078 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006079 if (!mVibrator.hasVibrator()) {
6080 return false;
6081 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006082 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6083 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006084 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006085 return false;
6086 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006087 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006088 switch (effectId) {
6089 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006090 pattern = mLongPressVibePattern;
6091 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006092 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006093 pattern = mVirtualKeyVibePattern;
6094 break;
6095 case HapticFeedbackConstants.KEYBOARD_TAP:
6096 pattern = mKeyboardTapVibePattern;
6097 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006098 case HapticFeedbackConstants.CLOCK_TICK:
6099 pattern = mClockTickVibePattern;
6100 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006101 case HapticFeedbackConstants.CALENDAR_DATE:
6102 pattern = mCalendarDateVibePattern;
6103 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006104 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006105 pattern = mSafeModeDisabledVibePattern;
6106 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006107 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006108 pattern = mSafeModeEnabledVibePattern;
6109 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006110 default:
6111 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006112 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006113 int owningUid;
6114 String owningPackage;
6115 if (win != null) {
6116 owningUid = win.getOwningUid();
6117 owningPackage = win.getOwningPackage();
6118 } else {
6119 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006120 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006121 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006122 if (pattern.length == 1) {
6123 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006124 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006125 } else {
6126 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006127 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006128 }
6129 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006130 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006131
6132 @Override
6133 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006134 }
6135
Jeff Brownc38c9be2012-10-04 13:16:19 -07006136 @Override
6137 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006138 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006139 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006140 }
6141 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006142
Dianne Hackborndf89e652011-10-06 22:35:11 -07006143 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006144 // If there is no window focused, there will be nobody to handle the events
6145 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006146 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6147 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006148 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006149 return 0;
6150 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006151 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006152 // We are updating at a point where the keyguard has gotten
6153 // focus, but we were last in a state where the top window is
6154 // hiding it. This is probably because the keyguard as been
6155 // shown while the top window was displayed, so we want to ignore
6156 // it here because this is just a very transient change and it
6157 // will quickly lose focus once it correctly gets hidden.
6158 return 0;
6159 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006160
John Spurlock1db8b682014-02-18 11:18:59 -05006161 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006162 & ~mResettingSystemUiFlags
6163 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006164 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006165 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006166 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006167 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006168 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006169 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006170 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006171 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006172 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006173 return 0;
6174 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006175 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006176 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006177 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006178 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006179 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006180 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006181 try {
6182 IStatusBarService statusbar = getStatusBarService();
6183 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006184 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006185 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006186 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006187 } catch (RemoteException e) {
6188 // re-acquire status bar service next time it is needed.
6189 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006190 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006191 }
6192 });
6193 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006194 }
6195
Adrian Rooscd3884d2015-02-18 17:25:23 +01006196 private int updateLightStatusBarLw(int vis) {
6197 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6198 ? mStatusBar
6199 : mTopFullscreenOpaqueOrDimmingWindowState;
6200
6201 if (statusColorWin != null) {
6202 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6203 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6204 // its light flag.
6205 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6206 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6207 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6208 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6209 // Otherwise if it's dimming, clear the light flag.
6210 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6211 }
6212 }
6213 return vis;
6214 }
6215
John Spurlock79da8332013-09-20 12:04:47 -04006216 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006217 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006218 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6219 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006220 : mTopFullscreenOpaqueWindowState;
6221 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6222 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6223
John Spurlock27735a42013-08-14 17:57:38 -04006224 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04006225 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006226 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006227 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6228 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006229 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006230 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6231 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006232 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006233 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6234 }
John Spurlockbd957402013-10-03 11:38:39 -04006235 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006236 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006237
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006238 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006239 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6240 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006241 }
6242
John Spurlock27735a42013-08-14 17:57:38 -04006243 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006244 boolean immersiveSticky =
6245 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006246 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006247 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006248 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006249 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6250 boolean hideStatusBarSysui =
6251 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006252 boolean hideNavBarSysui =
6253 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006254
John Spurlock27735a42013-08-14 17:57:38 -04006255 boolean transientStatusBarAllowed =
6256 mStatusBar != null && (
6257 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006258 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006259 || statusBarHasFocus);
6260
John Spurlockf1a36642013-10-12 17:50:42 -04006261 boolean transientNavBarAllowed =
6262 mNavigationBar != null &&
6263 hideNavBarSysui && immersiveSticky;
6264
John Spurlockf25706f2013-11-07 18:02:43 -05006265 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006266 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006267 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006268 && !transientNavBarAllowed;
6269 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006270 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006271 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006272 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006273 }
John Spurlock27735a42013-08-14 17:57:38 -04006274
6275 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6276
6277 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006278 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6279 boolean newImmersiveMode = isImmersiveMode(vis);
6280 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006281 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006282 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6283 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006284 }
John Spurlock27735a42013-08-14 17:57:38 -04006285
John Spurlockf1a36642013-10-12 17:50:42 -04006286 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6287
John Spurlocke1f366f2013-08-05 12:22:40 -04006288 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006289 }
6290
John Spurlockf1a36642013-10-12 17:50:42 -04006291 private void clearClearableFlagsLw() {
6292 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6293 if (newVal != mResettingSystemUiFlags) {
6294 mResettingSystemUiFlags = newVal;
6295 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6296 }
6297 }
6298
6299 private boolean isImmersiveMode(int vis) {
6300 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006301 return mNavigationBar != null
6302 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006303 && (vis & flags) != 0
6304 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006305 }
6306
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006307 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006308 * @return whether the navigation or status bar can be made translucent
6309 *
6310 * This should return true unless touch exploration is not enabled or
6311 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006312 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006313 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006314 return mTranslucentDecorEnabled
6315 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006316 }
6317
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006318 // Use this instead of checking config_showNavigationBar so that it can be consistently
6319 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006320 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006321 public boolean hasNavigationBar() {
6322 return mHasNavigationBar;
6323 }
6324
satok1bc0a492012-04-25 22:47:12 +09006325 @Override
6326 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6327 mLastInputMethodWindow = ime;
6328 mLastInputMethodTargetWindow = target;
6329 }
6330
Craig Mautnerf1b67412012-09-19 13:18:29 -07006331 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006332 public int getInputMethodWindowVisibleHeightLw() {
6333 return mDockBottom - mCurBottom;
6334 }
6335
6336 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006337 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006338 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006339 if (mKeyguardDelegate != null) {
6340 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006341 }
John Spurlock13451a22012-09-28 14:40:41 -04006342 if (mStatusBarService != null) {
6343 try {
6344 mStatusBarService.setCurrentUser(newUserId);
6345 } catch (RemoteException e) {
6346 // oh well
6347 }
6348 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006349 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006350 }
6351
6352 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006353 public boolean canMagnifyWindow(int windowType) {
6354 switch (windowType) {
6355 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6356 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6357 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6358 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6359 return false;
6360 }
6361 }
6362 return true;
6363 }
6364
6365 @Override
6366 public boolean isTopLevelWindow(int windowType) {
6367 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6368 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6369 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6370 }
6371 return true;
6372 }
6373
Jim Miller4eeb4f62012-11-08 00:04:29 -08006374 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006375 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006376 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006377 pw.print(" mSystemReady="); pw.print(mSystemReady);
6378 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006379 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006380 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006381 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006382 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006383 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6384 || mForceClearedSystemUiFlags != 0) {
6385 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6386 pw.print(Integer.toHexString(mLastSystemUiFlags));
6387 pw.print(" mResettingSystemUiFlags=0x");
6388 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6389 pw.print(" mForceClearedSystemUiFlags=0x");
6390 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006391 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006392 if (mLastFocusNeedsMenu) {
6393 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6394 pw.println(mLastFocusNeedsMenu);
6395 }
Jeff Browna20dda42014-05-27 20:57:24 -07006396 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6397 pw.println(mWakeGestureEnabledSetting);
6398
Jeff Brownbcdfc622014-03-06 19:13:04 -08006399 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006400 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6401 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006402 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6403 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6404 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6405 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006406 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006407 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006408 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6409 pw.print(mCarDockEnablesAccelerometer);
6410 pw.print(" mDeskDockEnablesAccelerometer=");
6411 pw.println(mDeskDockEnablesAccelerometer);
6412 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6413 pw.print(mLidKeyboardAccessibility);
6414 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006415 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006416 pw.print(prefix);
6417 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6418 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006419 pw.print(prefix);
6420 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6421 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006422 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006423 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6424 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6425 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6426 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6427 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6428 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6429 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006430 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6431 pw.print(","); pw.print(mOverscanScreenTop);
6432 pw.print(") "); pw.print(mOverscanScreenWidth);
6433 pw.print("x"); pw.println(mOverscanScreenHeight);
6434 if (mOverscanLeft != 0 || mOverscanTop != 0
6435 || mOverscanRight != 0 || mOverscanBottom != 0) {
6436 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6437 pw.print(" top="); pw.print(mOverscanTop);
6438 pw.print(" right="); pw.print(mOverscanRight);
6439 pw.print(" bottom="); pw.println(mOverscanBottom);
6440 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006441 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6442 pw.print(mRestrictedOverscanScreenLeft);
6443 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6444 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6445 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006446 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6447 pw.print(","); pw.print(mUnrestrictedScreenTop);
6448 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6449 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6450 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6451 pw.print(","); pw.print(mRestrictedScreenTop);
6452 pw.print(") "); pw.print(mRestrictedScreenWidth);
6453 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006454 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6455 pw.print(","); pw.print(mStableFullscreenTop);
6456 pw.print(")-("); pw.print(mStableFullscreenRight);
6457 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006458 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6459 pw.print(","); pw.print(mStableTop);
6460 pw.print(")-("); pw.print(mStableRight);
6461 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006462 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6463 pw.print(","); pw.print(mSystemTop);
6464 pw.print(")-("); pw.print(mSystemRight);
6465 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006466 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6467 pw.print(","); pw.print(mCurTop);
6468 pw.print(")-("); pw.print(mCurRight);
6469 pw.print(","); pw.print(mCurBottom); pw.println(")");
6470 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6471 pw.print(","); pw.print(mContentTop);
6472 pw.print(")-("); pw.print(mContentRight);
6473 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006474 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6475 pw.print(","); pw.print(mVoiceContentTop);
6476 pw.print(")-("); pw.print(mVoiceContentRight);
6477 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006478 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6479 pw.print(","); pw.print(mDockTop);
6480 pw.print(")-("); pw.print(mDockRight);
6481 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006482 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6483 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006484 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6485 pw.print(" mShowingDream="); pw.print(mShowingDream);
6486 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006487 if (mLastInputMethodWindow != null) {
6488 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6489 pw.println(mLastInputMethodWindow);
6490 }
6491 if (mLastInputMethodTargetWindow != null) {
6492 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6493 pw.println(mLastInputMethodTargetWindow);
6494 }
6495 if (mStatusBar != null) {
6496 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006497 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6498 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006499 }
6500 if (mNavigationBar != null) {
6501 pw.print(prefix); pw.print("mNavigationBar=");
6502 pw.println(mNavigationBar);
6503 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006504 if (mFocusedWindow != null) {
6505 pw.print(prefix); pw.print("mFocusedWindow=");
6506 pw.println(mFocusedWindow);
6507 }
6508 if (mFocusedApp != null) {
6509 pw.print(prefix); pw.print("mFocusedApp=");
6510 pw.println(mFocusedApp);
6511 }
6512 if (mWinDismissingKeyguard != null) {
6513 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6514 pw.println(mWinDismissingKeyguard);
6515 }
6516 if (mTopFullscreenOpaqueWindowState != null) {
6517 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6518 pw.println(mTopFullscreenOpaqueWindowState);
6519 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006520 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6521 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6522 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6523 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006524 if (mForcingShowNavBar) {
6525 pw.print(prefix); pw.print("mForcingShowNavBar=");
6526 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6527 pw.println(mForcingShowNavBarLayer);
6528 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006529 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006530 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006531 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6532 pw.print(" mForceStatusBarFromKeyguard=");
6533 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006534 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006535 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006536 pw.print(" mHomePressed="); pw.println(mHomePressed);
6537 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6538 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6539 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6540 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6541 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6542 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6543 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6544 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6545 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6546 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006547 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6548 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6549 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006550
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006551 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006552 mStatusBarController.dump(pw, prefix);
6553 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006554 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006555
Jeff Browna20dda42014-05-27 20:57:24 -07006556 if (mWakeGestureListener != null) {
6557 mWakeGestureListener.dump(pw, prefix);
6558 }
Jeff Brown600f0032014-05-22 17:06:00 -07006559 if (mOrientationListener != null) {
6560 mOrientationListener.dump(pw, prefix);
6561 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006562 if (mBurnInProtectionHelper != null) {
6563 mBurnInProtectionHelper.dump(prefix, pw);
6564 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006565 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006566}